Transaction: return a slice, not the original Buffer
This commit is contained in:
parent
6eae0241aa
commit
cc1af7d6a3
1 changed files with 5 additions and 2 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue