2017-11-18 20:33:53 +00:00
|
|
|
import { CustomNode } from 'libs/nodes';
|
2018-01-20 20:06:28 +00:00
|
|
|
import { NODES, NodeConfig, CustomNodeConfig } from 'config';
|
2017-11-18 20:33:53 +00:00
|
|
|
|
|
|
|
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 {
|
2018-01-20 20:06:28 +00:00
|
|
|
interface Override extends NodeConfig {
|
|
|
|
network: any;
|
|
|
|
}
|
|
|
|
|
|
|
|
const customConfig: Override = {
|
2017-11-18 20:33:53 +00:00
|
|
|
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
|
|
|
};
|
2018-01-20 20:06:28 +00:00
|
|
|
|
|
|
|
return customConfig;
|
2017-11-18 20:33:53 +00:00
|
|
|
}
|