eth.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #!/usr/bin/env python3
  2. #
  3. # mmgen = Multi-Mode GENerator, a command-line cryptocurrency wallet
  4. # Copyright (C)2013-2022 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
  9. # https://gitlab.com/mmgen/mmgen
  10. """
  11. Ethereum protocol
  12. """
  13. from ..globalvars import g
  14. from ..protocol import CoinProtocol,_nw,parsed_addr
  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. base_coin = 'ETH'
  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 = ('key','addr','rpc_init','tx')
  30. base_proto = 'Ethereum'
  31. avg_bdi = 15
  32. ignore_daemon_version = False
  33. chain_ids = {
  34. 1: 'ethereum', # ethereum mainnet
  35. 2: 'morden', # morden testnet (deprecated)
  36. 3: 'ropsten', # ropsten testnet
  37. 4: 'rinkeby', # rinkeby testnet
  38. 5: 'goerli', # goerli testnet
  39. 42: 'kovan', # kovan testnet
  40. 61: 'classic', # ethereum classic mainnet
  41. 62: 'morden', # ethereum classic testnet
  42. 17: 'developmentchain', # parity dev chain
  43. 1337: 'developmentchain', # geth dev chain
  44. }
  45. @property
  46. def dcoin(self):
  47. return self.tokensym or self.coin
  48. def parse_addr(self,addr):
  49. if is_hex_str_lc(addr) and len(addr) == self.addr_len * 2:
  50. return parsed_addr( bytes.fromhex(addr), 'ethereum' )
  51. if g.debug:
  52. Msg(f'Invalid address: {addr}')
  53. return False
  54. def checksummed_addr(self,addr):
  55. h = self.keccak_256(addr.encode()).digest().hex()
  56. return ''.join(addr[i].upper() if int(h[i],16) > 7 else addr[i] for i in range(len(addr)))
  57. def pubhash2addr(self,pubhash,p2sh):
  58. assert len(pubhash) == 20, f'{len(pubhash)}: invalid length for {self.name} pubkey hash'
  59. assert not p2sh, f'{self.name} protocol has no P2SH address format'
  60. return pubhash.hex()
  61. class testnet(mainnet):
  62. chain_names = ['kovan','goerli','rinkeby']
  63. class regtest(testnet):
  64. chain_names = ['developmentchain']