From 01f6a1d8772d8d5288ccc01664c5e36c1e020244 Mon Sep 17 00:00:00 2001 From: tecnovert Date: Fri, 22 Nov 2024 20:46:50 +0200 Subject: [PATCH] Fix missing wallets page entries. --- basicswap/basicswap.py | 22 ++++++++++++---------- basicswap/db.py | 5 +++++ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/basicswap/basicswap.py b/basicswap/basicswap.py index 35174bf..c99da05 100644 --- a/basicswap/basicswap.py +++ b/basicswap/basicswap.py @@ -6767,9 +6767,9 @@ class BasicSwap(BaseApp): cursor = self.openDB() query = "SELECT action_type, linked_id FROM actions WHERE active_ind = 1 AND trigger_at <= :now" - q = cursor.execute(query, {"now": now}) + rows = cursor.execute(query, {"now": now}).fetchall() - for row in q: + for row in rows: action_type, linked_id = row accepting_bid: bool = False try: @@ -6801,7 +6801,7 @@ class BasicSwap(BaseApp): accepting_bid = True self.acceptADSReverseBid(linked_id, cursor) else: - self.log.warning("Unknown event type: %d", action_type) + self.log.warning(f"Unknown event type: {action_type}") except Exception as ex: err_msg = f"checkQueuedActions failed: {ex}" self.logException(err_msg) @@ -7059,7 +7059,7 @@ class BasicSwap(BaseApp): rv = cursor.execute( query_str, {"addr": msg["to"], "use_type": int(AddressTypes.RECV_OFFER)}, - )[0] + ).fetchone() if rv[0] < 1: raise ValueError("Offer received on incorrect address") @@ -10363,18 +10363,20 @@ class BasicSwap(BaseApp): # Ensure the latest addresses are displayed coin_name: str = chainparams[coin_id]["name"] - q = cursor.execute( + c2 = self.getNewDBCursor() + q2 = c2.execute( "SELECT key, value FROM kv_string WHERE key = ? OR key = ?", (f"receive_addr_{coin_name}", f"stealth_addr_{coin_name}"), ) - for row in q: - if row[0].startswith("stealth"): + for row2 in q2: + if row2[0].startswith("stealth"): if coin_id == Coins.LTC: - wallet_data["mweb_address"] = row[1] + wallet_data["mweb_address"] = row2[1] else: - wallet_data["stealth_address"] = row[1] + wallet_data["stealth_address"] = row2[1] else: - wallet_data["deposit_address"] = row[1] + wallet_data["deposit_address"] = row2[1] + c2.close() if coin_id in rv: rv[coin_id].update(wallet_data) diff --git a/basicswap/db.py b/basicswap/db.py index a6e1a3e..5f3a07c 100644 --- a/basicswap/db.py +++ b/basicswap/db.py @@ -737,6 +737,10 @@ class DBMethods: self._db_con = sqlite3.connect(self.sqlite_file) return self._db_con.cursor() + def getNewDBCursor(self): + assert self.mxDB.locked() + return self._db_con.cursor() + def commitDB(self): assert self.mxDB.locked() self._db_con.commit() @@ -751,6 +755,7 @@ class DBMethods: if commit: self._db_con.commit() + cursor.close() self._db_con.close() self.mxDB.release()