mtx: add by-value sorting.

This commit is contained in:
Christopher Jeffrey 2017-03-08 07:40:36 -08:00
parent a81733a720
commit 695305cf68
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -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();