LCOV - code coverage report
Current view: top level - src - bitcoin-wallet.cpp (source / functions) Hit Total Coverage
Test: test_dash_coverage.info Lines: 0 73 0.0 %
Date: 2026-06-25 07:23:51 Functions: 0 4 0.0 %

          Line data    Source code
       1             : // Copyright (c) 2016-2021 The Bitcoin Core developers
       2             : // Distributed under the MIT software license, see the accompanying
       3             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       4             : 
       5             : #if defined(HAVE_CONFIG_H)
       6             : #include <config/bitcoin-config.h>
       7             : #endif
       8             : 
       9             : #include <chainparams.h>
      10             : #include <chainparamsbase.h>
      11             : #include <common/url.h>
      12             : #include <compat/compat.h>
      13             : #include <interfaces/init.h>
      14             : #include <logging.h>
      15             : #include <util/strencodings.h>
      16             : #include <clientversion.h>
      17             : #include <key.h>
      18             : #include <pubkey.h>
      19             : #include <tinyformat.h>
      20             : #include <util/system.h>
      21             : #include <util/translation.h>
      22             : #include <wallet/wallettool.h>
      23             : 
      24             : #include <exception>
      25             : #include <string>
      26             : #include <tuple>
      27           0 : const std::function<std::string(const char*)> G_TRANSLATION_FUN = nullptr;
      28             : UrlDecodeFn* const URL_DECODE = nullptr;
      29             : 
      30           0 : static void SetupWalletToolArgs(ArgsManager& argsman)
      31             : {
      32           0 :     SetupHelpOptions(argsman);
      33           0 :     SetupChainParamsBaseOptions(argsman);
      34             : 
      35           0 :     argsman.AddArg("-version", "Print version and exit", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
      36           0 :     argsman.AddArg("-usehd", strprintf("Create HD (hierarchical deterministic) wallet (default: %d)", true), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
      37           0 :     argsman.AddArg("-datadir=<dir>", "Specify data directory", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
      38           0 :     argsman.AddArg("-wallet=<wallet-name>", "Specify wallet name", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
      39           0 :     argsman.AddArg("-dumpfile=<file name>", "When used with 'dump', writes out the records to this file. When used with 'createfromdump', loads the records into a new wallet.", ArgsManager::ALLOW_ANY | ArgsManager::DISALLOW_NEGATION, OptionsCategory::OPTIONS);
      40           0 :     argsman.AddArg("-debug=<category>", "Output debugging information (default: 0).", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
      41           0 :     argsman.AddArg("-descriptors", "Create descriptors wallet. Only for 'create'", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
      42           0 :     argsman.AddArg("-legacy", "Create legacy wallet. Only for 'create'", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
      43           0 :     argsman.AddArg("-format=<format>", "The format of the wallet file to create. Either \"bdb\" or \"sqlite\". Only used with 'createfromdump'", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
      44           0 :     argsman.AddArg("-printtoconsole", "Send trace/debug info to console (default: 1 when no -debug is true, 0 otherwise).", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
      45             : 
      46           0 :     argsman.AddCommand("info", "Get wallet info");
      47           0 :     argsman.AddCommand("create", "Create new wallet file");
      48           0 :     argsman.AddCommand("salvage", "Attempt to recover private keys from a corrupt wallet. Warning: 'salvage' is experimental.");
      49           0 :     argsman.AddCommand("wipetxes", "Wipe all transactions from a wallet");
      50           0 :     argsman.AddCommand("dump", "Print out all of the wallet key-value records");
      51           0 :     argsman.AddCommand("createfromdump", "Create new wallet file from dumped records");
      52           0 : }
      53             : 
      54           0 : static std::optional<int> WalletAppInit(ArgsManager& args, int argc, char* argv[])
      55             : {
      56           0 :     SetupWalletToolArgs(args);
      57           0 :     std::string error_message;
      58           0 :     if (!args.ParseParameters(argc, argv, error_message)) {
      59           0 :         tfm::format(std::cerr, "Error parsing command line arguments: %s\n", error_message);
      60           0 :         return EXIT_FAILURE;
      61             :     }
      62           0 :     const bool missing_args{argc < 2};
      63           0 :     if (missing_args || HelpRequested(args) || args.IsArgSet("-version")) {
      64           0 :         std::string strUsage = strprintf("%s dash-wallet version", PACKAGE_NAME) + " " + FormatFullVersion() + "\n";
      65             : 
      66           0 :         if (args.IsArgSet("-version")) {
      67           0 :             strUsage += FormatParagraph(LicenseInfo());
      68           0 :         } else {
      69           0 :             strUsage += "\n"
      70             :                     "dash-wallet is an offline tool for creating and interacting with " PACKAGE_NAME " wallet files.\n"
      71             :                     "By default dash-wallet will act on wallets in the default mainnet wallet directory in the datadir.\n"
      72             :                     "To change the target wallet, use the -datadir, -wallet and -regtest/-testnet arguments.\n\n"
      73             :                     "Usage:\n"
      74             :                     "  dash-wallet [options] <command>\n";
      75           0 :             strUsage += "\n" + args.GetHelpMessage();
      76             :         }
      77           0 :         tfm::format(std::cout, "%s", strUsage);
      78           0 :         if (missing_args) {
      79           0 :             tfm::format(std::cerr, "Error: too few parameters\n");
      80           0 :             return EXIT_FAILURE;
      81             :         }
      82           0 :         return EXIT_SUCCESS;
      83           0 :     }
      84             : 
      85             :     // check for printtoconsole, allow -debug
      86           0 :     LogInstance().m_print_to_console = args.GetBoolArg("-printtoconsole", args.GetBoolArg("-debug", false));
      87             : 
      88           0 :     if (!CheckDataDirOption()) {
      89           0 :         tfm::format(std::cerr, "Error: Specified data directory \"%s\" does not exist.\n", args.GetArg("-datadir", ""));
      90           0 :         return EXIT_FAILURE;
      91             :     }
      92             :     // Check for chain settings (Params() calls are only valid after this clause)
      93           0 :     SelectParams(args.GetChainName());
      94             : 
      95           0 :     return std::nullopt;
      96           0 : }
      97             : 
      98           0 : MAIN_FUNCTION
      99             : {
     100           0 :     ArgsManager& args = gArgs;
     101             : #ifdef WIN32
     102             :     util::WinCmdLineArgs winArgs;
     103             :     std::tie(argc, argv) = winArgs.get();
     104             : #endif
     105             : 
     106             :     int exit_status;
     107           0 :     std::unique_ptr<interfaces::Init> init = interfaces::MakeWalletInit(argc, argv, exit_status);
     108           0 :     if (!init) {
     109           0 :         return exit_status;
     110             :     }
     111             : 
     112           0 :     SetupEnvironment();
     113           0 :     RandomInit();
     114             :     try {
     115           0 :         if (const auto maybe_exit{WalletAppInit(args, argc, argv)}) return *maybe_exit;
     116           0 :     } catch (...) {
     117           0 :         PrintExceptionContinue(std::current_exception(), "WalletAppInit()");
     118           0 :         return EXIT_FAILURE;
     119           0 :     }
     120             : 
     121           0 :     const auto command = args.GetCommand();
     122           0 :     if (!command) {
     123           0 :         tfm::format(std::cerr, "No method provided. Run `dash-wallet -help` for valid methods.\n");
     124           0 :         return EXIT_FAILURE;
     125             :     }
     126           0 :     if (command->args.size() != 0) {
     127           0 :         tfm::format(std::cerr, "Error: Additional arguments provided (%s). Methods do not take arguments. Please refer to `-help`.\n", Join(command->args, ", "));
     128           0 :         return EXIT_FAILURE;
     129             :     }
     130             : 
     131           0 :     ECC_Start();
     132           0 :     if (!wallet::WalletTool::ExecuteWalletToolFunc(args, command->command)) {
     133           0 :         return EXIT_FAILURE;
     134             :     }
     135           0 :     ECC_Stop();
     136           0 :     return EXIT_SUCCESS;
     137           0 : }

Generated by: LCOV version 1.16