aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorglozow <gloriajzhao@gmail.com>2023-08-30 12:29:56 +0100
committerTheCharlatan <seb.kung@gmail.com>2023-11-10 16:44:32 +0100
commit8892d6b744e3cbda2cf93721f573ffa7017bd898 (patch)
tree83a75513dda4ef587750b3f2a4770403cd72d430
parentfad61aa56189f98d97af1d6f70c4eb46b8f98bf0 (diff)
downloadbitcoin-8892d6b744e3cbda2cf93721f573ffa7017bd898.tar.xz
[refactor] remove access to mapTx from rpc/mempool.cpp
-rw-r--r--src/rpc/mempool.cpp25
1 files changed, 11 insertions, 14 deletions
diff --git a/src/rpc/mempool.cpp b/src/rpc/mempool.cpp
index a97bf0b112..dbef5b0764 100644
--- a/src/rpc/mempool.cpp
+++ b/src/rpc/mempool.cpp
@@ -315,9 +315,7 @@ static void entryToJSON(const CTxMemPool& pool, UniValue& info, const CTxMemPool
info.pushKV("depends", depends);
UniValue spent(UniValue::VARR);
- const CTxMemPool::txiter& it = pool.mapTx.find(tx.GetHash());
- const CTxMemPoolEntry::Children& children = it->GetMemPoolChildrenConst();
- for (const CTxMemPoolEntry& child : children) {
+ for (const CTxMemPoolEntry& child : e.GetMemPoolChildrenConst()) {
spent.push_back(child.GetTx().GetHash().ToString());
}
@@ -459,12 +457,12 @@ static RPCHelpMan getmempoolancestors()
const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
LOCK(mempool.cs);
- CTxMemPool::txiter it = mempool.mapTx.find(hash);
- if (it == mempool.mapTx.end()) {
+ const auto entry{mempool.GetEntry(Txid::FromUint256(hash))};
+ if (entry == nullptr) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not in mempool");
}
- auto ancestors{mempool.AssumeCalculateMemPoolAncestors(self.m_name, *it, CTxMemPool::Limits::NoLimits(), /*fSearchForParents=*/false)};
+ auto ancestors{mempool.AssumeCalculateMemPoolAncestors(self.m_name, *entry, CTxMemPool::Limits::NoLimits(), /*fSearchForParents=*/false)};
if (!fVerbose) {
UniValue o(UniValue::VARR);
@@ -520,15 +518,15 @@ static RPCHelpMan getmempooldescendants()
const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
LOCK(mempool.cs);
- CTxMemPool::txiter it = mempool.mapTx.find(hash);
- if (it == mempool.mapTx.end()) {
+ const auto it{mempool.GetIter(hash)};
+ if (!it) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not in mempool");
}
CTxMemPool::setEntries setDescendants;
- mempool.CalculateDescendants(it, setDescendants);
+ mempool.CalculateDescendants(*it, setDescendants);
// CTxMemPool::CalculateDescendants will include the given tx
- setDescendants.erase(it);
+ setDescendants.erase(*it);
if (!fVerbose) {
UniValue o(UniValue::VARR);
@@ -572,14 +570,13 @@ static RPCHelpMan getmempoolentry()
const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
LOCK(mempool.cs);
- CTxMemPool::txiter it = mempool.mapTx.find(hash);
- if (it == mempool.mapTx.end()) {
+ const auto entry{mempool.GetEntry(Txid::FromUint256(hash))};
+ if (entry == nullptr) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Transaction not in mempool");
}
- const CTxMemPoolEntry &e = *it;
UniValue info(UniValue::VOBJ);
- entryToJSON(mempool, info, e);
+ entryToJSON(mempool, info, *entry);
return info;
},
};