From 3bff2c63afbbe2fa75a21070cbc52b651f730c1b Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Sun, 9 Oct 2016 22:53:41 +1100 Subject: [PATCH] transaction: simplify toBuffer offset management --- src/bufferutils.js | 1 + src/transaction.js | 23 ++++------------------- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/src/bufferutils.js b/src/bufferutils.js index bd5f278..ca3e439 100644 --- a/src/bufferutils.js +++ b/src/bufferutils.js @@ -94,6 +94,7 @@ function writeUInt64LE (buffer, value, offset) { buffer.writeInt32LE(value & -1, offset) buffer.writeUInt32LE(Math.floor(value / 0x100000000), offset + 4) + return offset + 8 } // TODO: remove in 4.0.0? diff --git a/src/transaction.js b/src/transaction.js index 676a53c..a996d55 100644 --- a/src/transaction.js +++ b/src/transaction.js @@ -259,25 +259,10 @@ Transaction.prototype.toBuffer = function (buffer, initialOffset) { if (!buffer) buffer = new Buffer(this.byteLength()) var offset = initialOffset || 0 - function writeSlice (slice) { - slice.copy(buffer, offset) - offset += slice.length - } - - function writeUInt32 (i) { - buffer.writeUInt32LE(i, offset) - offset += 4 - } - - function writeUInt64 (i) { - bufferutils.writeUInt64LE(buffer, i, offset) - offset += 8 - } - - function writeVarInt (i) { - var n = bufferutils.writeVarInt(buffer, i, offset) - offset += n - } + function writeSlice (slice) { offset += slice.copy(buffer, offset) } + function writeUInt32 (i) { offset = buffer.writeUInt32LE(i, offset) } + function writeUInt64 (i) { offset = bufferutils.writeUInt64LE(buffer, i, offset) } + function writeVarInt (i) { offset += bufferutils.writeVarInt(buffer, i, offset) } writeUInt32(this.version) writeVarInt(this.ins.length)