diff --git a/lib/coins.py b/lib/coins.py index c473696..8e0ad0a 100644 --- a/lib/coins.py +++ b/lib/coins.py @@ -53,7 +53,6 @@ class Coin(object): address = cls.P2PKH_hash168_from_hash160, script_hash = cls.P2SH_hash168_from_hash160, pubkey = cls.P2PKH_hash168_from_pubkey, - unknown = lambda x : None, ) @classmethod diff --git a/lib/script.py b/lib/script.py index 7037f80..503d38b 100644 --- a/lib/script.py +++ b/lib/script.py @@ -142,8 +142,7 @@ class ScriptPubKey(object): TO_P2SH_OPS = [OpCodes.OP_HASH160, -1, OpCodes.OP_EQUAL] TO_PUBKEY_OPS = [-1, OpCodes.OP_CHECKSIG] - PayToHandlers = namedtuple('PayToHandlers', - 'address script_hash pubkey unknown') + PayToHandlers = namedtuple('PayToHandlers', 'address script_hash pubkey') @classmethod def pay_to(cls, script, handlers): @@ -154,9 +153,12 @@ class ScriptPubKey(object): handlers.address(hash160) handlers.script_hash(hash160) handlers.pubkey(pubkey) - handlers.unknown(None) + or None is returned if the script is invalid or unregonised. ''' - ops, datas = Script.get_ops(script) + try: + ops, datas = Script.get_ops(script) + except ScriptError: + return None if Script.match_ops(ops, cls.TO_ADDRESS_OPS): return handlers.address(datas[2]) @@ -164,7 +166,8 @@ class ScriptPubKey(object): return handlers.script_hash(datas[1]) if Script.match_ops(ops, cls.TO_PUBKEY_OPS): return handlers.pubkey(datas[0]) - return handlers.unknown(None) + + return None @classmethod def P2SH_script(cls, hash160):