proto.parse_addr() -> proto.decode_addr()

This commit is contained in:
The MMGen Project 2022-09-26 14:56:18 +00:00
commit 01e2830296
Signed by: mmgen
GPG key ID: 3F8B1861E32B7DA2
8 changed files with 16 additions and 16 deletions

View file

@ -144,7 +144,7 @@ class CoinAddr(str,Hilite,InitErrors,MMGenObject):
try:
assert addr.isascii() and addr.isalnum(), 'not an ASCII alphanumeric string'
me = str.__new__(cls,addr)
ap = proto.parse_addr(addr)
ap = proto.decode_addr(addr)
assert ap, f'coin address {addr!r} could not be parsed'
me.addr_fmt = ap.fmt
me.hex = ap.bytes.hex()

View file

@ -22,7 +22,7 @@ from ....util import msg,dmsg,make_chksum_6,die
def addr2scriptPubKey(proto,addr):
def decode_addr(proto,addr):
ap = proto.parse_addr(addr)
ap = proto.decode_addr(addr)
assert ap, f'coin address {addr!r} could not be parsed'
return ap.bytes.hex()

View file

@ -229,7 +229,7 @@ class coin_msg:
'sig': sig,
}
if self.msg_cls.include_pubhash:
data.update({ 'pubhash': self.proto.parse_addr(e.addr_p2pkh or e.addr).bytes.hex() })
data.update({ 'pubhash': self.proto.decode_addr(e.addr_p2pkh or e.addr).bytes.hex() })
if e.addr_p2pkh:
data.update({'addr_p2pkh': e.addr_p2pkh})

View file

@ -12,7 +12,7 @@
Bitcoin protocol
"""
from ..protocol import CoinProtocol,parsed_wif,parsed_addr,_finfo,_nw
from ..protocol import CoinProtocol,parsed_wif,decoded_addr,_finfo,_nw
from .common import *
class mainnet(CoinProtocol.Secp256k1): # chainparams.cpp
@ -83,7 +83,7 @@ class mainnet(CoinProtocol.Secp256k1): # chainparams.cpp
pubkey_type = pubkey_type,
compressed = compressed )
def parse_addr(self,addr):
def decode_addr(self,addr):
if 'B' in self.mmtypes and addr[:len(self.bech32_hrp)] == self.bech32_hrp:
import mmgen.contrib.bech32 as bech32
@ -94,9 +94,9 @@ class mainnet(CoinProtocol.Secp256k1): # chainparams.cpp
msg(f'{ret[0]}: Invalid witness version number')
return False
return parsed_addr( bytes(ret[1]), 'bech32' ) if ret[1] else False
return decoded_addr( bytes(ret[1]), 'bech32' ) if ret[1] else False
return self.parse_addr_bytes(b58chk_decode(addr))
return self.decode_addr_bytes(b58chk_decode(addr))
def pubhash2addr(self,pubhash,p2sh):
assert len(pubhash) == 20, f'{len(pubhash)}: invalid length for pubkey hash'

View file

@ -13,7 +13,7 @@ Ethereum protocol
"""
from ..globalvars import g
from ..protocol import CoinProtocol,_nw,parsed_addr
from ..protocol import CoinProtocol,_nw,decoded_addr
from ..util import is_hex_str_lc,Msg
class mainnet(CoinProtocol.DummyWIF,CoinProtocol.Secp256k1):
@ -53,9 +53,9 @@ class mainnet(CoinProtocol.DummyWIF,CoinProtocol.Secp256k1):
def dcoin(self):
return self.tokensym or self.coin
def parse_addr(self,addr):
def decode_addr(self,addr):
if is_hex_str_lc(addr) and len(addr) == self.addr_len * 2:
return parsed_addr( bytes.fromhex(addr), 'ethereum' )
return decoded_addr( bytes.fromhex(addr), 'ethereum' )
if g.debug:
Msg(f'Invalid address: {addr}')
return False

View file

@ -40,7 +40,7 @@ class mainnet(CoinProtocol.DummyWIF,CoinProtocol.Base):
self.privkey_len,
'big' )[::-1]
def parse_addr(self,addr):
def decode_addr(self,addr):
from ..baseconv import baseconv
@ -57,7 +57,7 @@ class mainnet(CoinProtocol.DummyWIF,CoinProtocol.Base):
assert ret[-4:] == chk, f'{ret[-4:].hex()}: incorrect checksum. Correct value: {chk.hex()}'
return self.parse_addr_bytes(ret)
return self.decode_addr_bytes(ret)
def pubhash2addr(self,*args,**kwargs):
raise NotImplementedError('Monero addresses do not support pubhash2addr()')

View file

@ -26,7 +26,7 @@ from .devtools import *
from .globalvars import g
parsed_wif = namedtuple('parsed_wif',['sec','pubkey_type','compressed'])
parsed_addr = namedtuple('parsed_addr',['bytes','fmt'])
decoded_addr = namedtuple('decoded_addr',['bytes','fmt'])
_finfo = namedtuple('fork_info',['height','hash','name','replayable'])
_nw = namedtuple('coin_networks',['mainnet','testnet','regtest'])
@ -140,13 +140,13 @@ class CoinProtocol(MMGenObject):
def get_addr_len(self,addr_fmt):
return self.addr_len
def parse_addr_bytes(self,addr_bytes):
def decode_addr_bytes(self,addr_bytes):
for ver_hex,addr_fmt in self.addr_ver_bytes.items():
ver_bytes = bytes.fromhex(ver_hex)
vlen = len(ver_bytes)
if addr_bytes[:vlen] == ver_bytes:
if len(addr_bytes[vlen:]) == self.get_addr_len(addr_fmt):
return parsed_addr( addr_bytes[vlen:], addr_fmt )
return decoded_addr( addr_bytes[vlen:], addr_fmt )
return False

View file

@ -171,7 +171,7 @@ class tool_cmd(tool_cmd_base):
def addr2pubhash(self,addr:'sstr'):
"convert coin address to public key hash"
ap = self.proto.parse_addr(addr)
ap = self.proto.decode_addr(addr)
assert ap, f'coin address {addr!r} could not be parsed'
if ap.fmt not in MMGenAddrType.pkh_fmts:
from ..util import die