Skip to content

Commit

Permalink
feat: expose add_global_xpubs method on transaction builder
Browse files Browse the repository at this point in the history
  • Loading branch information
thunderbiscuit committed Aug 29, 2024
1 parent fe50d23 commit 34a33d8
Show file tree
Hide file tree
Showing 2 changed files with 14 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 @@ -435,6 +435,8 @@ interface Update {};
interface TxBuilder {
constructor();

TxBuilder add_global_xpubs();

TxBuilder add_recipient([ByRef] Script script, Amount amount);

TxBuilder set_recipients(sequence<ScriptAmount> recipients);
Expand Down
12 changes: 12 additions & 0 deletions bdk-ffi/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ pub struct SentAndReceivedValues {

#[derive(Clone, Debug)]
pub struct TxBuilder {
pub(crate) add_global_xpubs: bool,
pub(crate) recipients: Vec<(BdkScriptBuf, BdkAmount)>,
pub(crate) utxos: Vec<OutPoint>,
pub(crate) unspendable: HashSet<OutPoint>,
Expand All @@ -198,6 +199,7 @@ pub struct TxBuilder {
impl TxBuilder {
pub(crate) fn new() -> Self {
TxBuilder {
add_global_xpubs: false,
recipients: Vec::new(),
utxos: Vec::new(),
unspendable: HashSet::new(),
Expand All @@ -212,6 +214,13 @@ impl TxBuilder {
}
}

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

pub(crate) fn add_recipient(&self, script: &Script, amount: Arc<Amount>) -> Arc<Self> {
let mut recipients: Vec<(BdkScriptBuf, BdkAmount)> = self.recipients.clone();
recipients.append(&mut vec![(script.0.clone(), amount.0)]);
Expand Down Expand Up @@ -336,6 +345,9 @@ impl TxBuilder {
// 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();
let mut tx_builder = wallet.build_tx();
if self.add_global_xpubs {
tx_builder.add_global_xpubs();
}
for (script, amount) in &self.recipients {
tx_builder.add_recipient(script.clone(), *amount);
}
Expand Down

0 comments on commit 34a33d8

Please sign in to comment.