Allow specifying PSBT version in constructor

The constructor will create the PSBT of the specified version, as long
as it is 0 or 2.
This commit is contained in:
Ava Chow
2024-07-22 17:14:45 -04:00
parent dcc9a3c8df
commit b39c86ae60
3 changed files with 6 additions and 4 deletions

View File

@@ -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());

View File

@@ -1259,7 +1259,7 @@ public:
std::optional<uint32_t> ComputeTimeLock() const;
std::optional<CMutableTransaction> GetUnsignedTx() const;
std::optional<Txid> GetUniqueID() const;
explicit PartiallySignedTransaction(const CMutableTransaction& tx);
explicit PartiallySignedTransaction(const CMutableTransaction& tx, uint32_t version = 0);
template <typename Stream>
inline void Serialize(Stream& s) const {

View File

@@ -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]);
}