mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-20 13:37:28 +02:00
Add PSBT::GetUniqueID
The unique ID for PSBTv2 is different from v0. Use this function to get the ID without requiring the caller to know the version number.
This commit is contained in:
parent
32bdf2d97e
commit
bd1a57bd80
2 changed files with 19 additions and 1 deletions
19
src/psbt.cpp
19
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()) {
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue