1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 07:28:10 +00:00

common/tools: allow tokens to collide with nontokens

if explicitly supported in support.json

This reverts commit 7cf22c5227.
This commit is contained in:
matejcik 2019-04-29 18:04:19 +02:00
parent fe3d67e259
commit 6bd5345021
5 changed files with 60 additions and 57 deletions

View File

@ -4,8 +4,5 @@
"erc20:eth:LINK Platform": true,
"erc20:eth:NXX": false,
"erc20:eth:Hdp": true,
"erc20:eth:Hdp.ф": true,
"erc20:eth:USDT": false,
"erc20:eth:BNB": false,
"erc20:eth:QTUM": false
"erc20:eth:Hdp.ф": true
}

View File

@ -289,6 +289,7 @@
"erc20:eth:BRD": "1.6.2",
"erc20:eth:BRLN": "1.8.0",
"erc20:eth:BSDC": "1.6.2",
"erc20:eth:BST": "1.6.2",
"erc20:eth:BTCA": "1.8.0",
"erc20:eth:BTCE": "1.6.2",
"erc20:eth:BTCL": "1.6.2",
@ -1285,7 +1286,6 @@
"erc20:eth:BNC:ef51": "(AUTO) duplicate key",
"erc20:eth:BOX:63f5": "(AUTO) duplicate key",
"erc20:eth:BOX:e1a1": "(AUTO) duplicate key",
"erc20:eth:BST": "(AUTO) duplicate key",
"erc20:eth:BTL (Battle)": "(AUTO) duplicate key",
"erc20:eth:BTL (Bitlle)": "(AUTO) duplicate key",
"erc20:eth:BTR:499a": "(AUTO) duplicate key",
@ -1637,6 +1637,7 @@
"erc20:eth:BRD": "2.0.7",
"erc20:eth:BRLN": "2.0.10",
"erc20:eth:BSDC": "2.0.7",
"erc20:eth:BST": "2.0.7",
"erc20:eth:BTCA": "2.0.10",
"erc20:eth:BTCE": "2.0.7",
"erc20:eth:BTCL": "2.0.7",
@ -2636,7 +2637,6 @@
"erc20:eth:BNC:ef51": "(AUTO) duplicate key",
"erc20:eth:BOX:63f5": "(AUTO) duplicate key",
"erc20:eth:BOX:e1a1": "(AUTO) duplicate key",
"erc20:eth:BST": "(AUTO) duplicate key",
"erc20:eth:BTL (Battle)": "(AUTO) duplicate key",
"erc20:eth:BTL (Bitlle)": "(AUTO) duplicate key",
"erc20:eth:BTR:499a": "(AUTO) duplicate key",

View File

@ -304,16 +304,18 @@ def support_info_single(support_data, coin):
key = coin["key"]
dup = coin.get("duplicate")
for device, values in support_data.items():
if dup and is_token(coin):
support_value = False
elif key in values["unsupported"]:
if key in values["unsupported"]:
support_value = False
elif key in values["supported"]:
support_value = values["supported"][key]
elif device in MISSING_SUPPORT_MEANS_NO:
support_value = False
elif is_token(coin):
# tokens are implicitly supported in next release
if dup:
# if duplicate token that is not explicitly listed, it's unsupported
support_value = False
else:
# otherwise implicitly supported in next
support_value = "soon"
else:
support_value = None
@ -409,7 +411,7 @@ def deduplicate_erc20(buckets, networks):
This function works on results of `mark_duplicate_shortcuts`.
Buckets that contain at least one non-token are ignored - symbol collisions
with non-tokens are always fatal.
with non-tokens always apply.
Otherwise the following rules are applied:
@ -502,8 +504,6 @@ def collect_coin_info():
`erc20` for ERC20 tokens,
`nem` for NEM mosaics,
`misc` for other networks.
Automatically removes duplicate symbols from the result.
"""
all_coins = CoinsInfo(
bitcoin=_load_btc_coins(),
@ -548,13 +548,14 @@ def coin_info_with_duplicates():
def coin_info():
"""Collects coin info, marks and prunes duplicate ERC20 symbols, fills out support
info and returns the result.
"""Collects coin info, fills out support info and returns the result.
Does not auto-delete duplicates. This should now be based on support info.
"""
all_coins, _ = coin_info_with_duplicates()
all_coins["erc20"] = [
coin for coin in all_coins["erc20"] if not coin.get("duplicate")
]
# all_coins["erc20"] = [
# coin for coin in all_coins["erc20"] if not coin.get("duplicate")
# ]
return all_coins

View File

