diff --git a/src/apps/ethereum/layout.py b/src/apps/ethereum/layout.py index ce78827a32..0ee47763e4 100644 --- a/src/apps/ethereum/layout.py +++ b/src/apps/ethereum/layout.py @@ -60,7 +60,7 @@ def format_ethereum_amount(value: int, token, chain_id: int, tx_type=None): suffix = token[2] decimals = token[3] else: - suffix = networks.suffix_by_chain_id(chain_id, tx_type) + suffix = networks.shortcut_by_chain_id(chain_id, tx_type) decimals = 18 if value <= 1e9: diff --git a/src/apps/ethereum/networks.py b/src/apps/ethereum/networks.py index 9f8a603b4d..a106cfb3fa 100644 --- a/src/apps/ethereum/networks.py +++ b/src/apps/ethereum/networks.py @@ -1,19 +1,148 @@ -suffixes = { - 1: 'ETH', # Ethereum Mainnet - 2: 'EXP', # Expanse - 3: 'tETH', # Ethereum Testnet: Ropsten - 4: 'tETH', # Ethereum Testnet: Rinkeby - 8: 'UBQ', # UBIQ - 30: 'RSK', # Rootstock Mainnet - 31: 'tRSK', # Rootstock Testnet - 42: 'tETH', # Ethereum Testnet: Kovan - 61: 'ETC', # Ethereum Classic Mainnet - 62: 'tETC', # Ethereum Classic Testnet -} +class NetworkInfo: + + def __init__( + self, + chain_id: int, + slip44: int, + shortcut: str, + name: str, + rskip60: bool + ): + self.chain_id = chain_id + self.slip44 = slip44 + self.shortcut = shortcut + self.name = name + self.rskip60 = rskip60 -def suffix_by_chain_id(chain_id, tx_type=None): +# the following list is generated using tools/codegen/gen_eth_networks.py +# do not edit manually! +NETWORKS = [ + NetworkInfo( + chain_id=1, + slip44=60, + shortcut='ETH', + name='Ethereum', + rskip60=False, + ), + NetworkInfo( + chain_id=2, + slip44=40, + shortcut='EXP', + name='Expanse', + rskip60=False, + ), + NetworkInfo( + chain_id=3, + slip44=1, + shortcut='tETH', + name='Ethereum Testnet Ropsten', + rskip60=False, + ), + NetworkInfo( + chain_id=4, + slip44=1, + shortcut='tETH', + name='Ethereum Testnet Rinkeby', + rskip60=False, + ), + NetworkInfo( + chain_id=8, + slip44=108, + shortcut='UBQ', + name='UBIQ', + rskip60=False, + ), + NetworkInfo( + chain_id=20, + slip44=2018, + shortcut='EOSC', + name='EOS Classic', + rskip60=False, + ), + NetworkInfo( + chain_id=28, + slip44=1128, + shortcut='ETSC', + name='Ethereum Social', + rskip60=False, + ), + NetworkInfo( + chain_id=30, + slip44=137, + shortcut='RSK', + name='RSK', + rskip60=True, + ), + NetworkInfo( + chain_id=31, + slip44=1, + shortcut='tRSK', + name='RSK Testnet', + rskip60=True, + ), + NetworkInfo( + chain_id=42, + slip44=1, + shortcut='tETH', + name='Ethereum Testnet Kovan', + rskip60=False, + ), + NetworkInfo( + chain_id=61, + slip44=61, + shortcut='ETC', + name='Ethereum Classic', + rskip60=False, + ), + NetworkInfo( + chain_id=62, + slip44=1, + shortcut='tETC', + name='Ethereum Classic Testnet', + rskip60=False, + ), + NetworkInfo( + chain_id=64, + slip44=163, + shortcut='ELLA', + name='Ellaism', + rskip60=False, + ), + NetworkInfo( + chain_id=820, + slip44=820, + shortcut='CLO', + name='Callisto', + rskip60=False, + ), + NetworkInfo( + chain_id=1987, + slip44=1987, + shortcut='EGEM', + name='EtherGem', + rskip60=False, + ), +] + + +def shortcut_by_chain_id(chain_id, tx_type=None): if tx_type in [1, 6] and chain_id in [1, 3]: return 'WAN' else: - return suffixes.get(chain_id, 'UNKN') + n = by_chain_id(chain_id) + return n.shortcut if n is not None else 'UNKN' + + +def by_chain_id(chain_id): + for n in NETWORKS: + if n.chain_id == chain_id: + return n + return None + + +def by_slip44(slip44): + for n in NETWORKS: + if n.slip44 == slip44: + return n + return None diff --git a/tools/codegen/gen_eth_networks.py b/tools/codegen/gen_eth_networks.py new file mode 100755 index 0000000000..a9d57d9d01 --- /dev/null +++ b/tools/codegen/gen_eth_networks.py @@ -0,0 +1,14 @@ +#!/usr/bin/env python3 +import json + +j = json.load(open('../../vendor/trezor-common/defs/ethereum/networks.json', 'r')) + +print('NETWORKS = [') + +for n in j: + print(' NetworkInfo(') + for f in ['chain_id', 'slip44', 'shortcut', 'name', 'rskip60']: + print(' %s=%s,' % (f, repr(n[f]))) + print(' ),') + +print(']') diff --git a/vendor/trezor-common b/vendor/trezor-common index babc60a48e..57a31feb2e 160000 --- a/vendor/trezor-common +++ b/vendor/trezor-common @@ -1 +1 @@ -Subproject commit babc60a48ec95df8de0ddd11b9d7e24b0e7e1d46 +Subproject commit 57a31feb2e48ac5057761fd07e5c7b280b66b5c6