WalletDB() usage: trivial refactors and fixes
split off from https://github.com/spesmilo/electrum/pull/10027
This commit is contained in:
@@ -421,9 +421,11 @@ class JsonDB(Logger):
|
|||||||
|
|
||||||
@locked
|
@locked
|
||||||
def write(self):
|
def write(self):
|
||||||
if (not self.storage.file_exists()
|
if (
|
||||||
or self.storage.is_encrypted()
|
not self.storage.file_exists()
|
||||||
or self.storage.needs_consolidation()):
|
or self.storage.is_encrypted()
|
||||||
|
or self.storage.needs_consolidation()
|
||||||
|
):
|
||||||
self.write_and_force_consolidation()
|
self.write_and_force_consolidation()
|
||||||
else:
|
else:
|
||||||
self._append_pending_changes()
|
self._append_pending_changes()
|
||||||
|
|||||||
@@ -66,15 +66,16 @@ class WatchTower(Logger, EventListener):
|
|||||||
|
|
||||||
def __init__(self, network: 'Network'):
|
def __init__(self, network: 'Network'):
|
||||||
Logger.__init__(self)
|
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
|
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.callbacks = {} # address -> lambda function
|
||||||
self.register_callbacks()
|
self.register_callbacks()
|
||||||
# status gets populated when we run
|
# status gets populated when we run
|
||||||
self.channel_status = {}
|
self.channel_status = {}
|
||||||
self.network = network
|
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):
|
def remove_callback(self, address):
|
||||||
self.callbacks.pop(address, None)
|
self.callbacks.pop(address, None)
|
||||||
|
|||||||
@@ -84,8 +84,8 @@ if __name__ == '__main__':
|
|||||||
test_password = partial(test_password_for_storage_encryption, storage)
|
test_password = partial(test_password_for_storage_encryption, storage)
|
||||||
print(f"wallet found: with storage encryption.")
|
print(f"wallet found: with storage encryption.")
|
||||||
else:
|
else:
|
||||||
db = WalletDB(storage.read(), manual_upgrades=True)
|
db = WalletDB(storage.read(), storage=storage, upgrade=False)
|
||||||
wallet = Wallet(db, storage, config=config)
|
wallet = Wallet(db, config=config)
|
||||||
if not wallet.has_password():
|
if not wallet.has_password():
|
||||||
print("wallet found but it is not encrypted.")
|
print("wallet found but it is not encrypted.")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|||||||
@@ -4163,7 +4163,7 @@ class Wallet(object):
|
|||||||
This class is actually a factory that will return a wallet of the correct
|
This class is actually a factory that will return a wallet of the correct
|
||||||
type when passed a WalletStorage instance."""
|
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')
|
wallet_type = db.get('wallet_type')
|
||||||
WalletClass = Wallet.wallet_class(wallet_type)
|
WalletClass = Wallet.wallet_class(wallet_type)
|
||||||
wallet = WalletClass(db, config=config)
|
wallet = WalletClass(db, config=config)
|
||||||
|
|||||||
@@ -227,7 +227,7 @@ def get_password_for_hw_device_encrypted_storage(plugins: 'Plugins') -> str:
|
|||||||
sys.exit(0)
|
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')
|
cmdname = config.get('cmd')
|
||||||
cmd = known_commands[cmdname]
|
cmd = known_commands[cmdname]
|
||||||
password = config_options.get('password')
|
password = config_options.get('password')
|
||||||
|
|||||||
Reference in New Issue
Block a user