-
Notifications
You must be signed in to change notification settings - Fork 642
Open
Description
This code: aa206fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d619000000000087
should decode to:
OP_HASH256 OP_PUSHBYTES_32 6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000 OP_EQUAL
but it's decoded by python-bitcoinlib
(python-bitcoinlib==0.12.2
) to:
OP_HASH256 6fe28c0ab6f1b372c1a6a246ae63f74f931e8365e15a089c68d6190000000000 OP_EQUAL
Workaround:
if op in OPCODE_NAMES:
# Standard opcode (e.g., OP_HASH256, OP_EQUAL)
decoded.append(OPCODE_NAMES[op])
elif 0x01 <= op <= 0x4b:
# Data push (OP_PUSHBYTES_1 to OP_PUSHBYTES_75)
length = op
if i + length > len(script_bytes):
return f"Error decoding script '{hex_script}': Incomplete data push"
data = script_bytes[i:i + length]
decoded.append(f"OP_PUSHBYTES_{length} {data.hex()}")
i += length
elif op == 0x4c: # OP_PUSHDATA1
if i + 1 > len(script_bytes):
return f"Error decoding script '{hex_script}': Incomplete OP_PUSHDATA1"
length = script_bytes[i]
i += 1
if i + length > len(script_bytes):
return f"Error decoding script '{hex_script}': Incomplete OP_PUSHDATA1 data"
data = script_bytes[i:i + length]
decoded.append(f"OP_PUSHDATA1 {data.hex()}")
i += length
elif op == 0x4d: # OP_PUSHDATA2
if i + 2 > len(script_bytes):
return f"Error decoding script '{hex_script}': Incomplete OP_PUSHDATA2"
length = int.from_bytes(script_bytes[i:i + 2], "little")
i += 2
if i + length > len(script_bytes):
return f"Error decoding script '{hex_script}': Incomplete OP_PUSHDATA2 data"
data = script_bytes[i:i + length]
decoded.append(f"OP_PUSHDATA2 {data.hex()}")
i += length
elif op == 0x4e: # OP_PUSHDATA4
if i + 4 > len(script_bytes):
return f"Error decoding script '{hex_script}': Incomplete OP_PUSHDATA4"
length = int.from_bytes(script_bytes[i:i + 4], "little")
i += 4
if i + length > len(script_bytes):
return f"Error decoding script '{hex_script}': Incomplete OP_PUSHDATA4 data"
data = script_bytes[i:i + length]
decoded.append(f"OP_PUSHDATA4 {data.hex()}")
i += length
else:
decoded.append(f"UNKNOWN_OP({op})")
Metadata
Metadata
Assignees
Labels
No labels