aboutsummaryrefslogtreecommitdiff
path: root/src/policy/packages.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/policy/packages.cpp')
-rw-r--r--src/policy/packages.cpp18
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();
+}