Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions examples/example_cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use anyhow::Context;
use bdk_chain::bitcoin::{
absolute, address::NetworkUnchecked, bip32, consensus, constants, hex::DisplayHex, relative,
secp256k1::Secp256k1, transaction, Address, Amount, Network, NetworkKind, PrivateKey, Psbt,
PublicKey, Sequence, Transaction, TxIn, TxOut,
PublicKey, Sequence, Transaction, TxIn, TxOut, WitnessVersion,
};
use bdk_chain::miniscript::{
descriptor::{DescriptorSecretKey, SinglePubKey},
Expand Down Expand Up @@ -308,16 +308,12 @@ where
script_pubkey: address.script_pubkey(),
}];

let (change_keychain, _) = graph
.index
.keychains()
.last()
.expect("must have a keychain");
let change_keychain = Keychain::Internal;

let ((change_index, change_script), index_changeset) = graph
.index
.next_unused_spk(change_keychain)
.expect("Must exist");
.context("no change descriptor configured; cannot create change")?;
changeset.merge(index_changeset);

let mut change_output = TxOut {
Expand Down Expand Up @@ -346,9 +342,16 @@ where
},
};

let drain_weights = match change_desc.witness_version() {
Some(WitnessVersion::V1) => DrainWeights::TR_KEYSPEND,
Some(WitnessVersion::V0) => DrainWeights::WITNESS_V0_KEYSPEND,
None => DrainWeights::LEGACY_KEYSPEND,
_ => DrainWeights::TR_KEYSPEND,
};
Comment on lines +345 to +350
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code fails to compile due to missing APIs


let change_policy = ChangePolicy {
min_value: min_drain_value,
drain_weights: DrainWeights::TR_KEYSPEND,
drain_weights,
};

// run coin selection
Expand Down Expand Up @@ -379,7 +382,7 @@ where
// output
let mut change_info = Option::<ChangeInfo>::None;
let drain = selector.drain(target, change_policy);
if drain.value > min_drain_value {
if drain.value >= min_drain_value {
change_output.value = Amount::from_sat(drain.value);
outputs.push(change_output);
change_info = Some(ChangeInfo {
Expand Down