1
0

WalletDB() usage: trivial refactors and fixes

split off from https://github.com/spesmilo/electrum/pull/10027
This commit is contained in:
SomberNight
2025-07-15 12:25:47 +00:00
parent 7611d4c3b3
commit 3c82b00c5e
5 changed files with 13 additions and 10 deletions

View File

@@ -421,9 +421,11 @@ class JsonDB(Logger):
@locked
def write(self):
if (not self.storage.file_exists()
or self.storage.is_encrypted()
or self.storage.needs_consolidation()):
if (
not self.storage.file_exists()
or self.storage.is_encrypted()
or self.storage.needs_consolidation()
):
self.write_and_force_consolidation()
else:
self._append_pending_changes()

View File

@@ -66,15 +66,16 @@ class WatchTower(Logger, EventListener):
def __init__(self, network: 'Network'):
Logger.__init__(self)
self.adb = AddressSynchronizer(WalletDB('', storage=None, upgrade=True), network.config, name=self.diagnostic_name())
self.adb.start_network(network)
self.config = network.config
wallet_db = WalletDB('', storage=None, upgrade=True)
self.adb = AddressSynchronizer(wallet_db, self.config, name=self.diagnostic_name())
self.adb.start_network(network)
self.callbacks = {} # address -> lambda function
self.register_callbacks()
# status gets populated when we run
self.channel_status = {}
self.network = network
self.sweepstore = SweepStore(os.path.join(self.network.config.path, "watchtower_db"), network)
self.sweepstore = SweepStore(os.path.join(self.config.path, "watchtower_db"), network)
def remove_callback(self, address):
self.callbacks.pop(address, None)

View File

@@ -84,8 +84,8 @@ if __name__ == '__main__':
test_password = partial(test_password_for_storage_encryption, storage)
print(f"wallet found: with storage encryption.")
else:
db = WalletDB(storage.read(), manual_upgrades=True)
wallet = Wallet(db, storage, config=config)
db = WalletDB(storage.read(), storage=storage, upgrade=False)
wallet = Wallet(db, config=config)
if not wallet.has_password():
print("wallet found but it is not encrypted.")
sys.exit(0)

View File

@@ -4163,7 +4163,7 @@ class Wallet(object):
This class is actually a factory that will return a wallet of the correct
type when passed a WalletStorage instance."""
def __new__(cls, db: 'WalletDB', *, config: SimpleConfig):
def __new__(cls, db: 'WalletDB', *, config: SimpleConfig) -> Abstract_Wallet:
wallet_type = db.get('wallet_type')
WalletClass = Wallet.wallet_class(wallet_type)
wallet = WalletClass(db, config=config)

View File

@@ -227,7 +227,7 @@ def get_password_for_hw_device_encrypted_storage(plugins: 'Plugins') -> str:
sys.exit(0)
async def run_offline_command(config, config_options, wallet_path, plugins: 'Plugins'):
async def run_offline_command(config: 'SimpleConfig', config_options: dict, wallet_path: str, plugins: 'Plugins'):
cmdname = config.get('cmd')
cmd = known_commands[cmdname]
password = config_options.get('password')