mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-23 16:08:17 +00:00
insight api: use hex code
The insight api transaction parser used to look at the assembly to reconstruct the input and output scripts. This patch changes it to use the hex input directly. This fixes parsing some instructions with unknown opcodes (e.g. multisig inputs with "0" opcode).
This commit is contained in:
parent
bf539f0b47
commit
337fe029fd
@ -5,44 +5,6 @@ from decimal import Decimal
|
||||
from filecache import filecache, DAY
|
||||
import types_pb2 as proto_types
|
||||
|
||||
def op_push_data(data):
|
||||
l = len(data)
|
||||
if l < 0x4C:
|
||||
return chr(l) + data
|
||||
elif i < 0xFF:
|
||||
return '\x4C' + chr(l) + data
|
||||
elif i < 0xFFFF:
|
||||
return '\x4D' + struct.pack("<H", i) + data
|
||||
else:
|
||||
return '\x4E' + struct.pack("<I", i) + data
|
||||
|
||||
def opcode_serialize(opcode):
|
||||
mapping = {
|
||||
'OP_TRUE' : '\x51',
|
||||
'OP_RETURN' : '\x6A',
|
||||
'OP_DUP' : '\x76',
|
||||
'OP_EQUAL' : '\x87',
|
||||
'OP_EQUALVERIFY' : '\x88',
|
||||
'OP_RIPEMD160' : '\xA6',
|
||||
'OP_SHA1' : '\xA7',
|
||||
'OP_SHA256' : '\xA8',
|
||||
'OP_HASH160' : '\xA9',
|
||||
'OP_HASH256' : '\xAA',
|
||||
'OP_CHECKSIG' : '\xAC',
|
||||
'OP_CHECKSIGVERIFY' : '\xAD',
|
||||
'OP_CHECKMULTISIG' : '\xAE',
|
||||
'OP_CHECKMULTISIGVERIFY' : '\xAF',
|
||||
}
|
||||
# check if it is known opcode
|
||||
if mapping.has_key(opcode):
|
||||
return mapping[opcode]
|
||||
# it's probably hex data
|
||||
try:
|
||||
x = binascii.unhexlify(opcode)
|
||||
return op_push_data(x)
|
||||
except:
|
||||
raise Exception('Unknown script opcode: %s' % opcode)
|
||||
|
||||
def insight_tx(url, rawdata=False):
|
||||
if not rawdata:
|
||||
try:
|
||||
@ -68,17 +30,13 @@ def insight_tx(url, rawdata=False):
|
||||
else:
|
||||
i.prev_hash = binascii.unhexlify(vin['txid'])
|
||||
i.prev_index = vin['vout']
|
||||
asm = vin['scriptSig']['asm'].split(' ')
|
||||
asm = [ opcode_serialize(x) for x in asm ]
|
||||
i.script_sig = ''.join(asm)
|
||||
i.script_sig = binascii.unhexlify(vin['scriptSig']['hex'])
|
||||
i.sequence = vin['sequence']
|
||||
|
||||
for vout in data['vout']:
|
||||
o = t.bin_outputs.add()
|
||||
o.amount = int(Decimal(str(vout['value'])) * 100000000)
|
||||
asm = vout['scriptPubKey']['asm'].split(' ')
|
||||
asm = [ opcode_serialize(x) for x in asm ]
|
||||
o.script_pubkey = ''.join(asm)
|
||||
o.script_pubkey = binascii.unhexlify(vout['scriptPubKey']['hex'])
|
||||
|
||||
return t
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user