params.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, a command-line cryptocurrency wallet
  4. # Copyright (C)2013-2024 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. dfl_mmtype = 'E'
  21. mod_clsname = 'Ethereum'
  22. pubkey_type = 'std' # required by DummyWIF
  23. coin_amt = 'ETHAmt'
  24. max_tx_fee = '0.005'
  25. chain_names = ['ethereum','foundation']
  26. sign_mode = 'standalone'
  27. caps = ('token',)
  28. mmcaps = ('rpc', 'rpc_init', 'tw', 'msg')
  29. base_proto = 'Ethereum'
  30. base_proto_coin = 'ETH'
  31. base_coin = 'ETH'
  32. avg_bdi = 15
  33. ignore_daemon_version = False
  34. decimal_prec = 36
  35. chain_ids = {
  36. 1: 'ethereum', # ethereum mainnet
  37. 2: 'morden', # morden testnet (deprecated)
  38. 3: 'ropsten', # ropsten testnet
  39. 4: 'rinkeby', # rinkeby testnet
  40. 5: 'goerli', # goerli testnet
  41. 42: 'kovan', # kovan testnet
  42. 61: 'classic', # ethereum classic mainnet
  43. 62: 'morden', # ethereum classic testnet
  44. 17: 'developmentchain', # parity dev chain
  45. 1337: 'developmentchain', # geth dev chain
  46. 711: 'ethereum', # geth mainnet (empty chain)
  47. }
  48. @property
  49. def dcoin(self):
  50. return self.tokensym or self.coin
  51. def decode_addr(self, addr):
  52. if is_hex_str_lc(addr) and len(addr) == self.addr_len * 2:
  53. return decoded_addr(bytes.fromhex(addr), None, 'p2pkh')
  54. if self.cfg.debug:
  55. Msg(f'Invalid address: {addr}')
  56. return False
  57. def checksummed_addr(self,addr):
  58. h = self.keccak_256(addr.encode()).digest().hex()
  59. return ''.join(addr[i].upper() if int(h[i],16) > 7 else addr[i] for i in range(len(addr)))
  60. def pubhash2addr(self, pubhash, addr_type):
  61. assert len(pubhash) == 20, f'{len(pubhash)}: invalid length for {self.name} pubkey hash'
  62. assert addr_type == 'p2pkh', (
  63. f'{addr_type}: bad addr type - {self.name} protocol supports P2PKH address format only')
  64. return CoinAddr(self, pubhash.hex())
  65. class testnet(mainnet):
  66. chain_names = ['kovan','goerli','rinkeby']
  67. class regtest(testnet):
  68. chain_names = ['developmentchain']