mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-05-08 09:58:46 +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 = {}
|
latest = {}
|
||||||
for v in ("1", "2"):
|
for v in ("1", "2"):
|
||||||
releases = requests.get(RELEASES_URL.format(v)).json()
|
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
|
return latest
|
||||||
|
|
||||||
|
|
||||||
@ -421,8 +421,6 @@ def mark_duplicate_shortcuts(coins):
|
|||||||
# they *still* keep duplicate status (and possibly are deleted).
|
# they *still* keep duplicate status (and possibly are deleted).
|
||||||
continue
|
continue
|
||||||
|
|
||||||
nontokens = [coin for coin in values if not is_token(coin)]
|
|
||||||
|
|
||||||
for coin in values:
|
for coin in values:
|
||||||
# allow overrides to skip this; if not listed in overrides, assume True
|
# allow overrides to skip this; if not listed in overrides, assume True
|
||||||
is_dup = overrides.get(coin["key"], True)
|
is_dup = overrides.get(coin["key"], True)
|
||||||
@ -441,7 +439,7 @@ def _btc_sort_key(coin):
|
|||||||
return coin["name"]
|
return coin["name"]
|
||||||
|
|
||||||
|
|
||||||
def get_all(deduplicate=True):
|
def collect_coin_info():
|
||||||
"""Returns all definition as dict organized by coin type.
|
"""Returns all definition as dict organized by coin type.
|
||||||
`coins` for btc-like coins,
|
`coins` for btc-like coins,
|
||||||
`eth` for ethereum networks,
|
`eth` for ethereum networks,
|
||||||
@ -473,17 +471,35 @@ def get_all(deduplicate=True):
|
|||||||
|
|
||||||
_ensure_mandatory_values(coins)
|
_ensure_mandatory_values(coins)
|
||||||
|
|
||||||
if deduplicate:
|
return all_coins
|
||||||
mark_duplicate_shortcuts(all_coins.as_list())
|
|
||||||
all_coins["erc20"] = [
|
|
||||||
coin for coin in all_coins["erc20"] if not coin.get("duplicate")
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
|
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
|
return all_coins
|
||||||
|
|
||||||
|
|
||||||
def search(coins, keyword):
|
def search(coins, keyword):
|
||||||
kwl = keyword.lower()
|
kwl = keyword.lower()
|
||||||
|
if isinstance(coins, CoinsInfo):
|
||||||
|
coins = coins.as_list()
|
||||||
|
|
||||||
for coin in coins:
|
for coin in coins:
|
||||||
key = coin["key"].lower()
|
key = coin["key"].lower()
|
||||||
name = coin["name"].lower()
|
name = coin["name"].lower()
|
||||||
|
@ -153,8 +153,8 @@ def update_simple(coins, support_info, type):
|
|||||||
name=coin["name"],
|
name=coin["name"],
|
||||||
shortcut=coin["shortcut"],
|
shortcut=coin["shortcut"],
|
||||||
type=type,
|
type=type,
|
||||||
t1_enabled=_is_supported(support, 1),
|
t1_enabled=_is_supported(support, "trezor1"),
|
||||||
t2_enabled=_is_supported(support, 2),
|
t2_enabled=_is_supported(support, "trezor2"),
|
||||||
)
|
)
|
||||||
for k in OPTIONAL_KEYS:
|
for k in OPTIONAL_KEYS:
|
||||||
if k in coin:
|
if k in coin:
|
||||||
@ -294,7 +294,7 @@ if __name__ == "__main__":
|
|||||||
handler.setLevel(logging.DEBUG)
|
handler.setLevel(logging.DEBUG)
|
||||||
root.addHandler(handler)
|
root.addHandler(handler)
|
||||||
|
|
||||||
defs = coin_info.get_all()
|
defs = coin_info.coin_info()
|
||||||
support_info = coin_info.support_info(defs)
|
support_info = coin_info.support_info(defs)
|
||||||
|
|
||||||
coins = {}
|
coins = {}
|
||||||
|
@ -498,8 +498,7 @@ def check(backend, icons, show_duplicates):
|
|||||||
if icons and not CAN_BUILD_DEFS:
|
if icons and not CAN_BUILD_DEFS:
|
||||||
raise click.ClickException("Missing requirements for icon check")
|
raise click.ClickException("Missing requirements for icon check")
|
||||||
|
|
||||||
defs = coin_info.get_all(deduplicate=False)
|
defs, buckets = coin_info.coin_info_with_duplicates()
|
||||||
buckets = coin_info.mark_duplicate_shortcuts(defs.as_list())
|
|
||||||
all_checks_passed = True
|
all_checks_passed = True
|
||||||
|
|
||||||
print("Checking BTC-like coins...")
|
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")
|
@click.option("-o", "--outfile", type=click.File(mode="w"), default="./coins.json")
|
||||||
def coins_json(outfile):
|
def coins_json(outfile):
|
||||||
"""Generate coins.json for consumption in python-trezor and Connect/Wallet"""
|
"""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)
|
support_info = coin_info.support_info(coins)
|
||||||
by_name = {}
|
by_name = {}
|
||||||
for coin in coins:
|
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
|
This is currently unused but should enable us to add new coins without having to
|
||||||
update firmware.
|
update firmware.
|
||||||
"""
|
"""
|
||||||
coins = coin_info.get_all().coins
|
coins = coin_info.coin_info().coins
|
||||||
coindefs = {}
|
coindefs = {}
|
||||||
for coin in coins:
|
for coin in coins:
|
||||||
key = coin["key"]
|
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")
|
raise click.ClickException("Option -o can only be used with single input file")
|
||||||
|
|
||||||
# prepare defs
|
# prepare defs
|
||||||
defs = coin_info.get_all()
|
defs = coin_info.coin_info()
|
||||||
support_info = coin_info.support_info(defs)
|
support_info = coin_info.support_info(defs)
|
||||||
|
|
||||||
# munch dicts - make them attribute-accessible
|
# munch dicts - make them attribute-accessible
|
||||||
|
Loading…
Reference in New Issue
Block a user