Skip to content

Commit fac05cc

Browse files
author
MarcoFalke
committed
wallet: [refactor] Pass ArgsManager to WalletAppInit
1 parent 7f653c3 commit fac05cc

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

src/bitcoin-wallet.cpp

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,52 +40,53 @@ static void SetupWalletToolArgs(ArgsManager& argsman)
4040
argsman.AddArg("createfromdump", "Create new wallet file from dumped records", ArgsManager::ALLOW_ANY, OptionsCategory::COMMANDS);
4141
}
4242

43-
static bool WalletAppInit(int argc, char* argv[])
43+
static bool WalletAppInit(ArgsManager& args, int argc, char* argv[])
4444
{
45-
SetupWalletToolArgs(gArgs);
45+
SetupWalletToolArgs(args);
4646
std::string error_message;
47-
if (!gArgs.ParseParameters(argc, argv, error_message)) {
47+
if (!args.ParseParameters(argc, argv, error_message)) {
4848
tfm::format(std::cerr, "Error parsing command line arguments: %s\n", error_message);
4949
return false;
5050
}
51-
if (argc < 2 || HelpRequested(gArgs) || gArgs.IsArgSet("-version")) {
51+
if (argc < 2 || HelpRequested(args) || args.IsArgSet("-version")) {
5252
std::string strUsage = strprintf("%s bitcoin-wallet version", PACKAGE_NAME) + " " + FormatFullVersion() + "\n";
53-
if (!gArgs.IsArgSet("-version")) {
54-
strUsage += "\n"
55-
"bitcoin-wallet is an offline tool for creating and interacting with " PACKAGE_NAME " wallet files.\n"
56-
"By default bitcoin-wallet will act on wallets in the default mainnet wallet directory in the datadir.\n"
57-
"To change the target wallet, use the -datadir, -wallet and -testnet/-regtest arguments.\n\n"
58-
"Usage:\n"
59-
" bitcoin-wallet [options] <command>\n";
60-
strUsage += "\n" + gArgs.GetHelpMessage();
61-
}
53+
if (!args.IsArgSet("-version")) {
54+
strUsage += "\n"
55+
"bitcoin-wallet is an offline tool for creating and interacting with " PACKAGE_NAME " wallet files.\n"
56+
"By default bitcoin-wallet will act on wallets in the default mainnet wallet directory in the datadir.\n"
57+
"To change the target wallet, use the -datadir, -wallet and -testnet/-regtest arguments.\n\n"
58+
"Usage:\n"
59+
" bitcoin-wallet [options] <command>\n";
60+
strUsage += "\n" + args.GetHelpMessage();
61+
}
6262
tfm::format(std::cout, "%s", strUsage);
6363
return false;
6464
}
6565

6666
// check for printtoconsole, allow -debug
67-
LogInstance().m_print_to_console = gArgs.GetBoolArg("-printtoconsole", gArgs.GetBoolArg("-debug", false));
67+
LogInstance().m_print_to_console = args.GetBoolArg("-printtoconsole", args.GetBoolArg("-debug", false));
6868

6969
if (!CheckDataDirOption()) {
70-
tfm::format(std::cerr, "Error: Specified data directory \"%s\" does not exist.\n", gArgs.GetArg("-datadir", ""));
70+
tfm::format(std::cerr, "Error: Specified data directory \"%s\" does not exist.\n", args.GetArg("-datadir", ""));
7171
return false;
7272
}
7373
// Check for chain settings (Params() calls are only valid after this clause)
74-
SelectParams(gArgs.GetChainName());
74+
SelectParams(args.GetChainName());
7575

7676
return true;
7777
}
7878

7979
int main(int argc, char* argv[])
8080
{
81+
ArgsManager& args = gArgs;
8182
#ifdef WIN32
8283
util::WinCmdLineArgs winArgs;
8384
std::tie(argc, argv) = winArgs.get();
8485
#endif
8586
SetupEnvironment();
8687
RandomInit();
8788
try {
88-
if (!WalletAppInit(argc, argv)) return EXIT_FAILURE;
89+
if (!WalletAppInit(args, argc, argv)) return EXIT_FAILURE;
8990
} catch (const std::exception& e) {
9091
PrintExceptionContinue(&e, "WalletAppInit()");
9192
return EXIT_FAILURE;
@@ -111,16 +112,16 @@ int main(int argc, char* argv[])
111112
}
112113

113114
// A name must be provided when creating a file
114-
if (method == "create" && !gArgs.IsArgSet("-wallet")) {
115+
if (method == "create" && !args.IsArgSet("-wallet")) {
115116
tfm::format(std::cerr, "Wallet name must be provided when creating a new wallet.\n");
116117
return EXIT_FAILURE;
117118
}
118119

119-
std::string name = gArgs.GetArg("-wallet", "");
120+
std::string name = args.GetArg("-wallet", "");
120121

121122
ECCVerifyHandle globalVerifyHandle;
122123
ECC_Start();
123-
if (!WalletTool::ExecuteWalletToolFunc(gArgs, method, name)) {
124+
if (!WalletTool::ExecuteWalletToolFunc(args, method, name)) {
124125
return EXIT_FAILURE;
125126
}
126127
ECC_Stop();

0 commit comments

Comments
 (0)