Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
Show First 20 Lines • Show All 4,247 Lines • ▼ Show 20 Lines | if (gArgs.GetBoolArg("-zapwallettxes", false)) { | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
} | } | ||||
uiInterface.InitMessage(_("Loading wallet...")); | uiInterface.InitMessage(_("Loading wallet...")); | ||||
int64_t nStart = GetTimeMillis(); | int64_t nStart = GetTimeMillis(); | ||||
bool fFirstRun = true; | bool fFirstRun = true; | ||||
CWallet *walletInstance = | // Make a temporary wallet unique pointer so memory doesn't get leaked if | ||||
new CWallet(chainParams, name, WalletDatabase::Create(path)); | // wallet creation fails. | ||||
auto temp_wallet = std::make_unique<CWallet>(chainParams, name, | |||||
WalletDatabase::Create(path)); | |||||
CWallet *walletInstance = temp_wallet.get(); | |||||
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) { | ||||
InitError( | InitError( | ||||
strprintf(_("Error loading %s: Wallet corrupted"), walletFile)); | strprintf(_("Error loading %s: Wallet corrupted"), walletFile)); | ||||
return nullptr; | return nullptr; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 150 Lines • ▼ Show 20 Lines | if (!gArgs.GetBoolArg("-rescan", false)) { | ||||
WalletBatch batch(*walletInstance->database); | WalletBatch batch(*walletInstance->database); | ||||
CBlockLocator locator; | CBlockLocator locator; | ||||
if (batch.ReadBestBlock(locator)) { | if (batch.ReadBestBlock(locator)) { | ||||
pindexRescan = FindForkInGlobalIndex(chainActive, locator); | pindexRescan = FindForkInGlobalIndex(chainActive, locator); | ||||
} | } | ||||
} | } | ||||
walletInstance->m_last_block_processed = chainActive.Tip(); | walletInstance->m_last_block_processed = chainActive.Tip(); | ||||
RegisterValidationInterface(walletInstance); | |||||
if (chainActive.Tip() && chainActive.Tip() != pindexRescan) { | if (chainActive.Tip() && chainActive.Tip() != pindexRescan) { | ||||
// We can't rescan beyond non-pruned blocks, stop and throw an error. | // We can't rescan beyond non-pruned blocks, stop and throw an error. | ||||
// This might happen if a user uses an old wallet within a pruned node | // This might happen if a user uses an old wallet within a pruned node | ||||
// or if he ran -disablewallet for a longer time, then decided to | // or if he ran -disablewallet for a longer time, then decided to | ||||
// re-enable. | // re-enable. | ||||
if (fPruneMode) { | if (fPruneMode) { | ||||
CBlockIndex *block = chainActive.Tip(); | CBlockIndex *block = chainActive.Tip(); | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | if (chainActive.Tip() && chainActive.Tip() != pindexRescan) { | ||||
copyTo->strFromAccount = copyFrom->strFromAccount; | copyTo->strFromAccount = copyFrom->strFromAccount; | ||||
copyTo->nOrderPos = copyFrom->nOrderPos; | copyTo->nOrderPos = copyFrom->nOrderPos; | ||||
batch.WriteTx(*copyTo); | batch.WriteTx(*copyTo); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// Register with the validation interface. It's ok to do this after rescan | |||||
// since we're still holding cs_main. | |||||
RegisterValidationInterface(temp_wallet.release()); | |||||
walletInstance->SetBroadcastTransactions( | walletInstance->SetBroadcastTransactions( | ||||
gArgs.GetBoolArg("-walletbroadcast", DEFAULT_WALLETBROADCAST)); | gArgs.GetBoolArg("-walletbroadcast", DEFAULT_WALLETBROADCAST)); | ||||
LOCK(walletInstance->cs_wallet); | LOCK(walletInstance->cs_wallet); | ||||
LogPrintf("setKeyPool.size() = %u\n", walletInstance->GetKeyPoolSize()); | LogPrintf("setKeyPool.size() = %u\n", walletInstance->GetKeyPoolSize()); | ||||
LogPrintf("mapWallet.size() = %u\n", walletInstance->mapWallet.size()); | LogPrintf("mapWallet.size() = %u\n", walletInstance->mapWallet.size()); | ||||
LogPrintf("mapAddressBook.size() = %u\n", | LogPrintf("mapAddressBook.size() = %u\n", | ||||
walletInstance->mapAddressBook.size()); | walletInstance->mapAddressBook.size()); | ||||
▲ Show 20 Lines • Show All 194 Lines • Show Last 20 Lines |