refactor networks
This commit is contained in:
parent
fb591b39c1
commit
e25ffde6db
@ -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];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -115,7 +118,7 @@ addNetwork({
|
|||||||
pubkeyhash: 0x00,
|
pubkeyhash: 0x00,
|
||||||
privatekey: 0x80,
|
privatekey: 0x80,
|
||||||
scripthash: 0x05,
|
scripthash: 0x05,
|
||||||
xpubkey: 0x0488b21e,
|
xpubkey: 0x0488b21e,
|
||||||
xprivkey: 0x0488ade4,
|
xprivkey: 0x0488ade4,
|
||||||
networkMagic: 0xf9beb4d9,
|
networkMagic: 0xf9beb4d9,
|
||||||
port: 8333,
|
port: 8333,
|
||||||
@ -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
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user