drop fee recalculation.
This commit is contained in:
parent
016c85f8b5
commit
697718c940
@ -311,12 +311,8 @@ TX.prototype.scriptInput = function scriptInput(index, publicKey, redeem) {
|
||||
}
|
||||
|
||||
// P2SH requires the redeem script after signatures
|
||||
if (redeem) {
|
||||
if (redeem)
|
||||
input.script.push(redeem);
|
||||
// The fee can be calculated more accurately
|
||||
// now that the redeem script is available.
|
||||
this._recalculateFee();
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
@ -1149,9 +1145,6 @@ TX.prototype.fill = function fill(unspent, options) {
|
||||
if (!result.inputs)
|
||||
return result;
|
||||
|
||||
this._changeAddress = options.changeAddress;
|
||||
this._fee = options.fee;
|
||||
|
||||
result.inputs.forEach(function(input) {
|
||||
this.addInput(input);
|
||||
}, this);
|
||||
@ -1218,54 +1211,6 @@ TX.prototype.sortMembers = function sortMembers() {
|
||||
TX.prototype.fillUnspent = TX.prototype.fill;
|
||||
TX.prototype.fillInputs = TX.prototype.fill;
|
||||
|
||||
TX.prototype._recalculateFee = function recalculateFee() {
|
||||
var output = this.outputs[this.changeIndex];
|
||||
var size, real, fee;
|
||||
|
||||
if (!this._changeAddress)
|
||||
return;
|
||||
|
||||
if (this._fee)
|
||||
return;
|
||||
|
||||
if (!output) {
|
||||
this.addOutput({
|
||||
address: this._changeAddress,
|
||||
value: new bn(0)
|
||||
});
|
||||
output = this.outputs[this.outputs.length - 1];
|
||||
}
|
||||
|
||||
size = this.maxSize();
|
||||
real = Math.ceil(size / 1024) * constants.tx.minFee;
|
||||
fee = this.getFee().toNumber();
|
||||
|
||||
if (real === fee) {
|
||||
if (this.changeIndex === -1)
|
||||
this.outputs.pop();
|
||||
return;
|
||||
}
|
||||
|
||||
if (real > fee) {
|
||||
if (output.value.cmpn(real - fee) < 0) {
|
||||
this.outputs.pop();
|
||||
this.changeIndex = -1;
|
||||
return;
|
||||
}
|
||||
output.value.isubn(real - fee);
|
||||
} else {
|
||||
output.value.iaddn(fee - real);
|
||||
}
|
||||
|
||||
if (output.value.cmpn(constants.tx.dustThreshold) < 0) {
|
||||
this.outputs.pop();
|
||||
this.changeIndex = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
this.changeIndex = this.outputs.indexOf(output);
|
||||
};
|
||||
|
||||
TX.prototype.getFee = function getFee() {
|
||||
if (!this.hasPrevout())
|
||||
return new bn(0);
|
||||
@ -1790,8 +1735,6 @@ TX.prototype.inspect = function inspect() {
|
||||
copy.block = this.block;
|
||||
delete copy._raw;
|
||||
delete copy._chain;
|
||||
delete copy._changeAddress;
|
||||
delete copy._fee;
|
||||
delete copy.total;
|
||||
copy.hash = this.hash('hex');
|
||||
copy.rhash = this.rhash;
|
||||
|
||||
@ -501,20 +501,21 @@ Wallet.prototype.ownOutput = function ownOutput(tx, index) {
|
||||
};
|
||||
|
||||
Wallet.prototype.fill = function fill(tx, options) {
|
||||
var unspent, result;
|
||||
var result;
|
||||
|
||||
if (!options)
|
||||
options = {};
|
||||
|
||||
assert(this._initialized);
|
||||
|
||||
unspent = this.getUnspent();
|
||||
|
||||
result = tx.fill(unspent, utils.merge(options || {}, {
|
||||
result = tx.fill(this.getUnspent(), {
|
||||
// wallet: this,
|
||||
fee: options.fee,
|
||||
subtractFee: options.subtractFee,
|
||||
changeAddress: this.changeAddress.getAddress(),
|
||||
m: this.m,
|
||||
n: this.n
|
||||
}));
|
||||
});
|
||||
|
||||
if (!result.inputs)
|
||||
return false;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user