Address: Fix indentation, typos and simplify isValid
This commit is contained in:
parent
8f32063375
commit
0df97a42fe
|
@ -4,6 +4,7 @@ var base58check = require('./encoding/base58check');
|
|||
var networks = require('./networks');
|
||||
var Hash = require('./crypto/hash');
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* Bitcore Address
|
||||
|
@ -51,7 +52,7 @@ function Address(data, network, type) {
|
|||
throw new Error('Unrecognized data format');
|
||||
}
|
||||
|
||||
// set defaults is not set
|
||||
// set defaults if not set
|
||||
info.network = info.network || network || 'mainnet';
|
||||
info.type = info.type || type || 'pubkeyhash';
|
||||
|
||||
|
@ -105,25 +106,25 @@ Address._transformBuffer = function(buffer, network, type){
|
|||
var bufType = false;
|
||||
|
||||
switch(buffer[0]){ // the version byte
|
||||
case networks.mainnet.pubkeyhash:
|
||||
bufNetwork = 'mainnet';
|
||||
bufType = 'pubkeyhash';
|
||||
break;
|
||||
case networks.mainnet.pubkeyhash:
|
||||
bufNetwork = 'mainnet';
|
||||
bufType = 'pubkeyhash';
|
||||
break;
|
||||
|
||||
case networks.mainnet.scripthash:
|
||||
bufNetwork = 'mainnet';
|
||||
bufType = 'scripthash';
|
||||
break;
|
||||
case networks.mainnet.scripthash:
|
||||
bufNetwork = 'mainnet';
|
||||
bufType = 'scripthash';
|
||||
break;
|
||||
|
||||
case networks.testnet.pubkeyhash:
|
||||
bufNetwork = 'testnet';
|
||||
bufType = 'pubkeyhash';
|
||||
break;
|
||||
case networks.testnet.pubkeyhash:
|
||||
bufNetwork = 'testnet';
|
||||
bufType = 'pubkeyhash';
|
||||
break;
|
||||
|
||||
case networks.testnet.scripthash:
|
||||
bufNetwork = 'testnet';
|
||||
bufType = 'scripthash';
|
||||
break;
|
||||
case networks.testnet.scripthash:
|
||||
bufNetwork = 'testnet';
|
||||
bufType = 'scripthash';
|
||||
break;
|
||||
}
|
||||
|
||||
if (!bufNetwork || (network && network !== bufNetwork)) {
|
||||
|
@ -311,12 +312,7 @@ Address.getValidationError = function(data, network, type) {
|
|||
* @returns {null|Error} The corresponding error message
|
||||
*/
|
||||
Address.isValid = function(data, network, type) {
|
||||
var error = Address.getValidationError(data, network, type);
|
||||
if (error) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
return !Address.getValidationError(data, network, type);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -88,6 +88,16 @@ describe('Address', function() {
|
|||
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() {
|
||||
for(var i=0;i<validAddresses.length;i++){
|
||||
var error = Address.getValidationError(validAddresses[i]);
|
||||
|
|
Loading…
Reference in New Issue