Wallet: use enforceType where applicable
This commit is contained in:
parent
35542e115d
commit
deaf06b350
@ -1,6 +1,7 @@
|
|||||||
var assert = require('assert')
|
var assert = require('assert')
|
||||||
var bufferutils = require('./bufferutils')
|
var bufferutils = require('./bufferutils')
|
||||||
var crypto = require('crypto')
|
var crypto = require('crypto')
|
||||||
|
var enforceType = require('./types')
|
||||||
var networks = require('./networks')
|
var networks = require('./networks')
|
||||||
|
|
||||||
var Address = require('./address')
|
var Address = require('./address')
|
||||||
@ -300,15 +301,17 @@ Wallet.prototype.setUnspentOutputs = function(unspents) {
|
|||||||
index = unspent.outputIndex
|
index = unspent.outputIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.equal(typeof txId, 'string', 'Expected txId, got ' + txId)
|
enforceType('String', txId)
|
||||||
|
enforceType('Number', index)
|
||||||
|
enforceType('Number', unspent.value)
|
||||||
|
|
||||||
assert.equal(txId.length, 64, 'Expected valid txId, got ' + txId)
|
assert.equal(txId.length, 64, 'Expected valid txId, got ' + txId)
|
||||||
assert.doesNotThrow(function() { Address.fromBase58Check(unspent.address) }, 'Expected Base58 Address, got ' + unspent.address)
|
assert.doesNotThrow(function() { Address.fromBase58Check(unspent.address) }, 'Expected Base58 Address, got ' + unspent.address)
|
||||||
assert(isFinite(index), 'Expected number index, got ' + index)
|
assert(isFinite(index), 'Expected finite index, got ' + index)
|
||||||
assert.equal(typeof unspent.value, 'number', 'Expected number value, got ' + unspent.value)
|
|
||||||
|
|
||||||
// FIXME: remove branch in 2.0.0
|
// FIXME: remove branch in 2.0.0
|
||||||
if (unspent.confirmations !== undefined) {
|
if (unspent.confirmations !== undefined) {
|
||||||
assert.equal(typeof unspent.confirmations, 'number', 'Expected number confirmations, got ' + unspent.confirmations)
|
enforceType('Number', unspent.confirmations)
|
||||||
}
|
}
|
||||||
|
|
||||||
var txHash = bufferutils.reverse(new Buffer(txId, 'hex'))
|
var txHash = bufferutils.reverse(new Buffer(txId, 'hex'))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user