22 #include <system_error> 34 std::error_code error;
38 fs::path canonical_wallet_dir = fs::canonical(wallet_dir, error);
39 if (error || !
fs::exists(canonical_wallet_dir)) {
42 }
else if (!fs::is_directory(canonical_wallet_dir)) {
46 }
else if (!wallet_dir.is_absolute()) {
77 std::set<fs::path> wallet_paths;
81 chain.
initError(
_(
"Invalid value detected for '-wallet' or '-nowallet'. " 82 "'-wallet' requires a string value, while '-nowallet' accepts only '1' to disable all wallets"));
85 const auto& wallet_file =
wallet.get_str();
88 if (!wallet_paths.insert(path).second) {
116 std::set<fs::path> wallet_paths;
119 chain.
initError(
_(
"Invalid value detected for '-wallet' or '-nowallet'. " 120 "'-wallet' requires a string value, while '-nowallet' accepts only '1' to disable all wallets"));
133 std::vector<bilingual_str> warnings;
150 }
catch (
const std::runtime_error& e) {
158 for (
const std::shared_ptr<CWallet>& pwallet :
GetWallets(context)) {
159 pwallet->postInitProcess();
171 for (
const std::shared_ptr<CWallet>& pwallet :
GetWallets(context)) {
178 for (
const std::shared_ptr<CWallet>& pwallet :
GetWallets(context)) {
186 while (!wallets.empty()) {
187 auto wallet = wallets.back();
189 std::vector<bilingual_str> warnings;
static path PathFromString(const std::string &string)
Convert byte string to path object.
fs::path GetPathArg(std::string arg, const fs::path &default_value={}) const
Return path argument or default value.
void push_back(UniValue val)
bool IsArgSet(const std::string &strArg) const
Return true if the given argument has been manually set.
void ReadDatabaseArgs(const ArgsManager &args, DatabaseOptions &options)
fs::path AbsPathJoin(const fs::path &base, const fs::path &path)
Helper function for joining two paths.
void FlushWallets(WalletContext &context)
Flush all wallets in preparation for shutdown.
static const bool DEFAULT_FLUSHWALLET
Overview of wallet database classes:
virtual std::vector< common::SettingsValue > getSettingsList(const std::string &arg)=0
Get list of settings values.
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
bool GetBoolArg(const std::string &strArg, bool fDefault) const
Return boolean argument or default value.
void ForceSetArg(const std::string &strArg, const std::string &strValue)
fs::path GetWalletDir()
Get the path of the wallet directory.
consteval auto _(util::TranslatedLiteral str)
bool LoadWallets(WalletContext &context)
Load wallet databases.
void MaybeCompactWalletDB(WalletContext &context)
Compacts BDB state so that wallet.dat is self-contained (if there are changes)
void MaybeResendWalletTxs(WalletContext &context)
Called periodically by the schedule thread.
void StopWallets(WalletContext &context)
Stop all wallets. Wallets will be flushed first.
void StartWallets(WalletContext &context)
Complete startup of wallets.
bool VerifyWallets(WalletContext &context)
Responsible for reading and validating the -wallet arguments and verifying the wallet database...
void WaitForDeleteWallet(std::shared_ptr< CWallet > &&wallet)
Explicitly delete the wallet.
static std::string PathToString(const path &path)
Convert path object to a byte string.
virtual bool overwriteRwSetting(const std::string &name, common::SettingsValue value, SettingsAction action=SettingsAction::WRITE)=0
Replace a setting in <datadir>/settings.json with a new value.
void NotifyWalletLoaded(WalletContext &context, const std::shared_ptr< CWallet > &wallet)
virtual void initWarning(const bilingual_str &message)=0
Send init warning.
bool RemoveWallet(WalletContext &context, const std::shared_ptr< CWallet > &wallet, std::optional< bool > load_on_start, std::vector< bilingual_str > &warnings)
std::vector< std::shared_ptr< CWallet > > GetWallets(WalletContext &context)
Interface giving clients (wallet processes, maybe other analysis tools in the future) ability to acce...
virtual void initMessage(const std::string &message)=0
Send init message.
WalletContext struct containing references to state shared between CWallet instances, like the reference to the chain interface, and the list of opened wallets.
interfaces::Chain * chain
void UnloadWallets(WalletContext &context)
Close all wallets.
static bool exists(const path &p)
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
bool verify
Check data integrity on load.
auto Join(const C &container, const S &separator, UnaryOp unary_op)
Join all container items.
virtual void initError(const bilingual_str &message)=0
Send init error.
bool AddWallet(WalletContext &context, const std::shared_ptr< CWallet > &wallet)
void scheduleEvery(Function f, std::chrono::milliseconds delta) EXCLUSIVE_LOCKS_REQUIRED(!newTaskMutex)
Repeat f until the scheduler is stopped.
std::unique_ptr< WalletDatabase > MakeWalletDatabase(const std::string &name, const DatabaseOptions &options, DatabaseStatus &status, bilingual_str &error_string)
#define Assert(val)
Identity function.
static std::shared_ptr< CWallet > Create(WalletContext &context, const std::string &name, std::unique_ptr< WalletDatabase > database, uint64_t wallet_creation_flags, bilingual_str &error, std::vector< bilingual_str > &warnings)