| 149 | } |
| 150 | |
| 151 | uint256 GetPackageHash(const std::vector<CTransactionRef>& transactions) |
| 152 | { |
| 153 | // Create a vector of the wtxids. |
| 154 | std::vector<Wtxid> wtxids_copy; |
| 155 | std::transform(transactions.cbegin(), transactions.cend(), std::back_inserter(wtxids_copy), |
| 156 | [](const auto& tx){ return tx->GetWitnessHash(); }); |
| 157 | |
| 158 | // Sort in ascending order |
| 159 | std::sort(wtxids_copy.begin(), wtxids_copy.end(), [](const auto& lhs, const auto& rhs) { |
| 160 | return std::lexicographical_compare(std::make_reverse_iterator(lhs.end()), std::make_reverse_iterator(lhs.begin()), |
| 161 | std::make_reverse_iterator(rhs.end()), std::make_reverse_iterator(rhs.begin())); |
| 162 | }); |
| 163 | |
| 164 | // Get sha256 hash of the wtxids concatenated in this order |
| 165 | HashWriter hashwriter; |
| 166 | for (const auto& wtxid : wtxids_copy) { |
| 167 | hashwriter << wtxid; |
| 168 | } |
| 169 | return hashwriter.GetSHA256(); |
| 170 | } |