diff options
author | glozow <gloriajzhao@gmail.com> | 2024-04-16 11:58:25 +0100 |
---|---|---|
committer | glozow <gloriajzhao@gmail.com> | 2024-04-26 10:28:27 +0100 |
commit | 092c978a42e8f4a02291b994713505ba8aac8b28 (patch) | |
tree | 7e267f6faf0fe2aae3eb9a30a472720cecac952d /src/policy/packages.cpp | |
parent | c3c1e15831c463df7968b028a77e787da7e6256d (diff) | |
download | bitcoin-092c978a42e8f4a02291b994713505ba8aac8b28.tar.xz |
[txpackages] add canonical way to get hash of package
Diffstat (limited to 'src/policy/packages.cpp')
-rw-r--r-- | src/policy/packages.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/policy/packages.cpp b/src/policy/packages.cpp index 3a63a9fe46..99d2a6d514 100644 --- a/src/policy/packages.cpp +++ b/src/policy/packages.cpp @@ -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(); +} |