Add combine() method on PSBT

Closes #198
This commit is contained in:
thunderbiscuit 2022-09-28 16:27:07 -04:00
parent 75d0415bec
commit 2abccafb8f
No known key found for this signature in database
GPG Key ID: 88253696EB836462
2 changed files with 19 additions and 0 deletions

View File

@ -210,6 +210,9 @@ interface PartiallySignedBitcoinTransaction {
string serialize();
string txid();
[Throws=BdkError]
PartiallySignedBitcoinTransaction combine(PartiallySignedBitcoinTransaction other);
};
interface TxBuilder {

View File

@ -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<PartiallySignedBitcoinTransaction>,
) -> Result<Arc<PartiallySignedBitcoinTransaction>, 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.