diff --git a/lbry/lbry/extras/daemon/Daemon.py b/lbry/lbry/extras/daemon/Daemon.py index e2d923bde..fd6053d93 100644 --- a/lbry/lbry/extras/daemon/Daemon.py +++ b/lbry/lbry/extras/daemon/Daemon.py @@ -1096,6 +1096,19 @@ class Daemon(metaclass=JSONRPCServerType): return paginate_list([self.wallet_manager.get_wallet_or_error(wallet_id)], 1, 1) return paginate_list(self.wallet_manager.wallets, page, page_size) + def jsonrpc_wallet_restart(self): + """ + Restarts ledger, applying new configurations. + + Usage: + wallet_restart + + Options: + + Returns: None + """ + return self.wallet_manager.reset() + @requires("wallet") async def jsonrpc_wallet_create( self, wallet_id, skip_on_startup=False, create_account=False, single_key=False): diff --git a/lbry/lbry/wallet/manager.py b/lbry/lbry/wallet/manager.py index 5a012d68a..c25e42218 100644 --- a/lbry/lbry/wallet/manager.py +++ b/lbry/lbry/wallet/manager.py @@ -145,6 +145,21 @@ class LbryWalletManager(BaseWalletManager): await ledger.db.close() return manager + async def reset(self): + ledger_id = { + 'lbrycrd_main': 'lbc_mainnet', + 'lbrycrd_testnet': 'lbc_testnet', + 'lbrycrd_regtest': 'lbc_regtest' + }[self.config.blockchain_name] + ledger = self.get_or_create_ledger(ledger_id) + ledger.config = { + 'auto_connect': True, + 'default_servers': self.config.lbryum_servers, + 'data_path': self.config.wallet_dir, + } + await self.ledger.stop() + await self.ledger.start() + async def _migrate_addresses(self, receiving_addresses: set, change_addresses: set): async with self.default_account.receiving.address_generator_lock: migrated_receiving = set(await self.default_account.receiving._generate_keys(0, len(receiving_addresses))) diff --git a/torba/torba/client/basenetwork.py b/torba/torba/client/basenetwork.py index ad18b6e15..e443d2fc1 100644 --- a/torba/torba/client/basenetwork.py +++ b/torba/torba/client/basenetwork.py @@ -142,7 +142,7 @@ class BaseNetwork: PROTOCOL_VERSION = '1.2' def __init__(self, ledger): - self.config = ledger.config + self.ledger = ledger self.session_pool = SessionPool(network=self, timeout=self.config.get('connect_timeout', 6)) self.client: Optional[ClientSession] = None self._switch_task: Optional[asyncio.Task] = None @@ -164,6 +164,10 @@ class BaseNetwork: 'blockchain.address.subscribe': self._on_status_controller, } + @property + def config(self): + return self.ledger.config + async def switch_forever(self): while self.running: if self.is_connected: