LCOV - code coverage report
Current view: top level - src/wallet - init.cpp (source / functions) Hit Total Coverage
Test: coverage.lcov Lines: 69 76 90.8 %
Date: 2022-04-21 14:51:19 Functions: 4 4 100.0 %
Legend: Modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed

Not modified by patch:
Lines: hit not hit | Branches: + taken - not taken # not executed
Branches: 13 18 72.2 %

           Branch data     Line data    Source code
#       1                 :            : // Copyright (c) 2009-2010 Satoshi Nakamoto
#       2                 :            : // Copyright (c) 2009-2021 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/init.h>
#       9                 :            : #include <interfaces/wallet.h>
#      10                 :            : #include <net.h>
#      11                 :            : #include <node/context.h>
#      12                 :            : #include <node/ui_interface.h>
#      13                 :            : #include <outputtype.h>
#      14                 :            : #include <univalue.h>
#      15                 :            : #include <util/check.h>
#      16                 :            : #include <util/moneystr.h>
#      17                 :            : #include <util/system.h>
#      18                 :            : #include <util/translation.h>
#      19                 :            : #ifdef USE_BDB
#      20                 :            : #include <wallet/bdb.h>
#      21                 :            : #endif
#      22                 :            : #include <wallet/coincontrol.h>
#      23                 :            : #include <wallet/wallet.h>
#      24                 :            : #include <walletinitinterface.h>
#      25                 :            : 
#      26                 :            : using node::NodeContext;
#      27                 :            : 
#      28                 :            : namespace wallet {
#      29                 :            : class WalletInit : public WalletInitInterface
#      30                 :            : {
#      31                 :            : public:
#      32                 :            :     //! Was the wallet component compiled in.
#      33                 :       1580 :     bool HasWalletSupport() const override {return true;}
#      34                 :            : 
#      35                 :            :     //! Return the wallets help message.
#      36                 :            :     void AddWalletOptions(ArgsManager& argsman) const override;
#      37                 :            : 
#      38                 :            :     //! Wallets parameter interaction
#      39                 :            :     bool ParameterInteraction() const override;
#      40                 :            : 
#      41                 :            :     //! Add wallets that should be opened to list of chain clients.
#      42                 :            :     void Construct(NodeContext& node) const override;
#      43                 :            : };
#      44                 :            : 
#      45                 :            : void WalletInit::AddWalletOptions(ArgsManager& argsman) const
#      46                 :       1662 : {
#      47                 :       1662 :     argsman.AddArg("-addresstype", strprintf("What type of addresses to use (\"legacy\", \"p2sh-segwit\", \"bech32\", or \"bech32m\", default: \"%s\")", FormatOutputType(DEFAULT_ADDRESS_TYPE)), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
#      48                 :       1662 :     argsman.AddArg("-avoidpartialspends", strprintf("Group outputs by address, selecting many (possibly all) or none, instead of selecting on a per-output basis. Privacy is improved as addresses are mostly swept with fewer transactions and outputs are aggregated in clean change addresses. It may result in higher fees due to less optimal coin selection caused by this added limitation and possibly a larger-than-necessary number of inputs being used. Always enabled for wallets with \"avoid_reuse\" enabled, otherwise default: %u.", DEFAULT_AVOIDPARTIALSPENDS), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
#      49                 :       1662 :     argsman.AddArg("-changetype",
#      50                 :       1662 :                    "What type of change to use (\"legacy\", \"p2sh-segwit\", \"bech32\", or \"bech32m\"). Default is \"legacy\" when "
#      51                 :       1662 :                    "-addresstype=legacy, else it is an implementation detail.",
#      52                 :       1662 :                    ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
#      53                 :       1662 :     argsman.AddArg("-consolidatefeerate=<amt>", strprintf("The maximum feerate (in %s/kvB) at which transaction building may use more inputs than strictly necessary so that the wallet's UTXO pool can be reduced (default: %s).", CURRENCY_UNIT, FormatMoney(DEFAULT_CONSOLIDATE_FEERATE)), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
#      54                 :       1662 :     argsman.AddArg("-disablewallet", "Do not load the wallet and disable wallet RPC calls", ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
#      55                 :       1662 :     argsman.AddArg("-discardfee=<amt>", strprintf("The fee rate (in %s/kvB) that indicates your tolerance for discarding change by adding it to the fee (default: %s). "
#      56                 :       1662 :                                                                 "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",
#      57                 :       1662 :                                                               CURRENCY_UNIT, FormatMoney(DEFAULT_DISCARD_FEE)), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
#      58                 :            : 
#      59                 :       1662 :     argsman.AddArg("-fallbackfee=<amt>", strprintf("A fee rate (in %s/kvB) that will be used when fee estimation has insufficient data. 0 to entirely disable the fallbackfee feature. (default: %s)",
#      60                 :       1662 :                                                                CURRENCY_UNIT, FormatMoney(DEFAULT_FALLBACK_FEE)), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
#      61                 :       1662 :     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);
#      62                 :       1662 :     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);
#      63                 :       1662 :     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)",
#      64                 :       1662 :         CURRENCY_UNIT, FormatMoney(DEFAULT_TRANSACTION_MAXFEE)), ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
#      65                 :       1662 :     argsman.AddArg("-mintxfee=<amt>", strprintf("Fee rates (in %s/kvB) smaller than this are considered zero fee for transaction creation (default: %s)",
#      66                 :       1662 :                                                             CURRENCY_UNIT, FormatMoney(DEFAULT_TRANSACTION_MINFEE)), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
#      67                 :       1662 :     argsman.AddArg("-paytxfee=<amt>", strprintf("Fee rate (in %s/kvB) to add to transactions you send (default: %s)",
#      68                 :       1662 :                                                             CURRENCY_UNIT, FormatMoney(CFeeRate{DEFAULT_PAY_TX_FEE}.GetFeePerK())), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
#      69                 :       1662 : #ifdef ENABLE_EXTERNAL_SIGNER
#      70                 :       1662 :     argsman.AddArg("-signer=<cmd>", "External signing tool, see doc/external-signer.md", ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
#      71                 :       1662 : #endif
#      72                 :       1662 :     argsman.AddArg("-spendzeroconfchange", strprintf("Spend unconfirmed change when sending transactions (default: %u)", DEFAULT_SPEND_ZEROCONF_CHANGE), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
#      73                 :       1662 :     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);
#      74                 :       1662 :     argsman.AddArg("-wallet=<path>", "Specify wallet path to load at startup. Can be used multiple times to load multiple wallets. Path is to a directory containing wallet data and log files. If the path is not absolute, it is interpreted relative to <walletdir>. This only loads existing wallets and does not create new ones. For backwards compatibility this also accepts names of existing top-level data files in <walletdir>.", ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::WALLET);
#      75                 :       1662 :     argsman.AddArg("-walletbroadcast",  strprintf("Make the wallet broadcast transactions (default: %u)", DEFAULT_WALLETBROADCAST), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
#      76                 :       1662 :     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);
#      77                 :       1662 : #if HAVE_SYSTEM
#      78                 :       1662 :     argsman.AddArg("-walletnotify=<cmd>", "Execute command when a wallet transaction changes. %s in cmd is replaced by TxID, %w is replaced by wallet name, %b is replaced by the hash of the block including the transaction (set to 'unconfirmed' if the transaction is not included) and %h is replaced by the block height (-1 if not included). %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);
#      79                 :       1662 : #endif
#      80                 :       1662 :     argsman.AddArg("-walletrbf", strprintf("Send transactions with full-RBF opt-in enabled (RPC only, default: %u)", DEFAULT_WALLET_RBF), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
#      81                 :            : 
#      82                 :       1662 : #ifdef USE_BDB
#      83                 :       1662 :     argsman.AddArg("-dblogsize=<n>", strprintf("Flush wallet database activity from memory to disk log every <n> megabytes (default: %u)", DatabaseOptions().max_log_mb), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::WALLET_DEBUG_TEST);
#      84                 :       1662 :     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);
#      85                 :       1662 :     argsman.AddArg("-privdb", strprintf("Sets the DB_PRIVATE flag in the wallet db environment (default: %u)", !DatabaseOptions().use_shared_memory), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::WALLET_DEBUG_TEST);
#      86                 :            : #else
#      87                 :            :     argsman.AddHiddenArgs({"-dblogsize", "-flushwallet", "-privdb"});
#      88                 :            : #endif
#      89                 :            : 
#      90                 :       1662 : #ifdef USE_SQLITE
#      91                 :       1662 :     argsman.AddArg("-unsafesqlitesync", "Set SQLite synchronous=OFF to disable waiting for the database to sync to disk. This is unsafe and can cause data loss and corruption. This option is only used by tests to improve their performance (default: false)", ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::WALLET_DEBUG_TEST);
#      92                 :            : #else
#      93                 :            :     argsman.AddHiddenArgs({"-unsafesqlitesync"});
#      94                 :            : #endif
#      95                 :            : 
#      96                 :       1662 :     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);
#      97                 :            : 
#      98                 :       1662 :     argsman.AddHiddenArgs({"-zapwallettxes"});
#      99                 :       1662 : }
#     100                 :            : 
#     101                 :            : bool WalletInit::ParameterInteraction() const
#     102                 :       1634 : {
#     103                 :       1634 : #ifdef USE_BDB
#     104         [ -  + ]:       1634 :      if (!BerkeleyDatabaseSanityCheck()) {
#     105                 :          0 :          return InitError(Untranslated("A version conflict was detected between the run-time BerkeleyDB library and the one used during compilation."));
#     106                 :          0 :      }
#     107                 :       1634 : #endif
#     108         [ +  + ]:       1634 :     if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {
#     109         [ -  + ]:          4 :         for (const std::string& wallet : gArgs.GetArgs("-wallet")) {
#     110                 :          0 :             LogPrintf("%s: parameter interaction: -disablewallet -> ignoring -wallet=%s\n", __func__, wallet);
#     111                 :          0 :         }
#     112                 :            : 
#     113                 :          4 :         return true;
#     114                 :          4 :     }
#     115                 :            : 
#     116 [ +  + ][ +  + ]:       1630 :     if (gArgs.GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY) && gArgs.SoftSetBoolArg("-walletbroadcast", false)) {
#                 [ +  - ]
#     117                 :          6 :         LogPrintf("%s: parameter interaction: -blocksonly=1 -> setting -walletbroadcast=0\n", __func__);
#     118                 :          6 :     }
#     119                 :            : 
#     120         [ -  + ]:       1630 :     if (gArgs.IsArgSet("-zapwallettxes")) {
#     121                 :          0 :         return InitError(Untranslated("-zapwallettxes has been removed. If you are attempting to remove a stuck transaction from your wallet, please use abandontransaction instead."));
#     122                 :          0 :     }
#     123                 :            : 
#     124         [ -  + ]:       1630 :     if (gArgs.GetBoolArg("-sysperms", false))
#     125                 :          0 :         return InitError(Untranslated("-sysperms is not allowed in combination with enabled wallet functionality"));
#     126                 :            : 
#     127                 :       1630 :     return true;
#     128                 :       1630 : }
#     129                 :            : 
#     130                 :            : void WalletInit::Construct(NodeContext& node) const
#     131                 :        792 : {
#     132                 :        792 :     ArgsManager& args = *Assert(node.args);
#     133         [ +  + ]:        792 :     if (args.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {
#     134                 :          4 :         LogPrintf("Wallet disabled!\n");
#     135                 :          4 :         return;
#     136                 :          4 :     }
#     137                 :        788 :     auto wallet_loader = node.init->makeWalletLoader(*node.chain);
#     138                 :        788 :     node.wallet_loader = wallet_loader.get();
#     139                 :        788 :     node.chain_clients.emplace_back(std::move(wallet_loader));
#     140                 :        788 : }
#     141                 :            : } // namespace wallet
#     142                 :            : 
#     143                 :            : const WalletInitInterface& g_wallet_init_interface = wallet::WalletInit();

Generated by: LCOV version 0-eol-96201-ge66f56f4af6a