MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / LoadWallet

Method LoadWallet

src/wallet/walletdb.cpp:109–207  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

107}
108
109DBErrors CWalletDB::LoadWallet(CWallet* pWallet) {
110 pWallet->vchDefaultKey = CPubKey();
111 bool fNoncriticalErrors = false;
112 DBErrors result = DB_LOAD_OK;
113
114 try {
115 LOCK(pWallet->cs_wallet);
116 int32_t nMinVersion = 0;
117 if (Read((string) "minversion", nMinVersion)) {
118 if (nMinVersion > CLIENT_VERSION)
119 return DB_TOO_NEW;
120 pWallet->LoadMinVersion(nMinVersion);
121 }
122
123 // Get cursor
124 Dbc* pCursor = GetCursor();
125 if (!pCursor) {
126 LogPrint(BCLog::INFO, "Error getting wallet database cursor\n");
127 return DB_CORRUPT;
128 }
129
130 while (true) {
131 // Read next record
132 CDataStream ssKey(SER_DISK, CLIENT_VERSION);
133 CDataStream ssValue(SER_DISK, CLIENT_VERSION);
134 int32_t ret = ReadAtCursor(pCursor, ssKey, ssValue);
135 if (ret == DB_NOTFOUND)
136 break;
137 else if (ret != 0) {
138 LogPrint(BCLog::INFO, "Error reading next record from wallet database\n");
139 return DB_CORRUPT;
140 }
141
142 // Try to be tolerant of single corrupt records:
143 string strType, strErr;
144 if (!ReadKeyValue(pWallet, ssKey, ssValue, strType, strErr, GetMinVersion())) {
145 // losing keys is considered a catastrophic error, anything else
146 // we assume the user can live with:
147 if (strType == "keystore") {
148 return DB_CORRUPT;
149 } else {
150 // Leave other errors alone, if we try to fix them we might make things worse.
151 fNoncriticalErrors = true; // ... but do warn the user there is something wrong.
152 }
153 }
154 if (!strErr.empty())
155 LogPrint(BCLog::INFO, "%s\n", strErr);
156 }
157
158 pCursor->close();
159
160 } catch (boost::thread_interrupted) {
161 throw;
162 } catch (...) {
163 result = DB_CORRUPT;
164 }
165
166 if (fNoncriticalErrors && result == DB_LOAD_OK)

Callers

nothing calls this directly

Calls 11

CPubKeyClass · 0.85
ReadKeyValueFunction · 0.85
LoadMinVersionMethod · 0.80
MakeNewKeyMethod · 0.80
emptyMethod · 0.45
closeMethod · 0.45
IsEmptyMethod · 0.45
AddKeyMethod · 0.45
GetKeyIdMethod · 0.45
GetPubKeyMethod · 0.45
GetKeysMethod · 0.45

Tested by

no test coverage detected