Bitcoin Core  21.99.0
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 <interfaces/wallet.h>
9 #include <net.h>
10 #include <node/context.h>
11 #include <node/ui_interface.h>
12 #include <outputtype.h>
13 #include <univalue.h>
14 #include <util/check.h>
15 #include <util/moneystr.h>
16 #include <util/system.h>
17 #include <util/translation.h>
18 #ifdef USE_BDB
19 #include <wallet/bdb.h>
20 #endif
21 #include <wallet/coincontrol.h>
22 #include <wallet/wallet.h>
23 #include <walletinitinterface.h>
26 {
27 public:
29  bool HasWalletSupport() const override {return true;}
32  void AddWalletOptions(ArgsManager& argsman) const override;
35  bool ParameterInteraction() const override;
38  void Construct(NodeContext& node) const override;
39 };
44 {
45  argsman.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);
46  argsman.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);
47  argsman.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);
48  argsman.AddArg("-disablewallet", "Do not load the wallet and disable wallet RPC calls", ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
49  argsman.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). "
50  "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",
53  argsman.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)",
55  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);
56  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);
57  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)",
59  argsman.AddArg("-mintxfee=<amt>", strprintf("Fees (in %s/kB) smaller than this are considered zero fee for transaction creation (default: %s)",
61  argsman.AddArg("-paytxfee=<amt>", strprintf("Fee (in %s/kB) to add to transactions you send (default: %s)",
63  argsman.AddArg("-rescan", "Rescan the block chain for missing wallet transactions on startup", ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
64  argsman.AddArg("-spendzeroconfchange", strprintf("Spend unconfirmed change when sending transactions (default: %u)", DEFAULT_SPEND_ZEROCONF_CHANGE), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
65  argsman.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);
66  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);
67  argsman.AddArg("-walletbroadcast", strprintf("Make the wallet broadcast transactions (default: %u)", DEFAULT_WALLETBROADCAST), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
68  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);
70  argsman.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);
71 #endif
72  argsman.AddArg("-walletrbf", strprintf("Send transactions with full-RBF opt-in enabled (RPC only, default: %u)", DEFAULT_WALLET_RBF), ArgsManager::ALLOW_ANY, OptionsCategory::WALLET);
74 #ifdef USE_BDB
75  argsman.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);
76  argsman.AddArg("-flushwallet", strprintf("Run a thread to flush wallet periodically (default: %u)", DEFAULT_FLUSHWALLET), ArgsManager::ALLOW_ANY | ArgsManager::DEBUG_ONLY, OptionsCategory::WALLET_DEBUG_TEST);
77  argsman.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);
78 #else
79  argsman.AddHiddenArgs({"-dblogsize", "-flushwallet", "-privdb"});
80 #endif
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);
84  argsman.AddHiddenArgs({"-zapwallettxes"});
85 }
88 {
89  if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {
90  for (const std::string& wallet : gArgs.GetArgs("-wallet")) {
91  LogPrintf("%s: parameter interaction: -disablewallet -> ignoring -wallet=%s\n", __func__, wallet);
92  }
94  return true;
95  }
97  if (gArgs.GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY) && gArgs.SoftSetBoolArg("-walletbroadcast", false)) {
98  LogPrintf("%s: parameter interaction: -blocksonly=1 -> setting -walletbroadcast=0\n", __func__);
99  }
101  if (gArgs.IsArgSet("-zapwallettxes")) {
102  return InitError(Untranslated("-zapwallettxes has been removed. If you are attempting to remove a stuck transaction from your wallet, please use abandontransaction instead."));
103  }
105  if (gArgs.GetBoolArg("-sysperms", false))
106  return InitError(Untranslated("-sysperms is not allowed in combination with enabled wallet functionality"));
108  return true;
109 }
112 {
113  ArgsManager& args = *Assert(node.args);
114  if (args.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {
115  LogPrintf("Wallet disabled!\n");
116  return;
117  }
118  auto wallet_client = interfaces::MakeWalletClient(*node.chain, args);
119  node.wallet_client = wallet_client.get();
120  node.chain_clients.emplace_back(std::move(wallet_client));
121 }
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:47
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
Definition: system.cpp:371
maximum fee increase allowed to do partial spend avoidance, even for nodes with this feature disabled...
Definition: wallet.h:77
-maxtxfee default
Definition: wallet.h:93
bool SoftSetBoolArg(const std::string &strArg, bool fValue)
Set a boolean argument if it doesn&#39;t already have a value.
Definition: system.cpp:493
constexpr CAmount DEFAULT_PAY_TX_FEE
-paytxfee default
Definition: wallet.h:63
#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:40
void AddHiddenArgs(const std::vector< std::string > &args)
Add many hidden arguments.
Definition: system.cpp:526
std::unique_ptr< interfaces::Chain > chain
Definition: context.h:45
static void LogPrintf(const char *fmt, const Args &... args)
Definition: logging.h:166
void Construct(NodeContext &node) const override
Add wallets that should be opened to list of chain clients.
Definition: init.cpp:111
static const bool DEFAULT_DISABLE_WALLET
Definition: wallet.h:91
static const unsigned int DEFAULT_WALLET_DBLOGSIZE
Definition: bdb.h:34
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition: system.cpp:479
static const bool DEFAULT_WALLET_PRIVDB
Definition: bdb.h:35
bool HasWalletSupport() const override
Was the wallet component compiled in.
Definition: init.cpp:29
std::string FormatMoney(const CAmount &n)
Money parsing/formatting utilities.
Definition: moneystr.cpp:12
static const bool DEFAULT_WALLET_RBF
-walletrbf default
Definition: wallet.h:89
static const CAmount DEFAULT_FALLBACK_FEE
-fallbackfee default
Definition: wallet.h:65
NodeContext struct containing references to chain state and connection state.
Definition: context.h:37
static const unsigned int DEFAULT_KEYPOOL_SIZE
Default for -keypool.
interfaces::WalletClient * wallet_client
Reference to chain client that should used to load or create wallets opened by the gui...
Definition: context.h:50
void AddArg(const std::string &name, const std::string &help, unsigned int flags, const OptionsCategory &cat)
Add argument.
Definition: system.cpp:507
Definition: wallet.h:90
const std::string CURRENCY_UNIT
Definition: feerate.h:14
Default for -spendzeroconfchange.
Definition: wallet.h:83
constexpr OutputType DEFAULT_ADDRESS_TYPE
Default for -addresstype.
Definition: wallet.h:111
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:87
const std::string & FormatOutputType(OutputType type)
Definition: outputtype.cpp:37
void AddWalletOptions(ArgsManager &argsman) const override
Return the wallets help message.
Definition: init.cpp:43
Default for -walletrejectlongchains.
Definition: wallet.h:85
std::unique_ptr< WalletClient > MakeWalletClient(Chain &chain, ArgsManager &args)
Return implementation of ChainClient interface for a wallet client.
Definition: interfaces.cpp:583
ArgsManager * args
Definition: context.h:44
const WalletInitInterface & g_wallet_init_interface
Definition: init.cpp:41
-mintxfee default
Definition: wallet.h:69
static const bool DEFAULT_FLUSHWALLET
Overview of wallet database classes:
Definition: walletdb.h:31
ArgsManager gArgs
Definition: system.cpp:77
Fee rate in satoshis per kilobyte: CAmount / kB.
Definition: feerate.h:29
static const bool DEFAULT_BLOCKSONLY
Default for blocks only.
Definition: net.h:75
std::vector< std::string > GetArgs(const std::string &strArg) const
Return a vector of strings of the given argument.
Definition: system.cpp:362
bool ParameterInteraction() const override
Wallets parameter interaction.
Definition: init.cpp:87
static const CAmount DEFAULT_DISCARD_FEE
-discardfee default
Definition: wallet.h:67
#define Assert(val)
Identity function.
Definition: check.h:57