Skip to content

Commit 3df9252

Browse files
feat: add drain_to method on txbuilder
1 parent fe65c70 commit 3df9252

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

bdk-ffi/src/bdk.udl

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

141141
TxBuilder drain_wallet();
142142

143+
TxBuilder drain_to(Script script);
144+
143145
[Throws=BdkError]
144146
PartiallySignedTransaction finish([ByRef] Wallet wallet);
145147
};

bdk-ffi/src/wallet.rs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ pub struct TxBuilder {
301301
pub(crate) fee_rate: Option<f32>,
302302
pub(crate) fee_absolute: Option<u64>,
303303
pub(crate) drain_wallet: bool,
304-
// pub(crate) drain_to: Option<BdkScript>,
304+
pub(crate) drain_to: Option<BdkScriptBuf>,
305305
// pub(crate) rbf: Option<RbfValue>,
306306
// pub(crate) data: Vec<u8>,
307307
}
@@ -317,7 +317,7 @@ impl TxBuilder {
317317
fee_rate: None,
318318
fee_absolute: None,
319319
drain_wallet: false,
320-
// drain_to: None,
320+
drain_to: None,
321321
// rbf: None,
322322
// data: Vec::new(),
323323
}
@@ -439,20 +439,20 @@ impl TxBuilder {
439439
})
440440
}
441441

442-
// /// Sets the address to drain excess coins to. Usually, when there are excess coins they are sent to a change address
443-
// /// generated by the wallet. This option replaces the usual change address with an arbitrary ScriptPubKey of your choosing.
444-
// /// Just as with a change output, if the drain output is not needed (the excess coins are too small) it will not be included
445-
// /// in the resulting transaction. The only difference is that it is valid to use drain_to without setting any ordinary recipients
446-
// /// with add_recipient (but it is perfectly fine to add recipients as well). If you choose not to set any recipients, you should
447-
// /// either provide the utxos that the transaction should spend via add_utxos, or set drain_wallet to spend all of them.
448-
// /// When bumping the fees of a transaction made with this option, you probably want to use BumpFeeTxBuilder.allow_shrinking
449-
// /// to allow this output to be reduced to pay for the extra fees.
450-
// pub(crate) fn drain_to(&self, script: Arc<Script>) -> Arc<Self> {
451-
// Arc::new(TxBuilder {
452-
// drain_to: Some(script.inner.clone()),
453-
// ..self.clone()
454-
// })
455-
// }
442+
/// Sets the address to drain excess coins to. Usually, when there are excess coins they are sent to a change address
443+
/// generated by the wallet. This option replaces the usual change address with an arbitrary ScriptPubKey of your choosing.
444+
/// Just as with a change output, if the drain output is not needed (the excess coins are too small) it will not be included
445+
/// in the resulting transaction. The only difference is that it is valid to use drain_to without setting any ordinary recipients
446+
/// with add_recipient (but it is perfectly fine to add recipients as well). If you choose not to set any recipients, you should
447+
/// either provide the utxos that the transaction should spend via add_utxos, or set drain_wallet to spend all of them.
448+
/// When bumping the fees of a transaction made with this option, you probably want to use BumpFeeTxBuilder.allow_shrinking
449+
/// to allow this output to be reduced to pay for the extra fees.
450+
pub(crate) fn drain_to(&self, script: Arc<Script>) -> Arc<Self> {
451+
Arc::new(TxBuilder {
452+
drain_to: Some(script.0.clone()),
453+
..self.clone()
454+
})
455+
}
456456
//
457457
// /// Enable signaling RBF. This will use the default `nsequence` value of `0xFFFFFFFD`.
458458
// pub(crate) fn enable_rbf(&self) -> Arc<Self> {
@@ -514,9 +514,9 @@ impl TxBuilder {
514514
if self.drain_wallet {
515515
tx_builder.drain_wallet();
516516
}
517-
// if let Some(script) = &self.drain_to {
518-
// tx_builder.drain_to(script.clone());
519-
// }
517+
if let Some(script) = &self.drain_to {
518+
tx_builder.drain_to(script.clone());
519+
}
520520
// if let Some(rbf) = &self.rbf {
521521
// match *rbf {
522522
// RbfValue::Default => {

0 commit comments

Comments
 (0)