Bitcoin ABC  0.22.13
P2P Digital Currency
init.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2017 The Bitcoin Core developers
3 // Copyright (c) 2018-2020 The Bitcoin developers
4 // Distributed under the MIT software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 #include <config.h>
8 #include <init.h>
9 #include <interfaces/chain.h>
10 #include <net.h>
11 #include <network.h>
12 #include <node/context.h>
13 #include <node/ui_interface.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/rpcdump.h>
20 #include <wallet/wallet.h>
21 #include <walletinitinterface.h>
22 
24 public:
26  bool HasWalletSupport() const override { return true; }
27 
29  void AddWalletOptions(ArgsManager &argsman) const override;
30 
32  bool ParameterInteraction() const override;
33 
35  void Construct(NodeContext &node) const override;
36 };
37 
39 
41  argsman.AddArg(
42  "-avoidpartialspends",
43  strprintf("Group outputs by address, selecting all or none, instead of "
44  "selecting on a per-output basis. Privacy is improved as an "
45  "address is only used once (unless someone sends to it after "
46  "spending from it), but may result in slightly higher fees "
47  "as suboptimal coin selection may result due to the added "
48  "limitation (default: %u (always enabled for wallets with "
49  "\"avoid_reuse\" enabled))",
52 
53  argsman.AddArg("-disablewallet",
54  "Do not load the wallet and disable wallet RPC calls",
56  argsman.AddArg("-fallbackfee=<amt>",
57  strprintf("A fee rate (in %s/kB) that will be used when fee "
58  "estimation has insufficient data. 0 to entirely "
59  "disable the fallbackfee feature. (default: %s)",
62  argsman.AddArg(
63  "-keypool=<n>",
64  strprintf("Set key pool size to <n> (default: %u). Warning: Smaller "
65  "sizes may increase the risk of losing funds when restoring "
66  "from an old backup, if none of the addresses in the "
67  "original keypool have been used.",
70  argsman.AddArg(
71  "-maxapsfee=<n>",
72  strprintf(
73  "Spend up to this amount in additional (absolute) fees (in %s) if "
74  "it allows the use of partial spend avoidance (default: %s)",
77  argsman.AddArg(
78  "-maxtxfee=<amt>",
79  strprintf("Maximum total fees (in %s) to use in a single wallet "
80  "transaction or raw transaction; setting this too low may "
81  "abort large transactions (default: %s)",
84  argsman.AddArg("-mintxfee=<amt>",
85  strprintf("Fees (in %s/kB) smaller than this are considered "
86  "zero fee for transaction creation (default: %s)",
90  argsman.AddArg(
91  "-paytxfee=<amt>",
92  strprintf(
93  "Fee (in %s/kB) to add to transactions you send (default: %s)",
95  FormatMoney(CFeeRate{DEFAULT_PAY_TX_FEE}.GetFeePerK())),
97  argsman.AddArg(
98  "-rescan",
99  "Rescan the block chain for missing wallet transactions on startup",
101  argsman.AddArg(
102  "-spendzeroconfchange",
103  strprintf(
104  "Spend unconfirmed change when sending transactions (default: %d)",
107  argsman.AddArg(
108  "-wallet=<path>",
109  "Specify wallet database path. Can be specified multiple "
110  "times to load multiple wallets. Path is interpreted relative "
111  "to <walletdir> if it is not absolute, and will be created if "
112  "it does not exist (as a directory containing a wallet.dat "
113  "file and log files). For backwards compatibility this will "
114  "also accept names of existing data files in <walletdir>.)",
117  argsman.AddArg(
118  "-walletbroadcast",
119  strprintf("Make the wallet broadcast transactions (default: %d)",
122  argsman.AddArg("-walletdir=<dir>",
123  "Specify directory to hold wallets (default: "
124  "<datadir>/wallets if it exists, otherwise <datadir>)",
127 #if defined(HAVE_SYSTEM)
128  argsman.AddArg(
129  "-walletnotify=<cmd>",
130  "Execute command when a wallet transaction changes. %s in cmd "
131  "is replaced by TxID and %w is replaced by wallet name. %w is "
132  "not currently implemented on windows. On systems where %w is "
133  "supported, it should NOT be quoted because this would break "
134  "shell escaping used to invoke the command.",
136 #endif
137  argsman.AddArg(
138  "-zapwallettxes=<mode>",
139  "Delete all wallet transactions and only recover those parts of the "
140  "blockchain through -rescan on startup (1 = keep tx meta data e.g. "
141  "payment request information, 2 = drop tx meta data)",
143 
144  argsman.AddArg(
145  "-dblogsize=<n>",
146  strprintf("Flush wallet database activity from memory to disk "
147  "log every <n> megabytes (default: %u)",
151  argsman.AddArg(
152  "-flushwallet",
153  strprintf("Run a thread to flush wallet periodically (default: %d)",
157  argsman.AddArg("-privdb",
158  strprintf("Sets the DB_PRIVATE flag in the wallet db "
159  "environment (default: %d)",
163  argsman.AddArg("-walletrejectlongchains",
164  strprintf("Wallet will not create transactions that violate "
165  "mempool chain limits (default: %d)",
169 }
170 
172  if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {
173  for (const std::string &wallet : gArgs.GetArgs("-wallet")) {
174  LogPrintf("%s: parameter interaction: -disablewallet -> ignoring "
175  "-wallet=%s\n",
176  __func__, wallet);
177  }
178 
179  return true;
180  }
181 
182  const bool is_multiwallet = gArgs.GetArgs("-wallet").size() > 1;
183 
184  if (gArgs.GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY) &&
185  gArgs.SoftSetBoolArg("-walletbroadcast", false)) {
186  LogPrintf("%s: parameter interaction: -blocksonly=1 -> setting "
187  "-walletbroadcast=0\n",
188  __func__);
189  }
190 
191  bool zapwallettxes = gArgs.GetBoolArg("-zapwallettxes", false);
192  // -zapwallettxes implies dropping the mempool on startup
193  if (zapwallettxes && gArgs.SoftSetBoolArg("-persistmempool", false)) {
194  LogPrintf("%s: parameter interaction: -zapwallettxes enabled -> "
195  "setting -persistmempool=0\n",
196  __func__);
197  }
198 
199  // -zapwallettxes implies a rescan
200  if (zapwallettxes) {
201  if (is_multiwallet) {
202  return InitError(strprintf(
203  Untranslated("%s is only allowed with a single wallet file"),
204  "-zapwallettxes"));
205  }
206  if (gArgs.SoftSetBoolArg("-rescan", true)) {
207  LogPrintf("%s: parameter interaction: -zapwallettxes enabled -> "
208  "setting -rescan=1\n",
209  __func__);
210  }
211  }
212 
213  if (gArgs.GetBoolArg("-sysperms", false)) {
214  return InitError(
215  Untranslated("-sysperms is not allowed in combination with enabled "
216  "wallet functionality"));
217  }
218 
219  return true;
220 }
221 
223  ArgsManager &args = *Assert(node.args);
224  if (args.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {
225  LogPrintf("Wallet disabled!\n");
226  return;
227  }
228  args.SoftSetArg("-wallet", "");
230  *node.chain, args, args.GetArgs("-wallet")));
231 }
std::vector< std::unique_ptr< interfaces::ChainClient > > chain_clients
Definition: context.h:46
const std::string CURRENCY_UNIT
Definition: network.cpp:8
bool SoftSetBoolArg(const std::string &strArg, bool fValue)
Set a boolean argument if it doesn&#39;t already have a value.
Definition: system.cpp:515
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1201
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
Definition: translation.h:36
std::unique_ptr< interfaces::Chain > chain
Definition: context.h:45
static void LogPrintf(const char *fmt, const Args &... args)
Definition: logging.h:174
void Construct(NodeContext &node) const override
Add wallets that should be opened to list of chain clients.
Definition: init.cpp:222
static const bool DEFAULT_DISABLE_WALLET
Definition: wallet.h:103
static const unsigned int DEFAULT_WALLET_DBLOGSIZE
Definition: bdb.h:27
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition: system.cpp:498
static const bool DEFAULT_WALLET_PRIVDB
Definition: bdb.h:28
bool HasWalletSupport() const override
Was the wallet component compiled in.
Definition: init.cpp:26
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:505
NodeContext struct containing references to chain state and connection state.
Definition: context.h:35
static const Amount DEFAULT_FALLBACK_FEE
-fallbackfee default
Definition: wallet.h:80
constexpr Amount DEFAULT_PAY_TX_FEE
-paytxfee default
Definition: wallet.h:78
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:546
static const bool DEFAULT_WALLETBROADCAST
Definition: wallet.h:102
static const bool DEFAULT_SPEND_ZEROCONF_CHANGE
Default for -spendzeroconfchange.
Definition: wallet.h:99
bool InitError(const bilingual_str &str)
Show error message.
static constexpr bool DEFAULT_AVOIDPARTIALSPENDS
Default for -avoidpartialspends.
Definition: coincontrol.h:16
void AddWalletOptions(ArgsManager &argsman) const override
Return the wallets help message.
Definition: init.cpp:40
static const bool DEFAULT_WALLET_REJECT_LONG_CHAINS
Default for -walletrejectlongchains.
Definition: wallet.h:101
ArgsManager * args
Definition: context.h:44
const WalletInitInterface & g_wallet_init_interface
Definition: init.cpp:38
static const Amount DEFAULT_MAX_AVOIDPARTIALSPEND_FEE
maximum fee increase allowed to do partial spend avoidance, even for nodes with this feature disabled...
Definition: wallet.h:93
static const bool DEFAULT_FLUSHWALLET
Overview of wallet database classes:
Definition: walletdb.h:34
ArgsManager gArgs
Definition: system.cpp:76
Fee rate in satoshis per kilobyte: Amount / kB.
Definition: feerate.h:21
static const bool DEFAULT_BLOCKSONLY
Default for blocks only.
Definition: net.h:91
std::vector< std::string > GetArgs(const std::string &strArg) const
Return a vector of strings of the given argument.
Definition: system.cpp:381
bool ParameterInteraction() const override
Wallets parameter interaction.
Definition: init.cpp:171
constexpr Amount DEFAULT_TRANSACTION_MAXFEE
-maxtxfee default
Definition: wallet.h:105
std::unique_ptr< ChainClient > MakeWalletClient(Chain &chain, ArgsManager &args, std::vector< std::string > wallet_filenames)
Return implementation of ChainClient interface for a wallet client.
Definition: wallet.cpp:532
static const Amount DEFAULT_TRANSACTION_MINFEE_PER_KB
-mintxfee default
Definition: wallet.h:82
#define Assert(val)
Identity function.
Definition: check.h:57
std::string FormatMoney(const Amount amt)
Money parsing/formatting utilities.
Definition: moneystr.cpp:12