Bitcoin ABC  0.24.7
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 <interfaces/wallet.h>
11 #include <net.h>
12 #include <network.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/system.h>
19 #include <util/translation.h>
20 #include <wallet/coincontrol.h>
21 #include <wallet/rpcdump.h>
22 #include <wallet/wallet.h>
23 #include <walletinitinterface.h>
24 
26 public:
28  bool HasWalletSupport() const override { return true; }
29 
31  void AddWalletOptions(ArgsManager &argsman) const override;
32 
34  bool ParameterInteraction() const override;
35 
37  void Construct(NodeContext &node) const override;
38 };
39 
41 
43  argsman.AddArg(
44  "-avoidpartialspends",
45  strprintf("Group outputs by address, selecting all or none, instead of "
46  "selecting on a per-output basis. Privacy is improved as an "
47  "address is only used once (unless someone sends to it after "
48  "spending from it), but may result in slightly higher fees "
49  "as suboptimal coin selection may result due to the added "
50  "limitation (default: %u (always enabled for wallets with "
51  "\"avoid_reuse\" enabled))",
54 
55  argsman.AddArg("-disablewallet",
56  "Do not load the wallet and disable wallet RPC calls",
58  const auto &ticker = Currency::get().ticker;
59  argsman.AddArg("-fallbackfee=<amt>",
60  strprintf("A fee rate (in %s/kB) that will be used when fee "
61  "estimation has insufficient data. 0 to entirely "
62  "disable the fallbackfee feature. (default: %s)",
65  argsman.AddArg(
66  "-keypool=<n>",
67  strprintf("Set key pool size to <n> (default: %u). Warning: Smaller "
68  "sizes may increase the risk of losing funds when restoring "
69  "from an old backup, if none of the addresses in the "
70  "original keypool have been used.",
73  argsman.AddArg(
74  "-maxapsfee=<n>",
75  strprintf(
76  "Spend up to this amount in additional (absolute) fees (in %s) if "
77  "it allows the use of partial spend avoidance (default: %s)",
80  argsman.AddArg(
81  "-maxtxfee=<amt>",
82  strprintf("Maximum total fees (in %s) to use in a single wallet "
83  "transaction or raw transaction; setting this too low may "
84  "abort large transactions (default: %s)",
87  argsman.AddArg("-mintxfee=<amt>",
88  strprintf("Fees (in %s/kB) smaller than this are considered "
89  "zero fee for transaction creation (default: %s)",
90  ticker,
93  argsman.AddArg(
94  "-paytxfee=<amt>",
95  strprintf(
96  "Fee (in %s/kB) to add to transactions you send (default: %s)",
97  ticker, FormatMoney(CFeeRate{DEFAULT_PAY_TX_FEE}.GetFeePerK())),
99  argsman.AddArg(
100  "-rescan",
101  "Rescan the block chain for missing wallet transactions on startup",
103  argsman.AddArg(
104  "-spendzeroconfchange",
105  strprintf(
106  "Spend unconfirmed change when sending transactions (default: %d)",
109  argsman.AddArg(
110  "-wallet=<path>",
111  "Specify wallet database path. Can be specified multiple "
112  "times to load multiple wallets. Path is interpreted relative "
113  "to <walletdir> if it is not absolute, and will be created if "
114  "it does not exist (as a directory containing a wallet.dat "
115  "file and log files). For backwards compatibility this will "
116  "also accept names of existing data files in <walletdir>.)",
119  argsman.AddArg(
120  "-walletbroadcast",
121  strprintf("Make the wallet broadcast transactions (default: %d)",
124  argsman.AddArg("-walletdir=<dir>",
125  "Specify directory to hold wallets (default: "
126  "<datadir>/wallets if it exists, otherwise <datadir>)",
129 #if defined(HAVE_SYSTEM)
130  argsman.AddArg(
131  "-walletnotify=<cmd>",
132  "Execute command when a wallet transaction changes. %s in cmd "
133  "is replaced by TxID and %w is replaced by wallet name. %w is "
134  "not currently implemented on windows. On systems where %w is "
135  "supported, it should NOT be quoted because this would break "
136  "shell escaping used to invoke the command.",
138 #endif
139  argsman.AddArg(
140  "-dblogsize=<n>",
141  strprintf("Flush wallet database activity from memory to disk "
142  "log every <n> megabytes (default: %u)",
146  argsman.AddArg(
147  "-flushwallet",
148  strprintf("Run a thread to flush wallet periodically (default: %d)",
152  argsman.AddArg("-privdb",
153  strprintf("Sets the DB_PRIVATE flag in the wallet db "
154  "environment (default: %d)",
158  argsman.AddArg("-walletrejectlongchains",
159  strprintf("Wallet will not create transactions that violate "
160  "mempool chain limits (default: %d)",
164 
165  argsman.AddHiddenArgs({"-zapwallettxes"});
166 }
167 
169  if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {
170  for (const std::string &wallet : gArgs.GetArgs("-wallet")) {
171  LogPrintf("%s: parameter interaction: -disablewallet -> ignoring "
172  "-wallet=%s\n",
173  __func__, wallet);
174  }
175 
176  return true;
177  }
178 
179  if (gArgs.GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY) &&
180  gArgs.SoftSetBoolArg("-walletbroadcast", false)) {
181  LogPrintf("%s: parameter interaction: -blocksonly=1 -> setting "
182  "-walletbroadcast=0\n",
183  __func__);
184  }
185 
186  if (gArgs.IsArgSet("-zapwallettxes")) {
187  return InitError(
188  Untranslated("-zapwallettxes has been removed. If you are "
189  "attempting to remove a stuck transaction from your "
190  "wallet, please use abandontransaction instead."));
191  }
192 
193  if (gArgs.GetBoolArg("-sysperms", false)) {
194  return InitError(
195  Untranslated("-sysperms is not allowed in combination with enabled "
196  "wallet functionality"));
197  }
198 
199  return true;
200 }
201 
203  ArgsManager &args = *Assert(node.args);
204  if (args.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {
205  LogPrintf("Wallet disabled!\n");
206  return;
207  }
208  auto wallet_client = interfaces::MakeWalletClient(*node.chain, args);
209  node.wallet_client = wallet_client.get();
210  node.chain_clients.emplace_back(std::move(wallet_client));
211 }
g_wallet_init_interface
const WalletInitInterface & g_wallet_init_interface
Definition: init.cpp:40
ArgsManager::GetBoolArg
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition: system.cpp:517
ArgsManager::AddHiddenArgs
void AddHiddenArgs(const std::vector< std::string > &args)
Add many hidden arguments.
Definition: system.cpp:587
DEFAULT_KEYPOOL_SIZE
static const unsigned int DEFAULT_KEYPOOL_SIZE
Default for -keypool.
Definition: scriptpubkeyman.h:51
check.h
WalletInit::Construct
void Construct(NodeContext &node) const override
Add wallets that should be opened to list of chain clients.
Definition: init.cpp:202
wallet.h
DEFAULT_FLUSHWALLET
static const bool DEFAULT_FLUSHWALLET
Overview of wallet database classes:
Definition: walletdb.h:34
NodeContext::args
ArgsManager * args
Definition: context.h:44
ArgsManager::ALLOW_ANY
@ ALLOW_ANY
Definition: system.h:159
ArgsManager::SoftSetBoolArg
bool SoftSetBoolArg(const std::string &strArg, bool fValue)
Set a boolean argument if it doesn't already have a value.
Definition: system.cpp:534
moneystr.h
DEFAULT_WALLET_REJECT_LONG_CHAINS
static const bool DEFAULT_WALLET_REJECT_LONG_CHAINS
Default for -walletrejectlongchains.
Definition: wallet.h:104
ArgsManager::IsArgSet
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
Definition: system.cpp:400
DEFAULT_TRANSACTION_MAXFEE
constexpr Amount DEFAULT_TRANSACTION_MAXFEE
-maxtxfee default
Definition: wallet.h:108
chain.h
interfaces::MakeWalletClient
std::unique_ptr< WalletClient > MakeWalletClient(Chain &chain, ArgsManager &args)
Return implementation of ChainClient interface for a wallet client.
Definition: wallet.cpp:562
context.h
NodeContext::chain
std::unique_ptr< interfaces::Chain > chain
Definition: context.h:45
Assert
#define Assert(val)
Identity function.
Definition: check.h:56
CFeeRate
Fee rate in satoshis per kilobyte: Amount / kB.
Definition: feerate.h:21
WalletInitInterface
Definition: walletinitinterface.h:12
Untranslated
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
Definition: translation.h:36
init.h
ArgsManager::DEBUG_ONLY
@ DEBUG_ONLY
Definition: system.h:160
InitError
bool InitError(const bilingual_str &str)
Show error message.
Definition: ui_interface.cpp:96
ArgsManager::AddArg
void AddArg(const std::string &name, const std::string &help, unsigned int flags, const OptionsCategory &cat)
Add argument.
Definition: system.cpp:565
univalue.h
Currency::get
static const Currency & get()
Definition: amount.cpp:19
WalletInit::ParameterInteraction
bool ParameterInteraction() const override
Wallets parameter interaction.
Definition: init.cpp:168
DEFAULT_FALLBACK_FEE
static const Amount DEFAULT_FALLBACK_FEE
-fallbackfee default
Definition: wallet.h:83
walletinitinterface.h
DEFAULT_WALLET_PRIVDB
static const bool DEFAULT_WALLET_PRIVDB
Definition: bdb.h:28
DEFAULT_PAY_TX_FEE
constexpr Amount DEFAULT_PAY_TX_FEE
-paytxfee default
Definition: wallet.h:81
NodeContext::wallet_client
interfaces::WalletClient * wallet_client
Reference to chain client that should used to load or create wallets opened by the gui.
Definition: context.h:51
ui_interface.h
NodeContext::chain_clients
std::vector< std::unique_ptr< interfaces::ChainClient > > chain_clients
List of all chain clients (wallet processes or other client) connected to node.
Definition: context.h:48
system.h
Currency::ticker
std::string ticker
Definition: amount.h:160
strprintf
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1201
DEFAULT_SPEND_ZEROCONF_CHANGE
static const bool DEFAULT_SPEND_ZEROCONF_CHANGE
Default for -spendzeroconfchange.
Definition: wallet.h:102
WalletInit::HasWalletSupport
bool HasWalletSupport() const override
Was the wallet component compiled in.
Definition: init.cpp:28
ArgsManager
Definition: system.h:152
translation.h
OptionsCategory::WALLET_DEBUG_TEST
@ WALLET_DEBUG_TEST
gArgs
ArgsManager gArgs
Definition: system.cpp:75
FormatMoney
std::string FormatMoney(const Amount amt)
Money parsing/formatting utilities.
Definition: moneystr.cpp:12
OptionsCategory::WALLET
@ WALLET
network.h
DEFAULT_WALLETBROADCAST
static const bool DEFAULT_WALLETBROADCAST
Definition: wallet.h:105
OptionsCategory::DEBUG_TEST
@ DEBUG_TEST
DEFAULT_MAX_AVOIDPARTIALSPEND_FEE
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:96
rpcdump.h
wallet.h
config.h
DEFAULT_TRANSACTION_MINFEE_PER_KB
static const Amount DEFAULT_TRANSACTION_MINFEE_PER_KB
-mintxfee default
Definition: wallet.h:85
ArgsManager::GetArgs
std::vector< std::string > GetArgs(const std::string &strArg) const
Return a vector of strings of the given argument.
Definition: system.cpp:391
ArgsManager::NETWORK_ONLY
@ NETWORK_ONLY
Definition: system.h:166
NodeContext
NodeContext struct containing references to chain state and connection state.
Definition: context.h:36
coincontrol.h
DEFAULT_BLOCKSONLY
static const bool DEFAULT_BLOCKSONLY
Default for blocks only.
Definition: net.h:99
net.h
WalletInit::AddWalletOptions
void AddWalletOptions(ArgsManager &argsman) const override
Return the wallets help message.
Definition: init.cpp:42
DEFAULT_WALLET_DBLOGSIZE
static const unsigned int DEFAULT_WALLET_DBLOGSIZE
Definition: bdb.h:27
LogPrintf
static void LogPrintf(const char *fmt, const Args &... args)
Definition: logging.h:175
WalletInit
Definition: init.cpp:25
DEFAULT_DISABLE_WALLET
static const bool DEFAULT_DISABLE_WALLET
Definition: wallet.h:106
DEFAULT_AVOIDPARTIALSPENDS
static constexpr bool DEFAULT_AVOIDPARTIALSPENDS
Default for -avoidpartialspends.
Definition: coincontrol.h:18