params.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #!/usr/bin/env python3
  2. #
  3. # MMGen Wallet, a terminal-based cryptocurrency wallet
  4. # Copyright (C)2013-2025 The MMGen Project <mmgen@tuta.io>
  5. # Licensed under the GNU General Public License, Version 3:
  6. # https://www.gnu.org/licenses
  7. # Public project repositories:
  8. # https://github.com/mmgen/mmgen-wallet
  9. # https://gitlab.com/mmgen/mmgen-wallet
  10. """
  11. proto.eth.params: Ethereum protocol
  12. """
  13. from ...protocol import CoinProtocol, _nw, decoded_addr
  14. from ...addr import CoinAddr
  15. from ...util import is_hex_str_lc, Msg
  16. class mainnet(CoinProtocol.DummyWIF, CoinProtocol.Secp256k1):
  17. network_names = _nw('mainnet', 'testnet', 'devnet')
  18. addr_len = 20
  19. mmtypes = ('E',)
  20. preferred_mmtypes = ('E',)
  21. dfl_mmtype = 'E'
  22. mod_clsname = 'Ethereum'
  23. pubkey_type = 'std' # required by DummyWIF
  24. coin_amt = 'ETHAmt'
  25. max_tx_fee = 0.005
  26. chain_names = ['ethereum', 'foundation']
  27. sign_mode = 'standalone'
  28. caps = ('token',)
  29. mmcaps = ('rpc', 'rpc_init', 'tw', 'msg')
  30. base_proto = 'Ethereum'
  31. base_proto_coin = 'ETH'
  32. base_coin = 'ETH'
  33. avg_bdi = 15
  34. decimal_prec = 36
  35. address_reuse_ok = True
  36. is_vm = True
  37. is_evm = True
  38. # https://www.chainid.dev
  39. chain_ids = {
  40. 1: 'ethereum', # ethereum mainnet
  41. 2: 'morden', # morden testnet (deprecated)
  42. 3: 'ropsten', # ropsten testnet
  43. 4: 'rinkeby', # rinkeby testnet
  44. 5: 'goerli', # goerli testnet
  45. 42: 'kovan', # kovan testnet
  46. 61: 'classic', # ethereum classic mainnet
  47. 62: 'morden', # ethereum classic testnet
  48. 17: 'developmentchain', # parity dev chain
  49. 1337: 'developmentchain', # geth dev chain
  50. 711: 'ethereum', # geth mainnet (empty chain)
  51. 17000: 'holesky', # proof-of-stake testnet
  52. }
  53. coin_cfg_opts = (
  54. 'daemon_id',
  55. 'ignore_daemon_version',
  56. 'rpc_host',
  57. 'rpc_port',
  58. 'max_tx_fee',
  59. )
  60. proto_cfg_opts = (
  61. 'chain_names',
  62. )
  63. @property
  64. def dcoin(self):
  65. return self.tokensym or self.coin
  66. def decode_addr(self, addr):
  67. if is_hex_str_lc(addr) and len(addr) == self.addr_len * 2:
  68. return decoded_addr(bytes.fromhex(addr), None, 'p2pkh')
  69. if self.cfg.debug:
  70. Msg(f'Invalid address: {addr}')
  71. return False
  72. def checksummed_addr(self, addr):
  73. h = self.keccak_256(addr.encode()).digest().hex()
  74. return ''.join(addr[i].upper() if int(h[i], 16) > 7 else addr[i] for i in range(len(addr)))
  75. def pubhash2addr(self, pubhash, addr_type):
  76. assert len(pubhash) == 20, f'{len(pubhash)}: invalid length for {self.name} pubkey hash'
  77. assert addr_type == 'p2pkh', (
  78. f'{addr_type}: bad addr type - {self.name} protocol supports P2PKH address format only')
  79. return CoinAddr(self, pubhash.hex())
  80. class testnet(mainnet):
  81. chain_names = ['kovan', 'goerli', 'rinkeby']
  82. class regtest(testnet):
  83. chain_names = ['developmentchain']