diff --git a/src/wallet.js b/src/wallet.js index 22e3c73..b7fe55e 100644 --- a/src/wallet.js +++ b/src/wallet.js @@ -22,6 +22,9 @@ function Wallet(seed, options) { this.addresses = [] this.changeAddresses = [] + // Dust value + this.dustThreshold = 5430 + // Transaction output data this.outputs = {} @@ -168,7 +171,7 @@ function Wallet(seed, options) { } this.createTx = function(to, value, fixedFee, changeAddress) { - if (isDust(value)) throw new Error("Value must be above dust threshold") + if (value <= this.dustThreshold) throw new Error("Value must be above dust threshold") var utxos = getCandidateOutputs(value) var accum = 0 @@ -189,7 +192,7 @@ function Wallet(seed, options) { if (accum >= subTotal) { var change = accum - subTotal - if (!isDust(change)) { + if (change > this.dustThreshold) { tx.addOutput(changeAddress || getChangeAddress(), change) } @@ -205,12 +208,6 @@ function Wallet(seed, options) { return tx } - - this.dustThreshold = 5430 - function isDust(amount) { - return amount <= me.dustThreshold - } - function getCandidateOutputs(value){ var unspent = [] for (var key in me.outputs){