Transaction: extract Script size calculations
This commit is contained in:
parent
49345748bb
commit
dc253bb77c
1 changed files with 7 additions and 9 deletions
|
@ -68,7 +68,7 @@ Transaction.fromBuffer = function(buffer, __disableAssert) {
|
||||||
for (i = 0; i < voutLen; ++i) {
|
for (i = 0; i < voutLen; ++i) {
|
||||||
tx.outs.push({
|
tx.outs.push({
|
||||||
value: readUInt64(),
|
value: readUInt64(),
|
||||||
script: readScript(),
|
script: readScript()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,20 +252,18 @@ Transaction.prototype.getId = function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
Transaction.prototype.toBuffer = function () {
|
Transaction.prototype.toBuffer = function () {
|
||||||
var txInSize = this.ins.reduce(function(a, x) {
|
function scriptSize(script) {
|
||||||
return a + (40 + bufferutils.varIntSize(x.script.buffer.length) + x.script.buffer.length)
|
var length = script.buffer.length
|
||||||
}, 0)
|
|
||||||
|
|
||||||
var txOutSize = this.outs.reduce(function(a, x) {
|
return bufferutils.varIntSize(length) + length
|
||||||
return a + (8 + bufferutils.varIntSize(x.script.buffer.length) + x.script.buffer.length)
|
}
|
||||||
}, 0)
|
|
||||||
|
|
||||||
var buffer = new Buffer(
|
var buffer = new Buffer(
|
||||||
8 +
|
8 +
|
||||||
bufferutils.varIntSize(this.ins.length) +
|
bufferutils.varIntSize(this.ins.length) +
|
||||||
bufferutils.varIntSize(this.outs.length) +
|
bufferutils.varIntSize(this.outs.length) +
|
||||||
txInSize +
|
this.ins.reduce(function(sum, input) { return sum + 40 + scriptSize(input.script) }, 0) +
|
||||||
txOutSize
|
this.outs.reduce(function(sum, output) { return sum + 8 + scriptSize(output.script) }, 0)
|
||||||
)
|
)
|
||||||
|
|
||||||
var offset = 0
|
var offset = 0
|
||||||
|
|
Loading…
Add table
Reference in a new issue