MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / Verify

Method Verify

src/wallet/sqlite.cpp:191–246  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

189}
190
191bool SQLiteDatabase::Verify(bilingual_str& error)
192{
193 assert(m_db);
194
195 // Check the application ID matches our network magic
196 auto read_result = ReadPragmaInteger(m_db, "application_id", "the application id", error);
197 if (!read_result.has_value()) return false;
198 uint32_t app_id = static_cast<uint32_t>(read_result.value());
199 uint32_t net_magic = ReadBE32(Params().MessageStart().data());
200 if (app_id != net_magic) {
201 error = strprintf(_("SQLiteDatabase: Unexpected application id. Expected %u, got %u"), net_magic, app_id);
202 return false;
203 }
204
205 // Check our schema version
206 read_result = ReadPragmaInteger(m_db, "user_version", "sqlite wallet schema version", error);
207 if (!read_result.has_value()) return false;
208 int32_t user_ver = read_result.value();
209 if (user_ver != WALLET_SCHEMA_VERSION) {
210 error = strprintf(_("SQLiteDatabase: Unknown sqlite wallet schema version %d. Only version %d is supported"), user_ver, WALLET_SCHEMA_VERSION);
211 return false;
212 }
213
214 sqlite3_stmt* stmt{nullptr};
215 int ret = sqlite3_prepare_v2(m_db, "PRAGMA integrity_check", -1, &stmt, nullptr);
216 if (ret != SQLITE_OK) {
217 sqlite3_finalize(stmt);
218 error = strprintf(_("SQLiteDatabase: Failed to prepare statement to verify database: %s"), sqlite3_errstr(ret));
219 return false;
220 }
221 while (true) {
222 ret = sqlite3_step(stmt);
223 if (ret == SQLITE_DONE) {
224 break;
225 }
226 if (ret != SQLITE_ROW) {
227 error = strprintf(_("SQLiteDatabase: Failed to execute statement to verify database: %s"), sqlite3_errstr(ret));
228 break;
229 }
230 const char* msg = (const char*)sqlite3_column_text(stmt, 0);
231 if (!msg) {
232 error = strprintf(_("SQLiteDatabase: Failed to read database verification error: %s"), sqlite3_errstr(ret));
233 break;
234 }
235 std::string str_msg(msg);
236 if (str_msg == "ok") {
237 continue;
238 }
239 if (error.empty()) {
240 error = _("Failed to verify database") + Untranslated("\n");
241 }
242 error += Untranslated(strprintf("%s\n", str_msg));
243 }
244 sqlite3_finalize(stmt);
245 return error.empty();
246}
247
248void SQLiteDatabase::Open()

Callers 6

MakeSQLiteDatabaseFunction · 0.45
VerifyECDSASignatureMethod · 0.45
BOOST_AUTO_TEST_CASEFunction · 0.45
key.cppFile · 0.45
run_verify_testFunction · 0.45
BOOST_AUTO_TEST_CASEFunction · 0.45

Calls 9

ReadPragmaIntegerFunction · 0.85
ReadBE32Function · 0.85
_Function · 0.85
UntranslatedFunction · 0.85
ParamsClass · 0.50
has_valueMethod · 0.45
valueMethod · 0.45
dataMethod · 0.45
emptyMethod · 0.45

Tested by 3

BOOST_AUTO_TEST_CASEFunction · 0.36
run_verify_testFunction · 0.36
BOOST_AUTO_TEST_CASEFunction · 0.36