Skip to content

Commit

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

TxBuilder allow_dust(boolean allow_dust);

TxBuilder version(i32 version);

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

BumpFeeTxBuilder allow_dust(boolean allow_dust);

BumpFeeTxBuilder version(i32 version);

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

impl TxBuilder {
Expand All @@ -62,6 +63,7 @@ impl TxBuilder {
current_height: None,
locktime: None,
allow_dust: false,
version: None,
}
}

Expand Down Expand Up @@ -232,6 +234,13 @@ impl TxBuilder {
})
}

pub(crate) fn version(&self, version: i32) -> Arc<Self> {
Arc::new(TxBuilder {
version: Some(version),
..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 @@ -290,6 +299,9 @@ impl TxBuilder {
if self.allow_dust {
tx_builder.allow_dust(self.allow_dust);
}
if let Some(version) = self.version {
tx_builder.version(version);
}

let psbt = tx_builder.finish().map_err(CreateTxError::from)?;

Expand All @@ -305,6 +317,7 @@ pub(crate) struct BumpFeeTxBuilder {
pub(crate) current_height: Option<u32>,
pub(crate) locktime: Option<LockTime>,
pub(crate) allow_dust: bool,
pub(crate) version: Option<i32>,
}

impl BumpFeeTxBuilder {
Expand All @@ -316,6 +329,7 @@ impl BumpFeeTxBuilder {
current_height: None,
locktime: None,
allow_dust: false,
version: None,
}
}

Expand Down Expand Up @@ -347,6 +361,13 @@ impl BumpFeeTxBuilder {
})
}

pub(crate) fn version(&self, version: i32) -> Arc<Self> {
Arc::new(BumpFeeTxBuilder {
version: Some(version),
..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 @@ -367,6 +388,9 @@ impl BumpFeeTxBuilder {
if self.allow_dust {
tx_builder.allow_dust(self.allow_dust);
}
if let Some(version) = self.version {
tx_builder.version(version);
}

let psbt: BdkPsbt = tx_builder.finish()?;

Expand Down

0 comments on commit d0bec77

Please sign in to comment.