1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-18 12:28:09 +00:00

fix(common/tools): cleaner handling of duplicity overrides

This commit is contained in:
matejcik 2021-02-25 16:11:23 +01:00 committed by matejcik
parent 17fa6ab4ec
commit 090d103382

View File

@ -443,28 +443,27 @@ def mark_duplicate_shortcuts(coins):
dup_symbols[symbol].append(coin) dup_symbols[symbol].append(coin)
dup_symbols = {k: v for k, v in dup_symbols.items() if len(v) > 1} dup_symbols = {k: v for k, v in dup_symbols.items() if len(v) > 1}
# load overrides and put them into their own bucket
overrides = load_json("duplicity_overrides.json")
override_bucket = []
for coin in coins:
if overrides.get(coin["key"], False):
coin["duplicate"] = True
override_bucket.append(coin)
# mark duplicate symbols # mark duplicate symbols
for values in dup_symbols.values(): for values in dup_symbols.values():
for coin in values: for coin in values:
# allow overrides to skip this; if not listed in overrides, assume True
is_dup = overrides.get(coin["key"], True)
if is_dup:
coin["duplicate"] = True coin["duplicate"] = True
# again: still in dups, but not marked as duplicate and not deleted
dup_symbols["_override"] = override_bucket
return dup_symbols return dup_symbols
def apply_duplicity_overrides(coins):
overrides = load_json("duplicity_overrides.json")
override_bucket = []
for coin in coins:
override_value = overrides.get(coin["key"])
if override_value is True:
override_bucket.append(coin)
if override_value is not None:
coin["duplicate"] = override_value
return override_bucket
def deduplicate_erc20(buckets, networks): def deduplicate_erc20(buckets, networks):
"""Apply further processing to ERC20 duplicate buckets. """Apply further processing to ERC20 duplicate buckets.
@ -489,12 +488,10 @@ def deduplicate_erc20(buckets, networks):
""" """
testnet_networks = {n["chain"] for n in networks if "Testnet" in n["name"]} testnet_networks = {n["chain"] for n in networks if "Testnet" in n["name"]}
overrides = buckets["_override"]
def clear_bucket(bucket): def clear_bucket(bucket):
# allow all coins, except those that are explicitly marked through overrides # allow all coins, except those that are explicitly marked through overrides
for coin in bucket: for coin in bucket:
if coin not in overrides:
coin["duplicate"] = False coin["duplicate"] = False
for bucket in buckets.values(): for bucket in buckets.values():
@ -615,9 +612,15 @@ def coin_info_with_duplicates():
Returns the CoinsInfo object and duplicate buckets. Returns the CoinsInfo object and duplicate buckets.
""" """
all_coins = collect_coin_info() all_coins = collect_coin_info()
coin_list = all_coins.as_list()
# generate duplicity buckets based on shortcuts
buckets = mark_duplicate_shortcuts(all_coins.as_list()) buckets = mark_duplicate_shortcuts(all_coins.as_list())
# apply further processing to ERC20 tokens, generate deprecations etc.
deduplicate_erc20(buckets, all_coins.eth) deduplicate_erc20(buckets, all_coins.eth)
deduplicate_keys(all_coins.as_list()) # ensure the whole list has unique keys (taking into account changes from deduplicate_erc20)
deduplicate_keys(coin_list)
# apply duplicity overrides
buckets["_override"] = apply_duplicity_overrides(coin_list)
sort_coin_infos(all_coins) sort_coin_infos(all_coins)
return all_coins, buckets return all_coins, buckets