Browse Source

tool addr2pubhash: check input, rejecting non-PKH addresses

The MMGen Project 3 years ago
parent
commit
4e3b11a3
2 changed files with 5 additions and 1 deletions
  1. 1 0
      mmgen/addr.py
  2. 4 1
      mmgen/tool/coin.py

+ 1 - 0
mmgen/addr.py

@@ -43,6 +43,7 @@ class MMGenAddrType(str,Hilite,InitErrors,MMGenObject):
 	extra_attrs = ImmutableAttr(tuple,set_none_ok=True)
 	desc        = ImmutableAttr(str)
 
+	pkh_fmts = ('p2pkh','bech32','ethereum')
 	mmtypes = {
 		'L': ati('legacy',    'std', False,'p2pkh',   'p2pkh',   'wif', (), 'Legacy uncompressed address'),
 		'C': ati('compressed','std', True, 'p2pkh',   'p2pkh',   'wif', (), 'Compressed P2PKH address'),

+ 4 - 1
mmgen/tool/coin.py

@@ -160,9 +160,12 @@ class tool_cmd(tool_cmd_base):
 
 	def addr2pubhash(self,addr:'sstr'):
 		"convert coin address to public key hash"
+		from ..opts import opt
 		ap = self.proto.parse_addr(addr)
 		assert ap, f'coin address {addr!r} could not be parsed'
-		assert ap.fmt != 'p2sh', f'p2sh addresses cannot be converted to pubhash'
+		if ap.fmt not in MMGenAddrType.pkh_fmts:
+			from ..util import die
+			die(2,f'{ap.fmt} addresses cannot be converted to pubhash')
 		return ap.bytes.hex()
 
 	def addr2scriptpubkey(self,addr:'sstr'):