MCPcopy Create free account
hub / github.com/ElementsProject/elements / WriteKey

Method WriteKey

src/wallet/sqlite.cpp:407–444  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

405}
406
407bool SQLiteBatch::WriteKey(CDataStream&& key, CDataStream&& value, bool overwrite)
408{
409 if (!m_database.m_db) return false;
410 assert(m_insert_stmt && m_overwrite_stmt);
411
412 sqlite3_stmt* stmt;
413 if (overwrite) {
414 stmt = m_overwrite_stmt;
415 } else {
416 stmt = m_insert_stmt;
417 }
418
419 // Bind: leftmost parameter in statement is index 1
420 // Insert index 1 is key, 2 is value
421 int res = sqlite3_bind_blob(stmt, 1, key.data(), key.size(), SQLITE_STATIC);
422 if (res != SQLITE_OK) {
423 LogPrintf("%s: Unable to bind key to statement: %s\n", __func__, sqlite3_errstr(res));
424 sqlite3_clear_bindings(stmt);
425 sqlite3_reset(stmt);
426 return false;
427 }
428 res = sqlite3_bind_blob(stmt, 2, value.data(), value.size(), SQLITE_STATIC);
429 if (res != SQLITE_OK) {
430 LogPrintf("%s: Unable to bind value to statement: %s\n", __func__, sqlite3_errstr(res));
431 sqlite3_clear_bindings(stmt);
432 sqlite3_reset(stmt);
433 return false;
434 }
435
436 // Execute
437 res = sqlite3_step(stmt);
438 sqlite3_clear_bindings(stmt);
439 sqlite3_reset(stmt);
440 if (res != SQLITE_DONE) {
441 LogPrintf("%s: Unable to execute statement: %s\n", __func__, sqlite3_errstr(res));
442 }
443 return res == SQLITE_DONE;
444}
445
446bool SQLiteBatch::EraseKey(CDataStream&& key)
447{

Callers

nothing calls this directly

Calls 2

dataMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected