From 4afdbc9f6820b24fc3a6c5dc58339682a8e5c19a Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Tue, 20 May 2014 16:17:44 +1000 Subject: [PATCH] Wallet: use dustThreshold directly The definition of a dust amount is pretty clear, and I feel it is less readable when represented as isDust(amount) or !isDust(amount), by comparison to amount <= dustThreshold or amount > dustThreshold. Also means I don't have to stray my eyes to understand the implemention by looking up isDust does. --- src/wallet.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) 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){