Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sign_options argument to Wallet::sign and Wallet::finalize_psbt methods #650

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: add optional sign_options argument to Wallet::finalize_psbt method
thunderbiscuit committed Jan 15, 2025
commit 5ffdb912efaf85d46bfc2411e9f57bff481bf60d
2 changes: 1 addition & 1 deletion bdk-ffi/src/bdk.udl
Original file line number Diff line number Diff line change
@@ -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.
///
2 changes: 1 addition & 1 deletion bdk-ffi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
2 changes: 1 addition & 1 deletion bdk-ffi/src/types.rs
Original file line number Diff line number Diff line change
@@ -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;
19 changes: 14 additions & 5 deletions bdk-ffi/src/wallet.rs
Original file line number Diff line number Diff line change
@@ -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;
@@ -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)
}

Loading