Browse Source

transaction: simplify toBuffer offset management

hk-custom-address
Daniel Cousens 8 years ago
committed by Daniel Cousens
parent
commit
3bff2c63af
  1. 1
      src/bufferutils.js
  2. 23
      src/transaction.js

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

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

Loading…
Cancel
Save