Bitcoin Core  0.18.99
P2P Digital Currency
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2019 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 <net.h>
9 #include <outputtype.h>
10 #include <util/system.h>
11 #include <util/moneystr.h>
12 #include <walletinitinterface.h>
13 #include <wallet/wallet.h>
14 #include <wallet/walletutil.h>
17 public:
20  bool HasWalletSupport() const override {return true;}
23  void AddWalletOptions() const override;
26  bool ParameterInteraction() const override;
29  void Construct(InitInterfaces& interfaces) const override;
30 };
35 {
36  gArgs.AddArg("-addresstype", strprintf("What type of addresses to use (\"legacy\", \"p2sh-segwit\", or \"bech32\", default: \"%s\")", FormatOutputType(DEFAULT_ADDRESS_TYPE)), false, OptionsCategory::WALLET);
37  gArgs.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)", DEFAULT_AVOIDPARTIALSPENDS), false, OptionsCategory::WALLET);
38  gArgs.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)", false, OptionsCategory::WALLET);
39  gArgs.AddArg("-disablewallet", "Do not load the wallet and disable wallet RPC calls", false, OptionsCategory::WALLET);
40  gArgs.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). "
41  "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",
42  CURRENCY_UNIT, FormatMoney(DEFAULT_DISCARD_FEE)), false, OptionsCategory::WALLET);
43  gArgs.AddArg("-fallbackfee=<amt>", strprintf("A fee rate (in %s/kB) that will be used when fee estimation has insufficient data (default: %s)",
44  CURRENCY_UNIT, FormatMoney(DEFAULT_FALLBACK_FEE)), false, OptionsCategory::WALLET);
45  gArgs.AddArg("-keypool=<n>", strprintf("Set key pool size to <n> (default: %u)", DEFAULT_KEYPOOL_SIZE), false, OptionsCategory::WALLET);
46  gArgs.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)",
48  gArgs.AddArg("-mintxfee=<amt>", strprintf("Fees (in %s/kB) smaller than this are considered zero fee for transaction creation (default: %s)",
49  CURRENCY_UNIT, FormatMoney(DEFAULT_TRANSACTION_MINFEE)), false, OptionsCategory::WALLET);
50  gArgs.AddArg("-paytxfee=<amt>", strprintf("Fee (in %s/kB) to add to transactions you send (default: %s)",
52  gArgs.AddArg("-rescan", "Rescan the block chain for missing wallet transactions on startup", false, OptionsCategory::WALLET);
53  gArgs.AddArg("-salvagewallet", "Attempt to recover private keys from a corrupt wallet on startup", false, OptionsCategory::WALLET);
54  gArgs.AddArg("-spendzeroconfchange", strprintf("Spend unconfirmed change when sending transactions (default: %u)", DEFAULT_SPEND_ZEROCONF_CHANGE), false, OptionsCategory::WALLET);
55  gArgs.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), false, OptionsCategory::WALLET);
56  gArgs.AddArg("-upgradewallet", "Upgrade wallet to latest format on startup", false, OptionsCategory::WALLET);
57  gArgs.AddArg("-wallet=<path>", "Specify wallet database path. Can be specified multiple times to load multiple wallets. Path is interpreted relative to <walletdir> if it is not absolute, and will be created if it does not exist (as a directory containing a wallet.dat file and log files). For backwards compatibility this will also accept names of existing data files in <walletdir>.)", false, OptionsCategory::WALLET);
58  gArgs.AddArg("-walletbroadcast", strprintf("Make the wallet broadcast transactions (default: %u)", DEFAULT_WALLETBROADCAST), false, OptionsCategory::WALLET);
59  gArgs.AddArg("-walletdir=<dir>", "Specify directory to hold wallets (default: <datadir>/wallets if it exists, otherwise <datadir>)", false, OptionsCategory::WALLET);
60  gArgs.AddArg("-walletnotify=<cmd>", "Execute command when a wallet transaction changes (%s in cmd is replaced by TxID)", false, OptionsCategory::WALLET);
61  gArgs.AddArg("-walletrbf", strprintf("Send transactions with full-RBF opt-in enabled (RPC only, default: %u)", DEFAULT_WALLET_RBF), false, OptionsCategory::WALLET);
62  gArgs.AddArg("-zapwallettxes=<mode>", "Delete all wallet transactions and only recover those parts of the blockchain through -rescan on startup"
63  " (1 = keep tx meta data e.g. payment request information, 2 = drop tx meta data)", false, OptionsCategory::WALLET);
65  gArgs.AddArg("-dblogsize=<n>", strprintf("Flush wallet database activity from memory to disk log every <n> megabytes (default: %u)", DEFAULT_WALLET_DBLOGSIZE), true, OptionsCategory::WALLET_DEBUG_TEST);
66  gArgs.AddArg("-flushwallet", strprintf("Run a thread to flush wallet periodically (default: %u)", DEFAULT_FLUSHWALLET), true, OptionsCategory::WALLET_DEBUG_TEST);
67  gArgs.AddArg("-privdb", strprintf("Sets the DB_PRIVATE flag in the wallet db environment (default: %u)", DEFAULT_WALLET_PRIVDB), true, OptionsCategory::WALLET_DEBUG_TEST);
68  gArgs.AddArg("-walletrejectlongchains", strprintf("Wallet will not create transactions that violate mempool chain limits (default: %u)", DEFAULT_WALLET_REJECT_LONG_CHAINS), true, OptionsCategory::WALLET_DEBUG_TEST);
69 }
72 {
73  if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {
74  for (const std::string& wallet : gArgs.GetArgs("-wallet")) {
75  LogPrintf("%s: parameter interaction: -disablewallet -> ignoring -wallet=%s\n", __func__, wallet);
76  }
78  return true;
79  }
81  const bool is_multiwallet = gArgs.GetArgs("-wallet").size() > 1;
83  if (gArgs.GetBoolArg("-blocksonly", DEFAULT_BLOCKSONLY) && gArgs.SoftSetBoolArg("-walletbroadcast", false)) {
84  LogPrintf("%s: parameter interaction: -blocksonly=1 -> setting -walletbroadcast=0\n", __func__);
85  }
87  if (gArgs.GetBoolArg("-salvagewallet", false)) {
88  if (is_multiwallet) {
89  return InitError(strprintf("%s is only allowed with a single wallet file", "-salvagewallet"));
90  }
91  // Rewrite just private keys: rescan to find transactions
92  if (gArgs.SoftSetBoolArg("-rescan", true)) {
93  LogPrintf("%s: parameter interaction: -salvagewallet=1 -> setting -rescan=1\n", __func__);
94  }
95  }
97  bool zapwallettxes = gArgs.GetBoolArg("-zapwallettxes", false);
98  // -zapwallettxes implies dropping the mempool on startup
99  if (zapwallettxes && gArgs.SoftSetBoolArg("-persistmempool", false)) {
100  LogPrintf("%s: parameter interaction: -zapwallettxes enabled -> setting -persistmempool=0\n", __func__);
101  }
103  // -zapwallettxes implies a rescan
104  if (zapwallettxes) {
105  if (is_multiwallet) {
106  return InitError(strprintf("%s is only allowed with a single wallet file", "-zapwallettxes"));
107  }
108  if (gArgs.SoftSetBoolArg("-rescan", true)) {
109  LogPrintf("%s: parameter interaction: -zapwallettxes enabled -> setting -rescan=1\n", __func__);
110  }
111  }
113  if (is_multiwallet) {
114  if (gArgs.GetBoolArg("-upgradewallet", false)) {
115  return InitError(strprintf("%s is only allowed with a single wallet file", "-upgradewallet"));
116  }
117  }
119  if (gArgs.GetBoolArg("-sysperms", false))
120  return InitError("-sysperms is not allowed in combination with enabled wallet functionality");
121  if (gArgs.GetArg("-prune", 0) && gArgs.GetBoolArg("-rescan", false))
122  return InitError(_("Rescans are not possible in pruned mode. You will need to use -reindex which will download the whole blockchain again."));
124  return true;
125 }
128 {
129  if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) {
130  LogPrintf("Wallet disabled!\n");
131  return;
132  }
133  gArgs.SoftSetArg("-wallet", "");
134  interfaces.chain_clients.emplace_back(interfaces::MakeWalletClient(*interfaces.chain, gArgs.GetArgs("-wallet")));
135 }
-maxtxfee default
Definition: wallet.h:77
bool SoftSetBoolArg(const std::string &strArg, bool fValue)
Set a boolean argument if it doesn&#39;t already have a value.
Definition: system.cpp:526
constexpr CAmount DEFAULT_PAY_TX_FEE
-paytxfee default
Definition: wallet.h:55
#define strprintf
Definition: tinyformat.h:1066
void AddWalletOptions() const override
Return the wallets help message.
Definition: init.cpp:34
void Construct(InitInterfaces &interfaces) const override
Add wallets that should be opened to list of init interfaces.
Definition: init.cpp:127
std::vector< std::unique_ptr< interfaces::ChainClient > > chain_clients
Definition: init.h:22
std::unique_ptr< ChainClient > MakeWalletClient(Chain &chain, std::vector< std::string > wallet_filenames)
Return implementation of ChainClient interface for a wallet client.
Definition: wallet.cpp:528
const std::string CURRENCY_UNIT
Definition: feerate.cpp:10
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
Definition: system.cpp:510
bool HasWalletSupport() const override
Was the wallet component compiled in.
Definition: init.cpp:20
std::string FormatMoney(const CAmount &n)
Money parsing/formatting utilities.
Definition: moneystr.cpp:12
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:518
constexpr OutputType DEFAULT_ADDRESS_TYPE
Default for -addresstype.
Definition: wallet.h:114
std::string _(const char *psz)
Translation function.
Definition: system.h:52
const std::string & FormatOutputType(OutputType type)
Definition: outputtype.cpp:35
const WalletInitInterface & g_wallet_init_interface
Definition: init.cpp:32
bool InitError(const std::string &str)
Show error message.
void AddArg(const std::string &name, const std::string &help, const bool debug_only, const OptionsCategory &cat)
Add argument.
Definition: system.cpp:540
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
Definition: system.cpp:494
ArgsManager gArgs
Definition: system.cpp:72
Fee rate in satoshis per kilobyte: CAmount / kB.
Definition: feerate.h:19
std::unique_ptr< interfaces::Chain > chain
Definition: init.h:21
std::vector< std::string > GetArgs(const std::string &strArg) const
Return a vector of strings of the given argument.
Definition: system.cpp:451
bool ParameterInteraction() const override
Wallets parameter interaction.
Definition: init.cpp:71
Pointers to interfaces used during init and destroyed on shutdown.
Definition: init.h:19