mirror of
https://github.com/basicswap/basicswap.git
synced 2025-11-05 18:38:09 +01:00
Deduplicate getCoinIdFromTicker.
This commit is contained in:
@@ -32,7 +32,7 @@ from .interface.part import PARTInterface, PARTInterfaceAnon, PARTInterfaceBlind
|
|||||||
from . import __version__
|
from . import __version__
|
||||||
from .rpc import escape_rpcauth
|
from .rpc import escape_rpcauth
|
||||||
from .rpc_xmr import make_xmr_rpc2_func
|
from .rpc_xmr import make_xmr_rpc2_func
|
||||||
from .ui.util import getCoinName, known_chart_coins
|
from .ui.util import getCoinName
|
||||||
from .util import (
|
from .util import (
|
||||||
AutomationConstraint,
|
AutomationConstraint,
|
||||||
AutomationConstraintTemporary,
|
AutomationConstraintTemporary,
|
||||||
@@ -65,6 +65,7 @@ from basicswap.util.network import is_private_ip_address
|
|||||||
from .chainparams import (
|
from .chainparams import (
|
||||||
Coins,
|
Coins,
|
||||||
chainparams,
|
chainparams,
|
||||||
|
ticker_map,
|
||||||
)
|
)
|
||||||
from .script import (
|
from .script import (
|
||||||
OpCodes,
|
OpCodes,
|
||||||
@@ -9894,7 +9895,7 @@ class BasicSwap(BaseApp):
|
|||||||
seen_tickers = []
|
seen_tickers = []
|
||||||
for ticker in tickers:
|
for ticker in tickers:
|
||||||
upcased_ticker = ticker.strip().upper()
|
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}")
|
raise ValueError(f"Unknown coin: {ticker}")
|
||||||
if upcased_ticker in seen_tickers:
|
if upcased_ticker in seen_tickers:
|
||||||
raise ValueError(f"Duplicate coin: {ticker}")
|
raise ValueError(f"Duplicate coin: {ticker}")
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ from .basicswap_util import (
|
|||||||
from .chainparams import (
|
from .chainparams import (
|
||||||
Coins,
|
Coins,
|
||||||
chainparams,
|
chainparams,
|
||||||
|
getCoinIdFromTicker,
|
||||||
)
|
)
|
||||||
from .ui.util import (
|
from .ui.util import (
|
||||||
PAGE_LIMIT,
|
PAGE_LIMIT,
|
||||||
@@ -33,7 +34,6 @@ from .ui.util import (
|
|||||||
get_data_entry,
|
get_data_entry,
|
||||||
get_data_entry_or,
|
get_data_entry_or,
|
||||||
have_data_entry,
|
have_data_entry,
|
||||||
tickerToCoinId,
|
|
||||||
listOldBidStates,
|
listOldBidStates,
|
||||||
checkAddressesOwned,
|
checkAddressesOwned,
|
||||||
)
|
)
|
||||||
@@ -124,7 +124,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 = tickerToCoinId(ticker_str)
|
coin_type = getCoinIdFromTicker(ticker_str)
|
||||||
|
|
||||||
if len(url_split) > 4:
|
if len(url_split) > 4:
|
||||||
cmd = 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}"
|
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)
|
ci = swap_client.ci(coin_type)
|
||||||
|
|
||||||
r = 0
|
r = 0
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ from .util import (
|
|||||||
get_data_entry_or,
|
get_data_entry_or,
|
||||||
have_data_entry,
|
have_data_entry,
|
||||||
inputAmount,
|
inputAmount,
|
||||||
known_chart_coins,
|
|
||||||
listAvailableCoins,
|
listAvailableCoins,
|
||||||
PAGE_LIMIT,
|
PAGE_LIMIT,
|
||||||
setCoinFilter,
|
setCoinFilter,
|
||||||
@@ -40,6 +39,7 @@ from basicswap.basicswap_util import (
|
|||||||
)
|
)
|
||||||
from basicswap.chainparams import (
|
from basicswap.chainparams import (
|
||||||
Coins,
|
Coins,
|
||||||
|
ticker_map,
|
||||||
)
|
)
|
||||||
|
|
||||||
default_chart_api_key = (
|
default_chart_api_key = (
|
||||||
@@ -996,7 +996,8 @@ def page_offers(self, url_split, post_string, sent=False):
|
|||||||
enabled_chart_coins = []
|
enabled_chart_coins = []
|
||||||
enabled_chart_coins_setting = swap_client.settings.get("enabled_chart_coins", "")
|
enabled_chart_coins_setting = swap_client.settings.get("enabled_chart_coins", "")
|
||||||
if enabled_chart_coins_setting.lower() == "all":
|
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() == "":
|
elif enabled_chart_coins_setting.strip() == "":
|
||||||
for coin_id in swap_client.coin_clients:
|
for coin_id in swap_client.coin_clients:
|
||||||
if not swap_client.isCoinActive(coin_id):
|
if not swap_client.isCoinActive(coin_id):
|
||||||
@@ -1007,7 +1008,7 @@ def page_offers(self, url_split, post_string, sent=False):
|
|||||||
continue
|
continue
|
||||||
if (
|
if (
|
||||||
enabled_ticker not in enabled_chart_coins
|
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)
|
enabled_chart_coins.append(enabled_ticker)
|
||||||
else:
|
else:
|
||||||
@@ -1016,7 +1017,7 @@ def page_offers(self, url_split, post_string, sent=False):
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
upcased_ticker not in enabled_chart_coins
|
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)
|
enabled_chart_coins.append(upcased_ticker)
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright (c) 2020-2024 tecnovert
|
# 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
|
# 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.
|
||||||
|
|
||||||
@@ -15,6 +15,7 @@ from basicswap.util import (
|
|||||||
from basicswap.chainparams import (
|
from basicswap.chainparams import (
|
||||||
Coins,
|
Coins,
|
||||||
chainparams,
|
chainparams,
|
||||||
|
getCoinIdFromTicker,
|
||||||
)
|
)
|
||||||
from basicswap.basicswap_util import (
|
from basicswap.basicswap_util import (
|
||||||
ActionTypes,
|
ActionTypes,
|
||||||
@@ -34,30 +35,6 @@ from basicswap.basicswap_util import (
|
|||||||
from basicswap.protocols.xmr_swap_1 import getChainBSplitKey, getChainBRemoteSplitKey
|
from basicswap.protocols.xmr_swap_1 import getChainBSplitKey, getChainBRemoteSplitKey
|
||||||
|
|
||||||
PAGE_LIMIT = 1000
|
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):
|
def getCoinType(coin_type_ind):
|
||||||
@@ -65,7 +42,7 @@ def getCoinType(coin_type_ind):
|
|||||||
try:
|
try:
|
||||||
return int(coin_type_ind)
|
return int(coin_type_ind)
|
||||||
except Exception:
|
except Exception:
|
||||||
return tickerToCoinId(coin_type_ind)
|
return getCoinIdFromTicker(coin_type_ind)
|
||||||
|
|
||||||
|
|
||||||
def validateAmountString(amount, ci):
|
def validateAmountString(amount, ci):
|
||||||
@@ -667,12 +644,12 @@ def listAvailableCoins(swap_client, with_variants=True, split_from=False):
|
|||||||
continue
|
continue
|
||||||
if v["connection_type"] == "rpc":
|
if v["connection_type"] == "rpc":
|
||||||
coins.append((int(k), getCoinName(k)))
|
coins.append((int(k), getCoinName(k)))
|
||||||
if split_from and k not in invalid_coins_from:
|
if split_from:
|
||||||
coins_from.append(coins[-1])
|
coins_from.append(coins[-1])
|
||||||
if with_variants and k == Coins.PART:
|
if with_variants and k == Coins.PART:
|
||||||
for v in (Coins.PART_ANON, Coins.PART_BLIND):
|
for v in (Coins.PART_ANON, Coins.PART_BLIND):
|
||||||
coins.append((int(v), getCoinName(v)))
|
coins.append((int(v), getCoinName(v)))
|
||||||
if split_from and v not in invalid_coins_from:
|
if split_from:
|
||||||
coins_from.append(coins[-1])
|
coins_from.append(coins[-1])
|
||||||
if with_variants and k == Coins.LTC:
|
if with_variants and k == Coins.LTC:
|
||||||
for v in (Coins.LTC_MWEB,):
|
for v in (Coins.LTC_MWEB,):
|
||||||
|
|||||||
Reference in New Issue
Block a user