Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 3,246 Lines • ▼ Show 20 Lines | DBErrors CWallet::LoadWallet(bool &fFirstRunRet) { | ||||
// status may be not reliable. | // status may be not reliable. | ||||
auto locked_chain = LockChain(); | auto locked_chain = LockChain(); | ||||
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(); | if (auto spk_man = m_spk_man.get()) { | ||||
setExternalKeyPool.clear(); | spk_man->RewriteDB(); | ||||
m_spk_man->m_pool_key_to_index.clear(); | } | ||||
// Note: can't top-up keypool here, because wallet is locked. | |||||
// User will be prompted to unlock wallet the next operation | |||||
// that requires a new key. | |||||
} | } | ||||
} | } | ||||
{ | { | ||||
LOCK(cs_KeyStore); | LOCK(cs_KeyStore); | ||||
// This wallet is in its first run if all of these are empty | // This wallet is in its first run if all of these are empty | ||||
fFirstRunRet = mapKeys.empty() && mapCryptedKeys.empty() && | fFirstRunRet = mapKeys.empty() && mapCryptedKeys.empty() && | ||||
mapWatchKeys.empty() && setWatchOnly.empty() && | mapWatchKeys.empty() && setWatchOnly.empty() && | ||||
Show All 18 Lines | for (const TxId &txid : txIdsOut) { | ||||
const auto &it = mapWallet.find(txid); | const auto &it = mapWallet.find(txid); | ||||
wtxOrdered.erase(it->second.m_it_wtxOrdered); | wtxOrdered.erase(it->second.m_it_wtxOrdered); | ||||
mapWallet.erase(it); | mapWallet.erase(it); | ||||
NotifyTransactionChanged(this, txid, CT_DELETED); | NotifyTransactionChanged(this, txid, CT_DELETED); | ||||
} | } | ||||
if (nZapSelectTxRet == DBErrors::NEED_REWRITE) { | if (nZapSelectTxRet == DBErrors::NEED_REWRITE) { | ||||
if (database->Rewrite("\x04pool")) { | if (database->Rewrite("\x04pool")) { | ||||
setInternalKeyPool.clear(); | if (auto spk_man = m_spk_man.get()) { | ||||
setExternalKeyPool.clear(); | spk_man->RewriteDB(); | ||||
m_spk_man->m_pool_key_to_index.clear(); | } | ||||
// Note: can't top-up keypool here, because wallet is locked. | |||||
// User will be prompted to unlock wallet the next operation | |||||
// that requires a new key. | |||||
} | } | ||||
} | } | ||||
if (nZapSelectTxRet != DBErrors::LOAD_OK) { | if (nZapSelectTxRet != DBErrors::LOAD_OK) { | ||||
return nZapSelectTxRet; | return nZapSelectTxRet; | ||||
} | } | ||||
MarkDirty(); | MarkDirty(); | ||||
return DBErrors::LOAD_OK; | return DBErrors::LOAD_OK; | ||||
} | } | ||||
DBErrors CWallet::ZapWalletTx(std::vector<CWalletTx> &vWtx) { | DBErrors CWallet::ZapWalletTx(std::vector<CWalletTx> &vWtx) { | ||||
DBErrors nZapWalletTxRet = WalletBatch(*database, "cr+").ZapWalletTx(vWtx); | DBErrors nZapWalletTxRet = WalletBatch(*database, "cr+").ZapWalletTx(vWtx); | ||||
if (nZapWalletTxRet == DBErrors::NEED_REWRITE) { | if (nZapWalletTxRet == DBErrors::NEED_REWRITE) { | ||||
if (database->Rewrite("\x04pool")) { | if (database->Rewrite("\x04pool")) { | ||||
LOCK(cs_wallet); | if (auto spk_man = m_spk_man.get()) { | ||||
setInternalKeyPool.clear(); | spk_man->RewriteDB(); | ||||
setExternalKeyPool.clear(); | } | ||||
m_spk_man->m_pool_key_to_index.clear(); | |||||
// Note: can't top-up keypool here, because wallet is locked. | |||||
// User will be prompted to unlock wallet the next operation | |||||
// that requires a new key. | |||||
} | } | ||||
} | } | ||||
if (nZapWalletTxRet != DBErrors::LOAD_OK) { | if (nZapWalletTxRet != DBErrors::LOAD_OK) { | ||||
return nZapWalletTxRet; | return nZapWalletTxRet; | ||||
} | } | ||||
return DBErrors::LOAD_OK; | return DBErrors::LOAD_OK; | ||||
▲ Show 20 Lines • Show All 1,151 Lines • Show Last 20 Lines |