diff --git a/bdk-ffi/Cargo.lock b/bdk-ffi/Cargo.lock index 48e8b10..3d4b5f5 100644 --- a/bdk-ffi/Cargo.lock +++ b/bdk-ffi/Cargo.lock @@ -165,6 +165,7 @@ dependencies = [ "bdk_esplora", "bdk_file_store", "bitcoin-internals", + "serde_json", "thiserror", "uniffi", ] diff --git a/bdk-ffi/Cargo.toml b/bdk-ffi/Cargo.toml index 78a4f7a..751c94c 100644 --- a/bdk-ffi/Cargo.toml +++ b/bdk-ffi/Cargo.toml @@ -26,6 +26,7 @@ bdk_file_store = { version = "0.11.0" } uniffi = { version = "=0.27.1" } bitcoin-internals = { version = "0.2.0", features = ["alloc"] } thiserror = "1.0.58" +serde_json = "1.0.116" [build-dependencies] uniffi = { version = "=0.27.1", features = ["build"] } diff --git a/bdk-ffi/src/bdk.udl b/bdk-ffi/src/bdk.udl index 1d81b34..cc4b061 100644 --- a/bdk-ffi/src/bdk.udl +++ b/bdk-ffi/src/bdk.udl @@ -657,6 +657,11 @@ interface Psbt { [Throws=PsbtError] u64 fee(); + + [Throws=PsbtError] + Psbt combine(Psbt other); + + string json_serialize(); }; dictionary OutPoint { diff --git a/bdk-ffi/src/bitcoin.rs b/bdk-ffi/src/bitcoin.rs index d994205..488243d 100644 --- a/bdk-ffi/src/bitcoin.rs +++ b/bdk-ffi/src/bitcoin.rs @@ -18,6 +18,7 @@ use bdk::bitcoin::TxIn as BdkTxIn; use bdk::bitcoin::Txid; use std::io::Cursor; +use std::ops::Deref; use std::str::FromStr; use std::sync::{Arc, Mutex}; @@ -230,19 +231,20 @@ impl Psbt { .map_err(PsbtError::from) } - // - // pub(crate) fn combine( - // &self, - // other: Arc, - // ) -> Result, > { - // let other_psbt = other.inner.lock().unwrap().clone(); - // let mut original_psbt = self.inner.lock().unwrap().clone(); - // - // original_psbt.combine(other_psbt)?; - // Ok(Arc::new(PartiallySignedTransaction { - // inner: Mutex::new(original_psbt), - // })) - // } + pub(crate) fn combine( + &self, + other: Arc, + ) -> Result, PsbtError> { + let mut original_psbt = self.0.lock().unwrap().clone(); + let other_psbt = other.0.lock().unwrap().clone(); + original_psbt.combine(other_psbt)?; + Ok(Arc::new(Psbt(Mutex::new(original_psbt)))) + } + + pub(crate) fn json_serialize(&self) -> String { + let psbt = self.0.lock().unwrap(); + serde_json::to_string(psbt.deref()).unwrap() + } } impl From for Psbt {