From 07953592aa95df670f01b600ab904c39c8008374 Mon Sep 17 00:00:00 2001 From: Kashiko Koibumi Date: Thu, 30 May 2024 20:09:16 +0900 Subject: [PATCH 1/2] fix careless mistakes --- src/api.py | 4 ++-- src/bitmessageqt/__init__.py | 2 +- src/tests/core.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/api.py b/src/api.py index 87af4d32..80e9c24d 100644 --- a/src/api.py +++ b/src/api.py @@ -1467,10 +1467,10 @@ class BMRPCDispatcher(object): # Stream Number length readPosition += decodeVarint( payload[readPosition:readPosition + 10])[1] - t = (payload[readPosition:readPosition + 32], sqlite3.Binary(hash01)) + t = (sqlite3.Binary(payload[readPosition:readPosition + 32]), sqlite3.Binary(hash01)) _, rowcount = sql.execute("UPDATE inventory SET tag=? WHERE hash=?", *t) if rowcount < 1: - t = (payload[readPosition:readPosition + 32], hash01) + t = (sqlite3.Binary(payload[readPosition:readPosition + 32]), hash01) sql.execute("UPDATE inventory SET tag=? WHERE hash=CAST(? AS TEXT)", *t) queryreturn = sqlQuery( diff --git a/src/bitmessageqt/__init__.py b/src/bitmessageqt/__init__.py index 42ef6f80..add5fb95 100644 --- a/src/bitmessageqt/__init__.py +++ b/src/bitmessageqt/__init__.py @@ -3277,7 +3277,7 @@ class MyForm(settingsmixin.SMainWindow): if total_row_count < 1: sqlExecuteChunked( "UPDATE inbox SET folder='inbox' WHERE msgid IN({0})", - True, idCount, *inventoryHashesToTrash, as_text=True) + True, idCount, *inventoryHashesToTrash) tableWidget.selectRow(0 if currentRow == 0 else currentRow - 1) tableWidget.setUpdatesEnabled(True) self.propagateUnreadCount() diff --git a/src/tests/core.py b/src/tests/core.py index aa42ada0..c0de4d3b 100644 --- a/src/tests/core.py +++ b/src/tests/core.py @@ -357,7 +357,7 @@ class TestCore(unittest.TestCase): if len(column_type) < 1: column_type = sqlQuery( '''select typeof(msgid) from sent where ackdata=CAST(? AS TEXT)''', result) - self.assertEqual(column_type[0][0] if column_type else '', 'text') + self.assertEqual(column_type[0][0] if column_type else '', 'blob') @unittest.skipIf(frozen, 'not packed test_pattern into the bundle') def test_old_knownnodes_pickle(self): From 31dcbd6d5f12e4bac9935030c11eca2ea887e566 Mon Sep 17 00:00:00 2001 From: Kashiko Koibumi Date: Thu, 30 May 2024 20:59:59 +0900 Subject: [PATCH 2/2] add script to revert BLOB-keys into TEXT-keys --- revert_blob_to_text.sh | 3 +++ src/revert_blob_to_text.py | 52 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100755 revert_blob_to_text.sh create mode 100644 src/revert_blob_to_text.py diff --git a/revert_blob_to_text.sh b/revert_blob_to_text.sh new file mode 100755 index 00000000..fbac98c1 --- /dev/null +++ b/revert_blob_to_text.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +python3 pybitmessage/revert_blob_to_text.py "$@" diff --git a/src/revert_blob_to_text.py b/src/revert_blob_to_text.py new file mode 100644 index 00000000..bd38066d --- /dev/null +++ b/src/revert_blob_to_text.py @@ -0,0 +1,52 @@ +import helper_startup +import state +import shutil +import sqlite3 + +expected_ver = 11 + +print("Looking up database file..") +helper_startup.loadConfig() +db_path = state.appdata + "messages.dat" +print("Database path: {}".format(db_path)) +db_backup_path = db_path + ".blob-keys" +print("Backup path: {}".format(db_backup_path)) +shutil.copyfile(db_path, db_backup_path) +print("Copied to backup") + +print() + +print("Open the database") +conn = sqlite3.connect(db_path) +cur = conn.cursor() + +cur.execute("SELECT value FROM settings WHERE key='version';") +ver = int(cur.fetchall()[0][0]) +print("PyBitmessage database version: {}".format(ver)) +if ver != expected_ver: + print("Error: version must be {}".format(expected_ver)) + conn.close() + print("Quitting..") + quit() +print("Version OK") + +print() + +print("Converting..") +q = "UPDATE inbox SET msgid=CAST(msgid AS TEXT), sighash=CAST(sighash AS TEXT);" +print(q) +cur.execute(q) +q = "UPDATE pubkeys SET transmitdata=CAST(transmitdata AS TEXT);" +print(q) +cur.execute(q) +q = "UPDATE sent SET msgid=CAST(msgid AS TEXT), toripe=CAST(toripe AS TEXT), ackdata=CAST(ackdata AS TEXT);" +print(q) +cur.execute(q) + +print("Commiting..") +conn.commit() +print("Conversion done") + +print("Close the database") +conn.close() +print("Finished")