mirror of
https://github.com/basicswap/basicswap.git
synced 2025-04-06 14:27:30 +00:00
Deduplicate getCoinIdFromTicker.
This commit is contained in:
parent
0e9bb47902
commit
3cdab962d3
4 changed files with 16 additions and 37 deletions
|
@ -32,7 +32,7 @@ from .interface.part import PARTInterface, PARTInterfaceAnon, PARTInterfaceBlind
|
|||
from . import __version__
|
||||
from .rpc import escape_rpcauth
|
||||
from .rpc_xmr import make_xmr_rpc2_func
|
||||
from .ui.util import getCoinName, known_chart_coins
|
||||
from .ui.util import getCoinName
|
||||
from .util import (
|
||||
AutomationConstraint,
|
||||
AutomationConstraintTemporary,
|
||||
|
@ -65,6 +65,7 @@ from basicswap.util.network import is_private_ip_address
|
|||
from .chainparams import (
|
||||
Coins,
|
||||
chainparams,
|
||||
ticker_map,
|
||||
)
|
||||
from .script import (
|
||||
OpCodes,
|
||||
|
@ -9894,7 +9895,7 @@ class BasicSwap(BaseApp):
|
|||
seen_tickers = []
|
||||
for ticker in tickers:
|
||||
upcased_ticker = ticker.strip().upper()
|
||||
if upcased_ticker not in known_chart_coins:
|
||||
if upcased_ticker.lower() not in ticker_map:
|
||||
raise ValueError(f"Unknown coin: {ticker}")
|
||||
if upcased_ticker in seen_tickers:
|
||||
raise ValueError(f"Duplicate coin: {ticker}")
|
||||
|
|
|
@ -22,6 +22,7 @@ from .basicswap_util import (
|
|||
from .chainparams import (
|
||||
Coins,
|
||||
chainparams,
|
||||
getCoinIdFromTicker,
|
||||
)
|
||||
from .ui.util import (
|
||||
PAGE_LIMIT,
|
||||
|
@ -33,7 +34,6 @@ from .ui.util import (
|
|||
get_data_entry,
|
||||
get_data_entry_or,
|
||||
have_data_entry,
|
||||
tickerToCoinId,
|
||||
listOldBidStates,
|
||||
checkAddressesOwned,
|
||||
)
|
||||
|
@ -124,7 +124,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 = tickerToCoinId(ticker_str)
|
||||
coin_type = getCoinIdFromTicker(ticker_str)
|
||||
|
||||
if len(url_split) > 4:
|
||||
cmd = url_split[4]
|
||||
|
@ -820,7 +820,7 @@ def js_validateamount(self, url_split, post_string: str, is_json: bool) -> bytes
|
|||
f"Unknown rounding method, must be one of {valid_round_methods}"
|
||||
)
|
||||
|
||||
coin_type = tickerToCoinId(ticker_str)
|
||||
coin_type = getCoinIdFromTicker(ticker_str)
|
||||
ci = swap_client.ci(coin_type)
|
||||
|
||||
r = 0
|
||||
|
|
|
@ -15,7 +15,6 @@ from .util import (
|
|||
get_data_entry_or,
|
||||
have_data_entry,
|
||||
inputAmount,
|
||||
known_chart_coins,
|
||||
listAvailableCoins,
|
||||
PAGE_LIMIT,
|
||||
setCoinFilter,
|
||||
|
@ -40,6 +39,7 @@ from basicswap.basicswap_util import (
|
|||
)
|
||||
from basicswap.chainparams import (
|
||||
Coins,
|
||||
ticker_map,
|
||||
)
|
||||
|
||||
default_chart_api_key = (
|
||||
|
@ -996,7 +996,8 @@ def page_offers(self, url_split, post_string, sent=False):
|
|||
enabled_chart_coins = []
|
||||
enabled_chart_coins_setting = swap_client.settings.get("enabled_chart_coins", "")
|
||||
if enabled_chart_coins_setting.lower() == "all":
|
||||
enabled_chart_coins = known_chart_coins
|
||||
for coin_ticker in ticker_map:
|
||||
enabled_chart_coins.append(coin_ticker.upper())
|
||||
elif enabled_chart_coins_setting.strip() == "":
|
||||
for coin_id in swap_client.coin_clients:
|
||||
if not swap_client.isCoinActive(coin_id):
|
||||
|
@ -1007,7 +1008,7 @@ def page_offers(self, url_split, post_string, sent=False):
|
|||
continue
|
||||
if (
|
||||
enabled_ticker not in enabled_chart_coins
|
||||
and enabled_ticker in known_chart_coins
|
||||
and enabled_ticker.lower() in ticker_map
|
||||
):
|
||||
enabled_chart_coins.append(enabled_ticker)
|
||||
else:
|
||||
|
@ -1016,7 +1017,7 @@ def page_offers(self, url_split, post_string, sent=False):
|
|||
|
||||
if (
|
||||
upcased_ticker not in enabled_chart_coins
|
||||
and upcased_ticker in known_chart_coins
|
||||
and upcased_ticker.lower() in ticker_map
|
||||
):
|
||||
enabled_chart_coins.append(upcased_ticker)
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright (c) 2020-2024 tecnovert
|
||||
# Copyright (c) 2024 The Basicswap developers
|
||||
# Copyright (c) 2024-2025 The Basicswap developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
|
@ -15,6 +15,7 @@ from basicswap.util import (
|
|||
from basicswap.chainparams import (
|
||||
Coins,
|
||||
chainparams,
|
||||
getCoinIdFromTicker,
|
||||
)
|
||||
from basicswap.basicswap_util import (
|
||||
ActionTypes,
|
||||
|
@ -34,30 +35,6 @@ from basicswap.basicswap_util import (
|
|||
from basicswap.protocols.xmr_swap_1 import getChainBSplitKey, getChainBRemoteSplitKey
|
||||
|
||||
PAGE_LIMIT = 1000
|
||||
invalid_coins_from = []
|
||||
known_chart_coins = [
|
||||
"BTC",
|
||||
"PART",
|
||||
"XMR",
|
||||
"LTC",
|
||||
"FIRO",
|
||||
"DASH",
|
||||
"PIVX",
|
||||
"DOGE",
|
||||
"ETH",
|
||||
"DCR",
|
||||
"ZANO",
|
||||
"WOW",
|
||||
"BCH",
|
||||
]
|
||||
|
||||
|
||||
def tickerToCoinId(ticker):
|
||||
search_str = ticker.upper()
|
||||
for c in Coins:
|
||||
if c.name == search_str:
|
||||
return c.value
|
||||
raise ValueError("Unknown coin")
|
||||
|
||||
|
||||
def getCoinType(coin_type_ind):
|
||||
|
@ -65,7 +42,7 @@ def getCoinType(coin_type_ind):
|
|||
try:
|
||||
return int(coin_type_ind)
|
||||
except Exception:
|
||||
return tickerToCoinId(coin_type_ind)
|
||||
return getCoinIdFromTicker(coin_type_ind)
|
||||
|
||||
|
||||
def validateAmountString(amount, ci):
|
||||
|
@ -667,12 +644,12 @@ def listAvailableCoins(swap_client, with_variants=True, split_from=False):
|
|||
continue
|
||||
if v["connection_type"] == "rpc":
|
||||
coins.append((int(k), getCoinName(k)))
|
||||
if split_from and k not in invalid_coins_from:
|
||||
if split_from:
|
||||
coins_from.append(coins[-1])
|
||||
if with_variants and k == Coins.PART:
|
||||
for v in (Coins.PART_ANON, Coins.PART_BLIND):
|
||||
coins.append((int(v), getCoinName(v)))
|
||||
if split_from and v not in invalid_coins_from:
|
||||
if split_from:
|
||||
coins_from.append(coins[-1])
|
||||
if with_variants and k == Coins.LTC:
|
||||
for v in (Coins.LTC_MWEB,):
|
||||
|
|
Loading…
Reference in a new issue