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

Method WriteKey

src/wallet/sqlite.cpp:490–521  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

488}
489
490bool SQLiteBatch::WriteKey(DataStream&& key, DataStream&& value, bool overwrite)
491{
492 if (!m_database.m_db) return false;
493 assert(m_insert_stmt && m_overwrite_stmt);
494
495 sqlite3_stmt* stmt;
496 if (overwrite) {
497 stmt = m_overwrite_stmt;
498 } else {
499 stmt = m_insert_stmt;
500 }
501
502 // Bind: leftmost parameter in statement is index 1
503 // Insert index 1 is key, 2 is value
504 if (!BindBlobToStatement(stmt, 1, key, "key")) return false;
505 if (!BindBlobToStatement(stmt, 2, value, "value")) return false;
506
507 // Acquire semaphore if not previously acquired when creating a transaction.
508 if (!m_txn) m_database.m_write_semaphore.acquire();
509
510 // Execute
511 int res = sqlite3_step(stmt);
512 sqlite3_clear_bindings(stmt);
513 sqlite3_reset(stmt);
514 if (res != SQLITE_DONE) {
515 LogWarning("Unable to execute write statement: %s", sqlite3_errstr(res));
516 }
517
518 if (!m_txn) m_database.m_write_semaphore.release();
519
520 return res == SQLITE_DONE;
521}
522
523bool SQLiteBatch::ExecStatement(sqlite3_stmt* stmt, std::span<const std::byte> blob)
524{

Callers 1

WalletMigrationFunction · 0.45

Calls 2

BindBlobToStatementFunction · 0.85
releaseMethod · 0.80

Tested by

no test coverage detected