upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/wallet_sqlite.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/wallet_sqlite.cpp')
-rw-r--r--src/wallet_sqlite.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/wallet_sqlite.cpp b/src/wallet_sqlite.cpp
index 4369af6..8489cac 100644
--- a/src/wallet_sqlite.cpp
+++ b/src/wallet_sqlite.cpp
@@ -231,6 +231,60 @@ bool CWalletDBSQLite::ReadRecord(const vector<unsigned char>& vchKey,
231 return false; 231 return false;
232} 232}
233 233
234bool CWalletDBSQLite::ScanRecords(CWalletRecordVisitor& visitor,
235 string& strError)
236{
237 if (!pdb)
238 {
239 strError = "SQLite wallet is not open";
240 return false;
241 }
242
243 sqlite3_stmt* stmt = NULL;
244 const char* pszSql = "SELECT key, value FROM wallet_records ORDER BY rowid;";
245 int ret = sqlite3_prepare_v2(pdb, pszSql, -1, &stmt, NULL);
246 if (ret != SQLITE_OK)
247 {
248 SetSQLiteError(pdb, "cannot prepare SQLite wallet scan", strError);
249 return false;
250 }
251
252 while ((ret = sqlite3_step(stmt)) == SQLITE_ROW)
253 {
254 const unsigned char* pchKey =
255 (const unsigned char*)sqlite3_column_blob(stmt, 0);
256 int nKeyBytes = sqlite3_column_bytes(stmt, 0);
257 const unsigned char* pchValue =
258 (const unsigned char*)sqlite3_column_blob(stmt, 1);
259 int nValueBytes = sqlite3_column_bytes(stmt, 1);
260
261 vector<unsigned char> vchKey;
262 vector<unsigned char> vchValue;
263 if (nKeyBytes > 0 && pchKey)
264 vchKey.assign(pchKey, pchKey + nKeyBytes);
265 if (nValueBytes > 0 && pchValue)
266 vchValue.assign(pchValue, pchValue + nValueBytes);
267
268 CDataStream ssKey(vchKey, SER_DISK);
269 CDataStream ssValue(vchValue, SER_DISK);
270 if (!visitor.VisitWalletRecord(ssKey, ssValue, strError))
271 {
272 sqlite3_finalize(stmt);
273 return false;
274 }
275 }
276
277 if (ret != SQLITE_DONE)
278 {
279 SetSQLiteError(pdb, "cannot scan SQLite wallet records", strError);
280 sqlite3_finalize(stmt);
281 return false;
282 }
283
284 sqlite3_finalize(stmt);
285 return true;
286}
287
234bool CWalletDBSQLite::CountRecords(int& nRecordsRet, string& strError) 288bool CWalletDBSQLite::CountRecords(int& nRecordsRet, string& strError)
235{ 289{
236 nRecordsRet = 0; 290 nRecordsRet = 0;