Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
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 <common/args.h>
8#include <config.h>
9#include <init.h>
10#include <interfaces/chain.h>
11#include <interfaces/wallet.h>
12#include <net.h>
13#include <node/context.h>
14#include <node/ui_interface.h>
15#include <univalue.h>
16#include <util/check.h>
17#include <util/moneystr.h>
18#include <util/translation.h>
19#include <wallet/coincontrol.h>
20#include <wallet/rpc/backup.h>
21#include <wallet/wallet.h>
22#include <walletinitinterface.h>
23
25
27public:
29 bool HasWalletSupport() const override { return true; }
30
32 void AddWalletOptions(ArgsManager &argsman) const override;
33
35 bool ParameterInteraction() const override;
36
38 void Construct(NodeContext &node) const override;
39};
40
42
44 argsman.AddArg(
45 "-avoidpartialspends",
46 strprintf("Group outputs by address, selecting all or none, instead of "
47 "selecting on a per-output basis. Privacy is improved as an "
48 "address is only used once (unless someone sends to it after "
49 "spending from it), but may result in slightly higher fees "
50 "as suboptimal coin selection may result due to the added "
51 "limitation (default: %u (always enabled for wallets with "
52 "\"avoid_reuse\" enabled))",
55
56 argsman.AddArg("-disablewallet",
57 "Do not load the wallet and disable wallet RPC calls",
59 const auto &ticker = Currency::get().ticker;
60 argsman.AddArg("-fallbackfee=<amt>",
61 strprintf("A fee rate (in %s/kB) that will be used when fee "
62 "estimation has insufficient data. 0 to entirely "
63 "disable the fallbackfee feature. (default: %s)",
66 argsman.AddArg(
67 "-keypool=<n>",
68 strprintf("Set key pool size to <n> (default: %u). Warning: Smaller "
69 "sizes may increase the risk of losing funds when restoring "
70 "from an old backup, if none of the addresses in the "
71 "original keypool have been used.",
74 argsman.AddArg(
75 "-maxapsfee=<n>",
77 "Spend up to this amount in additional (absolute) fees (in %s) if "
78 "it allows the use of partial spend avoidance (default: %s)",
81 argsman.AddArg(
82 "-maxtxfee=<amt>",
83 strprintf("Maximum total fees (in %s) to use in a single wallet "
84 "transaction or raw transaction; setting this too low may "
85 "abort large transactions (default: %s)",
88 argsman.AddArg("-mintxfee=<amt>",
89 strprintf("Fees (in %s/kB) smaller than this are considered "
90 "zero fee for transaction creation (default: %s)",
91 ticker,
94 argsman.AddArg(
95 "-paytxfee=<amt>",
97 "Fee (in %s/kB) to add to transactions you send (default: %s)",
98 ticker, FormatMoney(CFeeRate{DEFAULT_PAY_TX_FEE}.GetFeePerK())),
100 argsman.AddArg(
101 "-rescan",
102 "Rescan the block chain for missing wallet transactions on startup",
104 argsman.AddArg(
105 "-spendzeroconfchange",
106 strprintf(
107 "Spend unconfirmed change when sending transactions (default: %d)",
110 argsman.AddArg(
111 "-wallet=<path>",
112 "Specify wallet path to load at startup. Can be used multiple times to "
113 "load multiple wallets. Path is to a directory containing wallet data "
114 "and log files. If the path is not absolute, it is interpreted "
115 "relative to <walletdir>. This only loads existing wallets and does "
116 "not create new ones. For backwards compatibility this also accepts "
117 "names of existing top-level data files in <walletdir>.",
120 argsman.AddArg(
121 "-walletbroadcast",
122 strprintf("Make the wallet broadcast transactions (default: %d)",
125 argsman.AddArg("-walletdir=<dir>",
126 "Specify directory to hold wallets (default: "
127 "<datadir>/wallets if it exists, otherwise <datadir>)",
130#if defined(HAVE_SYSTEM)
131 argsman.AddArg(
132 "-walletnotify=<cmd>",
133 "Execute command when a wallet transaction changes. %s in cmd "
134 "is replaced by TxID and %w is replaced by wallet name. %w is "
135 "not currently implemented on windows. On systems where %w is "
136 "supported, it should NOT be quoted because this would break "
137 "shell escaping used to invoke the command.",
139#endif
140 argsman.AddArg(
141 "-dblogsize=<n>",
142 strprintf("Flush wallet database activity from memory to disk "
143 "log every <n> megabytes (default: %u)",
147 argsman.AddArg(
148 "-flushwallet",
149 strprintf("Run a thread to flush wallet periodically (default: %d)",
153 argsman.AddArg("-privdb",
154 strprintf("Sets the DB_PRIVATE flag in the wallet db "
155 "environment (default: %d)",
159
160 argsman.AddHiddenArgs({"-zapwallettxes"});
161}
162
164 if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {
165 for (const std::string &wallet : gArgs.GetArgs("-wallet")) {
166 LogPrintf("%s: parameter interaction: -disablewallet -> ignoring "
167 "-wallet=%s\n",
169 }
170
171 return true;
172 }
173
174 if (gArgs.GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY) &&
175 gArgs.SoftSetBoolArg("-walletbroadcast", false)) {
176 LogPrintf("%s: parameter interaction: -blocksonly=1 -> setting "
177 "-walletbroadcast=0\n",
178 __func__);
179 }
180
181 if (gArgs.IsArgSet("-zapwallettxes")) {
182 return InitError(
183 Untranslated("-zapwallettxes has been removed. If you are "
184 "attempting to remove a stuck transaction from your "
185 "wallet, please use abandontransaction instead."));
186 }
187
188 if (gArgs.GetBoolArg("-sysperms", false)) {
189 return InitError(
190 Untranslated("-sysperms is not allowed in combination with enabled "
191 "wallet functionality"));
192 }
193
194 return true;
195}
196
198 ArgsManager &args = *Assert(node.args);
199 if (args.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {
200 LogPrintf("Wallet disabled!\n");
201 return;
202 }
203 auto wallet_client = interfaces::MakeWalletClient(*node.chain, args);
204 node.wallet_client = wallet_client.get();
205 node.chain_clients.emplace_back(std::move(wallet_client));
206}
ArgsManager gArgs
Definition args.cpp:38
static const unsigned int DEFAULT_WALLET_DBLOGSIZE
Definition bdb.h:28
static const bool DEFAULT_WALLET_PRIVDB
Definition bdb.h:29
#define Assert(val)
Identity function.
Definition check.h:84
@ NETWORK_ONLY
Definition args.h:110
@ ALLOW_ANY
Definition args.h:103
@ DEBUG_ONLY
Definition args.h:104
std::vector< std::string > GetArgs(const std::string &strArg) const
Return a vector of strings of the given argument.
Definition args.cpp:371
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
Definition args.cpp:381
bool SoftSetBoolArg(const std::string &strArg, bool fValue)
Set a boolean argument if it doesn't already have a value.
Definition args.cpp:589
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition args.cpp:556
Fee rate in satoshis per kilobyte: Amount / kB.
Definition feerate.h:21
void Construct(NodeContext &node) const override
Add wallets that should be opened to list of chain clients.
Definition init.cpp:197
bool ParameterInteraction() const override
Wallets parameter interaction.
Definition init.cpp:163
void AddWalletOptions(ArgsManager &argsman) const override
Return the wallets help message.
Definition init.cpp:43
bool HasWalletSupport() const override
Was the wallet component compiled in.
Definition init.cpp:29
static constexpr bool DEFAULT_AVOIDPARTIALSPENDS
Default for -avoidpartialspends.
Definition coincontrol.h:18
#define LogPrintf(...)
Definition logging.h:207
std::string FormatMoney(const Amount amt)
Do not use these functions to represent or parse monetary amounts to or from JSON but use AmountFromV...
Definition moneystr.cpp:13
std::unique_ptr< WalletClient > MakeWalletClient(Chain &chain, ArgsManager &args)
Return implementation of ChainClient interface for a wallet client.
Definition init.h:28
static const bool DEFAULT_BLOCKSONLY
Default for blocks only.
Definition net.h:94
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85
static const unsigned int DEFAULT_KEYPOOL_SIZE
Default for -keypool.
static const Currency & get()
Definition amount.cpp:18
std::string ticker
Definition amount.h:150
NodeContext struct containing references to chain state and connection state.
Definition context.h:43
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
Definition translation.h:36
bool InitError(const bilingual_str &str)
Show error message.
const WalletInitInterface & g_wallet_init_interface
Definition init.cpp:41
constexpr Amount DEFAULT_PAY_TX_FEE
-paytxfee default
Definition wallet.h:83
static const bool DEFAULT_DISABLE_WALLET
Definition wallet.h:106
static const Amount DEFAULT_FALLBACK_FEE
-fallbackfee default
Definition wallet.h:85
static const Amount DEFAULT_TRANSACTION_MINFEE_PER_KB
-mintxfee default
Definition wallet.h:87
static const bool DEFAULT_SPEND_ZEROCONF_CHANGE
Default for -spendzeroconfchange.
Definition wallet.h:104
constexpr Amount DEFAULT_TRANSACTION_MAXFEE
-maxtxfee default
Definition wallet.h:108
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:98
static const bool DEFAULT_WALLETBROADCAST
Definition wallet.h:105
static const bool DEFAULT_FLUSHWALLET
Overview of wallet database classes:
Definition walletdb.h:33