refactor networks

This commit is contained in:
Manuel Araoz 2015-04-20 12:21:14 -03:00
parent fb591b39c1
commit e25ffde6db
1 changed files with 15 additions and 12 deletions

View File

@ -26,7 +26,7 @@ Network.prototype.toString = function toString() {
* @param {string|Array} keys - if set, only check if the magic number associated with this name matches * @param {string|Array} keys - if set, only check if the magic number associated with this name matches
* @return Network * @return Network
*/ */
function getNetwork(arg, keys) { function get(arg, keys) {
if (~networks.indexOf(arg)) { if (~networks.indexOf(arg)) {
return arg; return arg;
} }
@ -34,8 +34,11 @@ function getNetwork(arg, keys) {
if (!_.isArray(keys)) { if (!_.isArray(keys)) {
keys = [keys]; keys = [keys];
} }
var containsArg = function(key) {
return networks[index][key] === arg;
};
for (var index in networks) { for (var index in networks) {
if (_.any(keys, function(key) { return networks[index][key] === arg; })) { if (_.any(keys, containsArg)) {
return networks[index]; return networks[index];
} }
} }
@ -148,16 +151,16 @@ addNetwork({
}); });
/** /**
* @instance * @instance
* @member Networks#livenet * @member Networks#livenet
*/ */
var livenet = getNetwork('livenet'); var livenet = get('livenet');
/** /**
* @instance * @instance
* @member Networks#testnet * @member Networks#testnet
*/ */
var testnet = getNetwork('testnet'); var testnet = get('testnet');
/** /**
* @namespace Networks * @namespace Networks
@ -169,5 +172,5 @@ module.exports = {
livenet: livenet, livenet: livenet,
mainnet: livenet, mainnet: livenet,
testnet: testnet, testnet: testnet,
get: getNetwork get: get
}; };