Browse Source

CoinProtocol.Ethereum: generate checksummed addresses

The MMGen Project 3 years ago
parent
commit
229107a8a9
2 changed files with 8 additions and 2 deletions
  1. 6 0
      mmgen/protocol.py
  2. 2 2
      test/test_py_d/ts_ethdev.py

+ 6 - 0
mmgen/protocol.py

@@ -422,6 +422,12 @@ class CoinProtocol(MMGenObject):
 				Msg(f'Invalid address: {addr}')
 				Msg(f'Invalid address: {addr}')
 			return False
 			return False
 
 
+		@classmethod
+		def checksummed_addr(cls,addr):
+			from .keccak import keccak_256
+			h = keccak_256(addr.encode()).digest().hex()
+			return ''.join(addr[i].upper() if int(h[i],16) > 7 else addr[i] for i in range(len(addr)))
+
 		def pubhash2addr(self,pubkey_hash,p2sh):
 		def pubhash2addr(self,pubkey_hash,p2sh):
 			assert len(pubkey_hash) == 40, f'{len(pubkey_hash)}: invalid length for {self.name} pubkey hash'
 			assert len(pubkey_hash) == 40, f'{len(pubkey_hash)}: invalid length for {self.name} pubkey hash'
 			assert not p2sh, f'{self.name} protocol has no P2SH address format'
 			assert not p2sh, f'{self.name} protocol has no P2SH address format'

+ 2 - 2
test/test_py_d/ts_ethdev.py

@@ -29,6 +29,7 @@ from mmgen.opts import opt
 from mmgen.util import die
 from mmgen.util import die
 from mmgen.exception import *
 from mmgen.exception import *
 from mmgen.obj import ETHAmt
 from mmgen.obj import ETHAmt
+from mmgen.protocol import CoinProtocol
 from ..include.common import *
 from ..include.common import *
 from .common import *
 from .common import *
 
 
@@ -37,7 +38,6 @@ dfl_sid = '98831F3A'
 
 
 # The OpenEthereum dev address with lots of coins.  Create with "ethkey -b info ''":
 # The OpenEthereum dev address with lots of coins.  Create with "ethkey -b info ''":
 dfl_devaddr = '00a329c0648769a73afac7f9381e08fb43dbea72'
 dfl_devaddr = '00a329c0648769a73afac7f9381e08fb43dbea72'
-dfl_addr_chk = '00a329c0648769A73afAc7F9381E08FB43dBEA72'
 dfl_devkey = '4d5db4107d237df6a3d58ee5f70ae63d73d7658d4026f2eefd2f204c81682cb7'
 dfl_devkey = '4d5db4107d237df6a3d58ee5f70ae63d73d7658d4026f2eefd2f204c81682cb7'
 burn_addr = 'deadbeef'*5
 burn_addr = 'deadbeef'*5
 amt1 = '999999.12345689012345678'
 amt1 = '999999.12345689012345678'
@@ -684,7 +684,7 @@ class TestSuiteEthdev(TestSuiteBase,TestSuiteShared):
 			'scripts/create-token.py',
 			'scripts/create-token.py',
 			'--coin=' + self.proto.coin,
 			'--coin=' + self.proto.coin,
 			'--outdir=' + odir
 			'--outdir=' + odir
-		] + cmd_args + [dfl_addr_chk]
+		] + cmd_args + [CoinProtocol.Ethereum.checksummed_addr(dfl_devaddr)]
 		imsg("Executing: {}".format(' '.join(cmd)))
 		imsg("Executing: {}".format(' '.join(cmd)))
 		cp = run(cmd,stdout=DEVNULL,stderr=PIPE)
 		cp = run(cmd,stdout=DEVNULL,stderr=PIPE)
 		if cp.returncode != 0:
 		if cp.returncode != 0: