2017-11-18 20:33:53 +00:00
|
|
|
import { CustomNode } from 'libs/nodes';
|
|
|
|
import { NODES, NodeConfig, CustomNodeConfig } from 'config/data';
|
|
|
|
|
|
|
|
export function makeCustomNodeId(config: CustomNodeConfig): string {
|
|
|
|
return `${config.url}:${config.port}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getCustomNodeConfigFromId(
|
2017-11-29 23:14:57 +00:00
|
|
|
id: string,
|
|
|
|
configs: CustomNodeConfig[]
|
2017-11-18 20:33:53 +00:00
|
|
|
): CustomNodeConfig | undefined {
|
2017-11-29 23:14:57 +00:00
|
|
|
return configs.find(node => makeCustomNodeId(node) === id);
|
2017-11-18 20:33:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getNodeConfigFromId(
|
2017-11-29 23:14:57 +00:00
|
|
|
id: string,
|
|
|
|
configs: CustomNodeConfig[]
|
2017-11-18 20:33:53 +00:00
|
|
|
): NodeConfig | undefined {
|
|
|
|
if (NODES[id]) {
|
|
|
|
return NODES[id];
|
|
|
|
}
|
|
|
|
|
|
|
|
const config = getCustomNodeConfigFromId(id, configs);
|
|
|
|
if (config) {
|
|
|
|
return makeNodeConfigFromCustomConfig(config);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-18 23:29:26 +00:00
|
|
|
export function makeNodeConfigFromCustomConfig(config: CustomNodeConfig): NodeConfig {
|
2017-11-18 20:33:53 +00:00
|
|
|
return {
|
|
|
|
network: config.network,
|
|
|
|
lib: new CustomNode(config),
|
2017-11-29 23:14:57 +00:00
|
|
|
service: 'your custom node',
|
|
|
|
estimateGas: true
|
2017-11-18 20:33:53 +00:00
|
|
|
};
|
|
|
|
}
|