MyCrypto/common/utils/node.ts

43 lines
1.0 KiB
TypeScript
Raw Normal View History

import { CustomNode } from 'libs/nodes';
2018-01-20 20:06:28 +00:00
import { NODES, NodeConfig, CustomNodeConfig } from 'config';
export function makeCustomNodeId(config: CustomNodeConfig): string {
return `${config.url}:${config.port}`;
}
export function getCustomNodeConfigFromId(
id: string,
configs: CustomNodeConfig[]
): CustomNodeConfig | undefined {
return configs.find(node => makeCustomNodeId(node) === id);
}
export function getNodeConfigFromId(
id: string,
configs: CustomNodeConfig[]
): NodeConfig | undefined {
if (NODES[id]) {
return NODES[id];
}
const config = getCustomNodeConfigFromId(id, configs);
if (config) {
return makeNodeConfigFromCustomConfig(config);
}
}
export function makeNodeConfigFromCustomConfig(config: CustomNodeConfig): NodeConfig {
2018-01-20 20:06:28 +00:00
interface Override extends NodeConfig {
network: any;
}
const customConfig: Override = {
network: config.network,
lib: new CustomNode(config),
service: 'your custom node',
estimateGas: true
};
2018-01-20 20:06:28 +00:00
return customConfig;
}