Merge pull request #445 from gerlofvanek/wallet_tables

Cleanup / Wallet tables use own schema.
This commit is contained in:
tecnovert
2026-04-08 20:05:41 +00:00
committed by GitHub
4 changed files with 19 additions and 45 deletions

View File

@@ -148,14 +148,7 @@ from .db import (
XmrSwap, XmrSwap,
) )
from .wallet_manager import WalletManager from .wallet_manager import WalletManager
from .db_wallet import (
WalletAddress,
WalletLockedUTXO,
WalletPendingTx,
WalletState,
WalletTxCache,
WalletWatchOnly,
)
from .explorers import ( from .explorers import (
ExplorerInsight, ExplorerInsight,
ExplorerBitAps, ExplorerBitAps,
@@ -614,15 +607,7 @@ class BasicSwap(BaseApp, BSXNetwork, UIApp):
if not db_exists: if not db_exists:
self.log.info("First run") self.log.info("First run")
wallet_tables = [ create_db(self.sqlite_file, self.log)
WalletAddress,
WalletLockedUTXO,
WalletPendingTx,
WalletState,
WalletTxCache,
WalletWatchOnly,
]
create_db(self.sqlite_file, self.log, extra_tables=wallet_tables)
cursor = self.openDB() cursor = self.openDB()
try: try:

View File

@@ -772,12 +772,8 @@ class NetworkPortal(Table):
created_at = Column("integer") created_at = Column("integer")
def extract_schema(extra_tables: list = None) -> dict: def extract_schema(input_globals: dict = None) -> dict:
g = globals().copy() g = (input_globals if input_globals else globals()).copy()
if extra_tables:
for table_class in extra_tables:
g[table_class.__name__] = table_class
tables = {} tables = {}
for name, obj in g.items(): for name, obj in g.items():
@@ -898,18 +894,21 @@ def create_table(c, table_name, table) -> None:
c.execute(query) c.execute(query)
def create_db_(con, log, extra_tables: list = None) -> None: def create_db_(con, log) -> None:
db_schema = extract_schema(extra_tables=extra_tables) from .db_wallet import extract_wallet_schema
db_schema = extract_schema()
db_schema.update(extract_wallet_schema())
c = con.cursor() c = con.cursor()
for table_name, table in db_schema.items(): for table_name, table in db_schema.items():
create_table(c, table_name, table) create_table(c, table_name, table)
def create_db(db_path: str, log, extra_tables: list = None) -> None: def create_db(db_path: str, log) -> None:
con = None con = None
try: try:
con = sqlite3.connect(db_path) con = sqlite3.connect(db_path)
create_db_(con, log, extra_tables=extra_tables) create_db_(con, log)
con.commit() con.commit()
finally: finally:
if con: if con:

View File

@@ -18,14 +18,7 @@ from .db import (
extract_schema, extract_schema,
) )
from .db_wallet import ( from .db_wallet import extract_wallet_schema
WalletAddress,
WalletLockedUTXO,
WalletPendingTx,
WalletState,
WalletTxCache,
WalletWatchOnly,
)
from .basicswap_util import ( from .basicswap_util import (
BidStates, BidStates,
@@ -277,15 +270,8 @@ def upgradeDatabase(self, db_version: int):
), ),
] ]
wallet_tables = [ expect_schema = extract_schema()
WalletAddress, expect_schema.update(extract_wallet_schema())
WalletLockedUTXO,
WalletPendingTx,
WalletState,
WalletTxCache,
WalletWatchOnly,
]
expect_schema = extract_schema(extra_tables=wallet_tables)
have_tables = {} have_tables = {}
try: try:
cursor = self.openDB() cursor = self.openDB()

View File

@@ -5,7 +5,7 @@
# file LICENSE or http://www.opensource.org/licenses/mit-license.php. # file LICENSE or http://www.opensource.org/licenses/mit-license.php.
from .db import Column, Index, Table, UniqueConstraint from .db import Column, Index, Table, UniqueConstraint, extract_schema
class WalletAddress(Table): class WalletAddress(Table):
@@ -120,3 +120,7 @@ class WalletPendingTx(Table):
__unique_1__ = UniqueConstraint("coin_type", "txid") __unique_1__ = UniqueConstraint("coin_type", "txid")
__index_pending_coin__ = Index("idx_pending_coin", "coin_type", "confirmed_at") __index_pending_coin__ = Index("idx_pending_coin", "coin_type", "confirmed_at")
def extract_wallet_schema() -> dict:
return extract_schema(input_globals=globals())