ledger.is_valid_address added

This commit is contained in:
Lex Berezhny 2019-03-20 01:36:30 -04:00
parent 9281bdb61b
commit ca4a07f766
3 changed files with 8 additions and 1 deletions

View file

@ -153,6 +153,11 @@ class BaseLedger(metaclass=LedgerRegistry):
def address_to_hash160(address): def address_to_hash160(address):
return Base58.decode(address)[1:21] return Base58.decode(address)[1:21]
@classmethod
def is_valid_address(cls, address):
decoded = Base58.decode(address)
return decoded[0] == cls.pubkey_address_prefix
@classmethod @classmethod
def public_key_to_address(cls, public_key): def public_key_to_address(cls, public_key):
return cls.hash160_to_address(hash160(public_key)) return cls.hash160_to_address(hash160(public_key))

View file

@ -64,7 +64,7 @@ def push_data(data):
else: else:
yield BCDataStream.uint8.pack(OP_PUSHDATA4) yield BCDataStream.uint8.pack(OP_PUSHDATA4)
yield BCDataStream.uint32.pack(size) yield BCDataStream.uint32.pack(size)
yield data yield bytes(data)
def read_data(token, stream): def read_data(token, stream):

View file

@ -61,6 +61,8 @@ class AsyncioTestCase(unittest.TestCase):
# Implementation inspired by discussion: # Implementation inspired by discussion:
# https://bugs.python.org/issue32972 # https://bugs.python.org/issue32972
maxDiff = None
async def asyncSetUp(self): # pylint: disable=C0103 async def asyncSetUp(self): # pylint: disable=C0103
pass pass