diff options
author | Carl Dong <contact@carldong.me> | 2021-04-12 18:25:13 -0400 |
---|---|---|
committer | Carl Dong <contact@carldong.me> | 2021-04-12 18:25:13 -0400 |
commit | 306b1cd3eeb2502904ed4698646d2c86d028aad2 (patch) | |
tree | ffb56a87c99acefbeb59d19d1007d6a27f03e18b /src/rpc/blockchain.cpp | |
parent | d7824acdb9b18fe8f151771a83ccae1681f16c66 (diff) |
rpc: Add alt Ensure* functions acepting NodeContext
Diffstat (limited to 'src/rpc/blockchain.cpp')
-rw-r--r-- | src/rpc/blockchain.cpp | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index ffabca0aff..cc7a29ffdb 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -64,18 +64,21 @@ NodeContext& EnsureNodeContext(const std::any& context) return *node_context; } -CTxMemPool& EnsureMemPool(const std::any& context) +CTxMemPool& EnsureMemPool(const NodeContext& node) { - const NodeContext& node = EnsureNodeContext(context); if (!node.mempool) { throw JSONRPCError(RPC_CLIENT_MEMPOOL_DISABLED, "Mempool disabled or instance not found"); } return *node.mempool; } -ChainstateManager& EnsureChainman(const std::any& context) +CTxMemPool& EnsureMemPool(const std::any& context) +{ + return EnsureMemPool(EnsureNodeContext(context)); +} + +ChainstateManager& EnsureChainman(const NodeContext& node) { - const NodeContext& node = EnsureNodeContext(context); if (!node.chainman) { throw JSONRPCError(RPC_INTERNAL_ERROR, "Node chainman not found"); } @@ -83,15 +86,24 @@ ChainstateManager& EnsureChainman(const std::any& context) return *node.chainman; } -CBlockPolicyEstimator& EnsureFeeEstimator(const std::any& context) +ChainstateManager& EnsureChainman(const std::any& context) +{ + return EnsureChainman(EnsureNodeContext(context)); +} + +CBlockPolicyEstimator& EnsureFeeEstimator(const NodeContext& node) { - NodeContext& node = EnsureNodeContext(context); if (!node.fee_estimator) { throw JSONRPCError(RPC_INTERNAL_ERROR, "Fee estimation disabled"); } return *node.fee_estimator; } +CBlockPolicyEstimator& EnsureFeeEstimator(const std::any& context) +{ + return EnsureFeeEstimator(EnsureNodeContext(context)); +} + /* Calculate the difficulty for a given block index. */ double GetDifficulty(const CBlockIndex* blockindex) |