mtx: add by-value sorting.
This commit is contained in:
parent
a81733a720
commit
695305cf68
@ -1448,7 +1448,7 @@ function CoinSelector(tx, options) {
|
||||
this.change = 0;
|
||||
this.fee = CoinSelector.MIN_FEE;
|
||||
|
||||
this.selection = 'age';
|
||||
this.selection = 'value';
|
||||
this.shouldSubtract = false;
|
||||
this.subtractFee = null;
|
||||
this.height = -1;
|
||||
@ -1600,6 +1600,9 @@ CoinSelector.prototype.init = function init(coins) {
|
||||
case 'age':
|
||||
this.coins.sort(sortAge);
|
||||
break;
|
||||
case 'value':
|
||||
this.coins.sort(sortValue);
|
||||
break;
|
||||
default:
|
||||
throw new FundingError('Bad selection type: ' + this.selection);
|
||||
}
|
||||
@ -1839,6 +1842,14 @@ function sortRandom(a, b) {
|
||||
return Math.random() > 0.5 ? 1 : -1;
|
||||
}
|
||||
|
||||
function sortValue(a, b) {
|
||||
if (a.height === -1 && b.height !== -1)
|
||||
return 1;
|
||||
if (a.height !== -1 && b.height === -1)
|
||||
return -1;
|
||||
return b.value - a.value;
|
||||
}
|
||||
|
||||
function sortInputs(a, b) {
|
||||
var ahash = a.prevout.txid();
|
||||
var bhash = b.prevout.txid();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user