diff --git a/strict_encoding/src/bitcoin.rs b/strict_encoding/src/bitcoin.rs index 3991094c..6bb4b636 100644 --- a/strict_encoding/src/bitcoin.rs +++ b/strict_encoding/src/bitcoin.rs @@ -15,14 +15,14 @@ use std::io; use std::io::{Read, Write}; +use bitcoin::psbt::serialize::{Deserialize, Serialize}; use bitcoin::psbt::{self, PsbtSighashType, TapTree}; use bitcoin::secp256k1::{ecdsa, schnorr, Secp256k1}; use bitcoin::util::address::{self, Address, WitnessVersion}; use bitcoin::util::bip32; use bitcoin::util::taproot::{ ControlBlock, FutureLeafVersion, LeafVersion, ScriptLeaf, TapBranchHash, - TapLeafHash, TapSighashHash, TapTweakHash, TaprootBuilder, - TaprootMerkleBranch, + TapLeafHash, TapSighashHash, TapTweakHash, TaprootMerkleBranch, }; use bitcoin::{ schnorr as bip340, secp256k1, Amount, BlockHash, EcdsaSig, @@ -742,28 +742,14 @@ impl Strategy for psbt::PartiallySignedTransaction { impl StrictEncode for TapTree { fn strict_encode(&self, e: E) -> Result { - impl StrictEncode for &Script { - fn strict_encode(&self, e: E) -> Result { - Script::strict_encode(self, e) - } - } - self.script_leaves() - .cloned() - .collect::>() - .strict_encode(e) + self.serialize().strict_encode(e) } } impl StrictDecode for TapTree { fn strict_decode(d: D) -> Result { - let builder = Vec::<(u8, Script)>::strict_decode(d)? - .into_iter() - .try_fold(TaprootBuilder::new(), |builder, (depth, script)| { - builder.add_leaf(depth, script) - }) - .map_err(|err| Error::DataIntegrityError(err.to_string()))?; - TapTree::try_from(builder) - .map_err(|_| Error::DataIntegrityError(s!("incomplete tree"))) + Ok(TapTree::deserialize(&Vec::::strict_decode(d)?) + .expect("incomplete tree")) } }