forked from paritytech/substrate-api-sidecar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
84 lines (77 loc) · 3.12 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { ApiPromise } from '@polkadot/api';
import AbstractController from 'src/controllers/AbstractController';
import { AbstractService } from 'src/services/AbstractService';
import { controllers } from '../controllers';
import { ControllerConfig } from '../types/chains-config';
import { acalaControllers } from './acalaControllers';
import { calamariControllers } from './calamariControllers';
import { defaultControllers } from './defaultControllers';
import { dockMainnetControllers } from './dockMainnetControllers';
import { dockPoSMainnetControllers } from './dockPoSMainnetControllers';
import { dockTestnetControllers } from './dockPoSTestnetControllers';
import { karuraControllers } from './karuraControllers';
import { kiltControllers } from './kiltControllers';
import { kulupuControllers } from './kulupuControllers';
import { kusamaControllers } from './kusamaControllers';
import { mandalaControllers } from './mandalaControllers';
import { mantaControllers } from './mantaControllers';
import { polkadotControllers } from './polkadotControllers';
import { polymeshControllers } from './polymeshControllers';
import { shidenControllers } from './shidenControllers';
import { soraControllers } from './soraControllers';
import { statemineControllers } from './statemineControllers';
import { statemintControllers } from './statemintControllers';
import { westendControllers } from './westendControllers';
const specToControllerMap = {
westend: westendControllers,
polkadot: polkadotControllers,
polymesh: polymeshControllers,
kusama: kusamaControllers,
kulupu: kulupuControllers,
kilt: kiltControllers,
mandala: mandalaControllers,
'dock-main-runtime': dockMainnetControllers,
'dock-pos-main-runtime': dockPoSMainnetControllers,
'dock-pos-test-runtime': dockTestnetControllers,
statemine: statemineControllers,
statemint: statemintControllers,
westmine: statemineControllers,
westmint: statemintControllers,
shiden: shidenControllers,
sora: soraControllers,
calamari: calamariControllers,
karura: karuraControllers,
acala: acalaControllers,
manta: mantaControllers,
};
/**
* Return an array of instantiated controller instances based off of a `specName`.
*
* @param api ApiPromise to inject into controllers
* @param implName
*/
export function getControllersForSpec(
api: ApiPromise,
specName: string
): AbstractController<AbstractService>[] {
if (specToControllerMap[specName]) {
return getControllersFromConfig(api, specToControllerMap[specName]);
}
// If we don't have the specName in the specToControllerMap we use the default
// contoller config
return getControllersFromConfig(api, defaultControllers);
}
/**
* Return an array of instantiated controller instances based off of a
* `ControllerConfig`.
*
* @param api ApiPromise to inject into controllers
* @param config controller mount configuration object
*/
function getControllersFromConfig(api: ApiPromise, config: ControllerConfig) {
const controllersToInclude = config.controllers;
return controllersToInclude.reduce((acc, controller) => {
acc.push(new controllers[controller](api, config.options));
return acc;
}, [] as AbstractController<AbstractService>[]);
}