mirror of
https://github.com/basicswap/basicswap.git
synced 2026-05-07 06:52:12 +02:00
fix: convert coin variant tickers
This commit is contained in:
@@ -552,16 +552,26 @@ chainparams = {
|
|||||||
|
|
||||||
name_map = {}
|
name_map = {}
|
||||||
ticker_map = {}
|
ticker_map = {}
|
||||||
|
variant_ticker_map = {}
|
||||||
|
|
||||||
|
|
||||||
for c, params in chainparams.items():
|
for c, params in chainparams.items():
|
||||||
name_map[params["name"].lower()] = c
|
name_map[params["name"].lower()] = c
|
||||||
ticker_map[params["ticker"].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:
|
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:
|
except Exception:
|
||||||
raise ValueError(f"Unknown coin {ticker}")
|
raise ValueError(f"Unknown coin {ticker}")
|
||||||
|
|
||||||
|
|||||||
@@ -449,11 +449,11 @@ class BTCInterface(Secp256k1Interface):
|
|||||||
# Wallet name is "" for some LTC and PART installs on older cores
|
# Wallet name is "" for some LTC and PART installs on older cores
|
||||||
if self._rpc_wallet not in wallets and len(wallets) > 0:
|
if self._rpc_wallet not in wallets and len(wallets) > 0:
|
||||||
if "" in wallets:
|
if "" in wallets:
|
||||||
|
# Setting wallet= in the coin .conf file should also work
|
||||||
self._log.warning(
|
self._log.warning(
|
||||||
f"Nameless {self.ticker()} wallet found."
|
f"Nameless {self.ticker()} wallet found."
|
||||||
+ '\nPlease set the "wallet_name" coin setting to "" or recreate the wallet'
|
+ '\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:
|
if self._rpc_wallet not in wallets:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
|
|||||||
@@ -290,7 +290,7 @@ def js_wallets(self, url_split, post_string, is_json):
|
|||||||
swap_client.checkSystemStatus()
|
swap_client.checkSystemStatus()
|
||||||
if len(url_split) > 3:
|
if len(url_split) > 3:
|
||||||
ticker_str = 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:
|
if len(url_split) > 4:
|
||||||
cmd = url_split[4]
|
cmd = url_split[4]
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright (c) 2021-2024 tecnovert
|
# 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
|
# Distributed under the MIT software license, see the accompanying
|
||||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
# 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)
|
ci0 = swap_clients[0].ci(self.test_coin_from)
|
||||||
ci1 = swap_clients[1].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_0 = ci0.rpc_wallet("getnewaddress", ["mweb addr test 0", "mweb"])
|
||||||
mweb_addr_1 = ci1.rpc_wallet("getnewaddress", ["mweb addr test 1", "mweb"])
|
mweb_addr_1 = ci1.rpc_wallet("getnewaddress", ["mweb addr test 1", "mweb"])
|
||||||
|
|
||||||
@@ -210,6 +219,19 @@ class TestLTC(BasicSwapTest):
|
|||||||
< 0.1
|
< 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:
|
try:
|
||||||
pause_event.clear() # Stop mining
|
pause_event.clear() # Stop mining
|
||||||
ci0.rpc_wallet("sendtoaddress", [mweb_addr_1, 10.0])
|
ci0.rpc_wallet("sendtoaddress", [mweb_addr_1, 10.0])
|
||||||
@@ -237,6 +259,7 @@ class TestLTC(BasicSwapTest):
|
|||||||
for utxo in utxos:
|
for utxo in utxos:
|
||||||
if utxo.get("address", "") == mweb_addr_1:
|
if utxo.get("address", "") == mweb_addr_1:
|
||||||
mweb_tx = utxo
|
mweb_tx = utxo
|
||||||
|
break
|
||||||
assert mweb_tx is not None
|
assert mweb_tx is not None
|
||||||
|
|
||||||
unspent_addr = ci1.getUnspentsByAddr()
|
unspent_addr = ci1.getUnspentsByAddr()
|
||||||
@@ -265,7 +288,9 @@ class TestLTC(BasicSwapTest):
|
|||||||
ltc_mweb_addr = read_json_api(
|
ltc_mweb_addr = read_json_api(
|
||||||
TEST_HTTP_PORT + 0, "wallets/ltc_mweb/nextdepositaddr"
|
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")
|
ltc_mweb_addr2 = read_json_api(TEST_HTTP_PORT + 0, "wallets/ltc/newmwebaddress")
|
||||||
|
assert ltc_mweb_addr2.startswith("tmweb1")
|
||||||
|
|
||||||
assert (
|
assert (
|
||||||
ci_mweb.rpc_wallet(
|
ci_mweb.rpc_wallet(
|
||||||
|
|||||||
Reference in New Issue
Block a user