From 9caae399d25e200bf59ec6f61e3e38836e6c5c3b Mon Sep 17 00:00:00 2001 From: tecnovert Date: Sat, 2 May 2026 22:59:35 +0200 Subject: [PATCH] fix: convert coin variant tickers --- basicswap/chainparams.py | 14 ++++++++++++-- basicswap/interface/btc.py | 2 +- basicswap/js_server.py | 2 +- tests/basicswap/test_ltc_xmr.py | 27 ++++++++++++++++++++++++++- 4 files changed, 40 insertions(+), 5 deletions(-) diff --git a/basicswap/chainparams.py b/basicswap/chainparams.py index 1e30cd6..8b9385c 100644 --- a/basicswap/chainparams.py +++ b/basicswap/chainparams.py @@ -552,16 +552,26 @@ chainparams = { name_map = {} ticker_map = {} +variant_ticker_map = {} for c, params in chainparams.items(): name_map[params["name"].lower()] = c ticker_map[params["ticker"].lower()] = c +# Add coin variants, eg: LTC_MWEB, PART_ANON +for c in Coins: + if c.name.lower() in ticker_map: + continue + variant_ticker_map[c.name.lower()] = c -def getCoinIdFromTicker(ticker: str) -> str: + +def getCoinIdFromTicker(ticker: str, inc_variant: bool = False) -> str: + lc_ticker: str = ticker.lower() try: - return ticker_map[ticker.lower()] + if inc_variant and lc_ticker in variant_ticker_map: + return variant_ticker_map[lc_ticker] + return ticker_map[lc_ticker] except Exception: raise ValueError(f"Unknown coin {ticker}") diff --git a/basicswap/interface/btc.py b/basicswap/interface/btc.py index c1cbd8a..2cc2bac 100644 --- a/basicswap/interface/btc.py +++ b/basicswap/interface/btc.py @@ -449,11 +449,11 @@ class BTCInterface(Secp256k1Interface): # Wallet name is "" for some LTC and PART installs on older cores if self._rpc_wallet not in wallets and len(wallets) > 0: if "" in wallets: + # Setting wallet= in the coin .conf file should also work self._log.warning( f"Nameless {self.ticker()} wallet found." + '\nPlease set the "wallet_name" coin setting to "" or recreate the wallet' ) - # backupwallet and restorewallet with name should work. if self._rpc_wallet not in wallets: raise RuntimeError( diff --git a/basicswap/js_server.py b/basicswap/js_server.py index b927a7f..fa83cae 100644 --- a/basicswap/js_server.py +++ b/basicswap/js_server.py @@ -290,7 +290,7 @@ def js_wallets(self, url_split, post_string, is_json): swap_client.checkSystemStatus() if len(url_split) > 3: ticker_str = url_split[3] - coin_type = getCoinIdFromTicker(ticker_str) + coin_type = getCoinIdFromTicker(ticker_str, inc_variant=True) if len(url_split) > 4: cmd = url_split[4] diff --git a/tests/basicswap/test_ltc_xmr.py b/tests/basicswap/test_ltc_xmr.py index 3bdb656..4fc38f9 100644 --- a/tests/basicswap/test_ltc_xmr.py +++ b/tests/basicswap/test_ltc_xmr.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # Copyright (c) 2021-2024 tecnovert -# Copyright (c) 2024 The Basicswap developers +# Copyright (c) 2024-2026 The Basicswap developers # Distributed under the MIT software license, see the accompanying # file LICENSE or http://www.opensource.org/licenses/mit-license.php. @@ -184,6 +184,15 @@ class TestLTC(BasicSwapTest): ci0 = swap_clients[0].ci(self.test_coin_from) ci1 = swap_clients[1].ci(self.test_coin_from) + # mweb utxos before sending to mweb + num_mweb: int = 0 + utxos_0 = ci0.rpc_wallet("listunspent") + for utxo in utxos_0: + addr_info = ci0.rpc_wallet("getaddressinfo", [utxo["address"]]) + if addr_info["ismweb"] is True: + num_mweb += 1 + assert num_mweb == 1 + mweb_addr_0 = ci0.rpc_wallet("getnewaddress", ["mweb addr test 0", "mweb"]) mweb_addr_1 = ci1.rpc_wallet("getnewaddress", ["mweb addr test 1", "mweb"]) @@ -210,6 +219,19 @@ class TestLTC(BasicSwapTest): < 0.1 ) + num_mweb: int = 0 + utxos_0 = ci0.rpc_wallet( + "listunspent", + [ + 0, + ], + ) + for utxo in utxos_0: + addr_info = ci0.rpc_wallet("getaddressinfo", [utxo["address"]]) + if addr_info["ismweb"] is True: + num_mweb += 1 + assert num_mweb > 1 + try: pause_event.clear() # Stop mining ci0.rpc_wallet("sendtoaddress", [mweb_addr_1, 10.0]) @@ -237,6 +259,7 @@ class TestLTC(BasicSwapTest): for utxo in utxos: if utxo.get("address", "") == mweb_addr_1: mweb_tx = utxo + break assert mweb_tx is not None unspent_addr = ci1.getUnspentsByAddr() @@ -265,7 +288,9 @@ class TestLTC(BasicSwapTest): ltc_mweb_addr = read_json_api( TEST_HTTP_PORT + 0, "wallets/ltc_mweb/nextdepositaddr" ) + assert ltc_mweb_addr.startswith("tmweb1") ltc_mweb_addr2 = read_json_api(TEST_HTTP_PORT + 0, "wallets/ltc/newmwebaddress") + assert ltc_mweb_addr2.startswith("tmweb1") assert ( ci_mweb.rpc_wallet(