Changeset View
Changeset View
Standalone View
Standalone View
src/wallet/wallet.cpp
| Show First 20 Lines • Show All 569 Lines • ▼ Show 20 Lines | bool CWallet::HasWalletSpend(const uint256 &txid) const { | ||||
| auto iter = mapTxSpends.lower_bound(COutPoint(txid, 0)); | auto iter = mapTxSpends.lower_bound(COutPoint(txid, 0)); | ||||
| return (iter != mapTxSpends.end() && iter->first.hash == txid); | return (iter != mapTxSpends.end() && iter->first.hash == txid); | ||||
| } | } | ||||
| void CWallet::Flush(bool shutdown) { | void CWallet::Flush(bool shutdown) { | ||||
| dbw->Flush(shutdown); | dbw->Flush(shutdown); | ||||
| } | } | ||||
| bool CWallet::Verify() { | bool CWallet::Verify(const CChainParams &chainParams) { | ||||
| if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) { | if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) { | ||||
| return true; | return true; | ||||
| } | } | ||||
| uiInterface.InitMessage(_("Verifying wallet(s)...")); | uiInterface.InitMessage(_("Verifying wallet(s)...")); | ||||
| // Keep track of each wallet absolute path to detect duplicates. | // Keep track of each wallet absolute path to detect duplicates. | ||||
| std::set<fs::path> wallet_paths; | std::set<fs::path> wallet_paths; | ||||
| Show All 30 Lines | for (const std::string &walletFile : gArgs.GetArgs("-wallet")) { | ||||
| std::string strError; | std::string strError; | ||||
| if (!CWalletDB::VerifyEnvironment(walletFile, GetDataDir().string(), | if (!CWalletDB::VerifyEnvironment(walletFile, GetDataDir().string(), | ||||
| strError)) { | strError)) { | ||||
| return InitError(strError); | return InitError(strError); | ||||
| } | } | ||||
| if (gArgs.GetBoolArg("-salvagewallet", false)) { | if (gArgs.GetBoolArg("-salvagewallet", false)) { | ||||
| // Recover readable keypairs: | // Recover readable keypairs: | ||||
| CWallet dummyWallet; | CWallet dummyWallet(chainParams); | ||||
| std::string backup_filename; | std::string backup_filename; | ||||
| if (!CWalletDB::Recover(walletFile, (void *)&dummyWallet, | if (!CWalletDB::Recover(walletFile, (void *)&dummyWallet, | ||||
| CWalletDB::RecoverKeysOnlyFilter, | CWalletDB::RecoverKeysOnlyFilter, | ||||
| backup_filename)) { | backup_filename)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 1,072 Lines • ▼ Show 20 Lines | |||||
| * before CWallet::nTimeFirstKey). Returns null if there is no such range, or | * before CWallet::nTimeFirstKey). Returns null if there is no such range, or | ||||
| * the range doesn't include chainActive.Tip(). | * the range doesn't include chainActive.Tip(). | ||||
| */ | */ | ||||
| CBlockIndex *CWallet::ScanForWalletTransactions(CBlockIndex *pindexStart, | CBlockIndex *CWallet::ScanForWalletTransactions(CBlockIndex *pindexStart, | ||||
| bool fUpdate) { | bool fUpdate) { | ||||
| LOCK2(cs_main, cs_wallet); | LOCK2(cs_main, cs_wallet); | ||||
| int64_t nNow = GetTime(); | int64_t nNow = GetTime(); | ||||
| const CChainParams &chainParams = Params(); | |||||
| CBlockIndex *pindex = pindexStart; | CBlockIndex *pindex = pindexStart; | ||||
| CBlockIndex *ret = pindexStart; | CBlockIndex *ret = pindexStart; | ||||
| // No need to read and scan block, if block was created before our wallet | // No need to read and scan block, if block was created before our wallet | ||||
| // birthday (as adjusted for block time variability) | // birthday (as adjusted for block time variability) | ||||
| while (pindex && nTimeFirstKey && | while (pindex && nTimeFirstKey && | ||||
| (pindex->GetBlockTime() < (nTimeFirstKey - 7200))) { | (pindex->GetBlockTime() < (nTimeFirstKey - 7200))) { | ||||
| ▲ Show 20 Lines • Show All 2,384 Lines • ▼ Show 20 Lines | if (showDebug) { | ||||
| strprintf(_("Wallet will not create transactions that violate " | strprintf(_("Wallet will not create transactions that violate " | ||||
| "mempool chain limits (default: %d)"), | "mempool chain limits (default: %d)"), | ||||
| DEFAULT_WALLET_REJECT_LONG_CHAINS)); | DEFAULT_WALLET_REJECT_LONG_CHAINS)); | ||||
| } | } | ||||
| return strUsage; | return strUsage; | ||||
| } | } | ||||
| CWallet *CWallet::CreateWalletFromFile(const std::string walletFile) { | CWallet *CWallet::CreateWalletFromFile(const CChainParams &chainParams, | ||||
| const std::string walletFile) { | |||||
| // 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)) { | ||||
| uiInterface.InitMessage(_("Zapping all transactions from wallet...")); | uiInterface.InitMessage(_("Zapping all transactions from wallet...")); | ||||
| std::unique_ptr<CWalletDBWrapper> dbw( | std::unique_ptr<CWalletDBWrapper> dbw( | ||||
| new CWalletDBWrapper(&bitdb, walletFile)); | new CWalletDBWrapper(&bitdb, walletFile)); | ||||
| CWallet *tempWallet = new CWallet(std::move(dbw)); | CWallet *tempWallet = new CWallet(chainParams, std::move(dbw)); | ||||
| DBErrors nZapWalletRet = tempWallet->ZapWalletTx(vWtx); | DBErrors nZapWalletRet = tempWallet->ZapWalletTx(vWtx); | ||||
| if (nZapWalletRet != DB_LOAD_OK) { | if (nZapWalletRet != DB_LOAD_OK) { | ||||
| InitError( | InitError( | ||||
| strprintf(_("Error loading %s: Wallet corrupted"), walletFile)); | strprintf(_("Error loading %s: Wallet corrupted"), walletFile)); | ||||
| return nullptr; | return nullptr; | ||||
| } | } | ||||
| delete tempWallet; | delete tempWallet; | ||||
| tempWallet = nullptr; | tempWallet = nullptr; | ||||
| } | } | ||||
| uiInterface.InitMessage(_("Loading wallet...")); | uiInterface.InitMessage(_("Loading wallet...")); | ||||
| int64_t nStart = GetTimeMillis(); | int64_t nStart = GetTimeMillis(); | ||||
| bool fFirstRun = true; | bool fFirstRun = true; | ||||
| std::unique_ptr<CWalletDBWrapper> dbw( | std::unique_ptr<CWalletDBWrapper> dbw( | ||||
| new CWalletDBWrapper(&bitdb, walletFile)); | new CWalletDBWrapper(&bitdb, walletFile)); | ||||
| CWallet *walletInstance = new CWallet(std::move(dbw)); | CWallet *walletInstance = new CWallet(chainParams, std::move(dbw)); | ||||
| DBErrors nLoadWalletRet = walletInstance->LoadWallet(fFirstRun); | DBErrors nLoadWalletRet = walletInstance->LoadWallet(fFirstRun); | ||||
| if (nLoadWalletRet != DB_LOAD_OK) { | if (nLoadWalletRet != DB_LOAD_OK) { | ||||
| if (nLoadWalletRet == DB_CORRUPT) { | if (nLoadWalletRet == DB_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 159 Lines • ▼ Show 20 Lines | CWallet *CWallet::CreateWalletFromFile(const CChainParams &chainParams, | ||||
| 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()); | ||||
| return walletInstance; | return walletInstance; | ||||
| } | } | ||||
| bool CWallet::InitLoadWallet() { | bool CWallet::InitLoadWallet(const CChainParams &chainParams) { | ||||
| if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) { | if (gArgs.GetBoolArg("-disablewallet", DEFAULT_DISABLE_WALLET)) { | ||||
| LogPrintf("Wallet disabled!\n"); | LogPrintf("Wallet disabled!\n"); | ||||
| return true; | return true; | ||||
| } | } | ||||
| for (const std::string &walletFile : gArgs.GetArgs("-wallet")) { | for (const std::string &walletFile : gArgs.GetArgs("-wallet")) { | ||||
| CWallet *const pwallet = CreateWalletFromFile(walletFile); | CWallet *const pwallet = CreateWalletFromFile(chainParams, walletFile); | ||||
| if (!pwallet) { | if (!pwallet) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| vpwallets.push_back(pwallet); | vpwallets.push_back(pwallet); | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 250 Lines • Show Last 20 Lines | |||||