2018-06-13 22:39:39 +03:00
|
|
|
'use strict';
|
|
|
|
var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
|
if (mod && mod.__esModule) return mod;
|
|
|
|
var result = {};
|
|
|
|
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
|
|
|
result["default"] = mod;
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
2018-09-24 23:07:14 +03:00
|
|
|
var errors = __importStar(require("../errors"));
|
2018-06-18 12:42:41 +03:00
|
|
|
var homestead = {
|
|
|
|
chainId: 1,
|
|
|
|
ensAddress: "0x314159265dd8dbb310642f98f50c066173c1259b",
|
|
|
|
name: "homestead"
|
|
|
|
};
|
|
|
|
var ropsten = {
|
|
|
|
chainId: 3,
|
|
|
|
ensAddress: "0x112234455c3a32fd11230c42e7bccd4a84e02010",
|
|
|
|
name: "ropsten"
|
|
|
|
};
|
|
|
|
var networks = {
|
|
|
|
unspecified: {
|
|
|
|
chainId: 0
|
2018-06-13 22:39:39 +03:00
|
|
|
},
|
2018-06-18 12:42:41 +03:00
|
|
|
homestead: homestead,
|
|
|
|
mainnet: homestead,
|
|
|
|
morden: {
|
|
|
|
chainId: 2
|
2018-06-13 22:39:39 +03:00
|
|
|
},
|
2018-06-18 12:42:41 +03:00
|
|
|
ropsten: ropsten,
|
|
|
|
testnet: ropsten,
|
|
|
|
rinkeby: {
|
|
|
|
chainId: 4,
|
|
|
|
ensAddress: "0xe7410170f87102DF0055eB195163A03B7F2Bff4A"
|
2018-06-13 22:39:39 +03:00
|
|
|
},
|
2018-06-18 12:42:41 +03:00
|
|
|
kovan: {
|
|
|
|
chainId: 42
|
2018-06-13 22:39:39 +03:00
|
|
|
},
|
2018-06-18 12:42:41 +03:00
|
|
|
classic: {
|
|
|
|
chainId: 61
|
2018-09-24 23:07:14 +03:00
|
|
|
},
|
|
|
|
classicTestnet: {
|
|
|
|
chainId: 62
|
2018-06-13 22:39:39 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
* getNetwork
|
|
|
|
*
|
2018-06-19 09:12:57 +03:00
|
|
|
* Converts a named common networks or chain ID (network ID) to a Network
|
|
|
|
* and verifies a network is a valid Network..
|
2018-06-13 22:39:39 +03:00
|
|
|
*/
|
|
|
|
function getNetwork(network) {
|
|
|
|
// No network (null) or unspecified (chainId = 0)
|
|
|
|
if (!network) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
if (typeof (network) === 'number') {
|
2018-06-18 12:42:41 +03:00
|
|
|
for (var name in networks) {
|
|
|
|
var n_1 = networks[name];
|
|
|
|
if (n_1.chainId === network) {
|
|
|
|
return {
|
|
|
|
name: name,
|
|
|
|
chainId: n_1.chainId,
|
|
|
|
ensAddress: n_1.ensAddress
|
|
|
|
};
|
2018-06-13 22:39:39 +03:00
|
|
|
}
|
|
|
|
}
|
2018-06-18 12:42:41 +03:00
|
|
|
return {
|
|
|
|
chainId: network,
|
|
|
|
name: 'unknown'
|
|
|
|
};
|
2018-06-13 22:39:39 +03:00
|
|
|
}
|
|
|
|
if (typeof (network) === 'string') {
|
2018-06-18 12:42:41 +03:00
|
|
|
var n_2 = networks[network];
|
|
|
|
if (n_2 == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
name: network,
|
|
|
|
chainId: n_2.chainId,
|
|
|
|
ensAddress: n_2.ensAddress
|
|
|
|
};
|
2018-06-13 22:39:39 +03:00
|
|
|
}
|
2018-06-18 12:42:41 +03:00
|
|
|
var n = networks[network.name];
|
2018-06-13 22:39:39 +03:00
|
|
|
// Not a standard network; check that it is a valid network in general
|
2018-06-18 12:42:41 +03:00
|
|
|
if (!n) {
|
2018-08-13 19:01:44 +03:00
|
|
|
if (typeof (network.chainId) !== 'number') {
|
2018-06-25 01:41:28 +03:00
|
|
|
errors.throwError('invalid network chainId', errors.INVALID_ARGUMENT, { arg: 'network', value: network });
|
2018-06-13 22:39:39 +03:00
|
|
|
}
|
|
|
|
return network;
|
|
|
|
}
|
|
|
|
// Make sure the chainId matches the expected network chainId (or is 0; disable EIP-155)
|
2018-06-18 12:42:41 +03:00
|
|
|
if (network.chainId !== 0 && network.chainId !== n.chainId) {
|
2018-06-25 01:41:28 +03:00
|
|
|
errors.throwError('network chainId mismatch', errors.INVALID_ARGUMENT, { arg: 'network', value: network });
|
2018-06-13 22:39:39 +03:00
|
|
|
}
|
2018-06-18 12:42:41 +03:00
|
|
|
// Standard Network
|
|
|
|
return {
|
|
|
|
name: network.name,
|
|
|
|
chainId: n.chainId,
|
|
|
|
ensAddress: n.ensAddress
|
|
|
|
};
|
2018-06-13 22:39:39 +03:00
|
|
|
}
|
|
|
|
exports.getNetwork = getNetwork;
|