feat: add sign method on wallet type

This commit is contained in:
thunderbiscuit 2023-11-17 13:24:59 -05:00
parent 787152e0b4
commit 26352edfbe
No known key found for this signature in database
GPG Key ID: 88253696EB836462
2 changed files with 24 additions and 1 deletions

View File

@ -92,6 +92,9 @@ interface Wallet {
[Throws=BdkError]
void apply_update(Update update);
[Throws=BdkError]
boolean sign(PartiallySignedTransaction psbt);
};
interface Update {};

View File

@ -7,7 +7,7 @@ use std::collections::HashSet;
use bdk::bitcoin::blockdata::script::ScriptBuf as BdkScriptBuf;
use bdk::bitcoin::OutPoint as BdkOutPoint;
use bdk::wallet::Update as BdkUpdate;
use bdk::Wallet as BdkWallet;
use bdk::{SignOptions, Wallet as BdkWallet};
use bdk::{Error as BdkError, FeeRate};
use bdk::wallet::tx_builder::ChangeSpendPolicy;
@ -73,6 +73,26 @@ impl Wallet {
self.get_wallet().is_mine(&script.0)
// self.get_wallet().is_mine(script.0.clone().as_script())
}
/// Sign a transaction with all the wallet's signers, in the order specified by every signer's
/// [`SignerOrdering`]. This function returns the `Result` type with an encapsulated `bool` that
/// has the value true if the PSBT was finalized, or false otherwise.
///
/// The [`SignOptions`] can be used to tweak the behavior of the software signers, and the way
/// the transaction is finalized at the end. Note that it can't be guaranteed that *every*
/// signers will follow the options, but the "software signers" (WIF keys and `xprv`) defined
/// in this library will.
pub(crate) fn sign(
&self,
psbt: Arc<PartiallySignedTransaction>,
// sign_options: Option<SignOptions>,
) -> Result<bool, BdkError> {
let mut psbt = psbt.inner.lock().unwrap();
self.get_wallet().sign(
&mut psbt,
SignOptions::default(),
).map_err(|e| BdkError::Generic(e.to_string()))
}
}
pub struct Update(pub(crate) BdkUpdate);