feat: add json_serialize method on psbt type

This commit is contained in:
thunderbiscuit 2024-05-10 16:20:17 -04:00
parent 5ef2bf8a1e
commit 093eb1fc7e
No known key found for this signature in database
GPG Key ID: 88253696EB836462
4 changed files with 22 additions and 13 deletions

1
bdk-ffi/Cargo.lock generated
View File

@ -165,6 +165,7 @@ dependencies = [
"bdk_esplora",
"bdk_file_store",
"bitcoin-internals",
"serde_json",
"thiserror",
"uniffi",
]

View File

@ -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"] }

View File

@ -657,6 +657,11 @@ interface Psbt {
[Throws=PsbtError]
u64 fee();
[Throws=PsbtError]
Psbt combine(Psbt other);
string json_serialize();
};
dictionary OutPoint {

View File

@ -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<Psbt>,
// ) -> Result<Arc<Psbt>, > {
// 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<Psbt>,
) -> Result<Arc<Psbt>, 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<BdkPsbt> for Psbt {