Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/init.cpp
Show First 20 Lines • Show All 343 Lines • ▼ Show 20 Lines | |||||
bool WalletInit::Open(const CChainParams &chainParams) const { | bool WalletInit::Open(const CChainParams &chainParams) const { | ||||
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::CreateWalletFromFile( | std::shared_ptr<CWallet> pwallet = CWallet::CreateWalletFromFile( | ||||
chainParams, walletFile, fs::absolute(walletFile, GetWalletDir())); | chainParams, walletFile, fs::absolute(walletFile, GetWalletDir())); | ||||
if (!pwallet) { | if (!pwallet) { | ||||
return false; | return false; | ||||
} | } | ||||
AddWallet(pwallet); | AddWallet(pwallet); | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
void WalletInit::Start(CScheduler &scheduler) const { | void WalletInit::Start(CScheduler &scheduler) const { | ||||
for (CWallet *pwallet : GetWallets()) { | for (const std::shared_ptr<CWallet> &pwallet : GetWallets()) { | ||||
pwallet->postInitProcess(); | pwallet->postInitProcess(); | ||||
} | } | ||||
// Run a thread to flush wallet periodically | // Run a thread to flush wallet periodically | ||||
scheduler.scheduleEvery( | scheduler.scheduleEvery( | ||||
[] { | [] { | ||||
MaybeCompactWalletDB(); | MaybeCompactWalletDB(); | ||||
return true; | return true; | ||||
}, | }, | ||||
500); | 500); | ||||
} | } | ||||
void WalletInit::Flush() const { | void WalletInit::Flush() const { | ||||
for (CWallet *pwallet : GetWallets()) { | for (const std::shared_ptr<CWallet> &pwallet : GetWallets()) { | ||||
pwallet->Flush(false); | pwallet->Flush(false); | ||||
} | } | ||||
} | } | ||||
void WalletInit::Stop() const { | void WalletInit::Stop() const { | ||||
for (CWallet *pwallet : GetWallets()) { | for (const std::shared_ptr<CWallet> &pwallet : GetWallets()) { | ||||
pwallet->Flush(true); | pwallet->Flush(true); | ||||
} | } | ||||
} | } | ||||
void WalletInit::Close() const { | void WalletInit::Close() const { | ||||
for (CWallet *pwallet : GetWallets()) { | for (const std::shared_ptr<CWallet> &pwallet : GetWallets()) { | ||||
RemoveWallet(pwallet); | RemoveWallet(pwallet); | ||||
delete pwallet; | |||||
} | } | ||||
} | } |