From 768f7e314c6f78f756d88b840d3bbb6d93c83d53 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Wed, 9 Nov 2016 11:54:17 +1100 Subject: [PATCH] Transaction: initialize to ZERO earlier --- src/transaction.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/transaction.js b/src/transaction.js index 90fd755..db28666 100644 --- a/src/transaction.js +++ b/src/transaction.js @@ -306,8 +306,6 @@ Transaction.prototype.hashForSignature = function (inIndex, prevOutScript, hashT Transaction.prototype.hashForWitnessV0 = function (inIndex, prevOutScript, amount, hashType) { typeforce(types.tuple(types.UInt32, types.Buffer, types.Satoshi, types.UInt32), arguments) - var hashOutputs, hashPrevouts, hashSequence - var tbuffer, toffset function writeSlice (slice) { toffset += slice.copy(tbuffer, toffset) } function writeUInt32 (i) { toffset = tbuffer.writeUInt32LE(i, toffset) } @@ -315,6 +313,10 @@ Transaction.prototype.hashForWitnessV0 = function (inIndex, prevOutScript, amoun function writeVarInt (i) { toffset += bufferutils.writeVarInt(tbuffer, i, toffset) } function writeVarSlice (slice) { writeVarInt(slice.length); writeSlice(slice) } + var hashOutputs = ZERO + var hashPrevouts = ZERO + var hashSequence = ZERO + if (!(hashType & Transaction.SIGHASH_ANYONECANPAY)) { tbuffer = new Buffer(36 * this.ins.length) toffset = 0 @@ -366,10 +368,6 @@ Transaction.prototype.hashForWitnessV0 = function (inIndex, prevOutScript, amoun hashOutputs = bcrypto.hash256(tbuffer) } - hashPrevouts = hashPrevouts || ZERO - hashSequence = hashSequence || ZERO - hashOutputs = hashOutputs || ZERO - tbuffer = new Buffer(156 + varSliceSize(prevOutScript)) toffset = 0