From 229107a8a9053ded606bad42d942a59781a76da9 Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Sun, 26 Sep 2021 21:16:21 +0000 Subject: [PATCH] CoinProtocol.Ethereum: generate checksummed addresses --- mmgen/protocol.py | 6 ++++++ test/test_py_d/ts_ethdev.py | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/mmgen/protocol.py b/mmgen/protocol.py index 9e294d08..57c68214 100755 --- a/mmgen/protocol.py +++ b/mmgen/protocol.py @@ -422,6 +422,12 @@ class CoinProtocol(MMGenObject): Msg(f'Invalid address: {addr}') 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): 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' diff --git a/test/test_py_d/ts_ethdev.py b/test/test_py_d/ts_ethdev.py index 2a444956..3cea6f7c 100755 --- a/test/test_py_d/ts_ethdev.py +++ b/test/test_py_d/ts_ethdev.py @@ -29,6 +29,7 @@ from mmgen.opts import opt from mmgen.util import die from mmgen.exception import * from mmgen.obj import ETHAmt +from mmgen.protocol import CoinProtocol from ..include.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 ''": dfl_devaddr = '00a329c0648769a73afac7f9381e08fb43dbea72' -dfl_addr_chk = '00a329c0648769A73afAc7F9381E08FB43dBEA72' dfl_devkey = '4d5db4107d237df6a3d58ee5f70ae63d73d7658d4026f2eefd2f204c81682cb7' burn_addr = 'deadbeef'*5 amt1 = '999999.12345689012345678' @@ -684,7 +684,7 @@ class TestSuiteEthdev(TestSuiteBase,TestSuiteShared): 'scripts/create-token.py', '--coin=' + self.proto.coin, '--outdir=' + odir - ] + cmd_args + [dfl_addr_chk] + ] + cmd_args + [CoinProtocol.Ethereum.checksummed_addr(dfl_devaddr)] imsg("Executing: {}".format(' '.join(cmd))) cp = run(cmd,stdout=DEVNULL,stderr=PIPE) if cp.returncode != 0: