mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-02 09:46:52 -05:00
Merge bitcoin/bitcoin#23936: rpc: Add and use EnsureArgsman helper
fa5bb37611
rpc: Use EnsureAnyArgsman in rpc/blockchain (MarcoFalke)fa98b6f644
rpc: Add EnsureArgsman helper (MarcoFalke) Pull request description: This refactor doesn't change anything for the rpc layer, but it helps a bit with removing gArgs (See #21005) ACKs for top commit: shaavan: Code Review ACKfa5bb37611
Tree-SHA512: 18f9cc90830a168acb94452b541b6e97ba9a50a0f4834698a16994c3884c833dc606e36a5538a16352e5e5cc43d3ac77cb498f877f8f5bc5dd52fa84f8bf2056
This commit is contained in:
commit
300124dedf
4 changed files with 25 additions and 9 deletions
|
@ -1544,6 +1544,7 @@ RPCHelpMan getblockchaininfo()
|
|||
},
|
||||
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||
{
|
||||
const ArgsManager& args{EnsureAnyArgsman(request.context)};
|
||||
ChainstateManager& chainman = EnsureAnyChainman(request.context);
|
||||
LOCK(cs_main);
|
||||
CChainState& active_chainstate = chainman.ActiveChainstate();
|
||||
|
@ -1574,7 +1575,7 @@ RPCHelpMan getblockchaininfo()
|
|||
obj.pushKV("pruneheight", block->nHeight);
|
||||
|
||||
// if 0, execution bypasses the whole if block.
|
||||
bool automatic_pruning = (gArgs.GetIntArg("-prune", 0) != 1);
|
||||
bool automatic_pruning{args.GetIntArg("-prune", 0) != 1};
|
||||
obj.pushKV("automatic_pruning", automatic_pruning);
|
||||
if (automatic_pruning) {
|
||||
obj.pushKV("prune_target_size", nPruneTarget);
|
||||
|
@ -2270,10 +2271,9 @@ static RPCHelpMan savemempool()
|
|||
},
|
||||
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||
{
|
||||
const ArgsManager& args{EnsureAnyArgsman(request.context)};
|
||||
const CTxMemPool& mempool = EnsureAnyMemPool(request.context);
|
||||
|
||||
const NodeContext& node = EnsureAnyNodeContext(request.context);
|
||||
|
||||
if (!mempool.IsLoaded()) {
|
||||
throw JSONRPCError(RPC_MISC_ERROR, "The mempool was not loaded yet");
|
||||
}
|
||||
|
@ -2283,7 +2283,7 @@ static RPCHelpMan savemempool()
|
|||
}
|
||||
|
||||
UniValue ret(UniValue::VOBJ);
|
||||
ret.pushKV("filename", fs::path((node.args->GetDataDirNet() / "mempool.dat")).u8string());
|
||||
ret.pushKV("filename", fs::path((args.GetDataDirNet() / "mempool.dat")).u8string());
|
||||
|
||||
return ret;
|
||||
},
|
||||
|
@ -2628,10 +2628,11 @@ static RPCHelpMan dumptxoutset()
|
|||
},
|
||||
[&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
|
||||
{
|
||||
const fs::path path = fsbridge::AbsPathJoin(gArgs.GetDataDirNet(), fs::u8path(request.params[0].get_str()));
|
||||
const ArgsManager& args{EnsureAnyArgsman(request.context)};
|
||||
const fs::path path = fsbridge::AbsPathJoin(args.GetDataDirNet(), fs::u8path(request.params[0].get_str()));
|
||||
// Write to a temporary path and then move into `path` on completion
|
||||
// to avoid confusion due to an interruption.
|
||||
const fs::path temppath = fsbridge::AbsPathJoin(gArgs.GetDataDirNet(), fs::u8path(request.params[0].get_str() + ".incomplete"));
|
||||
const fs::path temppath = fsbridge::AbsPathJoin(args.GetDataDirNet(), fs::u8path(request.params[0].get_str() + ".incomplete"));
|
||||
|
||||
if (fs::exists(path)) {
|
||||
throw JSONRPCError(
|
||||
|
|
|
@ -21,7 +21,6 @@ class CBlock;
|
|||
class CBlockIndex;
|
||||
class CChainState;
|
||||
class CTxMemPool;
|
||||
class ChainstateManager;
|
||||
class UniValue;
|
||||
struct NodeContext;
|
||||
|
||||
|
|
|
@ -37,6 +37,19 @@ CTxMemPool& EnsureAnyMemPool(const std::any& context)
|
|||
return EnsureMemPool(EnsureAnyNodeContext(context));
|
||||
}
|
||||
|
||||
ArgsManager& EnsureArgsman(const NodeContext& node)
|
||||
{
|
||||
if (!node.args) {
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Node args not found");
|
||||
}
|
||||
return *node.args;
|
||||
}
|
||||
|
||||
ArgsManager& EnsureAnyArgsman(const std::any& context)
|
||||
{
|
||||
return EnsureArgsman(EnsureAnyNodeContext(context));
|
||||
}
|
||||
|
||||
ChainstateManager& EnsureChainman(const NodeContext& node)
|
||||
{
|
||||
if (!node.chainman) {
|
||||
|
|
|
@ -7,16 +7,19 @@
|
|||
|
||||
#include <any>
|
||||
|
||||
class ArgsManager;
|
||||
class CBlockPolicyEstimator;
|
||||
class CConnman;
|
||||
class ChainstateManager;
|
||||
class CTxMemPool;
|
||||
struct NodeContext;
|
||||
class ChainstateManager;
|
||||
class PeerManager;
|
||||
struct NodeContext;
|
||||
|
||||
NodeContext& EnsureAnyNodeContext(const std::any& context);
|
||||
CTxMemPool& EnsureMemPool(const NodeContext& node);
|
||||
CTxMemPool& EnsureAnyMemPool(const std::any& context);
|
||||
ArgsManager& EnsureArgsman(const NodeContext& node);
|
||||
ArgsManager& EnsureAnyArgsman(const std::any& context);
|
||||
ChainstateManager& EnsureChainman(const NodeContext& node);
|
||||
ChainstateManager& EnsureAnyChainman(const std::any& context);
|
||||
CBlockPolicyEstimator& EnsureFeeEstimator(const NodeContext& node);
|
||||
|
|
Loading…
Add table
Reference in a new issue