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 finalize to Psbt #580

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions bdk-ffi/src/bdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,9 @@ interface Psbt {
[Throws=PsbtError]
Psbt combine(Psbt other);

[Throws=PsbtError]
Psbt finalize();

string json_serialize();
};

Expand Down
11 changes: 11 additions & 0 deletions bdk-ffi/src/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ use bdk_wallet::bitcoin::consensus::encode::serialize;
use bdk_wallet::bitcoin::consensus::Decodable;
use bdk_wallet::bitcoin::io::Cursor;
use bdk_wallet::bitcoin::psbt::ExtractTxError;
use bdk_wallet::bitcoin::secp256k1::Secp256k1;
use bdk_wallet::bitcoin::Address as BdkAddress;
use bdk_wallet::bitcoin::Network;
use bdk_wallet::bitcoin::Psbt as BdkPsbt;
use bdk_wallet::bitcoin::Transaction as BdkTransaction;
use bdk_wallet::bitcoin::TxIn as BdkTxIn;
use bdk_wallet::bitcoin::TxOut as BdkTxOut;
use bdk_wallet::miniscript::psbt::PsbtExt as MiniscriptPsbtExt;

use std::fmt::Display;
use std::ops::Deref;
Expand Down Expand Up @@ -166,6 +168,15 @@ impl Psbt {
psbt.to_string()
}

pub(crate) fn finalize(&self) -> Result<Arc<Psbt>, PsbtError> {
let secp = Secp256k1::new();
let result = self.0.lock().unwrap().clone().finalize(&secp);
match result {
Ok(psbt) => Ok(Arc::new(Psbt::from(psbt))),
Err((_psbt, _errors)) => Err(PsbtError::OtherPsbtErr),
}
}

pub(crate) fn extract_tx(&self) -> Result<Arc<Transaction>, ExtractTxError> {
let tx: BdkTransaction = self.0.lock().unwrap().clone().extract_tx()?;
let transaction: Transaction = tx.into();
Expand Down
Loading