use std::error::Error;
pub struct BitcoinSPV {
pub tx_hash: [u8; 32],
pub block_header: BlockHeader,
pub merkle_path: Vec<[u8; 32]>,
pub tx_index: u32,
}
pub struct BlockHeader {
pub version: u32,
pub prev_block_hash: [u8; 32],
pub merkle_root: [u8; 32],
pub timestamp: u32,
pub bits: u32,
pub nonce: u32,
pub height: u32,
}
pub struct RskBitcoinVerifier {
pub node_url: String,
pub contract_address: String,
}
impl RskBitcoinVerifier {
pub fn new(node_url: &str, contract_address: &str) -> Self {
Self {
node_url: node_url.to_string(),
contract_address: contract_address.to_string(),
}
}
#[rsk_bind]
pub fn verify_bitcoin_payment(&self, proof: BitcoinSPV) -> Result<bool, Box<dyn Error>> {
verify_merkle_proof(proof.tx_hash, proof.block_header)
}
}
pub fn verify_merkle_proof(tx_hash: [u8; 32], block_header: BlockHeader) -> Result<bool, Box<dyn Error>> {
println!("Verifying tx hash {} in block at height {}",
hex::encode(&tx_hash),
block_header.height);
let claimed_root = block_header.merkle_root;
Ok(true)
}