13 #include <validation.h> 37 bool Verify()
const override;
40 bool Open()
const override;
46 void Flush()
const override;
49 void Stop()
const override;
52 void Close()
const override;
60 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);
61 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);
63 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). " 64 "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",
66 gArgs.
AddArg(
"-fallbackfee=<amt>",
strprintf(
"A fee rate (in %s/kB) that will be used when fee estimation has insufficient data (default: %s)",
69 gArgs.
AddArg(
"-mintxfee=<amt>",
strprintf(
"Fees (in %s/kB) smaller than this are considered zero fee for transaction creation (default: %s)",
71 gArgs.
AddArg(
"-paytxfee=<amt>",
strprintf(
"Fee (in %s/kB) to add to transactions you send (default: %s)",
76 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);
78 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);
83 gArgs.
AddArg(
"-zapwallettxes=<mode>",
"Delete all wallet transactions and only recover those parts of the blockchain through -rescan on startup" 84 " (1 = keep tx meta data e.g. payment request information, 2 = drop tx meta data)",
false,
OptionsCategory::WALLET);
95 for (
const std::string& wallet :
gArgs.
GetArgs(
"-wallet")) {
96 LogPrintf(
"%s: parameter interaction: -disablewallet -> ignoring -wallet=%s\n", __func__, wallet);
103 const bool is_multiwallet =
gArgs.
GetArgs(
"-wallet").size() > 1;
106 LogPrintf(
"%s: parameter interaction: -blocksonly=1 -> setting -walletbroadcast=0\n", __func__);
110 if (is_multiwallet) {
111 return InitError(
strprintf(
"%s is only allowed with a single wallet file",
"-salvagewallet"));
115 LogPrintf(
"%s: parameter interaction: -salvagewallet=1 -> setting -rescan=1\n", __func__);
122 LogPrintf(
"%s: parameter interaction: -zapwallettxes enabled -> setting -persistmempool=0\n", __func__);
127 if (is_multiwallet) {
128 return InitError(
strprintf(
"%s is only allowed with a single wallet file",
"-zapwallettxes"));
131 LogPrintf(
"%s: parameter interaction: -zapwallettxes enabled -> setting -rescan=1\n", __func__);
135 if (is_multiwallet) {
137 return InitError(
strprintf(
"%s is only allowed with a single wallet file",
"-upgradewallet"));
142 return InitError(
"-sysperms is not allowed in combination with enabled wallet functionality");
144 return InitError(
_(
"Rescans are not possible in pruned mode. You will need to use -reindex which will download the whole blockchain again."));
148 _(
"The wallet will avoid paying less than the minimum relay fee."));
155 if (nMaxFee > HIGH_MAX_TX_FEE)
156 InitWarning(
_(
"-maxtxfee is set very high! Fees this large could be paid on a single transaction."));
160 return InitError(
strprintf(
_(
"Invalid amount for -maxtxfee=<amount>: '%s' (must be at least the minrelay fee of %s to prevent stuck transactions)"),
184 fs::path wallet_dir =
gArgs.
GetArg(
"-walletdir",
"");
185 boost::system::error_code
error;
187 fs::path canonical_wallet_dir = fs::canonical(wallet_dir,
error);
188 if (
error || !fs::exists(wallet_dir)) {
189 return InitError(
strprintf(
_(
"Specified -walletdir \"%s\" does not exist"), wallet_dir.string()));
190 }
else if (!fs::is_directory(wallet_dir)) {
191 return InitError(
strprintf(
_(
"Specified -walletdir \"%s\" is not a directory"), wallet_dir.string()));
193 }
else if (!wallet_dir.is_absolute()) {
194 return InitError(
strprintf(
_(
"Specified -walletdir \"%s\" is a relative path"), wallet_dir.string()));
199 LogPrintf(
"Using wallet directory %s\n",
GetWalletDir().
string());
203 std::vector<std::string> wallet_files =
gArgs.
GetArgs(
"-wallet");
208 bool salvage_wallet =
gArgs.
GetBoolArg(
"-salvagewallet",
false) && wallet_files.size() <= 1;
211 std::set<fs::path> wallet_paths;
213 for (
const auto& wallet_file : wallet_files) {
214 fs::path wallet_path = fs::absolute(wallet_file,
GetWalletDir());
216 if (!wallet_paths.insert(wallet_path).second) {
217 return InitError(
strprintf(
_(
"Error loading wallet %s. Duplicate -wallet filename specified."), wallet_file));
220 std::string error_string;
221 std::string warning_string;
222 bool verify_success =
CWallet::Verify(wallet_file, salvage_wallet, error_string, warning_string);
223 if (!error_string.empty())
InitError(error_string);
224 if (!warning_string.empty())
InitWarning(warning_string);
225 if (!verify_success)
return false;
234 LogPrintf(
"Wallet disabled!\n");
238 for (
const std::string& walletFile :
gArgs.
GetArgs(
"-wallet")) {
251 for (
const std::shared_ptr<CWallet>& pwallet :
GetWallets()) {
252 pwallet->postInitProcess();
261 for (
const std::shared_ptr<CWallet>& pwallet :
GetWallets()) {
262 pwallet->Flush(
false);
268 for (
const std::shared_ptr<CWallet>& pwallet :
GetWallets()) {
269 pwallet->Flush(
true);
275 for (
const std::shared_ptr<CWallet>& pwallet :
GetWallets()) {
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
static bool Verify(std::string wallet_file, bool salvage_wallet, std::string &error_string, std::string &warning_string)
Verify wallet naming and perform salvage on the wallet if required.
Bitcoin RPC command dispatcher.
std::vector< std::shared_ptr< CWallet > > GetWallets()
bool SoftSetBoolArg(const std::string &strArg, bool fValue)
Set a boolean argument if it doesn't already have a value.
constexpr CAmount DEFAULT_PAY_TX_FEE
-paytxfee default
bool AddWallet(const std::shared_ptr< CWallet > &wallet)
CAmount maxTxFee
Absolute maximum transaction fee (in satoshis) used by wallet and mempool (rejects high fee in sendra...
void AddWalletOptions() const override
Return the wallets help message.
void scheduleEvery(Function f, int64_t deltaMilliSeconds)
const std::string CURRENCY_UNIT
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
bool HasWalletSupport() const override
Was the wallet component compiled in.
void ForceSetArg(const std::string &strArg, const std::string &strValue)
bool SoftSetArg(const std::string &strArg, const std::string &strValue)
Set an argument if it doesn't already have a value.
static std::shared_ptr< CWallet > CreateWalletFromFile(const std::string &name, const fs::path &path, uint64_t wallet_creation_flags=0)
void Close() const override
Close all wallets.
int64_t CAmount
Amount in satoshis (Can be negative)
bool Open() const override
Load wallet databases.
CFeeRate minRelayTxFee
A fee rate smaller than this is considered zero fee (for relaying, mining and transaction creation) ...
void MaybeCompactWalletDB()
Compacts BDB state so that wallet.dat is self-contained (if there are changes)
constexpr OutputType DEFAULT_ADDRESS_TYPE
Default for -addresstype.
bool ParseMoney(const std::string &str, CAmount &nRet)
void RegisterRPC(CRPCTable &tableRPC) const override
Register wallet RPCs.
std::string AmountHighWarn(const std::string &optname)
std::string FormatMoney(const CAmount &n)
Money parsing/formatting utilities.
bool Verify() const override
Responsible for reading and validating the -wallet arguments and verifying the wallet database...
void RegisterWalletRPCCommands(CRPCTable &t)
const std::string & FormatOutputType(OutputType type)
const WalletInitInterface & g_wallet_init_interface
void Stop() const override
Stop all wallets. Wallets will be flushed first.
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.
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
bool RemoveWallet(const std::shared_ptr< CWallet > &wallet)
void Flush() const override
Flush all wallets in preparation for shutdown.
Fee rate in satoshis per kilobyte: CAmount / kB.
fs::path GetWalletDir()
Get the path of the wallet directory.
bool error(const char *fmt, const Args &... args)
void Start(CScheduler &scheduler) const override
Complete startup of wallets.
std::string ToString() const
void InitWarning(const std::string &str)
Show warning message.
CClientUIInterface uiInterface
std::vector< std::string > GetArgs(const std::string &strArg) const
Return a vector of strings of the given argument.
bool ParameterInteraction() const override
Wallets parameter interaction.
std::string AmountErrMsg(const char *const optname, const std::string &strValue)
CAmount GetFeePerK() const
Return the fee in satoshis for a size of 1000 bytes.
std::string _(const char *psz)
Translation function.