| 62 | } |
| 63 | |
| 64 | bool IsChildWithParents(const Package& package) |
| 65 | { |
| 66 | assert(std::all_of(package.cbegin(), package.cend(), [](const auto& tx){return tx != nullptr;})); |
| 67 | if (package.size() < 2) return false; |
| 68 | |
| 69 | // The package is expected to be sorted, so the last transaction is the child. |
| 70 | const auto& child = package.back(); |
| 71 | std::unordered_set<uint256, SaltedTxidHasher> input_txids; |
| 72 | std::transform(child->vin.cbegin(), child->vin.cend(), |
| 73 | std::inserter(input_txids, input_txids.end()), |
| 74 | [](const auto& input) { return input.prevout.hash; }); |
| 75 | |
| 76 | // Every transaction must be a parent of the last transaction in the package. |
| 77 | return std::all_of(package.cbegin(), package.cend() - 1, |
| 78 | [&input_txids](const auto& ptx) { return input_txids.count(ptx->GetHash()) > 0; }); |
| 79 | } |