params.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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,decoded_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. 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 = ('key','addr','rpc_init','tx')
  29. base_proto = 'Ethereum'
  30. base_proto_coin = 'ETH'
  31. base_coin = 'ETH'
  32. avg_bdi = 15
  33. ignore_daemon_version = False
  34. chain_ids = {
  35. 1: 'ethereum', # ethereum mainnet
  36. 2: 'morden', # morden testnet (deprecated)
  37. 3: 'ropsten', # ropsten testnet
  38. 4: 'rinkeby', # rinkeby testnet
  39. 5: 'goerli', # goerli testnet
  40. 42: 'kovan', # kovan testnet
  41. 61: 'classic', # ethereum classic mainnet
  42. 62: 'morden', # ethereum classic testnet
  43. 17: 'developmentchain', # parity dev chain
  44. 1337: 'developmentchain', # geth dev chain
  45. }
  46. @property
  47. def dcoin(self):
  48. return self.tokensym or self.coin
  49. def decode_addr(self,addr):
  50. if is_hex_str_lc(addr) and len(addr) == self.addr_len * 2:
  51. return decoded_addr( bytes.fromhex(addr), None, 'ethereum' )
  52. if g.debug:
  53. Msg(f'Invalid address: {addr}')
  54. return False
  55. def checksummed_addr(self,addr):
  56. h = self.keccak_256(addr.encode()).digest().hex()
  57. return ''.join(addr[i].upper() if int(h[i],16) > 7 else addr[i] for i in range(len(addr)))
  58. def pubhash2addr(self,pubhash,p2sh):
  59. assert len(pubhash) == 20, f'{len(pubhash)}: invalid length for {self.name} pubkey hash'
  60. assert not p2sh, f'{self.name} protocol has no P2SH address format'
  61. return pubhash.hex()
  62. class testnet(mainnet):
  63. chain_names = ['kovan','goerli','rinkeby']
  64. class regtest(testnet):
  65. chain_names = ['developmentchain']