fixup! chore(core): add coin support info for T3T1

Ioan Bizău 4 weeks ago
parent 864ba85aca
commit e96e0cd0ba

@ -42,8 +42,8 @@ def generate(env):
# replace "utils.BITCOIN_ONLY" with literal constant (True/False)
# so the compiler can optimize out the things we don't want
btc_only = env["bitcoin_only"] == "1"
is_t2b1 = env["TREZOR_MODEL"] == "R"
is_t3t1 = env["TREZOR_MODEL"] == "T3T1"
trezor_model_t2b1 = env["TREZOR_MODEL"] == "R"
trezor_model_t3t1 = env["TREZOR_MODEL"] == "T3T1"
backlight = env["backlight"]
optiga = env["optiga"]
layout_tt = env["ui_layout"] == "UI_LAYOUT_TT"
@ -51,8 +51,8 @@ def generate(env):
interim = f"{target[:-4]}.i" # replace .mpy with .i
sed_scripts = " ".join(
[
rf"-e 's/utils\.MODEL_IS_T2B1/{is_t2b1}/g'",
rf"-e 's/utils\.MODEL_IS_T3T1/{is_t3t1}/g'",
rf"-e 's/utils\.TREZOR_MODEL == \"TR\"/{trezor_model_t2b1}/g'",
rf"-e 's/utils\.TREZOR_MODEL == \"T3T1\"/{trezor_model_t3t1}/g'",
rf"-e 's/utils\.BITCOIN_ONLY/{btc_only}/g'",
rf"-e 's/utils\.USE_BACKLIGHT/{backlight}/g'",
rf"-e 's/utils\.USE_OPTIGA/{optiga}/g'",

@ -127,7 +127,7 @@ def get_features() -> Features:
]
# We don't support some currencies on T2B1 and T3T1 (see #2793)
if not (utils.MODEL_IS_T2B1 or utils.MODEL_IS_T3T1):
if not utils.TREZOR_MODEL in ("T2B1", "T3T1"):
f.capabilities.extend(
[
Capability.NEM,

@ -94,7 +94,7 @@ class CoinInfo:
# fmt: off
def by_name(name: str) -> CoinInfo:
if utils.MODEL_IS_T2B1:
if utils.TREZOR_MODEL == "T2B1":
if name == "Bitcoin":
return CoinInfo(
name, # coin_name
@ -1402,7 +1402,7 @@ def by_name(name: str) -> CoinInfo:
None, # confidential_assets
)
raise ValueError # Unknown coin name
elif utils.MODEL_IS_T3T1:
if utils.TREZOR_MODEL == "T3T1":
if name == "Bitcoin":
return CoinInfo(
name, # coin_name
@ -2710,7 +2710,7 @@ def by_name(name: str) -> CoinInfo:
None, # confidential_assets
)
raise ValueError # Unknown coin name
else:
if utils.TREZOR_MODEL == "T2T1":
if name == "Bitcoin":
return CoinInfo(
name, # coin_name

@ -134,23 +134,19 @@ ATTRIBUTES = (
("confidential_assets", optional_dict),
)
btc_names = ["Bitcoin", "Testnet", "Regtest"]
# TODO: make this easily extendable for more models
coins_btc_t2t1 = [c for c in supported_on("T2T1", bitcoin) if c.name in btc_names]
coins_alt_t2t1 = [c for c in supported_on("T2T1", bitcoin) if c.name not in btc_names]
models = ["T2B1", "T3T1", "T2T1"]
coins_btc_t2b1 = [c for c in supported_on("T2B1", bitcoin) if c.name in btc_names]
coins_alt_t2b1 = [c for c in supported_on("T2B1", bitcoin) if c.name not in btc_names]
coins_btc_t3t1 = [c for c in supported_on("T3T1", bitcoin) if c.name in btc_names]
coins_alt_t3t1 = [c for c in supported_on("T3T1", bitcoin) if c.name not in btc_names]
btc_names = ["Bitcoin", "Testnet", "Regtest"]
coins = {}
for model in models:
coins.setdefault('btc', {})[model] = [c for c in supported_on(model, bitcoin) if c.name in btc_names]
coins.setdefault('alt', {})[model] = [c for c in supported_on(model, bitcoin) if c.name not in btc_names]
%>\
def by_name(name: str) -> CoinInfo:
if utils.MODEL_IS_T2B1:
% for coin in coins_btc_t2b1:
% for model in models:
if utils.TREZOR_MODEL == "${model}":
% for coin in coins['btc'][model]:
if name == ${black_repr(coin["coin_name"])}:
return CoinInfo(
% for attr, func in ATTRIBUTES:
@ -159,7 +155,7 @@ def by_name(name: str) -> CoinInfo:
)
% endfor
if not utils.BITCOIN_ONLY:
% for coin in coins_alt_t2b1:
% for coin in coins['alt'][model]:
if name == ${black_repr(coin["coin_name"])}:
return CoinInfo(
% for attr, func in ATTRIBUTES:
@ -168,41 +164,4 @@ def by_name(name: str) -> CoinInfo:
)
% endfor
raise ValueError # Unknown coin name
elif utils.MODEL_IS_T3T1:
% for coin in coins_btc_t3t1:
if name == ${black_repr(coin["coin_name"])}:
return CoinInfo(
% for attr, func in ATTRIBUTES:
${func(coin[attr])}, # ${attr}
% endfor
)
% endfor
if not utils.BITCOIN_ONLY:
% for coin in coins_alt_t3t1:
if name == ${black_repr(coin["coin_name"])}:
return CoinInfo(
% for attr, func in ATTRIBUTES:
${func(coin[attr])}, # ${attr}
% endfor
)
% endfor
raise ValueError # Unknown coin name
else:
% for coin in coins_btc_t2t1:
if name == ${black_repr(coin["coin_name"])}:
return CoinInfo(
% for attr, func in ATTRIBUTES:
${func(coin[attr])}, # ${attr}
% endfor
)
% endfor
if not utils.BITCOIN_ONLY:
% for coin in coins_alt_t2t1:
if name == ${black_repr(coin["coin_name"])}:
return CoinInfo(
% for attr, func in ATTRIBUTES:
${func(coin[attr])}, # ${attr}
% endfor
)
% endfor
raise ValueError # Unknown coin name

@ -59,7 +59,7 @@ def by_slip44(slip44: int) -> EthereumNetworkInfo:
# fmt: off
def _networks_iterator() -> Iterator[NetworkInfoTuple]:
if utils.MODEL_IS_T2B1:
if utils.TREZOR_MODEL == "T2B1":
yield (
1, # chain_id
60, # slip44
@ -102,7 +102,7 @@ def _networks_iterator() -> Iterator[NetworkInfoTuple]:
"MATIC", # symbol
"Polygon", # name
)
elif utils.MODEL_IS_T3T1:
if utils.TREZOR_MODEL == "T3T1":
yield (
1, # chain_id
60, # slip44
@ -145,7 +145,7 @@ def _networks_iterator() -> Iterator[NetworkInfoTuple]:
"MATIC", # symbol
"Polygon", # name
)
else:
if utils.TREZOR_MODEL == "T2T1":
yield (
1, # chain_id
60, # slip44

@ -59,8 +59,9 @@ def by_slip44(slip44: int) -> EthereumNetworkInfo:
# fmt: off
def _networks_iterator() -> Iterator[NetworkInfoTuple]:
if utils.MODEL_IS_T2B1:
% for n in sorted(supported_on("T2B1", eth), key=lambda network: (int(network.chain_id), network.name)):
% for model in ["T2B1", "T3T1", "T2T1"]:
if utils.TREZOR_MODEL == "${model}":
% for n in sorted(supported_on(model, eth), key=lambda network: (int(network.chain_id), network.name)):
yield (
${n.chain_id}, # chain_id
${n.slip44}, # slip44
@ -68,21 +69,4 @@ def _networks_iterator() -> Iterator[NetworkInfoTuple]:
"${n.name}", # name
)
% endfor
elif utils.MODEL_IS_T3T1:
% for n in sorted(supported_on("T3T1", eth), key=lambda network: (int(network.chain_id), network.name)):
yield (
${n.chain_id}, # chain_id
${n.slip44}, # slip44
"${n.shortcut}", # symbol
"${n.name}", # name
)
% endfor
else:
% for n in sorted(supported_on("T2T1", eth), key=lambda network: (int(network.chain_id), network.name)):
yield (
${n.chain_id}, # chain_id
${n.slip44}, # slip44
"${n.shortcut}", # symbol
"${n.name}", # name
)
% endfor

@ -42,7 +42,7 @@ def token_by_chain_address(chain_id: int, address: bytes) -> EthereumTokenInfo |
def _token_iterator(chain_id: int) -> Iterator[tuple[bytes, str, int, str]]:
if utils.MODEL_IS_T2B1:
if utils.TREZOR_MODEL == "T2B1":
if chain_id == 1: # eth
yield ( # address, symbol, decimals, name
b"\x7f\xc6\x65\x00\xc8\x4a\x76\xad\x7e\x9c\x93\x43\x7b\xfc\x5a\xc3\x3e\x2d\xda\xe9",
@ -190,7 +190,7 @@ def _token_iterator(chain_id: int) -> Iterator[tuple[bytes, str, int, str]]:
18,
"Wrapped AVAX",
)
elif utils.MODEL_IS_T3T1:
if utils.TREZOR_MODEL == "T3T1":
if chain_id == 1: # eth
yield ( # address, symbol, decimals, name
b"\x7f\xc6\x65\x00\xc8\x4a\x76\xad\x7e\x9c\x93\x43\x7b\xfc\x5a\xc3\x3e\x2d\xda\xe9",
@ -338,7 +338,7 @@ def _token_iterator(chain_id: int) -> Iterator[tuple[bytes, str, int, str]]:
18,
"Wrapped AVAX",
)
else:
if utils.TREZOR_MODEL == "T2T1":
if chain_id == 1: # eth
yield ( # address, symbol, decimals, name
b"\x7f\xc6\x65\x00\xc8\x4a\x76\xad\x7e\x9c\x93\x43\x7b\xfc\x5a\xc3\x3e\x2d\xda\xe9",

@ -51,8 +51,9 @@ def token_by_chain_address(chain_id: int, address: bytes) -> EthereumTokenInfo |
def _token_iterator(chain_id: int) -> Iterator[tuple[bytes, str, int, str]]:
if utils.MODEL_IS_T2B1:
% for token_chain_id, tokens in group_tokens(supported_on("T2B1", erc20)).items():
% for model in ["T2B1", "T3T1", "T2T1"]:
if utils.TREZOR_MODEL == "${model}":
% for token_chain_id, tokens in group_tokens(supported_on(model, erc20)).items():
if chain_id == ${token_chain_id}: # ${tokens[0].chain}
% for t in tokens:
yield ( # address, symbol, decimals, name
@ -63,27 +64,4 @@ def _token_iterator(chain_id: int) -> Iterator[tuple[bytes, str, int, str]]:
)
% endfor
% endfor
elif utils.MODEL_IS_T3T1:
% for token_chain_id, tokens in group_tokens(supported_on("T3T1", erc20)).items():
if chain_id == ${token_chain_id}: # ${tokens[0].chain}
% for t in tokens:
yield ( # address, symbol, decimals, name
${black_repr(t.address_bytes)},
${black_repr(t.symbol)},
${t.decimals},
${black_repr(t.name.strip())},
)
% endfor
% endfor
else:
% for token_chain_id, tokens in group_tokens(supported_on("T2T1", erc20)).items():
if chain_id == ${token_chain_id}: # ${tokens[0].chain}
% for t in tokens:
yield ( # address, symbol, decimals, name
${black_repr(t.address_bytes)},
${black_repr(t.symbol)},
${t.decimals},
${black_repr(t.name.strip())},
)
% endfor
% endfor

@ -29,10 +29,9 @@ from trezorutils import ( # noqa: F401
)
from typing import TYPE_CHECKING
# Will get replaced by "True" / "False" in the build process
# Will get replaced by the actual model in the build process
# However, needs to stay as an exported symbol for the unit tests
MODEL_IS_T2B1: bool = INTERNAL_MODEL == "T2B1"
MODEL_IS_T3T1: bool = INTERNAL_MODEL == "T3T1"
TREZOR_MODEL: str = INTERNAL_MODEL
DISABLE_ANIMATION = 0

@ -1,6 +1,6 @@
from common import * # isort:skip
if not (utils.MODEL_IS_T2B1 or utils.MODEL_IS_T3T1):
if not (utils.TREZOR_MODEL in ("T2B1", "T3T1")):
from trezor.crypto import bip39
from trezor.enums import AmountUnit, OutputScriptType
from trezor.enums.RequestType import TXFINISHED, TXINPUT, TXMETA, TXOUTPUT
@ -405,5 +405,5 @@ class TestSignTxDecred(unittest.TestCase):
if __name__ == "__main__":
if not (utils.MODEL_IS_T2B1 or utils.MODEL_IS_T3T1):
if not (utils.TREZOR_MODEL in ("T2B1", "T3T1")):
unittest.main()

@ -22,7 +22,7 @@ class TestCoins(unittest.TestCase):
("ZEC", "Zcash", 7352),
("TAZ", "Zcash Testnet", 7461),
]
if not (utils.MODEL_IS_T2B1 or utils.MODEL_IS_T3T1):
if not (utils.TREZOR_MODEL in ("T2B1", "T3T1")):
ref.extend(
[
("NMC", "Namecoin", 52),

Loading…
Cancel
Save