Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 1,228 Lines • ▼ Show 20 Lines | if (!strCmd.empty()) { | ||||
std::thread t(runCommand, strCmd); | std::thread t(runCommand, strCmd); | ||||
// Thread runs free. | // Thread runs free. | ||||
t.detach(); | t.detach(); | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
void CWallet::LoadToWallet(const CWalletTx &wtxIn) { | void CWallet::LoadToWallet(CWalletTx &wtxIn) { | ||||
// If wallet doesn't have a chain (e.g wallet-tool), lock can't be taken. | |||||
auto locked_chain = LockChain(); | |||||
// If tx hasn't been reorged out of chain while wallet being shutdown | |||||
// change tx status to UNCONFIRMED and reset hashBlock/nIndex. | |||||
if (!wtxIn.m_confirm.hashBlock.IsNull()) { | |||||
if (locked_chain && | |||||
!locked_chain->getBlockHeight(wtxIn.m_confirm.hashBlock)) { | |||||
wtxIn.setUnconfirmed(); | |||||
wtxIn.m_confirm.hashBlock = BlockHash(); | |||||
wtxIn.m_confirm.nIndex = 0; | |||||
} | |||||
} | |||||
const TxId &txid = wtxIn.GetId(); | const TxId &txid = wtxIn.GetId(); | ||||
const auto &ins = mapWallet.emplace(txid, wtxIn); | const auto &ins = mapWallet.emplace(txid, wtxIn); | ||||
CWalletTx &wtx = ins.first->second; | CWalletTx &wtx = ins.first->second; | ||||
wtx.BindWallet(this); | wtx.BindWallet(this); | ||||
if (/* insertion took place */ ins.second) { | if (/* insertion took place */ ins.second) { | ||||
wtx.m_it_wtxOrdered = | wtx.m_it_wtxOrdered = | ||||
wtxOrdered.insert(std::make_pair(wtx.nOrderPos, &wtx)); | wtxOrdered.insert(std::make_pair(wtx.nOrderPos, &wtx)); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 2,429 Lines • ▼ Show 20 Lines | if (fBroadcastTransactions) { | ||||
// instead delete wtx from the wallet and return failure. | // instead delete wtx from the wallet and return failure. | ||||
} | } | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
DBErrors CWallet::LoadWallet(bool &fFirstRunRet) { | DBErrors CWallet::LoadWallet(bool &fFirstRunRet) { | ||||
// Even if we don't use this lock in this function, we want to preserve | |||||
// lock order in LoadToWallet if query of chain state is needed to know | |||||
// tx status. If lock can't be taken (e.g wallet-tool), tx confirmation | |||||
// status may be not reliable. | |||||
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(); | setInternalKeyPool.clear(); | ||||
setExternalKeyPool.clear(); | setExternalKeyPool.clear(); | ||||
▲ Show 20 Lines • Show All 954 Lines • ▼ Show 20 Lines | try { | ||||
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; | ||||
// Even if we don't use this lock in this function, we want to preserve | |||||
// lock order in LoadToWallet if query of chain state is needed to know | |||||
// tx status. If lock can't be taken, tx confirmation status may be not | |||||
// reliable. | |||||
auto locked_chain = dummyWallet.LockChain(); | |||||
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; | ||||
} | } | ||||
} | } | ||||
return WalletBatch::VerifyDatabaseFile(wallet_path, warning_string, | return WalletBatch::VerifyDatabaseFile(wallet_path, warning_string, | ||||
▲ Show 20 Lines • Show All 783 Lines • Show Last 20 Lines |