From fdb5f74d5832cb684a0b1a7dbb70c9beef45bf10 Mon Sep 17 00:00:00 2001 From: A Date: Wed, 31 Jul 2024 21:09:29 +0200 Subject: [PATCH] Added finalize --- bdk-ffi/src/bdk.udl | 4 ++++ bdk-ffi/src/bitcoin.rs | 17 +++++++++++++++++ bdk-ffi/src/error.rs | 3 +++ 3 files changed, 24 insertions(+) diff --git a/bdk-ffi/src/bdk.udl b/bdk-ffi/src/bdk.udl index bacb8756..b88bae8d 100644 --- a/bdk-ffi/src/bdk.udl +++ b/bdk-ffi/src/bdk.udl @@ -179,6 +179,7 @@ interface PersistenceError { [Error] interface PsbtError { InvalidMagic(); + FinalizeError(); MissingUtxo(); InvalidSeparator(); PsbtUtxoOutOfBounds(); @@ -686,6 +687,9 @@ interface Psbt { [Throws=PsbtError] Psbt combine(Psbt other); + [Throws=PsbtError] + Psbt finalize(); + string json_serialize(); }; diff --git a/bdk-ffi/src/bitcoin.rs b/bdk-ffi/src/bitcoin.rs index 8f56d3de..fafbf307 100644 --- a/bdk-ffi/src/bitcoin.rs +++ b/bdk-ffi/src/bitcoin.rs @@ -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; @@ -223,6 +225,21 @@ impl Psbt { psbt.to_string() } + pub(crate) fn finalize(&self) -> Result, 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, ExtractTxError> { let tx: BdkTransaction = self.0.lock().unwrap().clone().extract_tx()?; let transaction: Transaction = tx.into(); diff --git a/bdk-ffi/src/error.rs b/bdk-ffi/src/error.rs index 30353222..19edfe11 100644 --- a/bdk-ffi/src/error.rs +++ b/bdk-ffi/src/error.rs @@ -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,