From 2abccafb8f8aad750381f15bf1c9078842d7745e Mon Sep 17 00:00:00 2001 From: thunderbiscuit Date: Wed, 28 Sep 2022 16:27:07 -0400 Subject: [PATCH] Add `combine()` method on PSBT Closes #198 --- src/bdk.udl | 3 +++ src/lib.rs | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/bdk.udl b/src/bdk.udl index cf68b8a..e995080 100644 --- a/src/bdk.udl +++ b/src/bdk.udl @@ -210,6 +210,9 @@ interface PartiallySignedBitcoinTransaction { string serialize(); string txid(); + + [Throws=BdkError] + PartiallySignedBitcoinTransaction combine(PartiallySignedBitcoinTransaction other); }; interface TxBuilder { diff --git a/src/lib.rs b/src/lib.rs index b154556..8c5cd7e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -364,6 +364,22 @@ impl PartiallySignedBitcoinTransaction { let txid = tx.txid(); txid.to_hex() } + + /// Combines this PartiallySignedTransaction with other PSBT as described by BIP 174. + /// + /// In accordance with BIP 174 this function is commutative i.e., `A.combine(B) == B.combine(A)` + fn combine( + &self, + other: Arc, + ) -> Result, Error> { + let other_psbt = other.internal.lock().unwrap().clone(); + let mut original_psbt = self.internal.lock().unwrap().clone(); + + original_psbt.combine(other_psbt)?; + Ok(Arc::new(PartiallySignedBitcoinTransaction { + internal: Mutex::new(original_psbt), + })) + } } /// A Bitcoin wallet.