minor changes; mmgen-tool: add 'redeem_script2addr' command
This commit is contained in:
parent
21125e389f
commit
4a73a0440b
4 changed files with 18 additions and 1 deletions
|
|
@ -678,7 +678,7 @@ class PrivKey(bytes,Hilite,InitErrors,MMGenObject):
|
|||
|
||||
try:
|
||||
assert s and type(compressed) == bool and pubkey_type,'Incorrect args for PrivKey()'
|
||||
assert len(s) == cls.width // 2,'Key length must be {}'.format(cls.width/2)
|
||||
assert len(s) == cls.width // 2,'Key length must be {}'.format(cls.width//2)
|
||||
if pubkey_type == 'password': # skip WIF creation and pre-processing for passwds
|
||||
me = bytes.__new__(cls,hexlify(s))
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -418,6 +418,13 @@ class MMGenToolCmdCoin(MMGenToolCmdBase):
|
|||
assert opt.type == 'segwit','This command is meaningful only for --type=segwit'
|
||||
return g.proto.pubhex2redeem_script(pubkeyhex)
|
||||
|
||||
def redeem_script2addr(self,redeem_scripthex:'sstr'): # new
|
||||
"convert a Segwit P2SH-P2WPKH redeem script to an address"
|
||||
assert opt.type == 'segwit','This command is meaningful only for --type=segwit'
|
||||
assert redeem_scripthex[:4] == '0014','{!r}: invalid redeem script'.format(redeem_scripthex)
|
||||
assert len(redeem_scripthex) == 44,'{} bytes: invalid redeem script length'.format(len(redeem_scripthex)//2)
|
||||
return self.pubhash2addr(self.hash160(redeem_scripthex).decode())
|
||||
|
||||
def pubhash2addr(self,pubhashhex:'sstr'):
|
||||
"convert public key hash to address"
|
||||
if opt.type == 'bech32':
|
||||
|
|
|
|||
|
|
@ -77,6 +77,9 @@ def pformat(d):
|
|||
def pmsg(*args):
|
||||
if not args: return
|
||||
msg(pformat(args if len(args) > 1 else args[0]))
|
||||
def Pmsg(*args):
|
||||
if not args: return
|
||||
Msg(pformat(args if len(args) > 1 else args[0]))
|
||||
def pdie(*args,exit_val=1):
|
||||
if not args: sys.exit(1)
|
||||
die(exit_val,(pformat(args if len(args) > 1 else args[0])))
|
||||
|
|
|
|||
|
|
@ -372,6 +372,13 @@ tests = {
|
|||
['--type=segwit'], 'opt.type="segwit"' ),
|
||||
],
|
||||
},
|
||||
'redeem_script2addr': {
|
||||
'btc_mainnet': [
|
||||
( ['0014d04134b9ddb7399907657514d846aa495b4e474c'],
|
||||
'3AhjTiWHhVJAi1s5CfKMcLzYps12x3gZhg',
|
||||
['--type=segwit'], 'opt.type="segwit"' ),
|
||||
],
|
||||
},
|
||||
'randpair': {
|
||||
'btc_mainnet': [ ( [], [is_wif,is_coin_addr], ['-r0'] ) ],
|
||||
'btc_testnet': [ ( [], [is_wif,is_coin_addr], ['-r0'] ) ],
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue