fn build_tx_proof(block: &L2Block, tx_index: u32) -> Result<(L2Transaction, CKBMerkleProof)> {
    let mut target_tx = None;
    let leaves: Vec<H256> = block
        .transactions()
        .into_iter()
        .enumerate()
        .map(|(idx, tx)| {
            let hash: H256 = tx.witness_hash().into();
            if idx == tx_index as usize {
                target_tx = Some(tx);
            }
            ckb_merkle_leaf_hash(idx as u32, &hash)
        })
        .collect();
    let tx = target_tx.ok_or_else(|| anyhow!("tx not found in block"))?;
    let proof = build_merkle_proof(&leaves, &[tx_index])?;
    Ok((tx, proof))
}
// Build proof with ckb merkle tree.
Build proof with ckb merkle tree.
Build proof with ckb merkle tree .
fn build_tx_proof(block: &L2Block, tx_index: u32) -> Result<(L2Transaction, CKBMerkleProof)> {
    let mut target_tx = None;
    let leaves: Vec<H256> = block
        .transactions()
        .into_iter()
        .enumerate()
        .map(|(idx, tx)| {
            let hash: H256 = tx.witness_hash().into();
            if idx == tx_index as usize {
                target_tx = Some(tx);
            }
            ckb_merkle_leaf_hash(idx as u32, &hash)
        })
        .collect();
    let tx = target_tx.ok_or_else(|| anyhow!("tx not found in block"))?;
    let proof = build_merkle_proof(&leaves, &[tx_index])?;
    Ok((tx, proof))
}
fn build_tx_proof ( block : & L2Block , tx_index : u32 ) -> Result < ( L2Transaction , CKBMerkleProof ) > { let mut target_tx = None ; let leaves : Vec < H256 > = block . transactions ( ) . into_iter ( ) . enumerate ( ) . map ( | ( idx , tx ) | { let hash : H256 = tx . witness_hash ( ) . into ( ) ; if idx == tx_index as usize { target_tx = Some ( tx ) ; } ckb_merkle_leaf_hash ( idx as u32 , & hash ) } ) . collect ( ) ; let tx = target_tx . ok_or_else ( | | anyhow ! ( " " ) ) ? ; let proof = build_merkle_proof ( & leaves , & [ tx_index ] ) ? ; Ok ( ( tx , proof ) ) }
Build proof with ckb merkle tree.
Build proof with ckb merkle tree .
block
&L2Block
tx_index
u32
block
&L2Block
tx_index
u32