Browse Source

Script: parseChunks now uses bufferutils

hk-custom-address
Daniel Cousens 11 years ago
parent
commit
3521584b3a
  1. 43
      src/script.js

43
src/script.js

@ -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 len var data = buffer.slice(i, i + d.number)
if (opcode > 0 && opcode < opcodes.OP_PUSHDATA1) { i += d.number
// Read some bytes of data, opcode value is the length of data
readChunk(opcode) chunks.push(data)
} 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…
Cancel
Save