Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 3,409 Lines • ▼ Show 20 Lines | if (fBroadcastTransactions) { | ||||
wtx.RelayWalletTransaction(*locked_chain); | wtx.RelayWalletTransaction(*locked_chain); | ||||
} | } | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
DBErrors CWallet::LoadWallet(bool &fFirstRunRet) { | DBErrors CWallet::LoadWallet(bool &fFirstRunRet) { | ||||
auto locked_chain = chain().lock(); | |||||
LOCK(cs_wallet); | LOCK(cs_wallet); | ||||
fFirstRunRet = false; | fFirstRunRet = false; | ||||
DBErrors nLoadWalletRet = WalletBatch(*database, "cr+").LoadWallet(this); | DBErrors nLoadWalletRet = WalletBatch(*database, "cr+").LoadWallet(this); | ||||
if (nLoadWalletRet == DBErrors::NEED_REWRITE) { | if (nLoadWalletRet == DBErrors::NEED_REWRITE) { | ||||
if (database->Rewrite("\x04pool")) { | if (database->Rewrite("\x04pool")) { | ||||
setInternalKeyPool.clear(); | setInternalKeyPool.clear(); | ||||
setExternalKeyPool.clear(); | setExternalKeyPool.clear(); | ||||
▲ Show 20 Lines • Show All 920 Lines • ▼ Show 20 Lines | try { | ||||
error_string = | error_string = | ||||
strprintf("Error loading wallet %s. %s", location.GetName(), | strprintf("Error loading wallet %s. %s", location.GetName(), | ||||
fsbridge::get_filesystem_error_message(e)); | fsbridge::get_filesystem_error_message(e)); | ||||
return false; | return false; | ||||
} | } | ||||
if (salvage_wallet) { | if (salvage_wallet) { | ||||
// Recover readable keypairs: | // Recover readable keypairs: | ||||
CWallet dummyWallet(chainParams, chain, WalletLocation(), | CWallet dummyWallet(chainParams, &chain, WalletLocation(), | ||||
WalletDatabase::CreateDummy()); | WalletDatabase::CreateDummy()); | ||||
std::string backup_filename; | std::string backup_filename; | ||||
if (!WalletBatch::Recover( | if (!WalletBatch::Recover( | ||||
wallet_path, static_cast<void *>(&dummyWallet), | wallet_path, static_cast<void *>(&dummyWallet), | ||||
WalletBatch::RecoverKeysOnlyFilter, backup_filename)) { | WalletBatch::RecoverKeysOnlyFilter, backup_filename)) { | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
Show All 30 Lines | std::shared_ptr<CWallet> CWallet::CreateWalletFromFile( | ||||
// Needed to restore wallet transaction meta data after -zapwallettxes | // Needed to restore wallet transaction meta data after -zapwallettxes | ||||
std::vector<CWalletTx> vWtx; | std::vector<CWalletTx> vWtx; | ||||
if (gArgs.GetBoolArg("-zapwallettxes", false)) { | if (gArgs.GetBoolArg("-zapwallettxes", false)) { | ||||
chain.initMessage( | chain.initMessage( | ||||
_("Zapping all transactions from wallet...").translated); | _("Zapping all transactions from wallet...").translated); | ||||
std::unique_ptr<CWallet> tempWallet = std::make_unique<CWallet>( | std::unique_ptr<CWallet> tempWallet = std::make_unique<CWallet>( | ||||
chainParams, chain, location, | chainParams, &chain, location, | ||||
WalletDatabase::Create(location.GetPath())); | WalletDatabase::Create(location.GetPath())); | ||||
DBErrors nZapWalletRet = tempWallet->ZapWalletTx(vWtx); | DBErrors nZapWalletRet = tempWallet->ZapWalletTx(vWtx); | ||||
if (nZapWalletRet != DBErrors::LOAD_OK) { | if (nZapWalletRet != DBErrors::LOAD_OK) { | ||||
chain.initError( | chain.initError( | ||||
strprintf(_("Error loading %s: Wallet corrupted").translated, | strprintf(_("Error loading %s: Wallet corrupted").translated, | ||||
walletFile)); | walletFile)); | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
} | } | ||||
chain.initMessage(_("Loading wallet...").translated); | chain.initMessage(_("Loading wallet...").translated); | ||||
int64_t nStart = GetTimeMillis(); | int64_t nStart = GetTimeMillis(); | ||||
bool fFirstRun = true; | bool fFirstRun = true; | ||||
// TODO: Can't use std::make_shared because we need a custom deleter but | // TODO: Can't use std::make_shared because we need a custom deleter but | ||||
// should be possible to use std::allocate_shared. | // should be possible to use std::allocate_shared. | ||||
std::shared_ptr<CWallet> walletInstance( | std::shared_ptr<CWallet> walletInstance( | ||||
new CWallet(chainParams, chain, location, | new CWallet(chainParams, &chain, location, | ||||
WalletDatabase::Create(location.GetPath())), | WalletDatabase::Create(location.GetPath())), | ||||
ReleaseWallet); | ReleaseWallet); | ||||
DBErrors nLoadWalletRet = walletInstance->LoadWallet(fFirstRun); | DBErrors nLoadWalletRet = walletInstance->LoadWallet(fFirstRun); | ||||
if (nLoadWalletRet != DBErrors::LOAD_OK) { | if (nLoadWalletRet != DBErrors::LOAD_OK) { | ||||
if (nLoadWalletRet == DBErrors::CORRUPT) { | if (nLoadWalletRet == DBErrors::CORRUPT) { | ||||
chain.initError( | chain.initError( | ||||
strprintf(_("Error loading %s: Wallet corrupted").translated, | strprintf(_("Error loading %s: Wallet corrupted").translated, | ||||
walletFile)); | walletFile)); | ||||
▲ Show 20 Lines • Show All 498 Lines • Show Last 20 Lines |