From b39c86ae60663df683ce8101d27e1ce292996ebe Mon Sep 17 00:00:00 2001 From: Ava Chow Date: Mon, 22 Jul 2024 17:14:45 -0400 Subject: [PATCH] Allow specifying PSBT version in constructor The constructor will create the PSBT of the specified version, as long as it is 0 or 2. --- src/psbt.cpp | 4 +++- src/psbt.h | 2 +- src/rpc/rawtransaction.cpp | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/psbt.cpp b/src/psbt.cpp index 6109d943182..9967a8169b6 100644 --- a/src/psbt.cpp +++ b/src/psbt.cpp @@ -15,8 +15,10 @@ using common::PSBTError; -PartiallySignedTransaction::PartiallySignedTransaction(const CMutableTransaction& tx) +PartiallySignedTransaction::PartiallySignedTransaction(const CMutableTransaction& tx, uint32_t version) : m_version(version) { + assert(m_version == 0 || m_version == 2); + tx_version = tx.version; fallback_locktime = tx.nLockTime; inputs.reserve(tx.vin.size()); diff --git a/src/psbt.h b/src/psbt.h index efb1ee1f109..fce90a83fe3 100644 --- a/src/psbt.h +++ b/src/psbt.h @@ -1259,7 +1259,7 @@ public: std::optional ComputeTimeLock() const; std::optional GetUnsignedTx() const; std::optional GetUniqueID() const; - explicit PartiallySignedTransaction(const CMutableTransaction& tx); + explicit PartiallySignedTransaction(const CMutableTransaction& tx, uint32_t version = 0); template inline void Serialize(Stream& s) const { diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index dfabf073b15..539c24cd06b 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -1876,7 +1876,7 @@ static RPCMethod joinpsbts() CMutableTransaction tx; tx.version = best_version; tx.nLockTime = best_locktime; - PartiallySignedTransaction merged_psbt(tx); + PartiallySignedTransaction merged_psbt(tx, psbtxs.at(0).GetVersion()); // Merge for (auto& psbt : psbtxs) { @@ -1908,7 +1908,7 @@ static RPCMethod joinpsbts() std::shuffle(input_indices.begin(), input_indices.end(), FastRandomContext()); std::shuffle(output_indices.begin(), output_indices.end(), FastRandomContext()); - PartiallySignedTransaction shuffled_psbt(tx); + PartiallySignedTransaction shuffled_psbt(tx, merged_psbt.GetVersion()); for (int i : input_indices) { shuffled_psbt.AddInput(merged_psbt.inputs[i]); }