Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/init.cpp
// Copyright (c) 2009-2010 Satoshi Nakamoto | // Copyright (c) 2009-2010 Satoshi Nakamoto | ||||
// Copyright (c) 2009-2017 The Bitcoin Core developers | // Copyright (c) 2009-2017 The Bitcoin Core developers | ||||
// Copyright (c) 2018 The Bitcoin developers | // Copyright (c) 2018 The Bitcoin developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include "wallet/init.h" | #include "wallet/init.h" | ||||
#include "config.h" | #include "config.h" | ||||
#include "net.h" | #include "net.h" | ||||
#include "util.h" | #include "util.h" | ||||
#include "utilmoneystr.h" | #include "utilmoneystr.h" | ||||
#include "validation.h" | #include "validation.h" | ||||
#include "wallet/rpcwallet.h" | #include "wallet/rpcwallet.h" | ||||
#include "wallet/wallet.h" | #include "wallet/wallet.h" | ||||
std::string GetWalletHelpString(bool showDebug) { | std::string WalletInit::GetHelpString(bool showDebug) { | ||||
std::string strUsage = HelpMessageGroup(_("Wallet options:")); | std::string strUsage = HelpMessageGroup(_("Wallet options:")); | ||||
strUsage += HelpMessageOpt( | strUsage += HelpMessageOpt( | ||||
"-disablewallet", | "-disablewallet", | ||||
_("Do not load the wallet and disable wallet RPC calls")); | _("Do not load the wallet and disable wallet RPC calls")); | ||||
strUsage += HelpMessageOpt( | strUsage += HelpMessageOpt( | ||||
"-keypool=<n>", strprintf(_("Set key pool size to <n> (default: %u)"), | "-keypool=<n>", strprintf(_("Set key pool size to <n> (default: %u)"), | ||||
DEFAULT_KEYPOOL_SIZE)); | DEFAULT_KEYPOOL_SIZE)); | ||||
strUsage += HelpMessageOpt( | strUsage += HelpMessageOpt( | ||||
▲ Show 20 Lines • Show All 70 Lines • ▼ Show 20 Lines | if (showDebug) { | ||||
strprintf(_("Wallet will not create transactions that violate " | strprintf(_("Wallet will not create transactions that violate " | ||||
"mempool chain limits (default: %d)"), | "mempool chain limits (default: %d)"), | ||||
DEFAULT_WALLET_REJECT_LONG_CHAINS)); | DEFAULT_WALLET_REJECT_LONG_CHAINS)); | ||||
} | } | ||||
return strUsage; | return strUsage; | ||||
} | } | ||||
bool WalletParameterInteraction() { | bool WalletInit::ParameterInteraction() { | ||||
CFeeRate minRelayTxFee = GetConfig().GetMinFeePerKB(); | CFeeRate minRelayTxFee = GetConfig().GetMinFeePerKB(); | ||||
gArgs.SoftSetArg("-wallet", DEFAULT_WALLET_DAT); | gArgs.SoftSetArg("-wallet", DEFAULT_WALLET_DAT); | ||||
const bool is_multiwallet = gArgs.GetArgs("-wallet").size() > 1; | const bool is_multiwallet = gArgs.GetArgs("-wallet").size() > 1; | ||||
if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) { | if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) { | ||||
return true; | return true; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 132 Lines • ▼ Show 20 Lines | bool WalletInit::ParameterInteraction() { | ||||
nTxConfirmTarget = | nTxConfirmTarget = | ||||
gArgs.GetArg("-txconfirmtarget", DEFAULT_TX_CONFIRM_TARGET); | gArgs.GetArg("-txconfirmtarget", DEFAULT_TX_CONFIRM_TARGET); | ||||
bSpendZeroConfChange = | bSpendZeroConfChange = | ||||
gArgs.GetBoolArg("-spendzeroconfchange", DEFAULT_SPEND_ZEROCONF_CHANGE); | gArgs.GetBoolArg("-spendzeroconfchange", DEFAULT_SPEND_ZEROCONF_CHANGE); | ||||
return true; | return true; | ||||
} | } | ||||
void RegisterWalletRPC(CRPCTable &t) { | void WalletInit::RegisterRPC(CRPCTable &t) { | ||||
if (gArgs.GetBoolArg("-disablewallet", false)) { | if (gArgs.GetBoolArg("-disablewallet", false)) { | ||||
return; | return; | ||||
} | } | ||||
RegisterWalletRPCCommands(t); | RegisterWalletRPCCommands(t); | ||||
} | } | ||||
bool VerifyWallets(const CChainParams &chainParams) { | bool WalletInit::Verify(const CChainParams &chainParams) { | ||||
if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) { | if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) { | ||||
return true; | return true; | ||||
} | } | ||||
uiInterface.InitMessage(_("Verifying wallet(s)...")); | uiInterface.InitMessage(_("Verifying wallet(s)...")); | ||||
// Keep track of each wallet absolute path to detect duplicates. | // Keep track of each wallet absolute path to detect duplicates. | ||||
std::set<fs::path> wallet_paths; | std::set<fs::path> wallet_paths; | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | for (const std::string &walletFile : gArgs.GetArgs("-wallet")) { | ||||
InitError(strError); | InitError(strError); | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
bool OpenWallets(const CChainParams &chainParams) { | bool WalletInit::Open(const CChainParams &chainParams) { | ||||
if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) { | if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) { | ||||
LogPrintf("Wallet disabled!\n"); | LogPrintf("Wallet disabled!\n"); | ||||
return true; | return true; | ||||
} | } | ||||
for (const std::string &walletFile : gArgs.GetArgs("-wallet")) { | for (const std::string &walletFile : gArgs.GetArgs("-wallet")) { | ||||
CWallet *const pwallet = | CWallet *const pwallet = | ||||
CWallet::CreateWalletFromFile(chainParams, walletFile); | CWallet::CreateWalletFromFile(chainParams, walletFile); | ||||
if (!pwallet) { | if (!pwallet) { | ||||
return false; | return false; | ||||
} | } | ||||
vpwallets.push_back(pwallet); | vpwallets.push_back(pwallet); | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
void StartWallets(CScheduler &scheduler) { | void WalletInit::Start(CScheduler &scheduler) { | ||||
for (CWalletRef pwallet : vpwallets) { | for (CWalletRef pwallet : vpwallets) { | ||||
pwallet->postInitProcess(scheduler); | pwallet->postInitProcess(scheduler); | ||||
} | } | ||||
} | } | ||||
void FlushWallets() { | void WalletInit::Flush() { | ||||
for (CWalletRef pwallet : vpwallets) { | for (CWalletRef pwallet : vpwallets) { | ||||
pwallet->Flush(false); | pwallet->Flush(false); | ||||
} | } | ||||
} | } | ||||
void StopWallets() { | void WalletInit::Stop() { | ||||
for (CWalletRef pwallet : vpwallets) { | for (CWalletRef pwallet : vpwallets) { | ||||
pwallet->Flush(true); | pwallet->Flush(true); | ||||
} | } | ||||
} | } | ||||
void CloseWallets() { | void WalletInit::Close() { | ||||
for (CWalletRef pwallet : vpwallets) { | for (CWalletRef pwallet : vpwallets) { | ||||
delete pwallet; | delete pwallet; | ||||
} | } | ||||
vpwallets.clear(); | vpwallets.clear(); | ||||
} | } |