improve coin selection.
This commit is contained in:
parent
0f6c19bcd5
commit
9fd3bbb827
@ -1075,12 +1075,6 @@ MTX.prototype.selectCoins = function selectCoins(coins, options) {
|
||||
// Null the inputs if there are any.
|
||||
tx.inputs.length = 0;
|
||||
|
||||
if (options.confirmed) {
|
||||
coins = coins.filter(function(coin) {
|
||||
return coin.height !== -1;
|
||||
});
|
||||
}
|
||||
|
||||
if (!options.selection || options.selection === 'age') {
|
||||
// Oldest unspents first
|
||||
coins = coins.slice().sort(function(a, b) {
|
||||
@ -1106,12 +1100,24 @@ MTX.prototype.selectCoins = function selectCoins(coins, options) {
|
||||
}
|
||||
|
||||
function addCoins() {
|
||||
var coin;
|
||||
|
||||
while (index < coins.length) {
|
||||
coin = coins[index];
|
||||
|
||||
if (options.confirmed && coin.height === -1)
|
||||
continue;
|
||||
|
||||
if (network.height !== -1 && coin.coinbase) {
|
||||
if (network.height + 1 < coin.height + constants.tx.coinbaseMaturity)
|
||||
continue;
|
||||
}
|
||||
|
||||
// Add new inputs until TX will have enough
|
||||
// funds to cover both minimum post cost
|
||||
// and fee.
|
||||
tx.addInput(coins[index]);
|
||||
chosen.push(coins[index]);
|
||||
tx.addInput(coin);
|
||||
chosen.push(coin);
|
||||
index++;
|
||||
|
||||
if (options.selection === 'all')
|
||||
|
||||
Loading…
Reference in New Issue
Block a user