Transaction: return a slice, not the original Buffer

This commit is contained in:
Daniel Cousens 2016-08-10 11:43:36 +10:00
parent 6eae0241aa
commit cc1af7d6a3

View file

@ -255,10 +255,10 @@ Transaction.prototype.getId = function () {
return bufferReverse(this.getHash()).toString('hex')
}
Transaction.prototype.toBuffer = function (buffer, offset) {
Transaction.prototype.toBuffer = function (buffer, initialOffset) {
if (!buffer) buffer = new Buffer(this.byteLength())
offset = offset || 0
var offset = initialOffset || 0
function writeSlice (slice) {
slice.copy(buffer, offset)
offset += slice.length
@ -304,6 +304,9 @@ Transaction.prototype.toBuffer = function (buffer, offset) {
writeUInt32(this.locktime)
// avoid slicing unless necessary
if (initialOffset !== undefined) return buffer.slice(initialOffset, offset)
return buffer
}