Skip to content

Commit

Permalink
Improve allowing tapret in change output
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-orlovsky committed Jul 2, 2022
1 parent ecbd86e commit d193c2a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
13 changes: 10 additions & 3 deletions psbt/src/construct/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -91,6 +92,7 @@ impl Psbt {
outputs: impl IntoIterator<Item = &'outputs (PubkeyScript, u64)>,
change_index: impl Into<UnhardenedIndex>,
fee: u64,
tapret: Option<&DfsPath>,
tx_resolver: &impl ResolveTx,
) -> Result<Psbt, Error> {
let mut xpub = bmap! {};
Expand Down Expand Up @@ -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::<bitcoin::PublicKey>::derive_descriptor(
Expand All @@ -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);
}

Expand Down
19 changes: 10 additions & 9 deletions src/bin/btc-cold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,16 +632,17 @@ impl Args {
)
})
.collect::<Vec<_>>();
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 {
Expand Down

0 comments on commit d193c2a

Please sign in to comment.