coinselect
Advanced tools
Comparing version 3.1.5 to 3.1.7
var utils = require('./utils') | ||
// O(n * n) | ||
// only add inputs if they don't bust the target value (aka, exact match) | ||
// worst-case: O(n) | ||
module.exports = function blackjack (utxos, outputs, feeRate) { | ||
@@ -9,3 +10,2 @@ if (!isFinite(utils.uintOrNaN(feeRate))) return {} | ||
// accumulate inputs until we bust | ||
var inAccum = 0 | ||
@@ -12,0 +12,0 @@ var inputs = [] |
11
index.js
@@ -1,3 +0,4 @@ | ||
var accumulative = require('./accum') | ||
var accumulative = require('./accumulative') | ||
var blackjack = require('./blackjack') | ||
var utils = require('./utils') | ||
@@ -32,6 +33,10 @@ // TODO | ||
// order by descending value, minus the inputs approximate fee | ||
function utxoScore (x, feeRate) { | ||
return x.value - (feeRate * utils.inputBytes(x)) | ||
} | ||
module.exports = function coinSelect (utxos, outputs, feeRate) { | ||
// order by descending value | ||
utxos = utxos.concat().sort(function (a, b) { | ||
return b.value - a.value | ||
return utxoScore(b, feeRate) - utxoScore(a, feeRate) | ||
}) | ||
@@ -38,0 +43,0 @@ |
{ | ||
"name": "coinselect", | ||
"version": "3.1.5", | ||
"version": "3.1.7", | ||
"description": "A transaction input selection module for bitcoin.", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -8,4 +8,4 @@ // baseline estimates, used to improve performance | ||
function inputBytes () { | ||
return TX_INPUT_BASE + TX_INPUT_PUBKEYHASH | ||
function inputBytes (input) { | ||
return TX_INPUT_BASE + (input.script ? input.script.length : TX_INPUT_PUBKEYHASH) | ||
} | ||
@@ -19,3 +19,3 @@ | ||
/* ... classify the output for input estimate */ | ||
return inputBytes() * feeRate | ||
return inputBytes({}) * feeRate | ||
} | ||
@@ -22,0 +22,0 @@ |
9941
8
184