forked from ChrisCho-H/bitcoinselect
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
21 lines (17 loc) · 726 Bytes
/
Copy pathindex.js
File metadata and controls
21 lines (17 loc) · 726 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
var accumulative = require('./accumulative')
var blackjack = require('./blackjack')
var utils = require('./utils')
// 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, changeAddress) {
utxos = utxos.concat().sort(function (a, b) {
return utxoScore(b, feeRate) - utxoScore(a, feeRate)
})
// attempt to use the blackjack strategy first (no change output)
var base = blackjack(utxos, outputs, feeRate, changeAddress)
if (base.inputs) return base
// else, try the accumulative strategy
return accumulative(utxos, outputs, feeRate, changeAddress)
}