Browse Source

Wallet: use assert for consistency

hk-custom-address
Daniel Cousens 11 years ago
parent
commit
3bce535e36
  1. 7
      src/wallet.js
  2. 4
      test/wallet.js

7
src/wallet.js

@ -1,3 +1,4 @@
var assert = require('assert')
var networks = require('./networks') var networks = require('./networks')
var rng = require('secure-random') var rng = require('secure-random')
@ -169,7 +170,7 @@ function Wallet(seed, network) {
} }
this.createTx = function(to, value, fixedFee, changeAddress) { this.createTx = function(to, value, fixedFee, changeAddress) {
if (value <= this.dustThreshold) throw new Error("Value must be above dust threshold") assert(value > this.dustThreshold, value + ' must be above dust threshold (' + this.dustThreshold + ' Satoshis)')
var utxos = getCandidateOutputs(value) var utxos = getCandidateOutputs(value)
var accum = 0 var accum = 0
@ -198,9 +199,7 @@ function Wallet(seed, network) {
} }
} }
if (accum < subTotal) { assert(accum >= subTotal, 'Not enough funds (incl. fee): ' + accum + ' < ' + subTotal)
throw new Error('Not enough funds: ' + accum + ' < ' + subTotal)
}
this.sign(tx) this.sign(tx)
return tx return tx

4
test/wallet.js

@ -546,7 +546,7 @@ describe('Wallet', function() {
assert.throws(function() { assert.throws(function() {
wallet.createTx(to, value) wallet.createTx(to, value)
}, /Value must be above dust threshold/) }, /5430 must be above dust threshold \(5430 Satoshis\)/)
}) })
}) })
@ -556,7 +556,7 @@ describe('Wallet', function() {
assert.throws(function() { assert.throws(function() {
wallet.createTx(to, value) wallet.createTx(to, value)
}, /Not enough funds: 1420000 < 1420001/) }, /Not enough funds \(incl. fee\): 1420000 < 1420001/)
}) })
}) })
}) })

Loading…
Cancel
Save