Skip to content

Commit fe65c70

Browse files
feat: add unspendable method on txbuilder
1 parent ce219e4 commit fe65c70

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

bdk-ffi/src/bdk.udl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ interface TxBuilder {
122122

123123
TxBuilder add_unspendable(OutPoint unspendable);
124124

125+
TxBuilder unspendable(sequence<OutPoint> unspendable);
126+
125127
TxBuilder add_utxo(OutPoint outpoint);
126128

127129
TxBuilder change_policy(ChangeSpendPolicy change_policy);

bdk-ffi/src/wallet.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,15 @@ impl TxBuilder {
356356
})
357357
}
358358

359+
/// Replace the internal list of unspendable utxos with a new list. It’s important to note that the "must-be-spent" utxos added with
360+
/// TxBuilder.addUtxo have priority over these. See the Rust docs of the two linked methods for more details.
361+
pub(crate) fn unspendable(&self, unspendable: Vec<OutPoint>) -> Arc<Self> {
362+
Arc::new(TxBuilder {
363+
unspendable: unspendable.into_iter().collect(),
364+
..self.clone()
365+
})
366+
}
367+
359368
/// Add an outpoint to the internal list of UTXOs that must be spent. These have priority over the "unspendable"
360369
/// utxos, meaning that if a utxo is present both in the "utxos" and the "unspendable" list, it will be spent.
361370
pub(crate) fn add_utxo(&self, outpoint: OutPoint) -> Arc<Self> {
@@ -406,15 +415,6 @@ impl TxBuilder {
406415
})
407416
}
408417

409-
// /// Replace the internal list of unspendable utxos with a new list. It’s important to note that the "must-be-spent" utxos added with
410-
// /// TxBuilder.addUtxo have priority over these. See the Rust docs of the two linked methods for more details.
411-
// pub(crate) fn unspendable(&self, unspendable: Vec<OutPoint>) -> Arc<Self> {
412-
// Arc::new(TxBuilder {
413-
// unspendable: unspendable.into_iter().collect(),
414-
// ..self.clone()
415-
// })
416-
// }
417-
418418
/// Set a custom fee rate.
419419
pub(crate) fn fee_rate(&self, sat_per_vb: f32) -> Arc<Self> {
420420
Arc::new(TxBuilder {
@@ -497,11 +497,11 @@ impl TxBuilder {
497497
let utxos: &[BdkOutPoint] = &bdk_utxos;
498498
tx_builder.add_utxos(utxos)?;
499499
}
500-
// if !self.unspendable.is_empty() {
501-
// let bdk_unspendable: Vec<BdkOutPoint> =
502-
// self.unspendable.iter().map(BdkOutPoint::from).collect();
503-
// tx_builder.unspendable(bdk_unspendable);
504-
// }
500+
if !self.unspendable.is_empty() {
501+
let bdk_unspendable: Vec<BdkOutPoint> =
502+
self.unspendable.iter().map(BdkOutPoint::from).collect();
503+
tx_builder.unspendable(bdk_unspendable);
504+
}
505505
if self.manually_selected_only {
506506
tx_builder.manually_selected_only();
507507
}

0 commit comments

Comments
 (0)