-
Notifications
You must be signed in to change notification settings - Fork 158
/
Copy pathindex.ts
117 lines (109 loc) · 4.88 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Copyright 2017-2025 Parity Technologies (UK) Ltd.
// This file is part of Substrate API Sidecar.
//
// Substrate API Sidecar is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
import { ApiPromise } from '@polkadot/api';
import { controllers } from '../controllers';
import AbstractController from '../controllers/AbstractController';
import { AbstractService } from '../services/AbstractService';
import { ControllerConfig } from '../types/chains-config';
import { acalaControllers } from './acalaControllers';
import { assetHubKusamaControllers } from './assetHubKusamaControllers';
import { assetHubPolkadotControllers } from './assetHubPolkadotControllers';
import { assetHubWestendControllers } from './assetHubWestendControllers';
import { astarControllers } from './astarControllers';
import { bifrostControllers } from './bifrostControllers';
import { bifrostPolkadotControllers } from './bifrostPolkadotControllers';
import { calamariControllers } from './calamariControllers';
import { coretimeControllers } from './coretimeControllers';
import { crustControllers } from './crustControllers';
import { defaultControllers } from './defaultControllers';
import { dockMainnetControllers } from './dockMainnetControllers';
import { dockPoSMainnetControllers } from './dockPoSMainnetControllers';
import { dockTestnetControllers } from './dockPoSTestnetControllers';
import { heikoControllers } from './heikoControllers';
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 { parallelControllers } from './parallelControllers';
import { polkadotControllers } from './polkadotControllers';
import { polymeshControllers } from './polymeshControllers';
import { shidenControllers } from './shidenControllers';
import { soraControllers } from './soraControllers';
import { westendControllers } from './westendControllers';
const specToControllerMap: { [x: string]: ControllerConfig } = {
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,
'asset-hub-kusama': assetHubKusamaControllers,
'asset-hub-polkadot': assetHubPolkadotControllers,
statemine: assetHubKusamaControllers,
statemint: assetHubPolkadotControllers,
westmine: assetHubKusamaControllers,
'asset-hub-westend': assetHubWestendControllers,
westmint: assetHubWestendControllers,
shiden: shidenControllers,
astar: astarControllers,
sora: soraControllers,
calamari: calamariControllers,
karura: karuraControllers,
acala: acalaControllers,
manta: mantaControllers,
crust: crustControllers,
bifrost: bifrostControllers,
bifrost_polkadot: bifrostPolkadotControllers,
heiko: heikoControllers,
parallel: parallelControllers,
'coretime-westend': coretimeControllers,
'coretime-polkadot': coretimeControllers,
'coretime-kusama': coretimeControllers,
};
/**
* 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>[]);
}