Rework assertion logic in coins.py
This commit is contained in:
parent
e9000f39db
commit
e2ef9dceaf
17
lib/coins.py
17
lib/coins.py
@ -89,8 +89,10 @@ class Coin(object):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def P2PKH_hash168_from_hash160(cls, hash160):
|
def P2PKH_hash168_from_hash160(cls, hash160):
|
||||||
assert len(hash160) == 20
|
'''Return a hash168 if hash160 is 160 bits otherwise None.'''
|
||||||
return bytes([cls.P2PKH_VERBYTE]) + hash160
|
if len(hash160) == 20:
|
||||||
|
return bytes([cls.P2PKH_VERBYTE]) + hash160
|
||||||
|
return None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def P2PKH_hash168_from_pubkey(cls, pubkey):
|
def P2PKH_hash168_from_pubkey(cls, pubkey):
|
||||||
@ -99,6 +101,7 @@ class Coin(object):
|
|||||||
@classmethod
|
@classmethod
|
||||||
def P2PKH_address_from_hash160(cls, hash160):
|
def P2PKH_address_from_hash160(cls, hash160):
|
||||||
'''Return a P2PKH address given a public key.'''
|
'''Return a P2PKH address given a public key.'''
|
||||||
|
assert len(hash160) == 20
|
||||||
return Base58.encode_check(cls.P2PKH_hash168_from_hash160(hash160))
|
return Base58.encode_check(cls.P2PKH_hash168_from_hash160(hash160))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -108,12 +111,15 @@ class Coin(object):
|
|||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def P2SH_hash168_from_hash160(cls, hash160):
|
def P2SH_hash168_from_hash160(cls, hash160):
|
||||||
assert len(hash160) == 20
|
'''Return a hash168 if hash160 is 160 bits otherwise None.'''
|
||||||
return bytes([cls.P2SH_VERBYTE]) + hash160
|
if len(hash160) == 20:
|
||||||
|
return bytes([cls.P2SH_VERBYTE]) + hash160
|
||||||
|
return None
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def P2SH_address_from_hash160(cls, hash160):
|
def P2SH_address_from_hash160(cls, hash160):
|
||||||
'''Return a coin address given a hash160.'''
|
'''Return a coin address given a hash160.'''
|
||||||
|
assert len(hash160) == 20
|
||||||
return Base58.encode_check(cls.P2SH_hash168_from_hash160(hash160))
|
return Base58.encode_check(cls.P2SH_hash168_from_hash160(hash160))
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ -126,8 +132,7 @@ class Coin(object):
|
|||||||
for, e.g., wallet recovery.
|
for, e.g., wallet recovery.
|
||||||
'''
|
'''
|
||||||
script = cls.pay_to_multisig_script(m, pubkeys)
|
script = cls.pay_to_multisig_script(m, pubkeys)
|
||||||
payload = bytes([cls.P2SH_VERBYTE]) + hash160(pubkey_bytes)
|
return cls.P2SH_address_from_hash160(hash160(script))
|
||||||
return Base58.encode_check(payload)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def pay_to_multisig_script(cls, m, pubkeys):
|
def pay_to_multisig_script(cls, m, pubkeys):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user