Skip to content

Commit a316e9c

Browse files
committed
refactor: add unused ArgsManager to replace gArgs
1 parent 2f71a1e commit a316e9c

File tree

10 files changed

+28
-23
lines changed

10 files changed

+28
-23
lines changed

src/bitcoin-cli.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ static const int CONTINUE_EXECUTION=-1;
4343
/** Default number of blocks to generate for RPC generatetoaddress. */
4444
static const std::string DEFAULT_NBLOCKS = "1";
4545

46-
static void SetupCliArgs()
46+
static void SetupCliArgs(ArgsManager& argsman)
4747
{
48-
SetupHelpOptions(gArgs);
48+
SetupHelpOptions(argsman);
4949

5050
const auto defaultBaseParams = CreateBaseChainParams(CBaseChainParams::MAIN);
5151
const auto testnetBaseParams = CreateBaseChainParams(CBaseChainParams::TESTNET);
@@ -56,7 +56,7 @@ static void SetupCliArgs()
5656
gArgs.AddArg("-datadir=<dir>", "Specify data directory", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
5757
gArgs.AddArg("-generate", strprintf("Generate blocks immediately, equivalent to RPC generatenewaddress followed by RPC generatetoaddress. Optional positional integer arguments are number of blocks to generate (default: %s) and maximum iterations to try (default: %s), equivalent to RPC generatetoaddress nblocks and maxtries arguments. Example: bitcoin-cli -generate 4 1000", DEFAULT_NBLOCKS, DEFAULT_MAX_TRIES), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
5858
gArgs.AddArg("-getinfo", "Get general information from the remote server. Note that unlike server-side RPC calls, the results of -getinfo is the result of multiple non-atomic requests. Some entries in the result may represent results from different states (e.g. wallet balance may be as of a different block from the chain state reported)", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
59-
SetupChainParamsBaseOptions();
59+
SetupChainParamsBaseOptions(argsman);
6060
gArgs.AddArg("-named", strprintf("Pass named instead of positional arguments (default: %s)", DEFAULT_NAMED), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
6161
gArgs.AddArg("-rpcclienttimeout=<n>", strprintf("Timeout in seconds during HTTP requests, or 0 for no timeout. (default: %d)", DEFAULT_HTTP_CLIENT_TIMEOUT), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
6262
gArgs.AddArg("-rpcconnect=<ip>", strprintf("Send commands to node running on <ip> (default: %s)", DEFAULT_RPCCONNECT), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
@@ -111,7 +111,7 @@ static int AppInitRPC(int argc, char* argv[])
111111
//
112112
// Parameters
113113
//
114-
SetupCliArgs();
114+
SetupCliArgs(gArgs);
115115
std::string error;
116116
if (!gArgs.ParseParameters(argc, argv, error)) {
117117
tfm::format(std::cerr, "Error parsing command line arguments: %s\n", error);

src/bitcoin-tx.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,14 @@ static const int CONTINUE_EXECUTION=-1;
3636

3737
const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;
3838

39-
static void SetupBitcoinTxArgs()
39+
static void SetupBitcoinTxArgs(ArgsManager &argsman)
4040
{
41-
SetupHelpOptions(gArgs);
41+
SetupHelpOptions(argsman);
4242

4343
gArgs.AddArg("-create", "Create new, empty TX.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
4444
gArgs.AddArg("-json", "Select JSON output", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
4545
gArgs.AddArg("-txid", "Output only the hex-encoded transaction id of the resultant transaction.", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
46-
SetupChainParamsBaseOptions();
46+
SetupChainParamsBaseOptions(argsman);
4747

4848
gArgs.AddArg("delin=N", "Delete input N from TX", ArgsManager::ALLOW_ANY, OptionsCategory::COMMANDS);
4949
gArgs.AddArg("delout=N", "Delete output N from TX", ArgsManager::ALLOW_ANY, OptionsCategory::COMMANDS);
@@ -81,7 +81,7 @@ static int AppInitRawTx(int argc, char* argv[])
8181
//
8282
// Parameters
8383
//
84-
SetupBitcoinTxArgs();
84+
SetupBitcoinTxArgs(gArgs);
8585
std::string error;
8686
if (!gArgs.ParseParameters(argc, argv, error)) {
8787
tfm::format(std::cerr, "Error parsing command line arguments: %s\n", error);

src/bitcoin-wallet.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;
2020
UrlDecodeFn* const URL_DECODE = nullptr;
2121

22-
static void SetupWalletToolArgs()
22+
static void SetupWalletToolArgs(ArgsManager& argsman)
2323
{
24-
SetupHelpOptions(gArgs);
25-
SetupChainParamsBaseOptions();
24+
SetupHelpOptions(argsman);
25+
SetupChainParamsBaseOptions(argsman);
2626

2727
gArgs.AddArg("-datadir=<dir>", "Specify data directory", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
2828
gArgs.AddArg("-wallet=<wallet-name>", "Specify wallet name", ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::OPTIONS);
@@ -36,7 +36,7 @@ static void SetupWalletToolArgs()
3636

3737
static bool WalletAppInit(int argc, char* argv[])
3838
{
39-
SetupWalletToolArgs();
39+
SetupWalletToolArgs(gArgs);
4040
std::string error_message;
4141
if (!gArgs.ParseParameters(argc, argv, error_message)) {
4242
tfm::format(std::cerr, "Error parsing command line arguments: %s\n", error_message);

src/chainparamsbase.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const std::string CBaseChainParams::MAIN = "main";
1515
const std::string CBaseChainParams::TESTNET = "test";
1616
const std::string CBaseChainParams::REGTEST = "regtest";
1717

18-
void SetupChainParamsBaseOptions()
18+
void SetupChainParamsBaseOptions(ArgsManager& argsman)
1919
{
2020
gArgs.AddArg("-chain=<chain>", "Use the chain <chain> (default: main). Allowed values: main, test, regtest", ArgsManager::ALLOW_ANY, OptionsCategory::CHAINPARAMS);
2121
gArgs.AddArg("-regtest", "Enter regression test mode, which uses a special chain in which blocks can be solved instantly. "

src/chainparamsbase.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <memory>
99
#include <string>
1010

11+
class ArgsManager;
12+
1113
/**
1214
* CBaseChainParams defines the base parameters (shared between bitcoin-cli and bitcoind)
1315
* of a given instance of the Bitcoin system.
@@ -43,7 +45,7 @@ std::unique_ptr<CBaseChainParams> CreateBaseChainParams(const std::string& chain
4345
/**
4446
*Set the arguments for chainparams
4547
*/
46-
void SetupChainParamsBaseOptions();
48+
void SetupChainParamsBaseOptions(ArgsManager& argsman);
4749

4850
/**
4951
* Return the currently selected parameters. This won't change after app

src/dummywallet.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ class DummyWalletInit : public WalletInitInterface {
2020
public:
2121

2222
bool HasWalletSupport() const override {return false;}
23-
void AddWalletOptions() const override;
23+
void AddWalletOptions(ArgsManager& argsman) const override;
2424
bool ParameterInteraction() const override {return true;}
2525
void Construct(NodeContext& node) const override {LogPrintf("No wallet support compiled in!\n");}
2626
};
2727

28-
void DummyWalletInit::AddWalletOptions() const
28+
void DummyWalletInit::AddWalletOptions(ArgsManager& argsman) const
2929
{
3030
gArgs.AddHiddenArgs({
3131
"-addresstype",

src/init.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ void SetupServerArgs(NodeContext& node)
369369
{
370370
assert(!node.args);
371371
node.args = &gArgs;
372+
ArgsManager& argsman = *node.args;
372373

373374
SetupHelpOptions(gArgs);
374375
gArgs.AddArg("-help-debug", "Print help message with debugging options and exit", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST); // server-only for now
@@ -478,7 +479,7 @@ void SetupServerArgs(NodeContext& node)
478479
"CIDR-notated network (e.g. 1.2.3.0/24). Uses the same permissions as "
479480
"-whitebind. Can be specified multiple times." , ArgsManager::ALLOW_ANY, OptionsCategory::CONNECTION);
480481

481-
g_wallet_init_interface.AddWalletOptions();
482+
g_wallet_init_interface.AddWalletOptions(argsman);
482483

483484
#if ENABLE_ZMQ
484485
gArgs.AddArg("-zmqpubhashblock=<address>", "Enable publish hash block in <address>", ArgsManager::ALLOW_ANY, OptionsCategory::ZMQ);
@@ -534,7 +535,7 @@ void SetupServerArgs(NodeContext& node)
534535
gArgs.AddArg("-shrinkdebugfile", "Shrink debug.log file on client startup (default: 1 when no -debug)", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
535536
gArgs.AddArg("-uacomment=<cmt>", "Append comment to the user agent string", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
536537

537-
SetupChainParamsBaseOptions();
538+
SetupChainParamsBaseOptions(argsman);
538539

539540
gArgs.AddArg("-acceptnonstdtxn", strprintf("Relay and mine \"non-standard\" transactions (%sdefault: %u)", "testnet/regtest only; ", !testnetChainParams->RequireStandard()), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::NODE_RELAY);
540541
gArgs.AddArg("-incrementalrelayfee=<amt>", strprintf("Fee rate (in %s/kB) used to define cost of relay, used for mempool limiting and BIP 125 replacement. (default: %s)", CURRENCY_UNIT, FormatMoney(DEFAULT_INCREMENTAL_RELAY_FEE)), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::NODE_RELAY);

src/qt/bitcoin.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ WId BitcoinApplication::getMainWinId() const
411411
return window->winId();
412412
}
413413

414-
static void SetupUIArgs()
414+
static void SetupUIArgs(ArgsManager& argsman)
415415
{
416416
gArgs.AddArg("-choosedatadir", strprintf("Choose data directory on startup (default: %u)", DEFAULT_CHOOSE_DATADIR), ArgsManager::ALLOW_ANY, OptionsCategory::GUI);
417417
gArgs.AddArg("-lang=<lang>", "Set language, for example \"de_DE\" (default: system locale)", ArgsManager::ALLOW_ANY, OptionsCategory::GUI);
@@ -454,7 +454,7 @@ int GuiMain(int argc, char* argv[])
454454
/// 2. Parse command-line options. We do this after qt in order to show an error if there are problems parsing these
455455
// Command-line options take precedence:
456456
node->setupServerArgs();
457-
SetupUIArgs();
457+
SetupUIArgs(gArgs);
458458
std::string error;
459459
if (!node->parseParameters(argc, argv, error)) {
460460
node->initError(strprintf(Untranslated("Error parsing command line arguments: %s\n"), error));

src/wallet/init.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class WalletInit : public WalletInitInterface
2424
bool HasWalletSupport() const override {return true;}
2525

2626
//! Return the wallets help message.
27-
void AddWalletOptions() const override;
27+
void AddWalletOptions(ArgsManager& argsman) const override;
2828

2929
//! Wallets parameter interaction
3030
bool ParameterInteraction() const override;
@@ -35,7 +35,7 @@ class WalletInit : public WalletInitInterface
3535

3636
const WalletInitInterface& g_wallet_init_interface = WalletInit();
3737

38-
void WalletInit::AddWalletOptions() const
38+
void WalletInit::AddWalletOptions(ArgsManager& argsman) const
3939
{
4040
gArgs.AddArg("-addresstype", strprintf("What type of addresses to use (\"legacy\", \"p2sh-segwit\", or \"bech32\", default: \"%s\")", FormatOutputType(DEFAULT_ADDRESS_TYPE)), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
4141
gArgs.AddArg("-avoidpartialspends", strprintf("Group outputs by address, selecting all or none, instead of selecting on a per-output basis. Privacy is improved as an address is only used once (unless someone sends to it after spending from it), but may result in slightly higher fees as suboptimal coin selection may result due to the added limitation (default: %u (always enabled for wallets with \"avoid_reuse\" enabled))", DEFAULT_AVOIDPARTIALSPENDS), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);

src/walletinitinterface.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
#ifndef BITCOIN_WALLETINITINTERFACE_H
66
#define BITCOIN_WALLETINITINTERFACE_H
77

8+
class ArgsManager;
9+
810
struct NodeContext;
911

1012
class WalletInitInterface {
1113
public:
1214
/** Is the wallet component enabled */
1315
virtual bool HasWalletSupport() const = 0;
1416
/** Get wallet help string */
15-
virtual void AddWalletOptions() const = 0;
17+
virtual void AddWalletOptions(ArgsManager& argsman) const = 0;
1618
/** Check wallet parameter interaction */
1719
virtual bool ParameterInteraction() const = 0;
1820
/** Add wallets that should be opened to list of chain clients. */

0 commit comments

Comments
 (0)