diff --git a/Cargo.lock b/Cargo.lock index 2450c1906..00d51c9d3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -973,9 +973,9 @@ checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb" [[package]] name = "bitcoin" -version = "0.32.0" +version = "0.32.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7170e7750a20974246f17ece04311b4205a6155f1db564c5b224af817663c3ea" +checksum = "4bf33434c870e98ecc8608588ccc990c5daba9ba9ad39733dc85fba22c211504" dependencies = [ "base58ck", "bech32", diff --git a/substrate/client/src/networks/bitcoin.rs b/substrate/client/src/networks/bitcoin.rs index 9f5ff1ddc..502bfb440 100644 --- a/substrate/client/src/networks/bitcoin.rs +++ b/substrate/client/src/networks/bitcoin.rs @@ -83,12 +83,6 @@ impl TryFrom> for Address { } fn try_to_vec(addr: &Address) -> Result, ()> { - let witness_program = |addr: &Address| { - let program_push = addr.0.as_script().instructions().last().ok_or(())?.map_err(|_| ())?; - let program = program_push.push_bytes().ok_or(())?.as_bytes(); - Ok::<_, ()>(program.to_vec()) - }; - let parsed_addr = BAddress::::from_script(&addr.0, Network::Bitcoin).map_err(|_| ())?; Ok( @@ -100,21 +94,19 @@ fn try_to_vec(addr: &Address) -> Result, ()> { EncodedAddress::P2SH(*parsed_addr.script_hash().unwrap().as_raw_hash().as_byte_array()) } Some(AddressType::P2wpkh) => { - let program = witness_program(addr)?; - let mut buf = [0; 20]; - buf.copy_from_slice(program.as_ref()); - EncodedAddress::P2WPKH(buf) + let program = parsed_addr.witness_program().ok_or(())?; + let program = program.program().as_bytes(); + EncodedAddress::P2WPKH(program.try_into().map_err(|_| ())?) } Some(AddressType::P2wsh) => { - let program = witness_program(addr)?; - let mut buf = [0; 32]; - buf.copy_from_slice(program.as_ref()); - EncodedAddress::P2WSH(buf) + let program = parsed_addr.witness_program().ok_or(())?; + let program = program.program().as_bytes(); + EncodedAddress::P2WSH(program.try_into().map_err(|_| ())?) } Some(AddressType::P2tr) => { - let program = witness_program(addr)?; - let program_ref: &[u8] = program.as_ref(); - EncodedAddress::P2TR(program_ref.try_into().map_err(|_| ())?) + let program = parsed_addr.witness_program().ok_or(())?; + let program = program.program().as_bytes(); + EncodedAddress::P2TR(program.try_into().map_err(|_| ())?) } _ => Err(())?, })