Skip to content

Commit

Permalink
Added finalize
Browse files Browse the repository at this point in the history
  • Loading branch information
www committed Jul 31, 2024
1 parent 3454331 commit fdb5f74
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions bdk-ffi/src/bdk.udl
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ interface PersistenceError {
[Error]
interface PsbtError {
InvalidMagic();
FinalizeError();
MissingUtxo();
InvalidSeparator();
PsbtUtxoOutOfBounds();
Expand Down Expand Up @@ -686,6 +687,9 @@ interface Psbt {
[Throws=PsbtError]
Psbt combine(Psbt other);

[Throws=PsbtError]
Psbt finalize();

string json_serialize();
};

Expand Down
17 changes: 17 additions & 0 deletions bdk-ffi/src/bitcoin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ use bdk_wallet::bitcoin::Transaction as BdkTransaction;
use bdk_wallet::bitcoin::TxIn as BdkTxIn;
use bdk_wallet::bitcoin::TxOut as BdkTxOut;
use bdk_wallet::bitcoin::Txid;
use bdk_wallet::miniscript::psbt::PsbtExt as MiniscriptPsbtExt;
use bdk_wallet::bitcoin::secp256k1::Secp256k1;

use std::fmt::Display;
use std::ops::Deref;
Expand Down Expand Up @@ -223,6 +225,21 @@ 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::FinalizeError)
}
}
}



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
3 changes: 3 additions & 0 deletions bdk-ffi/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,9 @@ pub enum PsbtError {
#[error("invalid magic")]
InvalidMagic,

#[error("finalize error with errors")]
FinalizeError,

#[error("UTXO information is not present in PSBT")]
MissingUtxo,

Expand Down

0 comments on commit fdb5f74

Please sign in to comment.