improve fee calculation.
This commit is contained in:
parent
ca03911d80
commit
3c8442b1bb
@ -153,7 +153,6 @@ TX.prototype._inputIndex = function _inputIndex(hash, index) {
|
|||||||
return -1;
|
return -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Build the scriptSigs for inputs, excluding the signatures
|
|
||||||
TX.prototype.scriptInput = function scriptInput(index, pub, redeem) {
|
TX.prototype.scriptInput = function scriptInput(index, pub, redeem) {
|
||||||
var input, s, n, i;
|
var input, s, n, i;
|
||||||
|
|
||||||
@ -206,10 +205,12 @@ TX.prototype.scriptInput = function scriptInput(index, pub, redeem) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// P2SH requires the redeem script after signatures
|
// P2SH requires the redeem script after signatures
|
||||||
if (redeem)
|
if (redeem) {
|
||||||
input.script.push(redeem);
|
input.script.push(redeem);
|
||||||
|
// The fee can be calculated more accurately
|
||||||
this._recalculateFee();
|
// now that the redeem script is available.
|
||||||
|
this._recalculateFee();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Sign the now-built scriptSigs
|
// Sign the now-built scriptSigs
|
||||||
@ -702,6 +703,18 @@ TX.prototype.maxSize = function maxSize() {
|
|||||||
// Get the previous output's subscript
|
// Get the previous output's subscript
|
||||||
s = input.out.tx.getSubscript(input.out.index);
|
s = input.out.tx.getSubscript(input.out.index);
|
||||||
|
|
||||||
|
// If we have access to the redeem script,
|
||||||
|
// we can use it to calculate size much easier.
|
||||||
|
if (this.inputs[i].script.length && bcoin.script.isScripthash(s)) {
|
||||||
|
s = this.inputs[i].script[this.inputs[i].script.length - 1];
|
||||||
|
// Need to add the redeem script size
|
||||||
|
// here since it will be ignored by
|
||||||
|
// the isMultisig clause.
|
||||||
|
// OP_PUSHDATA2 [redeem]
|
||||||
|
size += 3 + s.length;
|
||||||
|
s = bcoin.script.normalize(s);
|
||||||
|
}
|
||||||
|
|
||||||
if (bcoin.script.isPubkey(s)) {
|
if (bcoin.script.isPubkey(s)) {
|
||||||
// P2PK
|
// P2PK
|
||||||
// OP_PUSHDATA0 [signature]
|
// OP_PUSHDATA0 [signature]
|
||||||
@ -718,7 +731,6 @@ TX.prototype.maxSize = function maxSize() {
|
|||||||
m = s[0];
|
m = s[0];
|
||||||
if (Array.isArray(m))
|
if (Array.isArray(m))
|
||||||
m = m[0];
|
m = m[0];
|
||||||
assert(m >= 1 && m <= 3);
|
|
||||||
// OP_0
|
// OP_0
|
||||||
size += 1;
|
size += 1;
|
||||||
// OP_PUSHDATA0 [signature] ...
|
// OP_PUSHDATA0 [signature] ...
|
||||||
@ -880,7 +892,7 @@ TX.prototype._recalculateFee = function recalculateFee() {
|
|||||||
output = this.outputs[this.outputs.length - 1];
|
output = this.outputs[this.outputs.length - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
size = this.render().length;
|
size = this.maxSize();
|
||||||
real = Math.ceil(size / 1024) * constants.tx.fee;
|
real = Math.ceil(size / 1024) * constants.tx.fee;
|
||||||
fee = this.getFee().toNumber();
|
fee = this.getFee().toNumber();
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user