[refactor] Add helper for iterating through mempool entries

Instead of reaching into the mapTx data structure, use a helper method
that provides the required vector of CTxMemPoolEntry pointers.
This commit is contained in:
stickies-v
2023-11-09 17:51:20 +01:00
committed by TheCharlatan
parent d9007f51a7
commit 453b4813eb
5 changed files with 18 additions and 4 deletions

View File

@@ -344,14 +344,13 @@ UniValue MempoolToJSON(const CTxMemPool& pool, bool verbose, bool include_mempoo
}
LOCK(pool.cs);
UniValue o(UniValue::VOBJ);
for (const CTxMemPoolEntry& e : pool.mapTx) {
const uint256& hash = e.GetTx().GetHash();
for (const CTxMemPoolEntry& e : pool.entryAll()) {
UniValue info(UniValue::VOBJ);
entryToJSON(pool, info, e);
// Mempool has unique entries so there is no advantage in using
// UniValue::pushKV, which checks if the key already exists in O(N).
// UniValue::pushKVEnd is used instead which currently is O(1).
o.pushKVEnd(hash.ToString(), info);
o.pushKVEnd(e.GetTx().GetHash().ToString(), info);
}
return o;
} else {