Skip to content

Commit

Permalink
Revert "wallet/mtx: add extraOutputs option."
Browse files Browse the repository at this point in the history
This reverts commit 3957f83.
  • Loading branch information
chjj committed Aug 26, 2017
1 parent 140eece commit c6b76ec
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 93 deletions.
8 changes: 2 additions & 6 deletions bin/cli
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,7 @@ CLI.prototype.sendTX = async function sendTX() {
outputs: outputs,
smart: this.config.bool('smart'),
rate: this.config.ufixed('rate', 8),
subtractFee: this.config.bool('subtract-fee'),
extraOutputs: this.config.uint('extra'),
selection: this.config.str('selection')
subtractFee: this.config.bool('subtract-fee')
};

const tx = await this.wallet.send(options);
Expand Down Expand Up @@ -341,9 +339,7 @@ CLI.prototype.createTX = async function createTX() {
outputs: [output],
smart: this.config.bool('smart'),
rate: this.config.ufixed('rate', 8),
subtractFee: this.config.bool('subtract-fee'),
extraOutputs: this.config.uint('extra'),
selection: this.config.str('selection')
subtractFee: this.config.bool('subtract-fee')
};

const tx = await this.wallet.createTX(options);
Expand Down
93 changes: 9 additions & 84 deletions lib/primitives/mtx.js
Original file line number Diff line number Diff line change
Expand Up @@ -1289,96 +1289,33 @@ MTX.prototype.fund = async function fund(coins, options) {
// Do nothing. Change is added to fee.
this.changeIndex = -1;
assert.strictEqual(this.getFee(), select.fee + select.change);
assert(select.fee + select.change <= CoinSelector.MAX_FEE);
return select;
} else {
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;
};

/**
* 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.
* @see https://github.com/bitcoin/bips/blob/master/bip-0069.mediawiki
*/

MTX.prototype.sortMembers = function sortMembers() {
let change = null;
let changeOutput = null;

if (this.changeIndex !== -1) {
change = this.outputs[this.changeIndex];
assert(change);
changeOutput = this.outputs[this.changeIndex];
assert(changeOutput);
}

this.inputs.sort(sortInputs);
this.outputs.sort(sortOutputs);

if (change) {
this.changeIndex = this.outputs.indexOf(change);
if (this.changeIndex !== -1) {
this.changeIndex = this.outputs.indexOf(changeOutput);
assert(this.changeIndex !== -1);
}
};
Expand Down Expand Up @@ -1583,7 +1520,6 @@ function CoinSelector(tx, options) {
this.maxFee = -1;
this.round = false;
this.changeAddress = null;
this.extraOutputs = 0;

// Needed for size estimation.
this.estimate = null;
Expand Down Expand Up @@ -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) {
assert(typeof options.estimate === 'function');
this.estimate = options.estimate;
Expand Down Expand Up @@ -1893,10 +1822,6 @@ CoinSelector.prototype.selectEstimate = async function selectEstimate() {

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
// until we reach some sort of equilibrium.
do {
Expand Down
2 changes: 0 additions & 2 deletions lib/wallet/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,6 @@ HTTPServer.prototype.initRouter = function initRouter() {
smart: valid.bool('smart'),
subtractFee: valid.bool('subtractFee'),
depth: valid.u32(['confirmations', 'depth']),
extraOutputs: valid.u32('extraOutputs'),
outputs: []
};

Expand Down Expand Up @@ -429,7 +428,6 @@ HTTPServer.prototype.initRouter = function initRouter() {
smart: valid.bool('smart'),
subtractFee: valid.bool('subtractFee'),
depth: valid.u32(['confirmations', 'depth']),
extraOutputs: valid.u32('extraOutputs'),
outputs: []
};

Expand Down
1 change: 0 additions & 1 deletion lib/wallet/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -1397,7 +1397,6 @@ Wallet.prototype._fund = async function _fund(mtx, options) {
hardFee: options.hardFee,
subtractFee: options.subtractFee,
changeAddress: account.change.getAddress(),
extraOutputs: options.extraOutputs,
height: this.db.state.height,
rate: rate,
maxFee: options.maxFee,
Expand Down

0 comments on commit c6b76ec

Please sign in to comment.