transaction: simplify toBuffer offset management
This commit is contained in:
parent
f7b2fdfe60
commit
3bff2c63af
2 changed files with 5 additions and 19 deletions
|
@ -94,6 +94,7 @@ function writeUInt64LE (buffer, value, offset) {
|
||||||
|
|
||||||
buffer.writeInt32LE(value & -1, offset)
|
buffer.writeInt32LE(value & -1, offset)
|
||||||
buffer.writeUInt32LE(Math.floor(value / 0x100000000), offset + 4)
|
buffer.writeUInt32LE(Math.floor(value / 0x100000000), offset + 4)
|
||||||
|
return offset + 8
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: remove in 4.0.0?
|
// TODO: remove in 4.0.0?
|
||||||
|
|
|
@ -259,25 +259,10 @@ Transaction.prototype.toBuffer = function (buffer, initialOffset) {
|
||||||
if (!buffer) buffer = new Buffer(this.byteLength())
|
if (!buffer) buffer = new Buffer(this.byteLength())
|
||||||
|
|
||||||
var offset = initialOffset || 0
|
var offset = initialOffset || 0
|
||||||
function writeSlice (slice) {
|
function writeSlice (slice) { offset += slice.copy(buffer, offset) }
|
||||||
slice.copy(buffer, offset)
|
function writeUInt32 (i) { offset = buffer.writeUInt32LE(i, offset) }
|
||||||
offset += slice.length
|
function writeUInt64 (i) { offset = bufferutils.writeUInt64LE(buffer, i, offset) }
|
||||||
}
|
function writeVarInt (i) { offset += bufferutils.writeVarInt(buffer, i, offset) }
|
||||||
|
|
||||||
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
|
|
||||||
}
|
|
||||||
|
|
||||||
writeUInt32(this.version)
|
writeUInt32(this.version)
|
||||||
writeVarInt(this.ins.length)
|
writeVarInt(this.ins.length)
|
||||||
|
|
Loading…
Add table
Reference in a new issue