Browse Source

Address: Fix indentation, typos and simplify isValid

patch-2
Braydon Fuller 10 years ago
parent
commit
0df97a42fe
  1. 10
      lib/address.js
  2. 10
      test/address.js

10
lib/address.js

@ -4,6 +4,7 @@ var base58check = require('./encoding/base58check');
var networks = require('./networks'); var networks = require('./networks');
var Hash = require('./crypto/hash'); var Hash = require('./crypto/hash');
/** /**
* *
* Bitcore Address * Bitcore Address
@ -51,7 +52,7 @@ function Address(data, network, type) {
throw new Error('Unrecognized data format'); throw new Error('Unrecognized data format');
} }
// set defaults is not set // set defaults if not set
info.network = info.network || network || 'mainnet'; info.network = info.network || network || 'mainnet';
info.type = info.type || type || 'pubkeyhash'; info.type = info.type || type || 'pubkeyhash';
@ -311,12 +312,7 @@ Address.getValidationError = function(data, network, type) {
* @returns {null|Error} The corresponding error message * @returns {null|Error} The corresponding error message
*/ */
Address.isValid = function(data, network, type) { Address.isValid = function(data, network, type) {
var error = Address.getValidationError(data, network, type); return !Address.getValidationError(data, network, type);
if (error) {
return false;
} else {
return true;
}
}; };
/** /**

10
test/address.js

@ -88,6 +88,16 @@ describe('Address', function() {
should.exist(error); should.exist(error);
}); });
it('should should return a true boolean', function(){
var valid = Address.isValid('37BahqRsFrAd3qLiNNwLNV3AWMRD7itxTo', 'mainnet');
valid.should.equal(true);
});
it('should should return a false boolean', function(){
var valid = Address.isValid('37BahqRsFrAd3qLiNNwLNV3AWMRD7itxTo', 'testnet');
valid.should.equal(false);
});
it('should validate addresses', function() { it('should validate addresses', function() {
for(var i=0;i<validAddresses.length;i++){ for(var i=0;i<validAddresses.length;i++){
var error = Address.getValidationError(validAddresses[i]); var error = Address.getValidationError(validAddresses[i]);

Loading…
Cancel
Save