diff --git a/psbt/src/construct/mod.rs b/psbt/src/construct/mod.rs index 52398b4..0b14ec8 100644 --- a/psbt/src/construct/mod.rs +++ b/psbt/src/construct/mod.rs @@ -25,6 +25,7 @@ use bitcoin_hd::{ DerivationAccount, DeriveDescriptor, DeriveError, SegmentIndexes, UnhardenedIndex, }; use bitcoin_onchain::{ResolveTx, TxResolverError}; +use bitcoin_scripts::taproot::DfsPath; use bitcoin_scripts::PubkeyScript; use descriptors::InputDescriptor; use miniscript::{Descriptor, DescriptorTrait, ForEachKey, ToPublicKey}; @@ -91,6 +92,7 @@ impl Psbt { outputs: impl IntoIterator, change_index: impl Into, fee: u64, + tapret: Option<&DfsPath>, tx_resolver: &impl ResolveTx, ) -> Result { let mut xpub = bmap! {}; @@ -333,7 +335,13 @@ impl Psbt { .expect("insane miniscript taptree"); } psbt_change_output.tap_tree = - Some(TapTree::from_builder(builder).expect("non-finalzied TaprootBuilder")); + Some(TapTree::from_builder(builder).expect("non-finalized TaprootBuilder")); + } + + if let Some(dfs_path) = tapret { + psbt_change_output + .set_tapret_dfs_path(dfs_path) + .expect("enabling tapret on change output"); } } else { let change_descriptor = DeriveDescriptor::::derive_descriptor( @@ -353,10 +361,9 @@ impl Psbt { if dtype.has_witness_script() { psbt_change_output.witness_script = Some(lock_script); } - - psbt_change_output.bip32_derivation = bip32_derivation; } + psbt_change_output.bip32_derivation = bip32_derivation; psbt_outputs.push(psbt_change_output); } diff --git a/src/bin/btc-cold.rs b/src/bin/btc-cold.rs index c5d4718..ede6251 100644 --- a/src/bin/btc-cold.rs +++ b/src/bin/btc-cold.rs @@ -632,16 +632,17 @@ impl Args { ) }) .collect::>(); - let mut psbt = Psbt::construct(&descriptor, inputs, &outputs, change_index, fee, &tx_map)?; - psbt.fallback_locktime = Some(lock_time); - if let Some(tapret_path) = allow_tapret_path { - for output in &mut psbt.outputs { - if !output.bip32_derivation.is_empty() { - output.set_tapret_dfs_path(tapret_path); - } - } - } + let mut psbt = Psbt::construct( + &descriptor, + inputs, + &outputs, + change_index, + fee, + allow_tapret_path, + &tx_map, + )?; + psbt.fallback_locktime = Some(lock_time); for key in proprietary_keys { match key.location {