From fab9ae8ae561f0247022cc46b7c3c24180e0a8fe Mon Sep 17 00:00:00 2001 From: Steve Myers Date: Tue, 4 Apr 2023 15:09:37 -0500 Subject: [PATCH] Add PartiallySignedTransaction.json_serialize() function --- api-docs/kotlin/src/main/kotlin/org/bitcoindevkit/bdk.kt | 3 +++ bdk-ffi/src/bdk.udl | 2 ++ bdk-ffi/src/psbt.rs | 8 ++++++++ 3 files changed, 13 insertions(+) diff --git a/api-docs/kotlin/src/main/kotlin/org/bitcoindevkit/bdk.kt b/api-docs/kotlin/src/main/kotlin/org/bitcoindevkit/bdk.kt index 6ac135a..05ff215 100644 --- a/api-docs/kotlin/src/main/kotlin/org/bitcoindevkit/bdk.kt +++ b/api-docs/kotlin/src/main/kotlin/org/bitcoindevkit/bdk.kt @@ -369,6 +369,9 @@ class PartiallySignedTransaction(psbtBase64: String) { * In accordance with BIP 174 this function is commutative i.e., `A.combine(B) == B.combine(A)` */ fun combine(other: PartiallySignedTransaction): PartiallySignedTransaction + + /** Serialize the PSBT data structure as a String of JSON. */ + fun jsonSerialize(): String } /** diff --git a/bdk-ffi/src/bdk.udl b/bdk-ffi/src/bdk.udl index 032af86..e10d911 100644 --- a/bdk-ffi/src/bdk.udl +++ b/bdk-ffi/src/bdk.udl @@ -307,6 +307,8 @@ interface PartiallySignedTransaction { u64? fee_amount(); FeeRate? fee_rate(); + + string json_serialize(); }; dictionary TxBuilderResult { diff --git a/bdk-ffi/src/psbt.rs b/bdk-ffi/src/psbt.rs index 8741e6e..9529c77 100644 --- a/bdk-ffi/src/psbt.rs +++ b/bdk-ffi/src/psbt.rs @@ -1,6 +1,8 @@ use bdk::bitcoin::hashes::hex::ToHex; use bdk::bitcoin::util::psbt::PartiallySignedTransaction as BdkPartiallySignedTransaction; +use bdk::bitcoincore_rpc::jsonrpc::serde_json; use bdk::psbt::PsbtUtils; +use std::ops::Deref; use std::str::FromStr; use std::sync::{Arc, Mutex}; @@ -66,6 +68,12 @@ impl PartiallySignedTransaction { pub(crate) fn fee_rate(&self) -> Option> { self.internal.lock().unwrap().fee_rate().map(Arc::new) } + + /// Serialize the PSBT data structure as a String of JSON. + pub(crate) fn json_serialize(&self) -> String { + let psbt = self.internal.lock().unwrap(); + serde_json::to_string(psbt.deref()).unwrap() + } } // The goal of these tests to to ensure `bdk-ffi` intermediate code correctly calls `bdk` APIs.