MCPcopy Create free account
hub / github.com/LUX-Core/lux / LoadWallet

Method LoadWallet

src/walletdb.cpp:764–858  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

762}
763
764DBErrors CWalletDB::LoadWallet(CWallet* pwallet)
765{
766 pwallet->vchDefaultKey = CPubKey();
767 CWalletScanState wss;
768 bool fNoncriticalErrors = false;
769 DBErrors result = DB_LOAD_OK;
770
771 try {
772 LOCK(pwallet->cs_wallet);
773 int nMinVersion = 0;
774 if (Read((string) "minversion", nMinVersion)) {
775 if (nMinVersion > CLIENT_VERSION)
776 return DB_TOO_NEW;
777 pwallet->LoadMinVersion(nMinVersion);
778 }
779
780 // Get cursor
781 Dbc* pcursor = GetCursor();
782 if (!pcursor) {
783 LogPrintf("Error getting wallet database cursor\n");
784 return DB_CORRUPT;
785 }
786
787 while (true) {
788 // Read next record
789 CDataStream ssKey(SER_DISK, CLIENT_VERSION);
790 CDataStream ssValue(SER_DISK, CLIENT_VERSION);
791 int ret = ReadAtCursor(pcursor, ssKey, ssValue);
792 if (ret == DB_NOTFOUND)
793 break;
794 else if (ret != 0) {
795 LogPrintf("Error reading next record from wallet database\n");
796 return DB_CORRUPT;
797 }
798
799 // Try to be tolerant of single corrupt records:
800 string strType, strErr;
801 if (!ReadKeyValue(pwallet, ssKey, ssValue, wss, strType, strErr)) {
802 // losing keys is considered a catastrophic error, anything else
803 // we assume the user can live with:
804 if (IsKeyType(strType))
805 result = DB_CORRUPT;
806 else {
807 // Leave other errors alone, if we try to fix them we might make things worse.
808 fNoncriticalErrors = true; // ... but do warn the user there is something wrong.
809 if (strType == "tx")
810 // Rescan if there is a bad transaction record:
811 SoftSetBoolArg("-rescan", true);
812 }
813 }
814 if (!strErr.empty())
815 LogPrintf("%s\n", strErr);
816 }
817 pcursor->close();
818 // Store initial external keypool size since we mostly use external keys in mixing
819 pwallet->nKeysLeftSinceAutoBackup = pwallet->KeypoolCountExternalKeys();
820 LogPrintf("nKeysLeftSinceAutoBackup: %d\n", pwallet->nKeysLeftSinceAutoBackup);
821 } catch (boost::thread_interrupted) {

Callers

nothing calls this directly

Calls 9

ReadClass · 0.85
ReadKeyValueFunction · 0.85
IsKeyTypeFunction · 0.85
SoftSetBoolArgFunction · 0.85
LoadMinVersionMethod · 0.80
CPubKeyClass · 0.70
emptyMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected