OP_RETURN recognize fix
OP_RETURN_NON_STANDARD type
This commit is contained in:
parent
c3639b7cd8
commit
f4e5ec138e
@ -75,7 +75,8 @@ SCRIPT_TYPES = {"P2PKH": 0,
|
|||||||
"MULTISIG": 4,
|
"MULTISIG": 4,
|
||||||
"P2WPKH": 5,
|
"P2WPKH": 5,
|
||||||
"P2WSH": 6,
|
"P2WSH": 6,
|
||||||
"NON_STANDART": 7
|
"NON_STANDARD": 7,
|
||||||
|
"NULL_DATA_NON_STANDARD": 8
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -59,9 +59,16 @@ def parse_script(script, segwit=True):
|
|||||||
return {"nType": 2, "type": "PUBKEY", "reqSigs": 1, "addressHash": hash160(script[1:-1])}
|
return {"nType": 2, "type": "PUBKEY", "reqSigs": 1, "addressHash": hash160(script[1:-1])}
|
||||||
if l == 35 and script[-1] == 172:
|
if l == 35 and script[-1] == 172:
|
||||||
return {"nType": 2, "type": "PUBKEY", "reqSigs": 1, "addressHash": hash160(script[1:-1])}
|
return {"nType": 2, "type": "PUBKEY", "reqSigs": 1, "addressHash": hash160(script[1:-1])}
|
||||||
if script[0] == 106 and l > 1 and l <= 82:
|
if script[0] == OPCODE["OP_RETURN"]:
|
||||||
if script[1] == l - 2:
|
if l == 1:
|
||||||
return {"nType": 3, "type": "NULL_DATA", "reqSigs": 0, "data": script[2:]}
|
return {"nType": 3, "type": "NULL_DATA", "reqSigs": 0, "data": b""}
|
||||||
|
elif script[1] < OPCODE["OP_PUSHDATA1"]:
|
||||||
|
if script[1] == l - 2:
|
||||||
|
return {"nType": 3, "type": "NULL_DATA", "reqSigs": 0, "data": script[2:]}
|
||||||
|
elif script[1] == OPCODE["OP_PUSHDATA1"]:
|
||||||
|
if script[2] == l - 3 and script[2] <= 80:
|
||||||
|
return {"nType": 3, "type": "NULL_DATA", "reqSigs": 0, "data": script[3:]}
|
||||||
|
return {"nType": 8, "type": "NULL_DATA_NON_STANDARD", "reqSigs": 0, "script": script}
|
||||||
if script[0] >= 81 and script[0] <= 96:
|
if script[0] >= 81 and script[0] <= 96:
|
||||||
if script[-1] == 174:
|
if script[-1] == 174:
|
||||||
if script[-2] >= 81 and script[-2] <= 96:
|
if script[-2] >= 81 and script[-2] <= 96:
|
||||||
|
|||||||
@ -26,3 +26,30 @@ class ScriptFunctionsTests(unittest.TestCase):
|
|||||||
"bc1qwqdg6squsna38e46795at95yu9atm8azzmyvckulcc7kytlcckxswvvzej")
|
"bc1qwqdg6squsna38e46795at95yu9atm8azzmyvckulcc7kytlcckxswvvzej")
|
||||||
|
|
||||||
|
|
||||||
|
def test_op_return_parse(self):
|
||||||
|
self.assertEqual(parse_script(OP_RETURN + b"\x00")["type"], "NULL_DATA")
|
||||||
|
self.assertEqual(parse_script(OP_RETURN + b"\x00")["data"], b"")
|
||||||
|
self.assertEqual(parse_script(OP_RETURN + b"\x2012345678901234567890123456789012")["type"], "NULL_DATA")
|
||||||
|
self.assertEqual(parse_script(OP_RETURN + b"\x2012345678901234567890123456789012")["data"],
|
||||||
|
b"12345678901234567890123456789012")
|
||||||
|
|
||||||
|
self.assertEqual(parse_script(OP_RETURN + b"\x201234567890123456789012345678901211")["type"],
|
||||||
|
"NULL_DATA_NON_STANDARD")
|
||||||
|
|
||||||
|
self.assertEqual(parse_script(OP_RETURN + OP_PUSHDATA1 + b"\x00")["type"], "NULL_DATA")
|
||||||
|
self.assertEqual(parse_script(OP_RETURN + OP_PUSHDATA1 + b"\x00")["data"], b"")
|
||||||
|
self.assertEqual(parse_script(OP_RETURN + OP_PUSHDATA1 + b"\x2012345678901234567890123456789012")["type"],
|
||||||
|
"NULL_DATA")
|
||||||
|
self.assertEqual(parse_script(OP_RETURN + OP_PUSHDATA1 + b"\x2012345678901234567890123456789012")["data"],
|
||||||
|
b"12345678901234567890123456789012")
|
||||||
|
|
||||||
|
self.assertEqual(parse_script(OP_RETURN + OP_PUSHDATA1 + b"\x201234567890123456789012345678901211")["type"],
|
||||||
|
"NULL_DATA_NON_STANDARD")
|
||||||
|
self.assertEqual(parse_script(OP_RETURN + OP_PUSHDATA1 + b"\x5012345678901234567890123456789012345678901234567890123456789012345678901234567890")["type"],
|
||||||
|
"NULL_DATA")
|
||||||
|
self.assertEqual(parse_script(OP_RETURN + OP_PUSHDATA1 + b"\x5012345678901234567890123456789012345678901234567890123456789012345678901234567890")["data"],
|
||||||
|
b"12345678901234567890123456789012345678901234567890123456789012345678901234567890")
|
||||||
|
|
||||||
|
self.assertEqual(parse_script(
|
||||||
|
OP_RETURN + OP_PUSHDATA1 + b"\x51123456789012345678901234567890123456789012345678901234567890123456789012345678901")["type"],
|
||||||
|
"NULL_DATA_NON_STANDARD")
|
||||||
|
|||||||
@ -84,7 +84,7 @@ class Transaction(dict):
|
|||||||
if self["data"] is None:
|
if self["data"] is None:
|
||||||
if s["nType"] == 3:
|
if s["nType"] == 3:
|
||||||
self["data"] = s["data"]
|
self["data"] = s["data"]
|
||||||
if s["nType"] not in (3, 4, 7):
|
if s["nType"] not in (3, 4, 7, 8):
|
||||||
self["vOut"][k]["addressHash"] = s["addressHash"]
|
self["vOut"][k]["addressHash"] = s["addressHash"]
|
||||||
self["vOut"][k]["reqSigs"] = s["reqSigs"]
|
self["vOut"][k]["reqSigs"] = s["reqSigs"]
|
||||||
|
|
||||||
@ -500,7 +500,7 @@ class Transaction(dict):
|
|||||||
if self["data"] is None:
|
if self["data"] is None:
|
||||||
if s["nType"] == 3:
|
if s["nType"] == 3:
|
||||||
self["data"] = s["data"]
|
self["data"] = s["data"]
|
||||||
if s["nType"] not in (3, 4, 7):
|
if s["nType"] not in (3, 4, 7, 8):
|
||||||
self["vOut"][k]["addressHash"] = s["addressHash"]
|
self["vOut"][k]["addressHash"] = s["addressHash"]
|
||||||
self["vOut"][k]["reqSigs"] = s["reqSigs"]
|
self["vOut"][k]["reqSigs"] = s["reqSigs"]
|
||||||
else:
|
else:
|
||||||
@ -508,7 +508,7 @@ class Transaction(dict):
|
|||||||
if self["data"] is None:
|
if self["data"] is None:
|
||||||
if s["nType"] == 3:
|
if s["nType"] == 3:
|
||||||
self["data"] = s["data"].hex()
|
self["data"] = s["data"].hex()
|
||||||
if s["nType"] not in (3, 4, 7):
|
if s["nType"] not in (3, 4, 7, 8):
|
||||||
self["vOut"][k]["addressHash"] = s["addressHash"].hex()
|
self["vOut"][k]["addressHash"] = s["addressHash"].hex()
|
||||||
self["vOut"][k]["reqSigs"] = s["reqSigs"]
|
self["vOut"][k]["reqSigs"] = s["reqSigs"]
|
||||||
self["vOut"][k]["scriptPubKeyOpcodes"] = decode_script(script_pub_key)
|
self["vOut"][k]["scriptPubKeyOpcodes"] = decode_script(script_pub_key)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user