diff options
Diffstat (limited to 'src/policy/packages.cpp')
-rw-r--r-- | src/policy/packages.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/policy/packages.cpp b/src/policy/packages.cpp index 3a63a9fe46..693adcdfd0 100644 --- a/src/policy/packages.cpp +++ b/src/policy/packages.cpp @@ -147,3 +147,24 @@ 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 std::lexicographical_compare(std::make_reverse_iterator(lhs.end()), std::make_reverse_iterator(lhs.begin()), + std::make_reverse_iterator(rhs.end()), std::make_reverse_iterator(rhs.begin())); + }); + + // Get sha256 hash of the wtxids concatenated in this order + HashWriter hashwriter; + for (const auto& wtxid : wtxids_copy) { + hashwriter << wtxid; + } + return hashwriter.GetSHA256(); +} |