diff --git a/bdk-ffi/src/bdk.udl b/bdk-ffi/src/bdk.udl index 9f14aa3c..14373b7a 100644 --- a/bdk-ffi/src/bdk.udl +++ b/bdk-ffi/src/bdk.udl @@ -717,6 +717,8 @@ interface TxBuilder { TxBuilder nlocktime(LockTime locktime); + TxBuilder allow_dust(boolean allow_dust); + [Throws=CreateTxError] Psbt finish([ByRef] Wallet wallet); }; @@ -730,6 +732,8 @@ interface BumpFeeTxBuilder { BumpFeeTxBuilder nlocktime(LockTime locktime); + BumpFeeTxBuilder allow_dust(boolean allow_dust); + [Throws=CreateTxError] Psbt finish([ByRef] Wallet wallet); }; diff --git a/bdk-ffi/src/tx_builder.rs b/bdk-ffi/src/tx_builder.rs index a19b133a..e0f88997 100644 --- a/bdk-ffi/src/tx_builder.rs +++ b/bdk-ffi/src/tx_builder.rs @@ -39,6 +39,7 @@ pub struct TxBuilder { pub(crate) data: Vec, pub(crate) current_height: Option, pub(crate) locktime: Option, + pub(crate) allow_dust: bool, } impl TxBuilder { @@ -60,6 +61,7 @@ impl TxBuilder { data: Vec::new(), current_height: None, locktime: None, + allow_dust: false, } } @@ -223,6 +225,13 @@ impl TxBuilder { }) } + pub(crate) fn allow_dust(&self, allow_dust: bool) -> Arc { + Arc::new(TxBuilder { + allow_dust, + ..self.clone() + }) + } + pub(crate) fn finish(&self, wallet: &Arc) -> Result, CreateTxError> { // TODO: I had to change the wallet here to be mutable. Why is that now required with the 1.0 API? let mut wallet = wallet.get_wallet(); @@ -274,11 +283,13 @@ impl TxBuilder { if let Some(height) = self.current_height { tx_builder.current_height(height); } - // let bdk_locktime = locktime.try_into().map_err(CreateTxError::LockTimeConversionError)?; if let Some(locktime) = &self.locktime { let bdk_locktime: BdkLockTime = locktime.try_into()?; tx_builder.nlocktime(bdk_locktime); } + if self.allow_dust { + tx_builder.allow_dust(self.allow_dust); + } let psbt = tx_builder.finish().map_err(CreateTxError::from)?; @@ -293,6 +304,7 @@ pub(crate) struct BumpFeeTxBuilder { pub(crate) sequence: Option, pub(crate) current_height: Option, pub(crate) locktime: Option, + pub(crate) allow_dust: bool, } impl BumpFeeTxBuilder { @@ -303,6 +315,7 @@ impl BumpFeeTxBuilder { sequence: None, current_height: None, locktime: None, + allow_dust: false, } } @@ -327,6 +340,13 @@ impl BumpFeeTxBuilder { }) } + pub(crate) fn allow_dust(&self, allow_dust: bool) -> Arc { + Arc::new(BumpFeeTxBuilder { + allow_dust, + ..self.clone() + }) + } + pub(crate) fn finish(&self, wallet: &Arc) -> Result, CreateTxError> { let txid = Txid::from_str(self.txid.as_str()).map_err(|_| CreateTxError::UnknownUtxo { outpoint: self.txid.clone(), @@ -344,6 +364,9 @@ impl BumpFeeTxBuilder { let bdk_locktime: BdkLockTime = locktime.try_into()?; tx_builder.nlocktime(bdk_locktime); } + if self.allow_dust { + tx_builder.allow_dust(self.allow_dust); + } let psbt: BdkPsbt = tx_builder.finish()?;