From 23bae5748e56b2d025e40eeac37d5c7f516cfcdd Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Thu, 19 Feb 2015 12:30:23 +1100 Subject: [PATCH] Transaction: fix coinbase script handling --- src/transaction.js | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/src/transaction.js b/src/transaction.js index eae644b..ad6179d 100644 --- a/src/transaction.js +++ b/src/transaction.js @@ -51,17 +51,33 @@ Transaction.fromBuffer = function(buffer, __disableAssert) { return Script.fromBuffer(readSlice(readVarInt())) } + function readGenerationScript() { + return new Script(readSlice(readVarInt()), []) + } + 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 hash = readSlice(32) + + if (Transaction.isCoinbaseHash(hash)) { + tx.ins.push({ + hash: hash, + index: readUInt32(), + script: readGenerationScript(), + sequence: readUInt32() + }) + + } else { + tx.ins.push({ + hash: hash, + index: readUInt32(), + script: readScript(), + sequence: readUInt32() + }) + } } var voutLen = readVarInt()