mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-22 15:38:11 +00:00
coin_info: tweak API for less repetition
This commit is contained in:
parent
98c2fdc6df
commit
0abfb6cd91
@ -278,7 +278,7 @@ def latest_releases():
|
||||
latest = {}
|
||||
for v in ("1", "2"):
|
||||
releases = requests.get(RELEASES_URL.format(v)).json()
|
||||
latest[v] = max(tuple(r["version"]) for r in releases)
|
||||
latest["trezor" + v] = max(tuple(r["version"]) for r in releases)
|
||||
return latest
|
||||
|
||||
|
||||
@ -421,8 +421,6 @@ def mark_duplicate_shortcuts(coins):
|
||||
# they *still* keep duplicate status (and possibly are deleted).
|
||||
continue
|
||||
|
||||
nontokens = [coin for coin in values if not is_token(coin)]
|
||||
|
||||
for coin in values:
|
||||
# allow overrides to skip this; if not listed in overrides, assume True
|
||||
is_dup = overrides.get(coin["key"], True)
|
||||
@ -441,7 +439,7 @@ def _btc_sort_key(coin):
|
||||
return coin["name"]
|
||||
|
||||
|
||||
def get_all(deduplicate=True):
|
||||
def collect_coin_info():
|
||||
"""Returns all definition as dict organized by coin type.
|
||||
`coins` for btc-like coins,
|
||||
`eth` for ethereum networks,
|
||||
@ -473,17 +471,35 @@ def get_all(deduplicate=True):
|
||||
|
||||
_ensure_mandatory_values(coins)
|
||||
|
||||
if deduplicate:
|
||||
mark_duplicate_shortcuts(all_coins.as_list())
|
||||
all_coins["erc20"] = [
|
||||
coin for coin in all_coins["erc20"] if not coin.get("duplicate")
|
||||
]
|
||||
return all_coins
|
||||
|
||||
|
||||
def coin_info_with_duplicates():
|
||||
"""Collects coin info, detects duplicates but does not remove them.
|
||||
|
||||
Returns the CoinsInfo object and duplicate buckets.
|
||||
"""
|
||||
all_coins = collect_coin_info()
|
||||
buckets = mark_duplicate_shortcuts(all_coins.as_list())
|
||||
return all_coins, buckets
|
||||
|
||||
|
||||
def coin_info():
|
||||
"""Collects coin info, marks and prunes duplicate ERC20 symbols, fills out support
|
||||
info and returns the result.
|
||||
"""
|
||||
all_coins, _ = coin_info_with_duplicates()
|
||||
all_coins["erc20"] = [
|
||||
coin for coin in all_coins["erc20"] if not coin.get("duplicate")
|
||||
]
|
||||
return all_coins
|
||||
|
||||
|
||||
def search(coins, keyword):
|
||||
kwl = keyword.lower()
|
||||
if isinstance(coins, CoinsInfo):
|
||||
coins = coins.as_list()
|
||||
|
||||
for coin in coins:
|
||||
key = coin["key"].lower()
|
||||
name = coin["name"].lower()
|
||||
|
@ -153,8 +153,8 @@ def update_simple(coins, support_info, type):
|
||||
name=coin["name"],
|
||||
shortcut=coin["shortcut"],
|
||||
type=type,
|
||||
t1_enabled=_is_supported(support, 1),
|
||||
t2_enabled=_is_supported(support, 2),
|
||||
t1_enabled=_is_supported(support, "trezor1"),
|
||||
t2_enabled=_is_supported(support, "trezor2"),
|
||||
)
|
||||
for k in OPTIONAL_KEYS:
|
||||
if k in coin:
|
||||
@ -294,7 +294,7 @@ if __name__ == "__main__":
|
||||
handler.setLevel(logging.DEBUG)
|
||||
root.addHandler(handler)
|
||||
|
||||
defs = coin_info.get_all()
|
||||
defs = coin_info.coin_info()
|
||||
support_info = coin_info.support_info(defs)
|
||||
|
||||
coins = {}
|
||||
|
@ -498,8 +498,7 @@ def check(backend, icons, show_duplicates):
|
||||
if icons and not CAN_BUILD_DEFS:
|
||||
raise click.ClickException("Missing requirements for icon check")
|
||||
|
||||
defs = coin_info.get_all(deduplicate=False)
|
||||
buckets = coin_info.mark_duplicate_shortcuts(defs.as_list())
|
||||
defs, buckets = coin_info.coin_info_with_duplicates()
|
||||
all_checks_passed = True
|
||||
|
||||
print("Checking BTC-like coins...")
|
||||
@ -544,7 +543,7 @@ def check(backend, icons, show_duplicates):
|
||||
@click.option("-o", "--outfile", type=click.File(mode="w"), default="./coins.json")
|
||||
def coins_json(outfile):
|
||||
"""Generate coins.json for consumption in python-trezor and Connect/Wallet"""
|
||||
coins = coin_info.get_all().coins
|
||||
coins = coin_info.coin_info().coins
|
||||
support_info = coin_info.support_info(coins)
|
||||
by_name = {}
|
||||
for coin in coins:
|
||||
@ -564,7 +563,7 @@ def coindefs(outfile):
|
||||
This is currently unused but should enable us to add new coins without having to
|
||||
update firmware.
|
||||
"""
|
||||
coins = coin_info.get_all().coins
|
||||
coins = coin_info.coin_info().coins
|
||||
coindefs = {}
|
||||
for coin in coins:
|
||||
key = coin["key"]
|
||||
@ -603,7 +602,7 @@ def render(paths, outfile, verbose):
|
||||
raise click.ClickException("Option -o can only be used with single input file")
|
||||
|
||||
# prepare defs
|
||||
defs = coin_info.get_all()
|
||||
defs = coin_info.coin_info()
|
||||
support_info = coin_info.support_info(defs)
|
||||
|
||||
# munch dicts - make them attribute-accessible
|
||||
|
Loading…
Reference in New Issue
Block a user