Skip to content

Commit

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

BumpFeeTxBuilder set_exact_sequence(u32 nsequence);

TxBuilder current_height(u32 height);

[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 @@ -31,6 +31,7 @@ pub struct TxBuilder {
pub(crate) drain_to: Option<BdkScriptBuf>,
pub(crate) sequence: Option<u32>,
pub(crate) data: Vec<u8>,
pub(crate) current_height: Option<u32>,
}

impl TxBuilder {
Expand All @@ -48,6 +49,7 @@ impl TxBuilder {
drain_to: None,
sequence: None,
data: Vec::new(),
current_height: None,
}
}

Expand Down Expand Up @@ -178,6 +180,13 @@ impl TxBuilder {
})
}

pub(crate) fn current_height(&self, height: u32) -> Arc<Self> {
Arc::new(TxBuilder {
current_height: Some(height),
..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 @@ -220,6 +229,9 @@ impl TxBuilder {
let push_bytes = PushBytesBuf::try_from(self.data.clone())?;
tx_builder.add_data(&push_bytes);
}
if let Some(height) = self.current_height {
tx_builder.current_height(height);
}

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

Expand All @@ -232,6 +244,7 @@ pub(crate) struct BumpFeeTxBuilder {
pub(crate) txid: String,
pub(crate) fee_rate: Arc<FeeRate>,
pub(crate) sequence: Option<u32>,
pub(crate) current_height: Option<u32>,
}

impl BumpFeeTxBuilder {
Expand All @@ -240,6 +253,7 @@ impl BumpFeeTxBuilder {
txid,
fee_rate,
sequence: None,
current_height: None,
}
}

Expand All @@ -250,6 +264,13 @@ impl BumpFeeTxBuilder {
})
}

pub(crate) fn current_height(&self, height: u32) -> Arc<Self> {
Arc::new(BumpFeeTxBuilder {
current_height: Some(height),
..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 @@ -260,6 +281,9 @@ impl BumpFeeTxBuilder {
if let Some(sequence) = self.sequence {
tx_builder.set_exact_sequence(Sequence(sequence));
}
if let Some(height) = self.current_height {
tx_builder.current_height(height);
}

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

Expand Down

0 comments on commit 0ac8dce

Please sign in to comment.