feat: add drain_to method on txbuilder

This commit is contained in:
thunderbiscuit 2023-12-06 21:03:53 -05:00
parent fe65c70915
commit 3df92527e9
No known key found for this signature in database
GPG Key ID: 88253696EB836462
2 changed files with 21 additions and 19 deletions

View File

@ -140,6 +140,8 @@ interface TxBuilder {
TxBuilder drain_wallet();
TxBuilder drain_to(Script script);
[Throws=BdkError]
PartiallySignedTransaction finish([ByRef] Wallet wallet);
};

View File

@ -301,7 +301,7 @@ pub struct TxBuilder {
pub(crate) fee_rate: Option<f32>,
pub(crate) fee_absolute: Option<u64>,
pub(crate) drain_wallet: bool,
// pub(crate) drain_to: Option<BdkScript>,
pub(crate) drain_to: Option<BdkScriptBuf>,
// pub(crate) rbf: Option<RbfValue>,
// pub(crate) data: Vec<u8>,
}
@ -317,7 +317,7 @@ impl TxBuilder {
fee_rate: None,
fee_absolute: None,
drain_wallet: false,
// drain_to: None,
drain_to: None,
// rbf: None,
// data: Vec::new(),
}
@ -439,20 +439,20 @@ impl TxBuilder {
})
}
// /// Sets the address to drain excess coins to. Usually, when there are excess coins they are sent to a change address
// /// generated by the wallet. This option replaces the usual change address with an arbitrary ScriptPubKey of your choosing.
// /// Just as with a change output, if the drain output is not needed (the excess coins are too small) it will not be included
// /// in the resulting transaction. The only difference is that it is valid to use drain_to without setting any ordinary recipients
// /// with add_recipient (but it is perfectly fine to add recipients as well). If you choose not to set any recipients, you should
// /// either provide the utxos that the transaction should spend via add_utxos, or set drain_wallet to spend all of them.
// /// When bumping the fees of a transaction made with this option, you probably want to use BumpFeeTxBuilder.allow_shrinking
// /// to allow this output to be reduced to pay for the extra fees.
// pub(crate) fn drain_to(&self, script: Arc<Script>) -> Arc<Self> {
// Arc::new(TxBuilder {
// drain_to: Some(script.inner.clone()),
// ..self.clone()
// })
// }
/// Sets the address to drain excess coins to. Usually, when there are excess coins they are sent to a change address
/// generated by the wallet. This option replaces the usual change address with an arbitrary ScriptPubKey of your choosing.
/// Just as with a change output, if the drain output is not needed (the excess coins are too small) it will not be included
/// in the resulting transaction. The only difference is that it is valid to use drain_to without setting any ordinary recipients
/// with add_recipient (but it is perfectly fine to add recipients as well). If you choose not to set any recipients, you should
/// either provide the utxos that the transaction should spend via add_utxos, or set drain_wallet to spend all of them.
/// When bumping the fees of a transaction made with this option, you probably want to use BumpFeeTxBuilder.allow_shrinking
/// to allow this output to be reduced to pay for the extra fees.
pub(crate) fn drain_to(&self, script: Arc<Script>) -> Arc<Self> {
Arc::new(TxBuilder {
drain_to: Some(script.0.clone()),
..self.clone()
})
}
//
// /// Enable signaling RBF. This will use the default `nsequence` value of `0xFFFFFFFD`.
// pub(crate) fn enable_rbf(&self) -> Arc<Self> {
@ -514,9 +514,9 @@ impl TxBuilder {
if self.drain_wallet {
tx_builder.drain_wallet();
}
// if let Some(script) = &self.drain_to {
// tx_builder.drain_to(script.clone());
// }
if let Some(script) = &self.drain_to {
tx_builder.drain_to(script.clone());
}
// if let Some(rbf) = &self.rbf {
// match *rbf {
// RbfValue::Default => {