From 50dab3b6bfa199bac0b8156ffdadece3b857df83 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Thu, 19 Feb 2015 18:59:56 +1100 Subject: [PATCH] block: use Transaction.fromBuffer --- src/block.js | 35 +++-------------------------------- 1 file changed, 3 insertions(+), 32 deletions(-) diff --git a/src/block.js b/src/block.js index 8b786cb..3bef165 100644 --- a/src/block.js +++ b/src/block.js @@ -39,46 +39,17 @@ Block.fromBuffer = function(buffer) { if (buffer.length === 80) return block - function readUInt64() { - var i = bufferutils.readUInt64LE(buffer, offset) - offset += 8 - return i - } - function readVarInt() { var vi = bufferutils.readVarInt(buffer, offset) offset += vi.size return vi.number } - function readScript() { - return Script.fromBuffer(readSlice(readVarInt())) - } - + // FIXME: poor performance function readTransaction() { - var tx = new Transaction() - tx.version = readUInt32() - - var vinLen = readVarInt() - for (var i = 0; i < vinLen; ++i) { - tx.ins.push({ - hash: readSlice(32), - index: readUInt32(), - script: readScript(), - sequence: readUInt32() - }) - } - - var voutLen = readVarInt() - for (i = 0; i < voutLen; ++i) { - tx.outs.push({ - value: readUInt64(), - script: readScript(), - }) - } - - tx.locktime = readUInt32() + var tx = Transaction.fromBuffer(buffer.slice(offset), true) + offset += tx.toBuffer().length return tx }