Skip to content

Commit

Permalink
Match to inputs first if there are confirmations, if not, then match …
Browse files Browse the repository at this point in the history
…to all
  • Loading branch information
OstlerDev committed Jul 9, 2018
1 parent 898bdff commit 64fdf8c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "oip-hdmw",
"version": "1.0.4",
"version": "1.0.5",
"description": "BIP44 Javascript Wallet",
"main": "lib/index.js",
"scripts": {
Expand Down
13 changes: 11 additions & 2 deletions src/TransactionBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ class TransactionBuilder {
txId: utxo.txid,
vout: utxo.vout,
scriptPubKey: utxo.scriptPubKey,
value: utxo.satoshis
value: utxo.satoshis,
confirmations: utxo.confirmations
}
})

Expand All @@ -267,7 +268,15 @@ class TransactionBuilder {
if (extraBytes)
extraBytesLength = extraBytes.length

return coinselect(formattedUtxos, targets, Math.ceil(this.coin.feePerByte), extraBytesLength)
var utxosNoUnconfirmed = formattedUtxos.filter(utx => utx.confirmations > 0)

var selected = coinselect(utxosNoUnconfirmed, targets, Math.ceil(this.coin.feePerByte), extraBytesLength)

// Check if we are able to build inputs/outputs off only unconfirmed transactions with confirmations > 0
if (selected.inputs && selected.inputs.length > 0 && selected.outputs && selected.outputs.length > 0 && selected.fee)
return selected
else // else, build with the regular ones
return coinselect(formattedUtxos, targets, Math.ceil(this.coin.feePerByte), extraBytesLength)
}).catch(err => {throw new Error(err)})
}).catch(err => {throw new Error(err)})
}
Expand Down

0 comments on commit 64fdf8c

Please sign in to comment.