Bitcoin Core 32.99.0
P2P Digital Currency
init.cpp
Go to the documentation of this file.
1// Copyright (c) 2009-2010 Satoshi Nakamoto
2// Copyright (c) 2009-present 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 <bitcoin-build-config.h> // IWYU pragma: keep
7
8#include <common/args.h>
9#include <init.h>
10#include <interfaces/chain.h>
11#include <interfaces/init.h>
12#include <interfaces/wallet.h>
13#include <net.h>
14#include <node/context.h>
15#include <node/interface_ui.h>
16#include <outputtype.h>
17#include <univalue.h>
18#include <util/check.h>
19#include <util/moneystr.h>
20#include <util/translation.h>
21#include <wallet/coincontrol.h>
22#include <wallet/wallet.h>
23#include <walletinitinterface.h>
24
26
27namespace wallet {
29{
30public:
32 bool HasWalletSupport() const override {return true;}
33
35 void AddWalletOptions(ArgsManager& argsman) const override;
36
38 bool ParameterInteraction() const override;
39
41 void Construct(NodeContext& node) const override;
42};
43
45{
46 argsman.AddArg("-addresstype", strprintf("What type of addresses to use (%s, default: \"%s\")", FormatAllOutputTypes(), FormatOutputType(DEFAULT_ADDRESS_TYPE)), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
47 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);
48 argsman.AddArg("-changetype",
49 strprintf("What type of change to use (%s). Default is \"legacy\" when "
50 "-addresstype=legacy, else it is an implementation detail.", FormatAllOutputTypes()),
52 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);
53 argsman.AddArg("-disablewallet", "Do not load the wallet and disable wallet RPC calls", ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
54 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). "
55 "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
58 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 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);
61 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);
62 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 argsman.AddArg("-maxfeerate=<amt>", strprintf("Maximum fee rate (in %s/kvB) for wallet transactions (default: %s)", CURRENCY_UNIT, FormatMoney(DEFAULT_MAX_TRANSACTION_FEERATE.GetFeePerK())), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
65 argsman.AddArg("-mintxfee=<amt>", strprintf("Fee rates (in %s/kvB) smaller than this are considered zero fee for transaction creation (default: %s)",
67#ifdef ENABLE_EXTERNAL_SIGNER
68 argsman.AddArg("-signer=<cmd>", "External signing tool, see doc/external-signer.md", ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
69#endif
70 argsman.AddArg("-spendzeroconfchange", strprintf("Spend unconfirmed change when sending transactions (default: %u)", DEFAULT_SPEND_ZEROCONF_CHANGE), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
71 argsman.AddArg("-txconfirmtarget=<n>", strprintf("Include enough fee so transactions begin confirmation on average within n blocks (default: %u)", DEFAULT_TX_CONFIRM_TARGET), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
72 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);
73 argsman.AddArg("-walletbroadcast", strprintf("Make the wallet broadcast transactions (default: %u)", DEFAULT_WALLETBROADCAST), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
74 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);
75#if HAVE_SYSTEM
76 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);
77#endif
78 argsman.AddArg("-walletrbf", strprintf("(DEPRECATED) Send transactions with full-RBF opt-in enabled (default: %u)", DEFAULT_WALLET_RBF), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
79
80 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);
81
82 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);
83 argsman.AddArg("-walletcrosschain", strprintf("Allow reusing wallet files across chains (default: %u)", DEFAULT_WALLETCROSSCHAIN), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::WALLET_DEBUG_TEST);
84}
85
87{
88 if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {
89 for (const std::string& wallet : gArgs.GetArgs("-wallet")) {
90 LogInfo("Parameter interaction: -disablewallet -> ignoring -wallet=%s", wallet);
91 }
92
93 return true;
94 }
95
96 if (gArgs.GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY) && gArgs.SoftSetBoolArg("-walletbroadcast", false)) {
97 LogInfo("Parameter interaction: -blocksonly=1 -> setting -walletbroadcast=0");
98 }
99
100 return true;
101}
102
104{
105 ArgsManager& args = *Assert(node.args);
106 if (args.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {
107 LogInfo("Wallet disabled!");
108 return;
109 }
110 auto wallet_loader = node.init->makeWalletLoader(*node.chain);
111 node.wallet_loader = wallet_loader.get();
112 node.chain_clients.emplace_back(std::move(wallet_loader));
113}
114} // namespace wallet
115
ArgsManager gArgs
Definition: args.cpp:38
ArgsManager & args
Definition: bitcoind.cpp:280
#define Assert(val)
Identity function.
Definition: check.h:116
std::vector< std::string > GetArgs(const std::string &strArg) const EXCLUSIVE_LOCKS_REQUIRED(!cs_args)
Return a vector of strings of the given argument.
Definition: args.cpp:422
@ NETWORK_ONLY
Definition: args.h:128
@ ALLOW_ANY
disable validation
Definition: args.h:114
@ DEBUG_ONLY
Definition: args.h:122
void AddArg(const std::string &name, const std::string &help, unsigned int flags, const OptionsCategory &cat) EXCLUSIVE_LOCKS_REQUIRED(!cs_args)
Add argument.
Definition: args.cpp:657
bool SoftSetBoolArg(const std::string &strArg, bool fValue) EXCLUSIVE_LOCKS_REQUIRED(!cs_args)
Set a boolean argument if it doesn't already have a value.
Definition: args.cpp:619
bool GetBoolArg(const std::string &strArg, bool fDefault) const EXCLUSIVE_LOCKS_REQUIRED(!cs_args)
Return boolean argument or default value.
Definition: args.cpp:571
CAmount GetFeePerK() const
Return the fee in satoshis for a vsize of 1000 vbytes.
Definition: feerate.h:71
bool HasWalletSupport() const override
Was the wallet component compiled in.
Definition: init.cpp:32
bool ParameterInteraction() const override
Wallets parameter interaction.
Definition: init.cpp:86
void Construct(NodeContext &node) const override
Add wallets that should be opened to list of chain clients.
Definition: init.cpp:103
void AddWalletOptions(ArgsManager &argsman) const override
Return the wallets help message.
Definition: init.cpp:44
const std::string CURRENCY_UNIT
Definition: feerate.h:19
#define LogInfo(...)
Definition: log.h:125
std::string FormatMoney(const CAmount n)
Money parsing/formatting utilities.
Definition: moneystr.cpp:19
Definition: messages.h:21
constexpr bool DEFAULT_WALLET_RBF
-walletrbf default
Definition: wallet.h:135
constexpr bool DEFAULT_WALLETCROSSCHAIN
Definition: wallet.h:138
constexpr unsigned int DEFAULT_KEYPOOL_SIZE
Default for -keypool.
constexpr bool DEFAULT_WALLET_REJECT_LONG_CHAINS
Default for -walletrejectlongchains.
Definition: wallet.h:131
constexpr bool DEFAULT_AVOIDPARTIALSPENDS
Default for -avoidpartialspends.
Definition: coincontrol.h:27
constexpr CAmount DEFAULT_TRANSACTION_MAXFEE
-maxtxfee default
Definition: wallet.h:140
constexpr CAmount DEFAULT_MAX_AVOIDPARTIALSPEND_FEE
maximum fee increase allowed to do partial spend avoidance, even for nodes with this feature disabled...
Definition: wallet.h:123
constexpr bool DEFAULT_DISABLE_WALLET
Definition: wallet.h:137
constexpr CFeeRate DEFAULT_MAX_TRANSACTION_FEERATE
-maxfeerate default
Definition: wallet.h:142
constexpr OutputType DEFAULT_ADDRESS_TYPE
Default for -addresstype.
Definition: wallet.h:156
constexpr CAmount DEFAULT_FALLBACK_FEE
-fallbackfee default
Definition: wallet.h:109
constexpr CAmount DEFAULT_CONSOLIDATE_FEERATE
-consolidatefeerate default
Definition: wallet.h:115
constexpr CAmount DEFAULT_TRANSACTION_MINFEE
-mintxfee default
Definition: wallet.h:113
constexpr CAmount DEFAULT_DISCARD_FEE
-discardfee default
Definition: wallet.h:111
constexpr bool DEFAULT_WALLETBROADCAST
Definition: wallet.h:136
constexpr bool DEFAULT_SPEND_ZEROCONF_CHANGE
Default for -spendzeroconfchange.
Definition: wallet.h:129
constexpr unsigned int DEFAULT_TX_CONFIRM_TARGET
-txconfirmtarget default
Definition: wallet.h:133
constexpr bool DEFAULT_BLOCKSONLY
Default for blocks only.
Definition: net.h:87
std::string FormatAllOutputTypes()
Definition: outputtype.cpp:49
const std::string & FormatOutputType(OutputType type)
Definition: outputtype.cpp:37
NodeContext struct containing references to chain state and connection state.
Definition: context.h:57
#define strprintf
Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for...
Definition: tinyformat.h:1172
const WalletInitInterface & g_wallet_init_interface
Definition: init.cpp:116