Skip to content

Commit 306b1cd

Browse files
committed
rpc: Add alt Ensure* functions acepting NodeContext
1 parent d7824ac commit 306b1cd

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

src/rpc/blockchain.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,34 +64,46 @@ NodeContext& EnsureNodeContext(const std::any& context)
6464
return *node_context;
6565
}
6666

67-
CTxMemPool& EnsureMemPool(const std::any& context)
67+
CTxMemPool& EnsureMemPool(const NodeContext& node)
6868
{
69-
const NodeContext& node = EnsureNodeContext(context);
7069
if (!node.mempool) {
7170
throw JSONRPCError(RPC_CLIENT_MEMPOOL_DISABLED, "Mempool disabled or instance not found");
7271
}
7372
return *node.mempool;
7473
}
7574

76-
ChainstateManager& EnsureChainman(const std::any& context)
75+
CTxMemPool& EnsureMemPool(const std::any& context)
76+
{
77+
return EnsureMemPool(EnsureNodeContext(context));
78+
}
79+
80+
ChainstateManager& EnsureChainman(const NodeContext& node)
7781
{
78-
const NodeContext& node = EnsureNodeContext(context);
7982
if (!node.chainman) {
8083
throw JSONRPCError(RPC_INTERNAL_ERROR, "Node chainman not found");
8184
}
8285
WITH_LOCK(::cs_main, CHECK_NONFATAL(std::addressof(g_chainman) == std::addressof(*node.chainman)));
8386
return *node.chainman;
8487
}
8588

86-
CBlockPolicyEstimator& EnsureFeeEstimator(const std::any& context)
89+
ChainstateManager& EnsureChainman(const std::any& context)
90+
{
91+
return EnsureChainman(EnsureNodeContext(context));
92+
}
93+
94+
CBlockPolicyEstimator& EnsureFeeEstimator(const NodeContext& node)
8795
{
88-
NodeContext& node = EnsureNodeContext(context);
8996
if (!node.fee_estimator) {
9097
throw JSONRPCError(RPC_INTERNAL_ERROR, "Fee estimation disabled");
9198
}
9299
return *node.fee_estimator;
93100
}
94101

102+
CBlockPolicyEstimator& EnsureFeeEstimator(const std::any& context)
103+
{
104+
return EnsureFeeEstimator(EnsureNodeContext(context));
105+
}
106+
95107
/* Calculate the difficulty for a given block index.
96108
*/
97109
double GetDifficulty(const CBlockIndex* blockindex)

src/rpc/blockchain.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,11 @@ void ScriptPubKeyToUniv(const CScript& scriptPubKey, UniValue& out, bool fInclud
5757
void TxToUniv(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, bool include_hex = true, int serialize_flags = 0, const CTxUndo* txundo = nullptr);
5858

5959
NodeContext& EnsureNodeContext(const std::any& context);
60+
CTxMemPool& EnsureMemPool(const NodeContext& node);
6061
CTxMemPool& EnsureMemPool(const std::any& context);
62+
ChainstateManager& EnsureChainman(const NodeContext& node);
6163
ChainstateManager& EnsureChainman(const std::any& context);
64+
CBlockPolicyEstimator& EnsureFeeEstimator(const NodeContext& node);
6265
CBlockPolicyEstimator& EnsureFeeEstimator(const std::any& context);
6366

6467
/**

0 commit comments

Comments
 (0)