From 59fb6c18ed0c7bd97511bfe743d479cd97b40899 Mon Sep 17 00:00:00 2001 From: tecnovert Date: Mon, 24 Oct 2022 20:49:36 +0200 Subject: [PATCH] coins: Rename Pivx -> PIVX --- basicswap/basicswap.py | 13 ++-- basicswap/chainparams.py | 6 +- basicswap/http_server.py | 20 +++--- basicswap/js_server.py | 3 +- .../images/coins/{Pivx-20.png => PIVX-20.png} | Bin .../images/coins/{Pivx.png => PIVX.png} | Bin basicswap/templates/settings.html | 64 +++++++++--------- basicswap/ui/util.py | 6 +- bin/basicswap_prepare.py | 3 +- bin/basicswap_run.py | 14 ++-- 10 files changed, 75 insertions(+), 54 deletions(-) rename basicswap/static/images/coins/{Pivx-20.png => PIVX-20.png} (100%) rename basicswap/static/images/coins/{Pivx.png => PIVX.png} (100%) diff --git a/basicswap/basicswap.py b/basicswap/basicswap.py index 70705aa..239109a 100644 --- a/basicswap/basicswap.py +++ b/basicswap/basicswap.py @@ -38,6 +38,7 @@ from .interface.passthrough_btc import PassthroughBTCInterface from . import __version__ from .rpc_xmr import make_xmr_rpc2_func +from .ui.util import getCoinName from .util import ( TemporaryError, InactiveCoin, @@ -165,11 +166,11 @@ def threadPollXMRChainState(swap_client, coin_type): try: new_height = ci.getChainHeight() if new_height != cc['chain_height']: - swap_client.log.debug('New {} block at height: {}'.format(str(coin_type), new_height)) + swap_client.log.debug('New {} block at height: {}'.format(ci.ticker(), new_height)) with swap_client.mxDB: cc['chain_height'] = new_height except Exception as e: - swap_client.log.warning('threadPollXMRChainState {}, error: {}'.format(str(coin_type), str(e))) + swap_client.log.warning('threadPollXMRChainState {}, error: {}'.format(ci.ticker(), str(e))) swap_client.delay_event.wait(random.randrange(20, 30)) # random to stagger updates @@ -180,14 +181,14 @@ def threadPollChainState(swap_client, coin_type): try: chain_state = ci.getBlockchainInfo() if chain_state['bestblockhash'] != cc['chain_best_block']: - swap_client.log.debug('New {} block at height: {}'.format(str(coin_type), chain_state['blocks'])) + swap_client.log.debug('New {} block at height: {}'.format(ci.ticker(), chain_state['blocks'])) with swap_client.mxDB: cc['chain_height'] = chain_state['blocks'] cc['chain_best_block'] = chain_state['bestblockhash'] if 'mediantime' in chain_state: cc['chain_median_time'] = chain_state['mediantime'] except Exception as e: - swap_client.log.warning('threadPollChainState {}, error: {}'.format(str(coin_type), str(e))) + swap_client.log.warning('threadPollChainState {}, error: {}'.format(ci.ticker(), str(e))) swap_client.delay_event.wait(random.randrange(20, 30)) # random to stagger updates @@ -5487,7 +5488,7 @@ class BasicSwap(BaseApp): rv[key] = self.getWalletInfo(c) rv[key].update(self.getBlockchainInfo(c)) except Exception as ex: - rv[key] = {'name': chainparams[c]['name'].capitalize(), 'error': str(ex)} + rv[key] = {'name': getCoinName(c), 'error': str(ex)} return rv def getCachedWalletsInfo(self, opts=None): @@ -5537,7 +5538,7 @@ class BasicSwap(BaseApp): coin_id = int(c) if coin_id not in rv: rv[coin_id] = { - 'name': chainparams[c]['name'].capitalize(), + 'name': getCoinName(c), 'no_data': True, 'updating': self._updating_wallets_info.get(coin_id, False), } diff --git a/basicswap/chainparams.py b/basicswap/chainparams.py index b85e44e..7a61910 100644 --- a/basicswap/chainparams.py +++ b/basicswap/chainparams.py @@ -219,6 +219,7 @@ chainparams = { 'decimal_places': 8, 'has_csv': False, 'has_segwit': False, + 'use_ticker_as_name': True, 'mainnet': { 'rpcport': 51473, 'pubkey_address': 30, @@ -320,7 +321,10 @@ class CoinInterface: return format_amount(amount_int, self.exp()) def coin_name(self): - return chainparams[self.coin_type()]['name'].capitalize() + coin_chainparams = chainparams[self.coin_type()] + if coin_chainparams.get('use_ticker_as_name', False): + return coin_chainparams['ticker'] + return coin_chainparams['name'].capitalize() def ticker(self): ticker = chainparams[self.coin_type()]['ticker'] diff --git a/basicswap/http_server.py b/basicswap/http_server.py index 7a1f1ce..ee59edb 100644 --- a/basicswap/http_server.py +++ b/basicswap/http_server.py @@ -75,7 +75,7 @@ def listAvailableExplorers(swap_client): if c not in chainparams: continue for i, e in enumerate(swap_client.coin_clients[c]['explorers']): - explorers.append(('{}_{}'.format(int(c), i), swap_client.coin_clients[c]['name'].capitalize() + ' - ' + extractDomain(e.base_url))) + explorers.append(('{}_{}'.format(int(c), i), getCoinName(c) + ' - ' + extractDomain(e.base_url))) return explorers @@ -104,7 +104,7 @@ class HttpHandler(BaseHTTPRequestHandler): self.server.last_form_id[name] = form_id return form_data - def render_template(self, template, args_dict): + def render_template(self, template, args_dict, status_code=200): swap_client = self.server.swap_client if swap_client.ws_server: args_dict['ws_url'] = swap_client.ws_server.url @@ -141,7 +141,7 @@ class HttpHandler(BaseHTTPRequestHandler): if self.server.msg_id_counter >= 0x7FFFFFFF: self.server.msg_id_counter = 0 - self.putHeaders(200, 'text/html') + self.putHeaders(status_code, 'text/html') return bytes(template.render( title=self.server.title, h2=self.server.title, @@ -343,19 +343,26 @@ class HttpHandler(BaseHTTPRequestHandler): messages.append('Please restart BasicSwap.') elif have_data_entry(form_data, 'enable_' + name): swap_client.enableCoin(name) - messages.append(name.capitalize() + ' enabled, shutting down.') + display_name = getCoinName(swap_client.getCoinIdFromName(name)) + messages.append(display_name + ' enabled, shutting down.') swap_client.stopRunning() elif have_data_entry(form_data, 'disable_' + name): swap_client.disableCoin(name) - messages.append(name.capitalize() + ' disabled, shutting down.') + display_name = getCoinName(swap_client.getCoinIdFromName(name)) + messages.append(display_name + ' disabled, shutting down.') swap_client.stopRunning() chains_formatted = [] sorted_names = sorted(swap_client.settings['chainclients'].keys()) for name in sorted_names: c = swap_client.settings['chainclients'][name] + try: + display_name = getCoinName(swap_client.getCoinIdFromName(name)) + except Exception: + display_name = name chains_formatted.append({ 'name': name, + 'display_name': display_name, 'lookups': c.get('chain_lookups', 'local'), 'manage_daemon': c.get('manage_daemon', 'Unknown'), 'connection_type': c.get('connection_type', 'Unknown'), @@ -607,15 +614,12 @@ class HttpHandler(BaseHTTPRequestHandler): self.putHeaders(status_code, 'application/javascript') return fp.read() else: - self.putHeaders(status_code, 'text/html') return self.page_404(url_split) except FileNotFoundError: - self.putHeaders(status_code, 'text/html') return self.page_404(url_split) except Exception as ex: if self.server.swap_client.debug is True: self.server.swap_client.log.error(traceback.format_exc()) - self.putHeaders(status_code, 'text/html') return self.page_error(str(ex)) try: diff --git a/basicswap/js_server.py b/basicswap/js_server.py index c40d715..a5ce8ff 100644 --- a/basicswap/js_server.py +++ b/basicswap/js_server.py @@ -22,6 +22,7 @@ from .chainparams import ( ) from .ui.util import ( PAGE_LIMIT, + getCoinName, getCoinType, inputAmount, describeBid, @@ -73,7 +74,7 @@ def js_coins(self, url_split, post_string, is_json): entry = { 'id': int(coin), 'ticker': chainparams[cc['coin']]['ticker'], - 'name': cc['name'].capitalize(), + 'name': getCoinName(coin), 'active': False if cc['connection_type'] == 'none' else True, } if coin == Coins.PART_ANON: diff --git a/basicswap/static/images/coins/Pivx-20.png b/basicswap/static/images/coins/PIVX-20.png similarity index 100% rename from basicswap/static/images/coins/Pivx-20.png rename to basicswap/static/images/coins/PIVX-20.png diff --git a/basicswap/static/images/coins/Pivx.png b/basicswap/static/images/coins/PIVX.png similarity index 100% rename from basicswap/static/images/coins/Pivx.png rename to basicswap/static/images/coins/PIVX.png diff --git a/basicswap/templates/settings.html b/basicswap/templates/settings.html index fa5cf0e..fefcf06 100644 --- a/basicswap/templates/settings.html +++ b/basicswap/templates/settings.html @@ -106,7 +106,7 @@ {% endfor %} - +
@@ -141,9 +141,9 @@
-

+

- {{ c.name|capitalize }}

+ {{ c.display_name }}
@@ -214,7 +214,7 @@ {% endif %} Chain Lookups - + - + Debug Mode UI @@ -337,9 +337,9 @@ -
- - + + + @@ -352,7 +352,7 @@ Apply - + @@ -362,9 +362,9 @@
-

+

- Chart (todo)

+ Chart (todo)
@@ -379,7 +379,7 @@ Value - + Show Chart @@ -389,16 +389,16 @@ - + Chart API Key (URL) - - - + + +
@@ -409,7 +409,7 @@ Apply
- +
@@ -435,9 +435,9 @@
-

+

- Tor

+ Tor
@@ -452,7 +452,7 @@ Value - + Use TOR @@ -462,7 +462,7 @@ - + Use Tor Proxy @@ -485,15 +485,15 @@ Tor Proxy Port - + Tor Control Port - + - - + +
@@ -541,4 +541,4 @@ {% include 'footer.html' %} - \ No newline at end of file + diff --git a/basicswap/ui/util.py b/basicswap/ui/util.py index afd4e4a..4411f49 100644 --- a/basicswap/ui/util.py +++ b/basicswap/ui/util.py @@ -388,7 +388,11 @@ def getCoinName(c): return chainparams[Coins.PART]['name'].capitalize() + ' Anon' if c == Coins.PART_BLIND: return chainparams[Coins.PART]['name'].capitalize() + ' Blind' - return chainparams[c]['name'].capitalize() + + coin_chainparams = chainparams[c] + if coin_chainparams.get('use_ticker_as_name', False): + return coin_chainparams['ticker'] + return coin_chainparams['name'].capitalize() def listAvailableCoins(swap_client, with_variants=True, split_from=False): diff --git a/bin/basicswap_prepare.py b/bin/basicswap_prepare.py index 057304c..4f835b4 100755 --- a/bin/basicswap_prepare.py +++ b/bin/basicswap_prepare.py @@ -27,6 +27,7 @@ import basicswap.config as cfg from basicswap.base import getaddrinfo_tor from basicswap.basicswap import BasicSwap from basicswap.chainparams import Coins +from basicswap.ui.util import getCoinName from basicswap.util import toBool from basicswap.util.rfc2440 import rfc2440_hash_password from basicswap.contrib.rpcauth import generate_salt, password_to_hmac @@ -895,7 +896,7 @@ def initialise_wallets(particl_wallet_mnemonic, with_coins, data_dir, settings, # Create wallet if it doesn't exist yet wallets = swap_client.callcoinrpc(c, 'listwallets') if len(wallets) < 1: - logger.info('Creating wallet.dat for {}.'.format(coin_name.capitalize())) + logger.info('Creating wallet.dat for {}.'.format(getCoinName(c))) swap_client.callcoinrpc(c, 'createwallet', ['wallet.dat']) if 'particl' in with_coins and c == Coins.PART: diff --git a/bin/basicswap_run.py b/bin/basicswap_run.py index e7a62c2..df4b795 100755 --- a/bin/basicswap_run.py +++ b/bin/basicswap_run.py @@ -17,11 +17,11 @@ import subprocess import basicswap.config as cfg from basicswap import __version__ +from basicswap.ui.util import getCoinName from basicswap.basicswap import BasicSwap from basicswap.http_server import HttpThread from basicswap.contrib.websocket_server import WebsocketServer - logger = logging.getLogger() logger.level = logging.DEBUG if not len(logger.handlers): @@ -142,15 +142,21 @@ def runClient(fp, data_dir, chain): try: # Try start daemons for c, v in settings['chainclients'].items(): + try: + coin_id = swap_client.getCoinIdFromName(c) + display_name = getCoinName(coin_id) + except Exception as e: + logger.warning('Error getting coin display name for {}: {}'.format(c, str(e))) + display_name = 'Unknown' if c == 'monero': if v['manage_daemon'] is True: - swap_client.log.info('Starting {} daemon'.format(c.capitalize())) + swap_client.log.info(f'Starting {display_name} daemon') daemons.append(startXmrDaemon(v['datadir'], v['bindir'], 'monerod')) pid = daemons[-1].pid swap_client.log.info('Started {} {}'.format('monerod', pid)) if v['manage_wallet_daemon'] is True: - swap_client.log.info('Starting {} wallet daemon'.format(c.capitalize())) + swap_client.log.info(f'Starting {display_name} wallet daemon') daemon_addr = '{}:{}'.format(v['rpchost'], v['rpcport']) swap_client.log.info('daemon-address: {}'.format(daemon_addr)) opts = ['--daemon-address', daemon_addr, ] @@ -160,7 +166,7 @@ def runClient(fp, data_dir, chain): continue if v['manage_daemon'] is True: - swap_client.log.info('Starting {} daemon'.format(c.capitalize())) + swap_client.log.info(f'Starting {display_name} daemon') filename = c + 'd' + ('.exe' if os.name == 'nt' else '') daemons.append(startDaemon(v['datadir'], v['bindir'], filename))