| 117 | } |
| 118 | |
| 119 | bool IsChildWithParents(const Package& package) |
| 120 | { |
| 121 | assert(std::all_of(package.cbegin(), package.cend(), [](const auto& tx){return tx != nullptr;})); |
| 122 | if (package.size() < 2) return false; |
| 123 | |
| 124 | // The package is expected to be sorted, so the last transaction is the child. |
| 125 | const auto& child = package.back(); |
| 126 | std::unordered_set<Txid, SaltedTxidHasher> input_txids; |
| 127 | std::transform(child->vin.cbegin(), child->vin.cend(), |
| 128 | std::inserter(input_txids, input_txids.end()), |
| 129 | [](const auto& input) { return input.prevout.hash; }); |
| 130 | |
| 131 | // Every transaction must be a parent of the last transaction in the package. |
| 132 | return std::all_of(package.cbegin(), package.cend() - 1, |
| 133 | [&input_txids](const auto& ptx) { return input_txids.contains(ptx->GetHash()); }); |
| 134 | } |
| 135 | |
| 136 | bool IsChildWithParentsTree(const Package& package) |
| 137 | { |