Skip to content

Commit 7777105

Browse files
author
MarcoFalke
committed
refactor: Move all command dependend checks to ExecuteWalletToolFunc
1 parent fa06bce commit 7777105

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

src/bitcoin-wallet.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,9 @@ int main(int argc, char* argv[])
111111
return EXIT_FAILURE;
112112
}
113113

114-
// A name must be provided when creating a file
115-
if (method == "create" && !args.IsArgSet("-wallet")) {
116-
tfm::format(std::cerr, "Wallet name must be provided when creating a new wallet.\n");
117-
return EXIT_FAILURE;
118-
}
119-
120-
std::string name = args.GetArg("-wallet", "");
121-
122114
ECCVerifyHandle globalVerifyHandle;
123115
ECC_Start();
124-
if (!WalletTool::ExecuteWalletToolFunc(args, method, name)) {
116+
if (!WalletTool::ExecuteWalletToolFunc(args, method)) {
125117
return EXIT_FAILURE;
126118
}
127119
ECC_Stop();

src/wallet/wallettool.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,8 @@ static void WalletShowInfo(CWallet* wallet_instance)
103103
tfm::format(std::cout, "Address Book: %zu\n", wallet_instance->m_address_book.size());
104104
}
105105

106-
bool ExecuteWalletToolFunc(const ArgsManager& args, const std::string& command, const std::string& name)
106+
bool ExecuteWalletToolFunc(const ArgsManager& args, const std::string& command)
107107
{
108-
const fs::path path = fsbridge::AbsPathJoin(GetWalletDir(), name);
109-
110108
if (args.IsArgSet("-format") && command != "createfromdump") {
111109
tfm::format(std::cerr, "The -format option can only be used with the \"createfromdump\" command.\n");
112110
return false;
@@ -119,6 +117,12 @@ bool ExecuteWalletToolFunc(const ArgsManager& args, const std::string& command,
119117
tfm::format(std::cerr, "The -descriptors option can only be used with the 'create' command.\n");
120118
return false;
121119
}
120+
if (command == "create" && !args.IsArgSet("-wallet")) {
121+
tfm::format(std::cerr, "Wallet name must be provided when creating a new wallet.\n");
122+
return false;
123+
}
124+
const std::string name = args.GetArg("-wallet", "");
125+
const fs::path path = fsbridge::AbsPathJoin(GetWalletDir(), name);
122126

123127
if (command == "create") {
124128
DatabaseOptions options;

src/wallet/wallettool.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace WalletTool {
1111

1212
void WalletShowInfo(CWallet* wallet_instance);
13-
bool ExecuteWalletToolFunc(const ArgsManager& args, const std::string& command, const std::string& file);
13+
bool ExecuteWalletToolFunc(const ArgsManager& args, const std::string& command);
1414

1515
} // namespace WalletTool
1616

0 commit comments

Comments
 (0)