tool addr2pubhash: check input, rejecting non-PKH addresses
This commit is contained in:
parent
17539c0de1
commit
4e3b11a313
2 changed files with 5 additions and 1 deletions
|
|
@ -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'),
|
||||
|
|
|
|||
|
|
@ -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'):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue