Bitcoin Core  0.20.99
P2P Digital Currency
Go to the documentation of this file.
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
6 #include <init.h>
7 #include <interfaces/chain.h>
8 #include <net.h>
9 #include <node/context.h>
10 #include <outputtype.h>
11 #include <ui_interface.h>
12 #include <util/moneystr.h>
13 #include <util/system.h>
14 #include <util/translation.h>
15 #include <wallet/coincontrol.h>
16 #include <wallet/wallet.h>
17 #include <walletinitinterface.h>
20 public:
23  bool HasWalletSupport() const override {return true;}
26  void AddWalletOptions() const override;
29  bool ParameterInteraction() const override;
32  void Construct(NodeContext& node) const override;
33 };
38 {
39  gArgs.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);
40  gArgs.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);
41  gArgs.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);
42  gArgs.AddArg("-disablewallet", "Do not load the wallet and disable wallet RPC calls", ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
43  gArgs.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). "
44  "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",
47  gArgs.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)",
49  gArgs.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);
50  gArgs.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)",
52  gArgs.AddArg("-mintxfee=<amt>", strprintf("Fees (in %s/kB) smaller than this are considered zero fee for transaction creation (default: %s)",
54  gArgs.AddArg("-paytxfee=<amt>", strprintf("Fee (in %s/kB) to add to transactions you send (default: %s)",
56  gArgs.AddArg("-rescan", "Rescan the block chain for missing wallet transactions on startup", ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
57  gArgs.AddArg("-salvagewallet", "Attempt to recover private keys from a corrupt wallet on startup", ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
58  gArgs.AddArg("-spendzeroconfchange", strprintf("Spend unconfirmed change when sending transactions (default: %u)", DEFAULT_SPEND_ZEROCONF_CHANGE), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
59  gArgs.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);
60  gArgs.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);
61  gArgs.AddArg("-walletbroadcast", strprintf("Make the wallet broadcast transactions (default: %u)", DEFAULT_WALLETBROADCAST), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
62  gArgs.AddArg("-walletdir=<dir>", "Specify directory to hold wallets (default: <datadir>/wallets if it exists, otherwise <datadir>)", ArgsManager::ALLOW_ANY | ArgsManager::NETWORK_ONLY, OptionsCategory::WALLET);
64  gArgs.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);
65 #endif
66  gArgs.AddArg("-walletrbf", strprintf("Send transactions with full-RBF opt-in enabled (RPC only, default: %u)", DEFAULT_WALLET_RBF), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
67  gArgs.AddArg("-zapwallettxes=<mode>", "Delete all wallet transactions and only recover those parts of the blockchain through -rescan on startup"
68  " (1 = keep tx meta data e.g. payment request information, 2 = drop tx meta data)", ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
70  gArgs.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);
71  gArgs.AddArg("-flushwallet", strprintf("Run a thread to flush wallet periodically (default: %u)", DEFAULT_FLUSHWALLET), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::WALLET_DEBUG_TEST);
72  gArgs.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);
73  gArgs.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);
74 }
77 {
78  if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {
79  for (const std::string& wallet : gArgs.GetArgs("-wallet")) {
80  LogPrintf("%s: parameter interaction: -disablewallet -> ignoring -wallet=%s\n", __func__, wallet);
81  }
83  return true;
84  }
86  const bool is_multiwallet = gArgs.GetArgs("-wallet").size() > 1;
88  if (gArgs.GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY) && gArgs.SoftSetBoolArg("-walletbroadcast", false)) {
89  LogPrintf("%s: parameter interaction: -blocksonly=1 -> setting -walletbroadcast=0\n", __func__);
90  }
92  if (gArgs.GetBoolArg("-salvagewallet", false)) {
93  if (is_multiwallet) {
94  return InitError(strprintf(Untranslated("%s is only allowed with a single wallet file"), "-salvagewallet"));
95  }
96  // Rewrite just private keys: rescan to find transactions
97  if (gArgs.SoftSetBoolArg("-rescan", true)) {
98  LogPrintf("%s: parameter interaction: -salvagewallet=1 -> setting -rescan=1\n", __func__);
99  }
100  }
102  bool zapwallettxes = gArgs.GetBoolArg("-zapwallettxes", false);
103  // -zapwallettxes implies dropping the mempool on startup
104  if (zapwallettxes && gArgs.SoftSetBoolArg("-persistmempool", false)) {
105  LogPrintf("%s: parameter interaction: -zapwallettxes enabled -> setting -persistmempool=0\n", __func__);
106  }
108  // -zapwallettxes implies a rescan
109  if (zapwallettxes) {
110  if (is_multiwallet) {
111  return InitError(strprintf(Untranslated("%s is only allowed with a single wallet file"), "-zapwallettxes"));
112  }
113  if (gArgs.SoftSetBoolArg("-rescan", true)) {
114  LogPrintf("%s: parameter interaction: -zapwallettxes enabled -> setting -rescan=1\n", __func__);
115  }
116  }
118  if (gArgs.GetBoolArg("-sysperms", false))
119  return InitError(Untranslated("-sysperms is not allowed in combination with enabled wallet functionality"));
121  return true;
122 }
125 {
126  if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {
127  LogPrintf("Wallet disabled!\n");
128  return;
129  }
130  gArgs.SoftSetArg("-wallet", "");
131  node.chain_clients.emplace_back(interfaces::MakeWalletClient(*node.chain, gArgs.GetArgs("-wallet")));
132 }
std::vector< std::unique_ptr< interfaces::ChainClient > > chain_clients
Definition: context.h:42
-maxtxfee default
Definition: wallet.h:89
bool SoftSetBoolArg(const std::string &strArg, bool fValue)
Set a boolean argument if it doesn&#39;t already have a value.
Definition: system.cpp:405
constexpr CAmount DEFAULT_PAY_TX_FEE
-paytxfee default
Definition: wallet.h:69
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1164
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
Definition: translation.h:35
void AddWalletOptions() const override
Return the wallets help message.
Definition: init.cpp:37
std::unique_ptr< interfaces::Chain > chain
Definition: context.h:41
std::unique_ptr< ChainClient > MakeWalletClient(Chain &chain, std::vector< std::string > wallet_filenames)
Return implementation of ChainClient interface for a wallet client.
Definition: wallet.cpp:517
static void LogPrintf(const char *fmt, const Args &... args)
Definition: logging.h:164
void Construct(NodeContext &node) const override
Add wallets that should be opened to list of chain clients.
Definition: init.cpp:124
static const bool DEFAULT_DISABLE_WALLET
Definition: wallet.h:87
const std::string CURRENCY_UNIT
Definition: feerate.cpp:10
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition: system.cpp:391
bool HasWalletSupport() const override
Was the wallet component compiled in.
Definition: init.cpp:23
std::string FormatMoney(const CAmount &n)
Money parsing/formatting utilities.
Definition: moneystr.cpp:12
bool SoftSetArg(const std::string &strArg, const std::string &strValue)
Set an argument if it doesn&#39;t already have a value.
Definition: system.cpp:397
static const bool DEFAULT_WALLET_RBF
-walletrbf default
Definition: wallet.h:85
static const CAmount DEFAULT_FALLBACK_FEE
-fallbackfee default
Definition: wallet.h:71
NodeContext struct containing references to chain state and connection state.
Definition: context.h:34
static const unsigned int DEFAULT_KEYPOOL_SIZE
Default for -keypool.
void AddArg(const std::string &name, const std::string &help, unsigned int flags, const OptionsCategory &cat)
Add argument.
Definition: system.cpp:419
Definition: wallet.h:86
Default for -spendzeroconfchange.
Definition: wallet.h:79
constexpr OutputType DEFAULT_ADDRESS_TYPE
Default for -addresstype.
Definition: wallet.h:107
bool InitError(const bilingual_str &str)
Show error message.
Default for -avoidpartialspends.
Definition: coincontrol.h:19
static const unsigned int DEFAULT_TX_CONFIRM_TARGET
-txconfirmtarget default
Definition: wallet.h:83
static const unsigned int DEFAULT_WALLET_DBLOGSIZE
Definition: db.h:33
const std::string & FormatOutputType(OutputType type)
Definition: outputtype.cpp:39
Default for -walletrejectlongchains.
Definition: wallet.h:81
const WalletInitInterface & g_wallet_init_interface
Definition: init.cpp:35
-mintxfee default
Definition: wallet.h:75
static const bool DEFAULT_FLUSHWALLET
Overview of wallet database classes:
Definition: walletdb.h:31
ArgsManager gArgs
Definition: system.cpp:76
Fee rate in satoshis per kilobyte: CAmount / kB.
Definition: feerate.h:19
static const bool DEFAULT_BLOCKSONLY
Default for blocks only.
Definition: net.h:82
static const bool DEFAULT_WALLET_PRIVDB
Definition: db.h:34
std::vector< std::string > GetArgs(const std::string &strArg) const
Return a vector of strings of the given argument.
Definition: system.cpp:360
bool ParameterInteraction() const override
Wallets parameter interaction.
Definition: init.cpp:76
static const CAmount DEFAULT_DISCARD_FEE
-discardfee default
Definition: wallet.h:73