mirror of
https://github.com/dashpay/dash.git
synced 2024-12-28 05:23:01 +01:00
5a0e44ad32
5855cc564fd456463e6d335830526675626923c6 bitcoin-wallet: Use PACKAGE_NAME in usage help (Luke Dashjr) 7f5db163a4ebc607d441e2457af10942be511d2c GUI: Use PACKAGE_NAME in modal overlay (Luke Dashjr) Pull request description: ACKs for top commit: hebasto: ACK 5855cc564fd456463e6d335830526675626923c6, checked with fanquake: ACK 5855cc564fd456463e6d335830526675626923c6 - checked `bitcoin-wallet` and a `--disable-wallet` `bitcoin-qt`. Tree-SHA512: 3526eb122bfdbc63349d12251f17ffa20c7f3754af4ac9c554e6d36bb14b351f31c413c30401bb3d6e0e6200b72614dfc8475489b1f742b0423bd83fba758b94
116 lines
4.5 KiB
C++
116 lines
4.5 KiB
C++
// Copyright (c) 2016-2018 The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#if defined(HAVE_CONFIG_H)
|
|
#include <config/bitcoin-config.h>
|
|
#endif
|
|
|
|
#include <chainparams.h>
|
|
#include <chainparamsbase.h>
|
|
#include <logging.h>
|
|
#include <util/strencodings.h>
|
|
#include <util/system.h>
|
|
#include <util/translation.h>
|
|
#include <wallet/wallettool.h>
|
|
|
|
const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;
|
|
|
|
static void SetupWalletToolArgs(ArgsManager& argsman)
|
|
{
|
|
SetupHelpOptions(argsman);
|
|
SetupChainParamsBaseOptions(argsman);
|
|
|
|
argsman.AddArg("-datadir=<dir>", "Specify data directory", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
|
argsman.AddArg("-wallet=<wallet-name>", "Specify wallet name", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
|
|
argsman.AddArg("-debug=<category>", "Output debugging information (default: 0).", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
|
|
argsman.AddArg("-printtoconsole", "Send trace/debug info to console (default: 1 when no -debug is true, 0 otherwise).", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
|
|
|
|
argsman.AddArg("info", "Get wallet info", ArgsManager::ALLOW_ANY, OptionsCategory::COMMANDS);
|
|
argsman.AddArg("create", "Create new wallet file", ArgsManager::ALLOW_ANY, OptionsCategory::COMMANDS);
|
|
|
|
// Hidden
|
|
argsman.AddArg("salvage", "Attempt to recover private keys from a corrupt wallet", ArgsManager::ALLOW_ANY, OptionsCategory::COMMANDS);
|
|
}
|
|
|
|
static bool WalletAppInit(int argc, char* argv[])
|
|
{
|
|
SetupWalletToolArgs(gArgs);
|
|
std::string error_message;
|
|
if (!gArgs.ParseParameters(argc, argv, error_message)) {
|
|
tfm::format(std::cerr, "Error parsing command line arguments: %s\n", error_message);
|
|
return false;
|
|
}
|
|
if (argc < 2 || HelpRequested(gArgs)) {
|
|
std::string usage = strprintf("%s dash-wallet version", PACKAGE_NAME) + " " + FormatFullVersion() + "\n\n" +
|
|
"dash-wallet is an offline tool for creating and interacting with " PACKAGE_NAME " wallet files.\n" +
|
|
"By default dash-wallet will act on wallets in the default mainnet wallet directory in the datadir.\n" +
|
|
"To change the target wallet, use the -datadir, -wallet and -testnet/-regtest arguments.\n\n" +
|
|
"Usage:\n" +
|
|
" dash-wallet [options] <command>\n\n" +
|
|
gArgs.GetHelpMessage();
|
|
|
|
tfm::format(std::cout, "%s", usage);
|
|
return false;
|
|
}
|
|
|
|
// check for printtoconsole, allow -debug
|
|
LogInstance().m_print_to_console = gArgs.GetBoolArg("-printtoconsole", gArgs.GetBoolArg("-debug", false));
|
|
|
|
if (!CheckDataDirOption()) {
|
|
tfm::format(std::cerr, "Error: Specified data directory \"%s\" does not exist.\n", gArgs.GetArg("-datadir", ""));
|
|
return false;
|
|
}
|
|
// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
|
|
SelectParams(gArgs.GetChainName());
|
|
|
|
return true;
|
|
}
|
|
|
|
int main(int argc, char* argv[])
|
|
{
|
|
#ifdef WIN32
|
|
util::WinCmdLineArgs winArgs;
|
|
std::tie(argc, argv) = winArgs.get();
|
|
#endif
|
|
SetupEnvironment();
|
|
RandomInit();
|
|
try {
|
|
if (!WalletAppInit(argc, argv)) return EXIT_FAILURE;
|
|
} catch (...) {
|
|
PrintExceptionContinue(std::current_exception(), "WalletAppInit()");
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
std::string method {};
|
|
for(int i = 1; i < argc; ++i) {
|
|
if (!IsSwitchChar(argv[i][0])) {
|
|
if (!method.empty()) {
|
|
tfm::format(std::cerr, "Error: two methods provided (%s and %s). Only one method should be provided.\n", method, argv[i]);
|
|
return EXIT_FAILURE;
|
|
}
|
|
method = argv[i];
|
|
}
|
|
}
|
|
|
|
if (method.empty()) {
|
|
tfm::format(std::cerr, "No method provided. Run `dash-wallet -help` for valid methods.\n");
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
// A name must be provided when creating a file
|
|
if (method == "create" && !gArgs.IsArgSet("-wallet")) {
|
|
tfm::format(std::cerr, "Wallet name must be provided when creating a new wallet.\n");
|
|
return EXIT_FAILURE;
|
|
}
|
|
|
|
std::string name = gArgs.GetArg("-wallet", "");
|
|
|
|
ECCVerifyHandle globalVerifyHandle;
|
|
ECC_Start();
|
|
if (!WalletTool::ExecuteWalletToolFunc(method, name))
|
|
return EXIT_FAILURE;
|
|
ECC_Stop();
|
|
return EXIT_SUCCESS;
|
|
}
|