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.
This commit is contained in:
parent
bd3690bdc0
commit
4afdbc9f68
1 changed files with 5 additions and 8 deletions
|
@ -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){
|
||||
|
|
Loading…
Reference in a new issue