Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 3,534 Lines • ▼ Show 20 Lines | if (nZapSelectTxRet != DBErrors::LOAD_OK) { | ||||
return nZapSelectTxRet; | return nZapSelectTxRet; | ||||
} | } | ||||
MarkDirty(); | MarkDirty(); | ||||
return DBErrors::LOAD_OK; | return DBErrors::LOAD_OK; | ||||
} | } | ||||
DBErrors CWallet::ZapWalletTx(std::list<CWalletTx> &vWtx) { | |||||
DBErrors nZapWalletTxRet = WalletBatch(*database, "cr+").ZapWalletTx(vWtx); | |||||
if (nZapWalletTxRet == DBErrors::NEED_REWRITE) { | |||||
if (database->Rewrite("\x04pool")) { | |||||
for (const auto &spk_man_pair : m_spk_managers) { | |||||
spk_man_pair.second->RewriteDB(); | |||||
} | |||||
} | |||||
} | |||||
if (nZapWalletTxRet != DBErrors::LOAD_OK) { | |||||
return nZapWalletTxRet; | |||||
} | |||||
return DBErrors::LOAD_OK; | |||||
} | |||||
bool CWallet::SetAddressBookWithDB(WalletBatch &batch, | bool CWallet::SetAddressBookWithDB(WalletBatch &batch, | ||||
const CTxDestination &address, | const CTxDestination &address, | ||||
const std::string &strName, | const std::string &strName, | ||||
const std::string &strPurpose) { | const std::string &strPurpose) { | ||||
bool fUpdated = false; | bool fUpdated = false; | ||||
bool is_mine; | bool is_mine; | ||||
{ | { | ||||
LOCK(cs_wallet); | LOCK(cs_wallet); | ||||
▲ Show 20 Lines • Show All 623 Lines • ▼ Show 20 Lines | |||||
std::shared_ptr<CWallet> CWallet::CreateWalletFromFile( | std::shared_ptr<CWallet> CWallet::CreateWalletFromFile( | ||||
const CChainParams &chainParams, interfaces::Chain &chain, | const CChainParams &chainParams, interfaces::Chain &chain, | ||||
const WalletLocation &location, bilingual_str &error, | const WalletLocation &location, bilingual_str &error, | ||||
std::vector<bilingual_str> &warnings, uint64_t wallet_creation_flags) { | std::vector<bilingual_str> &warnings, uint64_t wallet_creation_flags) { | ||||
const std::string walletFile = | const std::string walletFile = | ||||
WalletDataFilePath(location.GetPath()).string(); | WalletDataFilePath(location.GetPath()).string(); | ||||
// Needed to restore wallet transaction meta data after -zapwallettxes | |||||
std::list<CWalletTx> vWtx; | |||||
if (gArgs.GetBoolArg("-zapwallettxes", false)) { | |||||
chain.initMessage( | |||||
_("Zapping all transactions from wallet...").translated); | |||||
std::unique_ptr<CWallet> tempWallet = std::make_unique<CWallet>( | |||||
&chain, location, CreateWalletDatabase(location.GetPath())); | |||||
DBErrors nZapWalletRet = tempWallet->ZapWalletTx(vWtx); | |||||
if (nZapWalletRet != DBErrors::LOAD_OK) { | |||||
error = | |||||
strprintf(_("Error loading %s: Wallet corrupted"), walletFile); | |||||
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(&chain, location, CreateWalletDatabase(location.GetPath())), | new CWallet(&chain, location, CreateWalletDatabase(location.GetPath())), | ||||
▲ Show 20 Lines • Show All 283 Lines • ▼ Show 20 Lines | if (tip_height && *tip_height != rescan_height) { | ||||
{} /* max height */, reserver, true /* update */) | {} /* max height */, reserver, true /* update */) | ||||
.status)) { | .status)) { | ||||
error = _("Failed to rescan the wallet during initialization"); | error = _("Failed to rescan the wallet during initialization"); | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
} | } | ||||
walletInstance->chainStateFlushed(chain.getTipLocator()); | walletInstance->chainStateFlushed(chain.getTipLocator()); | ||||
walletInstance->database->IncrementUpdateCounter(); | walletInstance->database->IncrementUpdateCounter(); | ||||
// Restore wallet transaction metadata after -zapwallettxes=1 | |||||
if (gArgs.GetBoolArg("-zapwallettxes", false) && | |||||
gArgs.GetArg("-zapwallettxes", "1") != "2") { | |||||
WalletBatch batch(*walletInstance->database); | |||||
for (const CWalletTx &wtxOld : vWtx) { | |||||
const TxId txid = wtxOld.GetId(); | |||||
std::map<TxId, CWalletTx>::iterator mi = | |||||
walletInstance->mapWallet.find(txid); | |||||
if (mi != walletInstance->mapWallet.end()) { | |||||
const CWalletTx *copyFrom = &wtxOld; | |||||
CWalletTx *copyTo = &mi->second; | |||||
copyTo->mapValue = copyFrom->mapValue; | |||||
copyTo->vOrderForm = copyFrom->vOrderForm; | |||||
copyTo->nTimeReceived = copyFrom->nTimeReceived; | |||||
copyTo->nTimeSmart = copyFrom->nTimeSmart; | |||||
copyTo->fFromMe = copyFrom->fFromMe; | |||||
copyTo->nOrderPos = copyFrom->nOrderPos; | |||||
batch.WriteTx(*copyTo); | |||||
} | |||||
} | |||||
} | |||||
} | } | ||||
{ | { | ||||
LOCK(cs_wallets); | LOCK(cs_wallets); | ||||
for (auto &load_wallet : g_load_wallet_fns) { | for (auto &load_wallet : g_load_wallet_fns) { | ||||
load_wallet(interfaces::MakeWallet(walletInstance)); | load_wallet(interfaces::MakeWallet(walletInstance)); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 533 Lines • Show Last 20 Lines |