add tx.setLockTime and tx.increaseFee (rbf).
This commit is contained in:
parent
911f9534e4
commit
1d5e3ca27e
@ -69,11 +69,8 @@ function TX(data, block) {
|
|||||||
this.ps = this.ts === 0 ? utils.now() : 0;
|
this.ps = this.ts === 0 ? utils.now() : 0;
|
||||||
|
|
||||||
// Discourage fee snipping a la bitcoind
|
// Discourage fee snipping a la bitcoind
|
||||||
// if (data.lock == null && this.chain) {
|
// if (data.lock == null)
|
||||||
// this.lock = this.chain.height();
|
// this._avoidFeeSnipping();
|
||||||
// if ((Math.random() * 10 | 0) === 0)
|
|
||||||
// this.lock = Math.max(0, this.lock - (Math.random() * 100 | 0));
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TX.prototype.clone = function clone() {
|
TX.prototype.clone = function clone() {
|
||||||
@ -136,14 +133,6 @@ TX.prototype._input = function _input(obj, index) {
|
|||||||
seq: options.seq
|
seq: options.seq
|
||||||
});
|
});
|
||||||
|
|
||||||
// Locktime won't work without a seq < uint32max
|
|
||||||
// if (this.lock !== 0)
|
|
||||||
// input.seq = 0;
|
|
||||||
|
|
||||||
// Replace by fee opt-in
|
|
||||||
// if (this.rbf)
|
|
||||||
// input.seq = 0xffffffff - 1;
|
|
||||||
|
|
||||||
// Try modifying existing input first
|
// Try modifying existing input first
|
||||||
i = this._inputIndex(input.out.hash, input.out.index);
|
i = this._inputIndex(input.out.hash, input.out.index);
|
||||||
if (i !== -1) {
|
if (i !== -1) {
|
||||||
@ -958,6 +947,9 @@ TX.prototype.getUnspent = function getUnspent(unspent, address, fee) {
|
|||||||
TX.prototype.fillUnspent = function fillUnspent(unspent, address, fee) {
|
TX.prototype.fillUnspent = function fillUnspent(unspent, address, fee) {
|
||||||
var result;
|
var result;
|
||||||
|
|
||||||
|
if (unspent)
|
||||||
|
this.unspent = unspent;
|
||||||
|
|
||||||
if (address)
|
if (address)
|
||||||
this.changeAddress = address;
|
this.changeAddress = address;
|
||||||
|
|
||||||
@ -966,7 +958,7 @@ TX.prototype.fillUnspent = function fillUnspent(unspent, address, fee) {
|
|||||||
|
|
||||||
assert(this.changeAddress);
|
assert(this.changeAddress);
|
||||||
|
|
||||||
result = this.getUnspent(unspent, this.changeAddress, this.hardFee);
|
result = this.getUnspent(this.unspent, this.changeAddress, this.hardFee);
|
||||||
|
|
||||||
if (!result.inputs)
|
if (!result.inputs)
|
||||||
return result;
|
return result;
|
||||||
@ -1013,6 +1005,9 @@ TX.prototype._recalculateFee = function recalculateFee() {
|
|||||||
real = Math.ceil(size / 1024) * constants.tx.fee;
|
real = Math.ceil(size / 1024) * constants.tx.fee;
|
||||||
fee = this.getFee().toNumber();
|
fee = this.getFee().toNumber();
|
||||||
|
|
||||||
|
// if (this.hardFee)
|
||||||
|
// real = this.hardFee;
|
||||||
|
|
||||||
if (real === fee) {
|
if (real === fee) {
|
||||||
if (this.changeIndex === -1)
|
if (this.changeIndex === -1)
|
||||||
this.outputs.pop();
|
this.outputs.pop();
|
||||||
@ -1076,6 +1071,40 @@ TX.prototype.funds = function funds(side) {
|
|||||||
return acc;
|
return acc;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
TX.prototype._avoidFeeSnipping = function _avoidFeeSnipping() {
|
||||||
|
if (!this.chain)
|
||||||
|
return;
|
||||||
|
|
||||||
|
this.lock = this.chain.height();
|
||||||
|
|
||||||
|
if ((Math.random() * 10 | 0) === 0)
|
||||||
|
this.lock = Math.max(0, this.lock - (Math.random() * 100 | 0));
|
||||||
|
};
|
||||||
|
|
||||||
|
TX.prototype.setLockTime = function setLockTime(lock) {
|
||||||
|
var i, input;
|
||||||
|
|
||||||
|
this.lock = lock;
|
||||||
|
|
||||||
|
for (i = 0; i < this.inputs.length; i++) {
|
||||||
|
input = this.inputs[i];
|
||||||
|
if (input.seq === 0xffffffff)
|
||||||
|
input.seq = 0;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TX.prototype.increaseFee = function increaseFee(fee) {
|
||||||
|
var i, input;
|
||||||
|
|
||||||
|
this.hardFee = fee || this.getFee().add(new bn(10000));
|
||||||
|
this.fillUnspent();
|
||||||
|
|
||||||
|
for (i = 0; i < this.inputs.length; i++) {
|
||||||
|
input = this.inputs[i];
|
||||||
|
input.seq = 0xffffffff - 1;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
TX.prototype.full = function full() {
|
TX.prototype.full = function full() {
|
||||||
if (this.inputs.length === 0)
|
if (this.inputs.length === 0)
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user