@ -145,6 +145,13 @@ def render_file(src, dst, coins, support_info):
# ====== validation functions ======
def mark_unsupported(support_info, coins):
for coin in coins:
key = coin["key"]
# checking for explicit False because None means unknown
coin["unsupported"] = all(v is False for v in support_info[key].values())
def highlight_key(coin, color):
"""Return a colorful string where the SYMBOL part is bold."""
keylist = coin["key"].split(":")
@ -193,7 +200,6 @@ def check_eth(coins):
def check_btc(coins):
check_passed = True
support_infos = coin_info.support_info(coins)
# validate individual coin data
for coin in coins:
@ -213,7 +219,7 @@ def check_btc(coins):
color = "green"
elif name == "Bitcoin":
color = "red"
elif coin.get("unsupported"):
elif coin["unsupported"]:
color = "grey"
prefix = crayon("blue", "(X)", bold=True)
else:
@ -239,15 +245,9 @@ def check_btc(coins):
and not c["name"].endswith("Regtest")
]
have_bitcoin = False
for coin in mainnets:
if coin["name"] == "Bitcoin":
have_bitcoin = True
if all(v is False for k, v in support_infos[coin["key"]].items()):
coin["unsupported"] = True
supported_mainnets = [c for c in mainnets if not c.get("unsupported")]
supported_networks = [c for c in bucket if not c.get("unsupported")]
have_bitcoin = any(coin["name"] == "Bitcoin" for coin in mainnets)
supported_mainnets = [c for c in mainnets if not c["unsupported"]]
supported_networks = [c for c in bucket if not c["unsupported"]]
if len(mainnets) > 1:
if (have_bitcoin or strict) and len(supported_networks) > 1:
@ -290,7 +290,7 @@ def check_btc(coins):
return check_passed
def check_dups(buckets, print_at_level=logging.ERROR):
def check_dups(buckets, print_at_level=logging.WARNING):
"""Analyze and pretty-print results of `coin_info.mark_duplicate_shortcuts`.
`print_at_level` can be one of logging levels.
@ -305,15 +305,19 @@ def check_dups(buckets, print_at_level=logging.ERROR):
"""Colorize coins. Tokens are cyan, nontokens are red. Coins that are NOT
marked duplicate get a green asterisk.
"""
if coin_info.is_token(coin):
prefix = ""
if coin["unsupported"]:
color = "grey"
prefix = crayon("blue", "(X)", bold=True)
elif coin_info.is_token(coin):
color = "cyan"
else:
color = "red"
highlighted = highlight_key(coin, color)
if not coin.get("duplicate"):
prefix = crayon("green", "*", bold=True)
else:
prefix = ""
prefix = crayon("green", "*", bold=True) + prefix
highlighted = highlight_key(coin, color)
return "{}{}".format(prefix, highlighted)
check_passed = True
@ -323,17 +327,29 @@ def check_dups(buckets, print_at_level=logging.ERROR):
if not bucket:
continue
supported = [coin for coin in bucket if not coin["unsupported"]]
nontokens = [coin for coin in bucket if not coin_info.is_token(coin)]
cleared = not any(coin.get("duplicate") for coin in bucket)
# string generation
dup_str = ", ".join(coin_str(coin) for coin in bucket)
if not nontokens:
level = logging.DEBUG
elif len(nontokens) == 1:
level = logging.INFO
else:
if len(nontokens) > 1:
# Two or more colliding nontokens. This is always fatal.
# XXX consider allowing two nontokens as long as only one is supported?
level = logging.ERROR
check_passed = False
elif len(supported) > 1:
# more than one supported coin in bucket
if cleared:
# some previous step has explicitly marked them as non-duplicate
level = logging.INFO
else:
# at most 1 non-token - we tenatively allow token collisions
# when explicitly marked as supported
level = logging.WARNING
else:
# At most 1 supported coin, at most 1 non-token. This is informational only.
level = logging.DEBUG
# deciding whether to print
if level < print_at_level:
@ -342,7 +358,7 @@ def check_dups(buckets, print_at_level=logging.ERROR):
if symbol == "_override":
print_log(level, "force-set duplicates:", dup_str)
else:
print_log(level, "duplicate symbol {}:".format(symbol), dup_str)
print_log(level, "duplicate symbol {}:".format(symbol.upper()), dup_str)
return check_passed
@ -571,6 +587,8 @@ def check(backend, icons, show_duplicates):
raise click.ClickException("Missing requirements for icon check")
defs, buckets = coin_info.coin_info_with_duplicates()
support_info = coin_info.support_info(defs)
mark_unsupported(support_info, defs.as_list())
all_checks_passed = True
print("Checking BTC-like coins...")
@ -586,7 +604,7 @@ def check(backend, icons, show_duplicates):
elif show_duplicates == "nontoken":
dup_level = logging.INFO
else:
dup_level = logging.ERROR
dup_level = logging.WARNING
print("Checking unexpected duplicates...")
if not check_dups(buckets, dup_level):
all_checks_passed = False

View File

@ -72,10 +72,6 @@ def print_support(coin):
key, name, shortcut = coin["key"], coin["name"], coin["shortcut"]
print(f"{key} - {name} ({shortcut})")
if coin.get("duplicate"):
if coin_info.is_token(coin):
print(" * DUPLICATE SYMBOL (no support)")
return
else:
print(" * DUPLICATE SYMBOL")
for dev, where in SUPPORT_INFO.items():
missing_means_no = dev in coin_info.MISSING_SUPPORT_MEANS_NO
@ -131,8 +127,6 @@ def find_unsupported_coins(coins_dict):
result[device] = []
for key, coin in coins_dict.items():
if coin.get("duplicate") and coin_info.is_token(coin):
continue
if key not in support_set:
result[device].append(coin)
@ -466,12 +460,6 @@ def set_support_value(key, entries, reason):
(or null, in case of trezor1/2)
Setting variable to empty ("trezor1=") will set to null, or clear the entry.
Setting to "soon", "planned", "2.1.1" etc. will set the literal string.
Entries that are always present:
trezor1 trezor2 webwallet connect
Entries with other names will be inserted into "others". This is a good place
to store links to 3rd party software, such as Electrum forks or claim tools.
"""
defs, _ = coin_info.coin_info_with_duplicates()
coins = defs.as_dict()
@ -483,7 +471,6 @@ def set_support_value(key, entries, reason):
if coins[key].get("duplicate") and coin_info.is_token(coins[key]):
shortcut = coins[key]["shortcut"]
click.echo(f"Note: shortcut {shortcut} is a duplicate.")
click.echo(f"Coin will NOT be listed regardless of support.json status.")
for entry in entries:
try: