diff --git a/basicswap/basicswap.py b/basicswap/basicswap.py index 039afdb..e396c22 100644 --- a/basicswap/basicswap.py +++ b/basicswap/basicswap.py @@ -4950,6 +4950,58 @@ class BasicSwap(BaseApp): json.dump(self.settings, fp, indent=4) return settings_changed + def enableCoin(self, coin_name): + self.log.info('Enabling coin %s', coin_name) + + coin_id = self.getCoinIdFromName(coin_name) + if coin_id in (Coins.PART, Coins.PART_BLIND, Coins.PART_ANON): + raise ValueError('Invalid coin') + + settings_cc = self.settings['chainclients'][coin_name] + if 'connection_type_prev' not in settings_cc: + raise ValueError('Can\'t find previous value.') + settings_cc['connection_type'] = settings_cc['connection_type_prev'] + del settings_cc['connection_type_prev'] + if 'manage_daemon_prev' in settings_cc: + settings_cc['manage_daemon'] = settings_cc['manage_daemon_prev'] + del settings_cc['manage_daemon_prev'] + if 'manage_wallet_daemon_prev' in settings_cc: + settings_cc['manage_wallet_daemon'] = settings_cc['manage_wallet_daemon_prev'] + del settings_cc['manage_wallet_daemon_prev'] + + settings_path = os.path.join(self.data_dir, cfg.CONFIG_FILENAME) + shutil.copyfile(settings_path, settings_path + '.last') + with open(settings_path, 'w') as fp: + json.dump(self.settings, fp, indent=4) + # Client must be restarted + + def disableCoin(self, coin_name): + self.log.info('Disabling coin %s', coin_name) + + coin_id = self.getCoinIdFromName(coin_name) + if coin_id in (Coins.PART, Coins.PART_BLIND, Coins.PART_ANON): + raise ValueError('Invalid coin') + + settings_cc = self.settings['chainclients'][coin_name] + + if settings_cc['connection_type'] != 'rpc': + raise ValueError('Already disabled.') + + settings_cc['manage_daemon_prev'] = settings_cc['manage_daemon'] + settings_cc['manage_daemon'] = False + settings_cc['connection_type_prev'] = settings_cc['connection_type'] + settings_cc['connection_type'] = 'none' + + if 'manage_wallet_daemon' in settings_cc: + settings_cc['manage_wallet_daemon_prev'] = settings_cc['manage_wallet_daemon'] + settings_cc['manage_wallet_daemon'] = False + + settings_path = os.path.join(self.data_dir, cfg.CONFIG_FILENAME) + shutil.copyfile(settings_path, settings_path + '.last') + with open(settings_path, 'w') as fp: + json.dump(self.settings, fp, indent=4) + # Client must be restarted + def getSummary(self, opts=None): num_watched_outputs = 0 for c, v in self.coin_clients.items(): diff --git a/basicswap/http_server.py b/basicswap/http_server.py index f4059be..c0ebe75 100644 --- a/basicswap/http_server.py +++ b/basicswap/http_server.py @@ -358,17 +358,34 @@ class HttpHandler(BaseHTTPRequestHandler): if swap_client.editSettings(name, data) is True: messages.append('Settings applied.') + elif bytes('enable_' + name, 'utf-8') in form_data: + swap_client.enableCoin(name) + messages.append(name.capitalize() + ' enabled, shutting down.') + swap_client.stopRunning() + elif bytes('disable_' + name, 'utf-8') in form_data: + swap_client.disableCoin(name) + messages.append(name.capitalize() + ' disabled, shutting down.') + swap_client.stopRunning() chains_formatted = [] for name, c in swap_client.settings['chainclients'].items(): chains_formatted.append({ 'name': name, - 'lookups': c.get('chain_lookups', 'local') + 'lookups': c.get('chain_lookups', 'local'), + 'manage_daemon': c.get('manage_daemon', 'Unknown'), + 'connection_type': c.get('connection_type', 'Unknown'), }) if name == 'monero': chains_formatted[-1]['fee_priority'] = c.get('fee_priority', 0) + chains_formatted[-1]['manage_wallet_daemon'] = c.get('manage_wallet_daemon', 'Unknown') else: chains_formatted[-1]['conf_target'] = c.get('conf_target', 2) + if name != 'particl': + if c.get('connection_type', 'Unknown') == 'none': + if 'connection_type_prev' in c: + chains_formatted[-1]['can_reenable'] = True + else: + chains_formatted[-1]['can_disable'] = True template = env.get_template('settings.html') return bytes(template.render( diff --git a/basicswap/templates/settings.html b/basicswap/templates/settings.html index 9076d6e..e8bd6b9 100644 --- a/basicswap/templates/settings.html +++ b/basicswap/templates/settings.html @@ -11,6 +11,15 @@ {% for c in chains %}

{{ c.name|capitalize }}

+{% if c.connection_type %} + +{% endif %} +{% if c.manage_daemon is defined %} + +{% endif %} +{% if c.manage_wallet_daemon is defined %} + +{% endif %} {% endif %} - +
Connection Type{{ c.connection_type }}
Manage Daemon{{ c.manage_daemon }}
Manage Wallet Daemon{{ c.manage_wallet_daemon }}
Chain Lookups
Blocks Confirmed Target
+{% if c.can_disable == true %} + +{% endif %} +{% if c.can_reenable == true %} + +{% endif %} +
{% endfor %} +

home

+