Script: parseChunks now uses bufferutils
This commit is contained in:
parent
005ca31fb3
commit
3521584b3a
1 changed files with 12 additions and 29 deletions
|
@ -40,47 +40,30 @@ Script.parseChunks = function(buffer) {
|
||||||
|
|
||||||
var chunks = []
|
var chunks = []
|
||||||
|
|
||||||
// Cursor
|
|
||||||
var i = 0
|
var i = 0
|
||||||
|
|
||||||
// Read n bytes and store result as a chunk
|
|
||||||
function readChunk(n) {
|
|
||||||
chunks.push(buffer.slice(i, i + n))
|
|
||||||
i += n
|
|
||||||
}
|
|
||||||
|
|
||||||
while (i < buffer.length) {
|
while (i < buffer.length) {
|
||||||
var opcode = buffer[i++]
|
var opcode = buffer.readUInt8(i)
|
||||||
if (opcode >= 0xF0) {
|
|
||||||
// Two byte opcode
|
if ((opcode > opcodes.OP_0) && (opcode <= opcodes.OP_PUSHDATA4)) {
|
||||||
opcode = (opcode << 8) | buffer[i++]
|
var d = bufferutils.readPushDataInt(buffer, i)
|
||||||
}
|
i += d.size
|
||||||
|
|
||||||
|
var data = buffer.slice(i, i + d.number)
|
||||||
|
i += d.number
|
||||||
|
|
||||||
|
chunks.push(data)
|
||||||
|
|
||||||
var len
|
|
||||||
if (opcode > 0 && opcode < opcodes.OP_PUSHDATA1) {
|
|
||||||
// Read some bytes of data, opcode value is the length of data
|
|
||||||
readChunk(opcode)
|
|
||||||
} else if (opcode == opcodes.OP_PUSHDATA1) {
|
|
||||||
len = buffer[i++]
|
|
||||||
readChunk(len)
|
|
||||||
} else if (opcode == opcodes.OP_PUSHDATA2) {
|
|
||||||
len = (buffer[i++] << 8) | buffer[i++]
|
|
||||||
readChunk(len)
|
|
||||||
} else if (opcode == opcodes.OP_PUSHDATA4) {
|
|
||||||
len = (buffer[i++] << 24) |
|
|
||||||
(buffer[i++] << 16) |
|
|
||||||
(buffer[i++] << 8) |
|
|
||||||
buffer[i++]
|
|
||||||
readChunk(len)
|
|
||||||
} else {
|
} else {
|
||||||
chunks.push(opcode)
|
chunks.push(opcode)
|
||||||
|
|
||||||
|
++i
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return chunks
|
return chunks
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compare the script to known templates of scriptPubKey.
|
* Compare the script to known templates of scriptPubKey.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue