diff --git a/src/psbt.cpp b/src/psbt.cpp index e3246c7969..ecb791d606 100644 --- a/src/psbt.cpp +++ b/src/psbt.cpp @@ -24,7 +24,7 @@ bool PartiallySignedTransaction::IsNull() const bool PartiallySignedTransaction::Merge(const PartiallySignedTransaction& psbt) { // Prohibited to merge two PSBTs over different transactions - if (tx->GetHash() != psbt.tx->GetHash()) { + if (GetUniqueID() != psbt.GetUniqueID()) { return false; } @@ -108,6 +108,23 @@ CMutableTransaction PartiallySignedTransaction::GetUnsignedTx() const return mtx; } +uint256 PartiallySignedTransaction::GetUniqueID() const +{ + if (tx != nullopt) { + return tx->GetHash(); + } + + // Get the unsigned transaction + CMutableTransaction mtx = GetUnsignedTx(); + // Set the locktime to 0 + mtx.nLockTime = 0; + // Set the sequence numbers to 0 + for (CTxIn& txin : mtx.vin) { + txin.nSequence = 0; + } + return mtx.GetHash(); +} + bool PartiallySignedTransaction::AddInput(const CTxIn& txin, PSBTInput& psbtin) { if (std::find(tx->vin.begin(), tx->vin.end(), txin) != tx->vin.end()) { diff --git a/src/psbt.h b/src/psbt.h index 1396b28674..3855cab1b2 100644 --- a/src/psbt.h +++ b/src/psbt.h @@ -743,6 +743,7 @@ struct PartiallySignedTransaction void CacheUnsignedTxPieces(); bool ComputeTimeLock(uint32_t& locktime) const; CMutableTransaction GetUnsignedTx() const; + uint256 GetUniqueID() const; PartiallySignedTransaction() {} explicit PartiallySignedTransaction(const CMutableTransaction& tx);