transaction: simplify toBuffer offset management

This commit is contained in:
Daniel Cousens 2016-10-09 22:53:41 +11:00 committed by Daniel Cousens
parent f7b2fdfe60
commit 3bff2c63af
2 changed files with 5 additions and 19 deletions

View file

@ -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?

View file

@ -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)