Skip to content

Commit 8892d6b

Browse files
glozowTheCharlatan
authored andcommitted
[refactor] remove access to mapTx from rpc/mempool.cpp
1 parent fad61aa commit 8892d6b

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

src/rpc/mempool.cpp

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -315,9 +315,7 @@ static void entryToJSON(const CTxMemPool& pool, UniValue& info, const CTxMemPool
315315
info.pushKV("depends", depends);
316316

317317
UniValue spent(UniValue::VARR);
318-
const CTxMemPool::txiter& it = pool.mapTx.find(tx.GetHash());
319-
const CTxMemPoolEntry::Children& children = it->GetMemPoolChildrenConst();
320-
for (const CTxMemPoolEntry& child : children) {
318+
for (const CTxMemPoolEntry& child : e.GetMemPoolChildrenConst()) {
321319
spent.push_back(child.GetTx().GetHash().ToString());
322320
}
323321

@@ -459,12 +457,12 @@ static RPCHelpMan getmempoolancestors()
459457
const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
460458
LOCK(mempool.cs);
461459

462-
CTxMemPool::txiter it = mempool.mapTx.find(hash);
463-
if (it == mempool.mapTx.end()) {
460+
const auto entry{mempool.GetEntry(Txid::FromUint256(hash))};
461+
if (entry == nullptr) {
464462
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not in mempool");
465463
}
466464

467-
auto ancestors{mempool.AssumeCalculateMemPoolAncestors(self.m_name, *it, CTxMemPool::Limits::NoLimits(), /*fSearchForParents=*/false)};
465+
auto ancestors{mempool.AssumeCalculateMemPoolAncestors(self.m_name, *entry, CTxMemPool::Limits::NoLimits(), /*fSearchForParents=*/false)};
468466

469467
if (!fVerbose) {
470468
UniValue o(UniValue::VARR);
@@ -520,15 +518,15 @@ static RPCHelpMan getmempooldescendants()
520518
const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
521519
LOCK(mempool.cs);
522520

523-
CTxMemPool::txiter it = mempool.mapTx.find(hash);
524-
if (it == mempool.mapTx.end()) {
521+
const auto it{mempool.GetIter(hash)};
522+
if (!it) {
525523
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not in mempool");
526524
}
527525

528526
CTxMemPool::setEntries setDescendants;
529-
mempool.CalculateDescendants(it, setDescendants);
527+
mempool.CalculateDescendants(*it, setDescendants);
530528
// CTxMemPool::CalculateDescendants will include the given tx
531-
setDescendants.erase(it);
529+
setDescendants.erase(*it);
532530

533531
if (!fVerbose) {
534532
UniValue o(UniValue::VARR);
@@ -572,14 +570,13 @@ static RPCHelpMan getmempoolentry()
572570
const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
573571
LOCK(mempool.cs);
574572

575-
CTxMemPool::txiter it = mempool.mapTx.find(hash);
576-
if (it == mempool.mapTx.end()) {
573+
const auto entry{mempool.GetEntry(Txid::FromUint256(hash))};
574+
if (entry == nullptr) {
577575
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not in mempool");
578576
}
579577

580-
const CTxMemPoolEntry &e = *it;
581578
UniValue info(UniValue::VOBJ);
582-
entryToJSON(mempool, info, e);
579+
entryToJSON(mempool, info, *entry);
583580
return info;
584581
},
585582
};

0 commit comments

Comments
 (0)