Skip to content

Commit

Permalink
feat: add optional sign_options argument to Wallet::finalize_psbt method
Browse files Browse the repository at this point in the history
  • Loading branch information
thunderbiscuit committed Jan 15, 2025
1 parent fcf4d07 commit 5ffdb91
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
2 changes: 1 addition & 1 deletion bdk-ffi/src/bdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ interface Wallet {
///
/// The [`SignOptions`] can be used to tweak the behavior of the finalizer.
[Throws=SignerError]
boolean finalize_psbt(Psbt psbt);
boolean finalize_psbt(Psbt psbt, SignOptions? sign_options);

/// Compute the `tx`'s sent and received [`Amount`]s.
///
Expand Down
2 changes: 1 addition & 1 deletion bdk-ffi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ use crate::types::Satisfaction;
use crate::types::SatisfiableItem;
use crate::types::ScriptAmount;
use crate::types::SentAndReceivedValues;
use crate::types::SignOptions;
use crate::types::SyncRequest;
use crate::types::SyncRequestBuilder;
use crate::types::SyncScriptInspector;
use crate::types::Update;
use crate::wallet::Wallet;
use crate::types::SignOptions;

use bitcoin_ffi::Amount;
use bitcoin_ffi::FeeRate;
Expand Down
2 changes: 1 addition & 1 deletion bdk-ffi/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ use bdk_wallet::descriptor::policy::{
Condition as BdkCondition, PkOrF as BdkPkOrF, Policy as BdkPolicy,
Satisfaction as BdkSatisfaction, SatisfiableItem as BdkSatisfiableItem,
};
use bdk_wallet::signer::{SignOptions as BdkSignOptions, TapLeavesOptions};
use bdk_wallet::AddressInfo as BdkAddressInfo;
use bdk_wallet::Balance as BdkBalance;
use bdk_wallet::KeychainKind;
use bdk_wallet::LocalOutput as BdkLocalOutput;
use bdk_wallet::Update as BdkUpdate;
use bdk_wallet::signer::{SignOptions as BdkSignOptions, TapLeavesOptions};

use std::collections::HashMap;
use std::convert::TryFrom;
Expand Down
19 changes: 14 additions & 5 deletions bdk-ffi/src/wallet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ use crate::error::{
use crate::store::Connection;
use crate::types::{
AddressInfo, Balance, CanonicalTx, FullScanRequestBuilder, KeychainAndIndex, LocalOutput,
Policy, SentAndReceivedValues, SyncRequestBuilder, Update, SignOptions
Policy, SentAndReceivedValues, SignOptions, SyncRequestBuilder, Update,
};

use bitcoin_ffi::{Amount, FeeRate, OutPoint, Script};

use bdk_wallet::signer::SignOptions as BdkSignOptions;
use bdk_wallet::bitcoin::{Network, Txid};
use bdk_wallet::rusqlite::Connection as BdkConnection;
use bdk_wallet::signer::SignOptions as BdkSignOptions;
use bdk_wallet::{KeychainKind, PersistedWallet, Wallet as BdkWallet};

use std::borrow::BorrowMut;
Expand Down Expand Up @@ -168,18 +168,27 @@ impl Wallet {
let mut psbt = psbt.0.lock().unwrap();
let bdk_sign_options: BdkSignOptions = match sign_options {
Some(sign_options) => BdkSignOptions::from(sign_options),
None => BdkSignOptions::default()
None => BdkSignOptions::default(),
};

self.get_wallet()
.sign(&mut psbt, bdk_sign_options)
.map_err(SignerError::from)
}

pub fn finalize_psbt(&self, psbt: Arc<Psbt>) -> Result<bool, SignerError> {
pub fn finalize_psbt(
&self,
psbt: Arc<Psbt>,
sign_options: Option<SignOptions>,
) -> Result<bool, SignerError> {
let mut psbt = psbt.0.lock().unwrap();
let bdk_sign_options: BdkSignOptions = match sign_options {
Some(sign_options) => BdkSignOptions::from(sign_options),
None => BdkSignOptions::default(),
};

self.get_wallet()
.finalize_psbt(&mut psbt, BdkSignOptions::default())
.finalize_psbt(&mut psbt, bdk_sign_options)
.map_err(SignerError::from)
}

Expand Down

0 comments on commit 5ffdb91

Please sign in to comment.