Add PartiallySignedTransaction.json_serialize() function

This commit is contained in:
Steve Myers 2023-04-04 15:09:37 -05:00 committed by thunderbiscuit
parent 478b12c489
commit fab9ae8ae5
No known key found for this signature in database
GPG Key ID: 88253696EB836462
3 changed files with 13 additions and 0 deletions

View File

@ -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
}
/**

View File

@ -307,6 +307,8 @@ interface PartiallySignedTransaction {
u64? fee_amount();
FeeRate? fee_rate();
string json_serialize();
};
dictionary TxBuilderResult {

View File

@ -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<Arc<FeeRate>> {
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.