sub-level mods: use match statement where practicable (4 files)
This commit is contained in:
parent
4540ccb40a
commit
c894598551
4 changed files with 35 additions and 31 deletions
|
|
@ -128,10 +128,11 @@ def get_bip_by_addr_type(addr_type):
|
|||
44)
|
||||
|
||||
def check_privkey(key_int):
|
||||
if key_int == 0:
|
||||
raise ValueError('private key is zero!')
|
||||
elif key_int >= secp256k1_order:
|
||||
raise ValueError(f'{key_int:x}: private key >= group order!')
|
||||
match key_int:
|
||||
case 0:
|
||||
raise ValueError('private key is zero!')
|
||||
case n if n >= secp256k1_order:
|
||||
raise ValueError(f'{n:x}: private key >= group order!')
|
||||
|
||||
class BipHDConfig(Lockable):
|
||||
|
||||
|
|
|
|||
|
|
@ -48,13 +48,14 @@ def parse_data():
|
|||
key = line[1:-1]
|
||||
continue
|
||||
p = parse_line(line)
|
||||
if key in out:
|
||||
out[key][p[1]] = p
|
||||
elif key == 'defaults':
|
||||
out['defaults'] = p
|
||||
defaults = p
|
||||
else:
|
||||
out[key] = {p[1]: p}
|
||||
match key:
|
||||
case k if k in out:
|
||||
out[key][p[1]] = p
|
||||
case 'defaults':
|
||||
out['defaults'] = p
|
||||
defaults = p
|
||||
case _:
|
||||
out[key] = {p[1]: p}
|
||||
|
||||
return out
|
||||
|
||||
|
|
|
|||
|
|
@ -165,14 +165,15 @@ class tool_cmd(tool_cmd_base):
|
|||
def pubhash2addr(self, pubhashhex: 'sstr'):
|
||||
"convert public key hash to address"
|
||||
pubhash = bytes.fromhex(pubhashhex)
|
||||
if self.mmtype.name == 'segwit':
|
||||
return self.proto.pubhash2segwitaddr(pubhash)
|
||||
elif self.mmtype.name == 'bech32':
|
||||
return self.proto.pubhash2bech32addr(pubhash)
|
||||
elif self.mmtype.name == 'bech32x':
|
||||
return self.proto.encode_addr_bech32x(pubhash)
|
||||
else:
|
||||
return self.proto.pubhash2addr(pubhash, self.mmtype.addr_fmt)
|
||||
match self.mmtype.name:
|
||||
case 'segwit':
|
||||
return self.proto.pubhash2segwitaddr(pubhash)
|
||||
case 'bech32':
|
||||
return self.proto.pubhash2bech32addr(pubhash)
|
||||
case 'bech32x':
|
||||
return self.proto.encode_addr_bech32x(pubhash)
|
||||
case _:
|
||||
return self.proto.pubhash2addr(pubhash, self.mmtype.addr_fmt)
|
||||
|
||||
def addr2pubhash(self, addr: 'sstr'):
|
||||
"convert coin address to public key hash"
|
||||
|
|
|
|||
|
|
@ -39,18 +39,19 @@ def _get_cls_info(clsname, modname, kwargs):
|
|||
raise ValueError(
|
||||
f"{clsname} must be instantiated with 'proto', 'data' or 'filename' keyword")
|
||||
|
||||
if clsname == 'Completed':
|
||||
from ..util import get_extension, die
|
||||
from .completed import Completed
|
||||
ext = get_extension(kwargs['filename'])
|
||||
cls = Completed.ext_to_cls(ext, proto)
|
||||
if not cls:
|
||||
die(1, f'{ext!r}: unrecognized file extension for CompletedTX')
|
||||
clsname = cls.__name__
|
||||
modname = cls.__module__.rsplit('.', maxsplit=1)[-1]
|
||||
elif clsname == 'New' and kwargs['target'] == 'swaptx':
|
||||
clsname = 'NewSwap'
|
||||
modname = 'new_swap'
|
||||
match clsname:
|
||||
case 'Completed':
|
||||
from ..util import get_extension, die
|
||||
from .completed import Completed
|
||||
ext = get_extension(kwargs['filename'])
|
||||
cls = Completed.ext_to_cls(ext, proto)
|
||||
if not cls:
|
||||
die(1, f'{ext!r}: unrecognized file extension for CompletedTX')
|
||||
clsname = cls.__name__
|
||||
modname = cls.__module__.rsplit('.', maxsplit=1)[-1]
|
||||
case 'New' if kwargs['target'] == 'swaptx':
|
||||
clsname = 'NewSwap'
|
||||
modname = 'new_swap'
|
||||
|
||||
kwargs['proto'] = proto
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue