27 const fs::path &path) {
28 if (fs::exists(path)) {
29 tfm::format(std::cerr,
"Error: File exists already\n");
33 std::shared_ptr<CWallet> wallet_instance(
37 LOCK(wallet_instance->cs_wallet);
38 bool first_run =
true;
39 DBErrors load_wallet_ret = wallet_instance->LoadWallet(first_run);
48 auto spk_man = wallet_instance->GetOrCreateLegacyScriptPubKeyMan();
49 CPubKey seed = spk_man->GenerateNewSeed();
50 spk_man->SetHDSeed(seed);
53 wallet_instance->TopUpKeyPool();
54 return wallet_instance;
58 const fs::path &path) {
59 if (!fs::exists(path)) {
60 tfm::format(std::cerr,
"Error: Wallet files does not exist\n");
65 std::shared_ptr<CWallet> wallet_instance(
72 load_wallet_ret = wallet_instance->LoadWallet(first_run);
73 }
catch (
const std::runtime_error &) {
76 "Error loading %s. Is wallet being used by another process?\n",
82 wallet_instance =
nullptr;
84 tfm::format(std::cerr,
"Error loading %s: Wallet corrupted", name);
89 "Error reading %s! All keys read correctly, but transaction " 90 "data or address book entries might be missing or incorrect.",
94 "Error loading %s: Wallet requires newer version of %s",
99 "Wallet needed to be rewritten: restart %s to complete",
108 return wallet_instance;
114 tfm::format(std::cout,
"Wallet info\n===========\n");
116 wallet_instance->
IsCrypted() ?
"yes" :
"no");
117 tfm::format(std::cout,
"HD (hd seed available): %s\n",
122 wallet_instance->mapWallet.size());
124 wallet_instance->m_address_book.size());
135 database->Verify(error_string);
136 }
catch (
const fs::filesystem_error &e) {
141 if (!error_string.
original.empty()) {
142 tfm::format(std::cerr,
"Failed to open wallet for salvage :%s\n",
152 const std::string &
name) {
155 if (command ==
"create") {
156 std::shared_ptr<CWallet> wallet_instance =
CreateWallet(name, path);
157 if (wallet_instance) {
159 wallet_instance->Flush(
true);
161 }
else if (command ==
"info" || command ==
"salvage") {
162 if (!fs::exists(path)) {
163 tfm::format(std::cerr,
"Error: no wallet file at %s\n", name);
167 if (command ==
"info") {
168 std::shared_ptr<CWallet> wallet_instance =
LoadWallet(name, path);
169 if (!wallet_instance) {
173 wallet_instance->Flush(
true);
174 }
else if (command ==
"salvage") {
178 tfm::format(std::cerr,
"Invalid command: %s\n", command);
unsigned int GetKeyPoolSize() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet)
bilingual_str Untranslated(std::string original)
Mark a bilingual_str as untranslated.
DBErrors
Error statuses for the wallet database.
void WalletLogPrintf(std::string fmt, Params... parameters) const
Prepends the wallet name in logging output to ease debugging in multi-wallet use cases.
An encapsulated public key.
void Flush(bool shutdown=false)
Flush wallet (bitdb flush)
static std::unique_ptr< BerkeleyDatabase > Create(const fs::path &path)
Return object for accessing database at specified path.
std::string get_filesystem_error_message(const fs::filesystem_error &e)
A CWallet maintains a set of transactions and balances, and provides the ability to create new transa...
fs::path GetWalletDir()
Get the path of the wallet directory.
The WalletLocation class provides wallet information.
bool RecoverDatabaseFile(const fs::path &file_path)