pub fn validate_balance_proof(
    hash: &Digest,
    balance_proof: &TrieMerkleProof<Key, StoredValue>,
    expected_purse_key: Key,
    expected_motes: &U512,
) -> Result<(), ValidationError> {
    let expected_balance_key = expected_purse_key
        .into_uref()
        .map(|uref| Key::Balance(uref.addr()))
        .ok_or_else(|| ValidationError::KeyIsNotAURef(expected_purse_key.to_owned()))?;

    if balance_proof.key() != &expected_balance_key.normalize() {
        return Err(ValidationError::UnexpectedKey);
    }

    if hash != &balance_proof.compute_state_hash()? {
        return Err(ValidationError::InvalidProofHash);
    }

    let balance_proof_stored_value = balance_proof.value().to_owned();

    let balance_proof_clvalue: CLValue = balance_proof_stored_value
        .try_into()
        .map_err(|_| ValidationError::ValueToCLValueConversion)?;

    let balance_motes: U512 = balance_proof_clvalue.into_t()?;

    if expected_motes != &balance_motes {
        return Err(ValidationError::UnexpectedValue);
    }

    Ok(())
}
/// Validates a proof of a balance request.
Validates a proof of a balance request.
Validates a proof of a balance request .
pub fn validate_balance_proof(
    hash: &Digest,
    balance_proof: &TrieMerkleProof<Key, StoredValue>,
    expected_purse_key: Key,
    expected_motes: &U512,
) -> Result<(), ValidationError> {
    let expected_balance_key = expected_purse_key
        .into_uref()
        .map(|uref| Key::Balance(uref.addr()))
        .ok_or_else(|| ValidationError::KeyIsNotAURef(expected_purse_key.to_owned()))?;
    if balance_proof.key() != &expected_balance_key.normalize() {
        return Err(ValidationError::UnexpectedKey);
    }
    if hash != &balance_proof.compute_state_hash()? {
        return Err(ValidationError::InvalidProofHash);
    }
    let balance_proof_stored_value = balance_proof.value().to_owned();
    let balance_proof_clvalue: CLValue = balance_proof_stored_value
        .try_into()
        .map_err(|_| ValidationError::ValueToCLValueConversion)?;
    let balance_motes: U512 = balance_proof_clvalue.into_t()?;
    if expected_motes != &balance_motes {
        return Err(ValidationError::UnexpectedValue);
    }
    Ok(())
}
pub fn validate_balance_proof ( hash : & Digest , balance_proof : & TrieMerkleProof < Key , StoredValue > , expected_purse_key : Key , expected_motes : & U512 , ) -> Result < ( ) , ValidationError > { let expected_balance_key = expected_purse_key . into_uref ( ) . map ( | uref | Key :: Balance ( uref . addr ( ) ) ) . ok_or_else ( | | ValidationError :: KeyIsNotAURef ( expected_purse_key . to_owned ( ) ) ) ? ; if balance_proof . key ( ) != & expected_balance_key . normalize ( ) { return Err ( ValidationError :: UnexpectedKey ) ; } if hash != & balance_proof . compute_state_hash ( ) ? { return Err ( ValidationError :: InvalidProofHash ) ; } let balance_proof_stored_value = balance_proof . value ( ) . to_owned ( ) ; let balance_proof_clvalue : CLValue = balance_proof_stored_value . try_into ( ) . map_err ( | _ | ValidationError :: ValueToCLValueConversion ) ? ; let balance_motes : U512 = balance_proof_clvalue . into_t ( ) ? ; if expected_motes != & balance_motes { return Err ( ValidationError :: UnexpectedValue ) ; } Ok ( ( ) ) }
Validates a proof of a balance request.
Validates a proof of a balance request .
hash
&Digest
balance_proof
&TrieMerkleProof<Key, StoredValue>
expected_purse_key
Key
expected_motes
&U512
hash
&Digest
balance_proof
&TrieMerkleProof<Key, StoredValue>
expected_purse_key
Key
expected_motes
&U512