pub fn check_message_proof(proof: &MerkleProof, msg: &Message, block_id: &UInt256, tr_id: Option<UInt256>) -> Result<()> {

    let block_virt_root = proof.proof.clone().virtualize(1);

    let block: Block = Block::construct_from(&mut block_virt_root.into())
        .map_err(
            |err| BlockError::WrongMerkleProof(
                format!("Error extracting block from proof: {}", err)
            )
        )?;

    // check if block id in message is corresponds to block in proof
    check_block_info_proof(&block, &proof.hash, block_id)?;

    // read message from block and check it

    let block_extra = block.read_extra()
        .map_err(
            |err| BlockError::WrongMerkleProof(
                format!("Error extracting block extra from proof: {}", err)
            )
        )?;

    let msg_hash = msg.hash()?;
    // attempt to read in msg descr, if fail - read out one
    if let Ok(in_msg_descr) = block_extra.read_in_msg_descr() {
        if let Ok(Some(in_msg)) = in_msg_descr.get(&msg_hash) {
            check_transaction_id(tr_id, in_msg.transaction_cell())?;
            if let Ok(msg_cell) = in_msg.message_cell() {
                if msg_cell.repr_hash() != msg_hash {
                    fail!(
                        BlockError::WrongMerkleProof("Wrong message's hash in proof".to_string())
                    )
                } else {
                    return Ok(())
                }
            } else {
                fail!(
                    BlockError::WrongMerkleProof(
                        "Error extracting message from in message".to_string()
                    )
                )
            }
        }
    }

    let out_msg_descr = block_extra.read_out_msg_descr()
        .map_err(
            |err| BlockError::WrongMerkleProof(
                format!("Error extracting out msg descr from proof: {}", err)
            )
        )?;
    if let Ok(Some(out_msg)) = out_msg_descr.get(&msg_hash) {
        if let Ok(real_msg_hash) = out_msg.read_message_hash() {
            check_transaction_id(tr_id, out_msg.transaction_cell())?;
            if real_msg_hash != msg_hash {
                fail!(
                    BlockError::WrongMerkleProof("Wrong message's hash in proof".to_string())
                )
            } else {
                Ok(())
            }
        } else {
            fail!(BlockError::WrongMerkleProof(
                "Error extracting message from out message".to_string()
            ))
        }
    } else {
        fail!(BlockError::WrongMerkleProof("No message in proof".to_string()))
    }
}
/// checks if message with given id is exist in block.
/// Proof must contain message's root cell and block info
checks if message with given id is exist in block.
Proof must contain message's root cell and block info
checks if message with given id is exist in block . Proof must contain message ' s root cell and block info
pub fn check_message_proof(proof: &MerkleProof, msg: &Message, block_id: &UInt256, tr_id: Option<UInt256>) -> Result<()> {
    let block_virt_root = proof.proof.clone().virtualize(1);
    let block: Block = Block::construct_from(&mut block_virt_root.into())
        .map_err(
            |err| BlockError::WrongMerkleProof(
                format!("Error extracting block from proof: {}", err)
            )
        )?;
    // check if block id in message is corresponds to block in proof
    check_block_info_proof(&block, &proof.hash, block_id)?;
    // read message from block and check it
    let block_extra = block.read_extra()
        .map_err(
            |err| BlockError::WrongMerkleProof(
                format!("Error extracting block extra from proof: {}", err)
            )
        )?;
    let msg_hash = msg.hash()?;
    // attempt to read in msg descr, if fail - read out one
    if let Ok(in_msg_descr) = block_extra.read_in_msg_descr() {
        if let Ok(Some(in_msg)) = in_msg_descr.get(&msg_hash) {
            check_transaction_id(tr_id, in_msg.transaction_cell())?;
            if let Ok(msg_cell) = in_msg.message_cell() {
                if msg_cell.repr_hash() != msg_hash {
                    fail!(
                        BlockError::WrongMerkleProof("Wrong message's hash in proof".to_string())
                    )
                } else {
                    return Ok(())
                }
            } else {
                fail!(
                    BlockError::WrongMerkleProof(
                        "Error extracting message from in message".to_string()
                    )
                )
            }
        }
    }
    let out_msg_descr = block_extra.read_out_msg_descr()
        .map_err(
            |err| BlockError::WrongMerkleProof(
                format!("Error extracting out msg descr from proof: {}", err)
            )
        )?;
    if let Ok(Some(out_msg)) = out_msg_descr.get(&msg_hash) {
        if let Ok(real_msg_hash) = out_msg.read_message_hash() {
            check_transaction_id(tr_id, out_msg.transaction_cell())?;
            if real_msg_hash != msg_hash {
                fail!(
                    BlockError::WrongMerkleProof("Wrong message's hash in proof".to_string())
                )
            } else {
                Ok(())
            }
        } else {
            fail!(BlockError::WrongMerkleProof(
                "Error extracting message from out message".to_string()
            ))
        }
    } else {
        fail!(BlockError::WrongMerkleProof("No message in proof".to_string()))
    }
}
pub fn check_message_proof ( proof : & MerkleProof , msg : & Message , block_id : & UInt256 , tr_id : Option < UInt256 > ) -> Result < ( ) > { let block_virt_root = proof . proof . clone ( ) . virtualize ( 1 ) ; let block : Block = Block :: construct_from ( & mut block_virt_root . into ( ) ) . map_err ( | err | BlockError :: WrongMerkleProof ( format ! ( " " err ) ) ) ? ; // check if block id in message is corresponds to block in proof check_block_info_proof ( & block , & proof . hash , block_id ) ? ; // read message from block and check it let block_extra = block . read_extra ( ) . map_err ( | err | BlockError :: WrongMerkleProof ( format ! ( " " err ) ) ) ? ; let msg_hash = msg . hash ( ) ? ; // attempt to read in msg descr, if fail - read out one if let Ok ( in_msg_descr ) = block_extra . read_in_msg_descr ( ) { if let Ok ( Some ( in_msg ) ) = in_msg_descr . get ( & msg_hash ) { check_transaction_id ( tr_id , in_msg . transaction_cell ( ) ) ? ; if let Ok ( msg_cell ) = in_msg . message_cell ( ) { if msg_cell . repr_hash ( ) != msg_hash { fail ! ( BlockError WrongMerkleProof ( " " to_string ( ) ) ) } else { return Ok ( ( ) ) } } else { fail ! ( BlockError WrongMerkleProof ( " " to_string ( ) ) ) } } } let out_msg_descr = block_extra . read_out_msg_descr ( ) . map_err ( | err | BlockError :: WrongMerkleProof ( format ! ( " " err ) ) ) ? ; if let Ok ( Some ( out_msg ) ) = out_msg_descr . get ( & msg_hash ) { if let Ok ( real_msg_hash ) = out_msg . read_message_hash ( ) { check_transaction_id ( tr_id , out_msg . transaction_cell ( ) ) ? ; if real_msg_hash != msg_hash { fail ! ( BlockError WrongMerkleProof ( " " to_string ( ) ) ) } else { Ok ( ( ) ) } } else { fail ! ( BlockError WrongMerkleProof ( " " to_string ( ) ) ) } } else { fail ! ( BlockError WrongMerkleProof ( " " to_string ( ) ) ) } }
checks if message with given id is exist in block.
checks if message with given id is exist in block .
proof
&MerkleProof
msg
&Message
block_id
&UInt256
tr_id
Option<UInt256>
proof
&MerkleProof
msg
&Message
block_id
&UInt256
tr_id
Option<UInt256>