Revert "wallet/mtx: add extraOutputs option."
This reverts commit 3957f83a59.
This commit is contained in:
parent
140eece7dd
commit
c6b76ec73f
8
bin/cli
8
bin/cli
@ -310,9 +310,7 @@ CLI.prototype.sendTX = async function sendTX() {
|
|||||||
outputs: outputs,
|
outputs: outputs,
|
||||||
smart: this.config.bool('smart'),
|
smart: this.config.bool('smart'),
|
||||||
rate: this.config.ufixed('rate', 8),
|
rate: this.config.ufixed('rate', 8),
|
||||||
subtractFee: this.config.bool('subtract-fee'),
|
subtractFee: this.config.bool('subtract-fee')
|
||||||
extraOutputs: this.config.uint('extra'),
|
|
||||||
selection: this.config.str('selection')
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const tx = await this.wallet.send(options);
|
const tx = await this.wallet.send(options);
|
||||||
@ -341,9 +339,7 @@ CLI.prototype.createTX = async function createTX() {
|
|||||||
outputs: [output],
|
outputs: [output],
|
||||||
smart: this.config.bool('smart'),
|
smart: this.config.bool('smart'),
|
||||||
rate: this.config.ufixed('rate', 8),
|
rate: this.config.ufixed('rate', 8),
|
||||||
subtractFee: this.config.bool('subtract-fee'),
|
subtractFee: this.config.bool('subtract-fee')
|
||||||
extraOutputs: this.config.uint('extra'),
|
|
||||||
selection: this.config.str('selection')
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const tx = await this.wallet.createTX(options);
|
const tx = await this.wallet.createTX(options);
|
||||||
|
|||||||
@ -1289,96 +1289,33 @@ MTX.prototype.fund = async function fund(coins, options) {
|
|||||||
// Do nothing. Change is added to fee.
|
// Do nothing. Change is added to fee.
|
||||||
this.changeIndex = -1;
|
this.changeIndex = -1;
|
||||||
assert.strictEqual(this.getFee(), select.fee + select.change);
|
assert.strictEqual(this.getFee(), select.fee + select.change);
|
||||||
assert(select.fee + select.change <= CoinSelector.MAX_FEE);
|
} else {
|
||||||
return select;
|
this.outputs.push(change);
|
||||||
|
this.changeIndex = this.outputs.length - 1;
|
||||||
|
assert.strictEqual(this.getFee(), select.fee);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a change output.
|
|
||||||
this.outputs.push(change);
|
|
||||||
this.changeIndex = this.outputs.length - 1;
|
|
||||||
|
|
||||||
// Add more change outputs if we want.
|
|
||||||
// This is specifically designed to
|
|
||||||
// easily allow large hot wallets to
|
|
||||||
// bypass the stupidity of the 25
|
|
||||||
// ancestor limit in the mempool.
|
|
||||||
//
|
|
||||||
// If core decides to add another
|
|
||||||
// ridiculous "spam prevention feature"
|
|
||||||
// like rejecting duplicate addresses,
|
|
||||||
// we can start making these addresses
|
|
||||||
// more dynamic.
|
|
||||||
if (select.extraOutputs > 0)
|
|
||||||
this.addExtra(select.extraOutputs);
|
|
||||||
|
|
||||||
assert.strictEqual(this.getFee(), select.fee);
|
|
||||||
assert(select.fee <= CoinSelector.MAX_FEE);
|
|
||||||
|
|
||||||
return select;
|
return select;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
|
||||||
* Add extra change outputs.
|
|
||||||
* @param {Number} outputs
|
|
||||||
*/
|
|
||||||
|
|
||||||
MTX.prototype.addExtra = function addExtra(outputs) {
|
|
||||||
assert(typeof outputs === 'number');
|
|
||||||
assert(outputs >= 0);
|
|
||||||
|
|
||||||
const index = this.changeIndex;
|
|
||||||
const output = this.outputs[index];
|
|
||||||
assert(output);
|
|
||||||
|
|
||||||
const change = output.value;
|
|
||||||
|
|
||||||
outputs += 1;
|
|
||||||
|
|
||||||
for (;;) {
|
|
||||||
assert(outputs !== 0);
|
|
||||||
|
|
||||||
output.value = Math.floor(change / outputs);
|
|
||||||
|
|
||||||
if (!output.isDust(policy.MIN_RELAY))
|
|
||||||
break;
|
|
||||||
|
|
||||||
outputs--;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let i = 0; i < outputs - 1; i++)
|
|
||||||
this.outputs.push(output.clone());
|
|
||||||
|
|
||||||
const left = change - (outputs * output.value);
|
|
||||||
output.value += left;
|
|
||||||
|
|
||||||
let total = 0;
|
|
||||||
|
|
||||||
for (let i = index; i < this.outputs.length; i++) {
|
|
||||||
const output = this.outputs[i];
|
|
||||||
total += output.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
assert.strictEqual(total, change);
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sort inputs and outputs according to BIP69.
|
* Sort inputs and outputs according to BIP69.
|
||||||
* @see https://github.com/bitcoin/bips/blob/master/bip-0069.mediawiki
|
* @see https://github.com/bitcoin/bips/blob/master/bip-0069.mediawiki
|
||||||
*/
|
*/
|
||||||
|
|
||||||
MTX.prototype.sortMembers = function sortMembers() {
|
MTX.prototype.sortMembers = function sortMembers() {
|
||||||
let change = null;
|
let changeOutput = null;
|
||||||
|
|
||||||
if (this.changeIndex !== -1) {
|
if (this.changeIndex !== -1) {
|
||||||
change = this.outputs[this.changeIndex];
|
changeOutput = this.outputs[this.changeIndex];
|
||||||
assert(change);
|
assert(changeOutput);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.inputs.sort(sortInputs);
|
this.inputs.sort(sortInputs);
|
||||||
this.outputs.sort(sortOutputs);
|
this.outputs.sort(sortOutputs);
|
||||||
|
|
||||||
if (change) {
|
if (this.changeIndex !== -1) {
|
||||||
this.changeIndex = this.outputs.indexOf(change);
|
this.changeIndex = this.outputs.indexOf(changeOutput);
|
||||||
assert(this.changeIndex !== -1);
|
assert(this.changeIndex !== -1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -1583,7 +1520,6 @@ function CoinSelector(tx, options) {
|
|||||||
this.maxFee = -1;
|
this.maxFee = -1;
|
||||||
this.round = false;
|
this.round = false;
|
||||||
this.changeAddress = null;
|
this.changeAddress = null;
|
||||||
this.extraOutputs = 0;
|
|
||||||
|
|
||||||
// Needed for size estimation.
|
// Needed for size estimation.
|
||||||
this.estimate = null;
|
this.estimate = null;
|
||||||
@ -1693,13 +1629,6 @@ CoinSelector.prototype.fromOptions = function fromOptions(options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.extraOutputs != null) {
|
|
||||||
assert(typeof options.extraOutputs === 'number');
|
|
||||||
assert(options.extraOutputs >= 0);
|
|
||||||
assert(options.extraOutputs <= 100);
|
|
||||||
this.extraOutputs = options.extraOutputs;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.estimate) {
|
if (options.estimate) {
|
||||||
assert(typeof options.estimate === 'function');
|
assert(typeof options.estimate === 'function');
|
||||||
this.estimate = options.estimate;
|
this.estimate = options.estimate;
|
||||||
@ -1893,10 +1822,6 @@ CoinSelector.prototype.selectEstimate = async function selectEstimate() {
|
|||||||
|
|
||||||
this.tx.outputs.push(change);
|
this.tx.outputs.push(change);
|
||||||
|
|
||||||
// Extra change outputs.
|
|
||||||
for (let i = 0; i < this.extraOutputs; i++)
|
|
||||||
this.tx.outputs.push(change.clone());
|
|
||||||
|
|
||||||
// Keep recalculating the fee and funding
|
// Keep recalculating the fee and funding
|
||||||
// until we reach some sort of equilibrium.
|
// until we reach some sort of equilibrium.
|
||||||
do {
|
do {
|
||||||
|
|||||||
@ -390,7 +390,6 @@ HTTPServer.prototype.initRouter = function initRouter() {
|
|||||||
smart: valid.bool('smart'),
|
smart: valid.bool('smart'),
|
||||||
subtractFee: valid.bool('subtractFee'),
|
subtractFee: valid.bool('subtractFee'),
|
||||||
depth: valid.u32(['confirmations', 'depth']),
|
depth: valid.u32(['confirmations', 'depth']),
|
||||||
extraOutputs: valid.u32('extraOutputs'),
|
|
||||||
outputs: []
|
outputs: []
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -429,7 +428,6 @@ HTTPServer.prototype.initRouter = function initRouter() {
|
|||||||
smart: valid.bool('smart'),
|
smart: valid.bool('smart'),
|
||||||
subtractFee: valid.bool('subtractFee'),
|
subtractFee: valid.bool('subtractFee'),
|
||||||
depth: valid.u32(['confirmations', 'depth']),
|
depth: valid.u32(['confirmations', 'depth']),
|
||||||
extraOutputs: valid.u32('extraOutputs'),
|
|
||||||
outputs: []
|
outputs: []
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -1397,7 +1397,6 @@ Wallet.prototype._fund = async function _fund(mtx, options) {
|
|||||||
hardFee: options.hardFee,
|
hardFee: options.hardFee,
|
||||||
subtractFee: options.subtractFee,
|
subtractFee: options.subtractFee,
|
||||||
changeAddress: account.change.getAddress(),
|
changeAddress: account.change.getAddress(),
|
||||||
extraOutputs: options.extraOutputs,
|
|
||||||
height: this.db.state.height,
|
height: this.db.state.height,
|
||||||
rate: rate,
|
rate: rate,
|
||||||
maxFee: options.maxFee,
|
maxFee: options.maxFee,
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user