From fe65c70915da9d5d8813ed90aa84e7aceabca792 Mon Sep 17 00:00:00 2001 From: thunderbiscuit Date: Wed, 6 Dec 2023 21:00:17 -0500 Subject: [PATCH] feat: add unspendable method on txbuilder --- bdk-ffi/src/bdk.udl | 2 ++ bdk-ffi/src/wallet.rs | 28 ++++++++++++++-------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/bdk-ffi/src/bdk.udl b/bdk-ffi/src/bdk.udl index 70e780b..8fe3a32 100644 --- a/bdk-ffi/src/bdk.udl +++ b/bdk-ffi/src/bdk.udl @@ -122,6 +122,8 @@ interface TxBuilder { TxBuilder add_unspendable(OutPoint unspendable); + TxBuilder unspendable(sequence unspendable); + TxBuilder add_utxo(OutPoint outpoint); TxBuilder change_policy(ChangeSpendPolicy change_policy); diff --git a/bdk-ffi/src/wallet.rs b/bdk-ffi/src/wallet.rs index cc6b686..a6e19ea 100644 --- a/bdk-ffi/src/wallet.rs +++ b/bdk-ffi/src/wallet.rs @@ -356,6 +356,15 @@ impl TxBuilder { }) } + /// Replace the internal list of unspendable utxos with a new list. It’s important to note that the "must-be-spent" utxos added with + /// TxBuilder.addUtxo have priority over these. See the Rust docs of the two linked methods for more details. + pub(crate) fn unspendable(&self, unspendable: Vec) -> Arc { + Arc::new(TxBuilder { + unspendable: unspendable.into_iter().collect(), + ..self.clone() + }) + } + /// Add an outpoint to the internal list of UTXOs that must be spent. These have priority over the "unspendable" /// utxos, meaning that if a utxo is present both in the "utxos" and the "unspendable" list, it will be spent. pub(crate) fn add_utxo(&self, outpoint: OutPoint) -> Arc { @@ -406,15 +415,6 @@ impl TxBuilder { }) } - // /// Replace the internal list of unspendable utxos with a new list. It’s important to note that the "must-be-spent" utxos added with - // /// TxBuilder.addUtxo have priority over these. See the Rust docs of the two linked methods for more details. - // pub(crate) fn unspendable(&self, unspendable: Vec) -> Arc { - // Arc::new(TxBuilder { - // unspendable: unspendable.into_iter().collect(), - // ..self.clone() - // }) - // } - /// Set a custom fee rate. pub(crate) fn fee_rate(&self, sat_per_vb: f32) -> Arc { Arc::new(TxBuilder { @@ -497,11 +497,11 @@ impl TxBuilder { let utxos: &[BdkOutPoint] = &bdk_utxos; tx_builder.add_utxos(utxos)?; } - // if !self.unspendable.is_empty() { - // let bdk_unspendable: Vec = - // self.unspendable.iter().map(BdkOutPoint::from).collect(); - // tx_builder.unspendable(bdk_unspendable); - // } + if !self.unspendable.is_empty() { + let bdk_unspendable: Vec = + self.unspendable.iter().map(BdkOutPoint::from).collect(); + tx_builder.unspendable(bdk_unspendable); + } if self.manually_selected_only { tx_builder.manually_selected_only(); }