mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-04-17 02:57:33 +02:00
[txpackages] add canonical way to get hash of package
This commit is contained in:
@@ -147,3 +147,21 @@ bool IsChildWithParentsTree(const Package& package)
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
uint256 GetPackageHash(const std::vector<CTransactionRef>& transactions)
|
||||
{
|
||||
// Create a vector of the wtxids.
|
||||
std::vector<Wtxid> wtxids_copy;
|
||||
std::transform(transactions.cbegin(), transactions.cend(), std::back_inserter(wtxids_copy),
|
||||
[](const auto& tx){ return tx->GetWitnessHash(); });
|
||||
|
||||
// Sort in ascending order
|
||||
std::sort(wtxids_copy.begin(), wtxids_copy.end(), [](const auto& lhs, const auto& rhs) { return lhs.GetHex() < rhs.GetHex(); });
|
||||
|
||||
// Get sha256 hash of the wtxids concatenated in this order
|
||||
HashWriter hashwriter;
|
||||
for (const auto& wtxid : wtxids_copy) {
|
||||
hashwriter << wtxid;
|
||||
}
|
||||
return hashwriter.GetSHA256();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user