Skip to content

Commit

Permalink
feat: expose TxBuilder::allow_dust
Browse files Browse the repository at this point in the history
  • Loading branch information
thunderbiscuit committed Nov 22, 2024
1 parent 99adbf7 commit 465dbeb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
4 changes: 4 additions & 0 deletions bdk-ffi/src/bdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,8 @@ interface TxBuilder {

TxBuilder nlocktime(LockTime locktime);

TxBuilder allow_dust(boolean allow_dust);

[Throws=CreateTxError]
Psbt finish([ByRef] Wallet wallet);
};
Expand All @@ -730,6 +732,8 @@ interface BumpFeeTxBuilder {

BumpFeeTxBuilder nlocktime(LockTime locktime);

BumpFeeTxBuilder allow_dust(boolean allow_dust);

[Throws=CreateTxError]
Psbt finish([ByRef] Wallet wallet);
};
Expand Down
25 changes: 24 additions & 1 deletion bdk-ffi/src/tx_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub struct TxBuilder {
pub(crate) data: Vec<u8>,
pub(crate) current_height: Option<u32>,
pub(crate) locktime: Option<LockTime>,
pub(crate) allow_dust: bool,
}

impl TxBuilder {
Expand All @@ -60,6 +61,7 @@ impl TxBuilder {
data: Vec::new(),
current_height: None,
locktime: None,
allow_dust: false,
}
}

Expand Down Expand Up @@ -223,6 +225,13 @@ impl TxBuilder {
})
}

pub(crate) fn allow_dust(&self, allow_dust: bool) -> Arc<Self> {
Arc::new(TxBuilder {
allow_dust,
..self.clone()
})
}

pub(crate) fn finish(&self, wallet: &Arc<Wallet>) -> Result<Arc<Psbt>, 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();
Expand Down Expand Up @@ -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)?;

Expand All @@ -293,6 +304,7 @@ pub(crate) struct BumpFeeTxBuilder {
pub(crate) sequence: Option<u32>,
pub(crate) current_height: Option<u32>,
pub(crate) locktime: Option<LockTime>,
pub(crate) allow_dust: bool,
}

impl BumpFeeTxBuilder {
Expand All @@ -303,6 +315,7 @@ impl BumpFeeTxBuilder {
sequence: None,
current_height: None,
locktime: None,
allow_dust: false,
}
}

Expand All @@ -327,6 +340,13 @@ impl BumpFeeTxBuilder {
})
}

pub(crate) fn allow_dust(&self, allow_dust: bool) -> Arc<Self> {
Arc::new(BumpFeeTxBuilder {
allow_dust,
..self.clone()
})
}

pub(crate) fn finish(&self, wallet: &Arc<Wallet>) -> Result<Arc<Psbt>, CreateTxError> {
let txid = Txid::from_str(self.txid.as_str()).map_err(|_| CreateTxError::UnknownUtxo {
outpoint: self.txid.clone(),
Expand All @@ -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()?;

Expand Down

0 comments on commit 465dbeb

Please sign in to comment.