LCOV - code coverage report
Current view: top level - src/wallet - init.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 61 64 95.3 %
Date: 2020-09-26 01:30:44 Functions: 11 12 91.7 %

          Line data    Source code
       1             : // Copyright (c) 2009-2010 Satoshi Nakamoto
       2             : // Copyright (c) 2009-2020 The Bitcoin Core developers
       3             : // Distributed under the MIT software license, see the accompanying
       4             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       5             : 
       6             : #include <init.h>
       7             : #include <interfaces/chain.h>
       8             : #include <interfaces/wallet.h>
       9             : #include <net.h>
      10             : #include <node/context.h>
      11             : #include <node/ui_interface.h>
      12             : #include <outputtype.h>
      13             : #include <univalue.h>
      14             : #include <util/check.h>
      15             : #include <util/moneystr.h>
      16             : #include <util/system.h>
      17             : #include <util/translation.h>
      18             : #include <wallet/coincontrol.h>
      19             : #include <wallet/wallet.h>
      20             : #include <walletinitinterface.h>
      21             : 
      22        2560 : class WalletInit : public WalletInitInterface
      23             : {
      24             : public:
      25             :     //! Was the wallet component compiled in.
      26        1054 :     bool HasWalletSupport() const override {return true;}
      27             : 
      28             :     //! Return the wallets help message.
      29             :     void AddWalletOptions(ArgsManager& argsman) const override;
      30             : 
      31             :     //! Wallets parameter interaction
      32             :     bool ParameterInteraction() const override;
      33             : 
      34             :     //! Add wallets that should be opened to list of chain clients.
      35             :     void Construct(NodeContext& node) const override;
      36             : };
      37             : 
      38         640 : const WalletInitInterface& g_wallet_init_interface = WalletInit();
      39             : 
      40        1010 : void WalletInit::AddWalletOptions(ArgsManager& argsman) const
      41             : {
      42        1010 :     argsman.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);
      43        1010 :     argsman.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);
      44        1010 :     argsman.AddArg("-changetype", "What type of change to use (\"legacy\", \"p2sh-segwit\", or \"bech32\"). Default is same as -addresstype, except when -addresstype=p2sh-segwit a native segwit output is used when sending to a native segwit address)", ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
      45        1010 :     argsman.AddArg("-disablewallet", "Do not load the wallet and disable wallet RPC calls", ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
      46        1010 :     argsman.AddArg("-discardfee=<amt>", strprintf("The fee rate (in %s/kB) that indicates your tolerance for discarding change by adding it to the fee (default: %s). "
      47             :                                                                 "Note: An output is discarded if it is dust at this rate, but we will always discard up to the dust relay fee and a discard fee above that is limited by the fee estimate for the longest target",
      48        2020 :                                                               CURRENCY_UNIT, FormatMoney(DEFAULT_DISCARD_FEE)), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
      49             : 
      50        1010 :     argsman.AddArg("-fallbackfee=<amt>", strprintf("A fee rate (in %s/kB) that will be used when fee estimation has insufficient data. 0 to entirely disable the fallbackfee feature. (default: %s)",
      51        2020 :                                                                CURRENCY_UNIT, FormatMoney(DEFAULT_FALLBACK_FEE)), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
      52        1010 :     argsman.AddArg("-keypool=<n>", strprintf("Set key pool size to <n> (default: %u). Warning: Smaller sizes may increase the risk of losing funds when restoring from an old backup, if none of the addresses in the original keypool have been used.", DEFAULT_KEYPOOL_SIZE), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
      53        1010 :     argsman.AddArg("-maxapsfee=<n>", strprintf("Spend up to this amount in additional (absolute) fees (in %s) if it allows the use of partial spend avoidance (default: %s)", CURRENCY_UNIT, FormatMoney(DEFAULT_MAX_AVOIDPARTIALSPEND_FEE)), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
      54        1010 :     argsman.AddArg("-maxtxfee=<amt>", strprintf("Maximum total fees (in %s) to use in a single wallet transaction; setting this too low may abort large transactions (default: %s)",
      55        2020 :         CURRENCY_UNIT, FormatMoney(DEFAULT_TRANSACTION_MAXFEE)), ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
      56        1010 :     argsman.AddArg("-mintxfee=<amt>", strprintf("Fees (in %s/kB) smaller than this are considered zero fee for transaction creation (default: %s)",
      57        2020 :                                                             CURRENCY_UNIT, FormatMoney(DEFAULT_TRANSACTION_MINFEE)), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
      58        2020 :     argsman.AddArg("-paytxfee=<amt>", strprintf("Fee (in %s/kB) to add to transactions you send (default: %s)",
      59        2020 :                                                             CURRENCY_UNIT, FormatMoney(CFeeRate{DEFAULT_PAY_TX_FEE}.GetFeePerK())), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
      60        1010 :     argsman.AddArg("-rescan", "Rescan the block chain for missing wallet transactions on startup", ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
      61        1010 :     argsman.AddArg("-spendzeroconfchange", strprintf("Spend unconfirmed change when sending transactions (default: %u)", DEFAULT_SPEND_ZEROCONF_CHANGE), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
      62        1010 :     argsman.AddArg("-txconfirmtarget=<n>", strprintf("If paytxfee is not set, include enough fee so transactions begin confirmation on average within n blocks (default: %u)", DEFAULT_TX_CONFIRM_TARGET), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
      63        1010 :     argsman.AddArg("-wallet=<path>", "Specify wallet database path. Can be specified multiple times to load multiple wallets. Path is interpreted relative to <walletdir> if it is not absolute, and will be created if it does not exist (as a directory containing a wallet.dat file and log files). For backwards compatibility this will also accept names of existing data files in <walletdir>.)", ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::WALLET);
      64        1010 :     argsman.AddArg("-walletbroadcast",  strprintf("Make the wallet broadcast transactions (default: %u)", DEFAULT_WALLETBROADCAST), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
      65        1010 :     argsman.AddArg("-walletdir=<dir>", "Specify directory to hold wallets (default: <datadir>/wallets if it exists, otherwise <datadir>)", ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::WALLET);
      66             : #if HAVE_SYSTEM
      67        1010 :     argsman.AddArg("-walletnotify=<cmd>", "Execute command when a wallet transaction changes. %s in cmd is replaced by TxID and %w is replaced by wallet name. %w is not currently implemented on windows. On systems where %w is supported, it should NOT be quoted because this would break shell escaping used to invoke the command.", ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
      68             : #endif
      69        1010 :     argsman.AddArg("-walletrbf", strprintf("Send transactions with full-RBF opt-in enabled (RPC only, default: %u)", DEFAULT_WALLET_RBF), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
      70             : 
      71        1010 :     argsman.AddArg("-dblogsize=<n>", strprintf("Flush wallet database activity from memory to disk log every <n> megabytes (default: %u)", DEFAULT_WALLET_DBLOGSIZE), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::WALLET_DEBUG_TEST);
      72        1010 :     argsman.AddArg("-flushwallet", strprintf("Run a thread to flush wallet periodically (default: %u)", DEFAULT_FLUSHWALLET), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::WALLET_DEBUG_TEST);
      73        1010 :     argsman.AddArg("-privdb", strprintf("Sets the DB_PRIVATE flag in the wallet db environment (default: %u)", DEFAULT_WALLET_PRIVDB), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::WALLET_DEBUG_TEST);
      74        1010 :     argsman.AddArg("-walletrejectlongchains", strprintf("Wallet will not create transactions that violate mempool chain limits (default: %u)", DEFAULT_WALLET_REJECT_LONG_CHAINS), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::WALLET_DEBUG_TEST);
      75             : 
      76        1010 :     argsman.AddHiddenArgs({"-zapwallettxes"});
      77        1010 : }
      78             : 
      79         991 : bool WalletInit::ParameterInteraction() const
      80             : {
      81         991 :     if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {
      82           5 :         for (const std::string& wallet : gArgs.GetArgs("-wallet")) {
      83           0 :             LogPrintf("%s: parameter interaction: -disablewallet -> ignoring -wallet=%s\n", __func__, wallet);
      84             :         }
      85             : 
      86           5 :         return true;
      87             :     }
      88             : 
      89         986 :     if (gArgs.GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY) && gArgs.SoftSetBoolArg("-walletbroadcast", false)) {
      90           2 :         LogPrintf("%s: parameter interaction: -blocksonly=1 -> setting -walletbroadcast=0\n", __func__);
      91           2 :     }
      92             : 
      93         986 :     if (gArgs.IsArgSet("-zapwallettxes")) {
      94           0 :         return InitError(Untranslated("-zapwallettxes has been removed. If you are attempting to remove a stuck transaction from your wallet, please use abandontransaction instead."));
      95             :     }
      96             : 
      97         986 :     if (gArgs.GetBoolArg("-sysperms", false))
      98           0 :         return InitError(Untranslated("-sysperms is not allowed in combination with enabled wallet functionality"));
      99             : 
     100         986 :     return true;
     101         991 : }
     102             : 
     103         990 : void WalletInit::Construct(NodeContext& node) const
     104             : {
     105        1980 :     ArgsManager& args = *Assert(node.args);
     106         990 :     if (args.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {
     107           5 :         LogPrintf("Wallet disabled!\n");
     108           5 :         return;
     109             :     }
     110             :     // If there's no -wallet setting with a list of wallets to load, set it to
     111             :     // load the default "" wallet.
     112         985 :     if (!args.IsArgSet("wallet")) {
     113         610 :         args.LockSettings([&](util::Settings& settings) {
     114         305 :             util::SettingsValue wallets(util::SettingsValue::VARR);
     115         305 :             wallets.push_back(""); // Default wallet name is ""
     116         305 :             settings.rw_settings["wallet"] = wallets;
     117         305 :         });
     118         305 :     }
     119         985 :     auto wallet_client = interfaces::MakeWalletClient(*node.chain, args, args.GetArgs("-wallet"));
     120         985 :     node.wallet_client = wallet_client.get();
     121         985 :     node.chain_clients.emplace_back(std::move(wallet_client));
     122         990 : }

Generated by: LCOV version 1.15