@osn/polkadot-api-container 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/apis/index.js +20 -2
package/package.json
CHANGED
package/src/apis/index.js
CHANGED
|
@@ -97,15 +97,32 @@ async function createApiInLimitTime(network, endpoint, logger = console) {
|
|
|
97
97
|
]);
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
async function createApiForChain(chain, endpoints, logger = console) {
|
|
101
|
+
for (const endpoint of endpoints) {
|
|
102
|
+
if (!endpoint) {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
try {
|
|
107
|
+
await createApiInLimitTime(chain, endpoint);
|
|
108
|
+
console.log(`${ chain }: ${ endpoint } created!`);
|
|
109
|
+
} catch (e) {
|
|
110
|
+
logger.info(
|
|
111
|
+
`Can not connected to ${ endpoint } in ${ nodeTimeoutSeconds } seconds, just disconnect it`
|
|
112
|
+
);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
100
117
|
function getApis(chain) {
|
|
101
118
|
return (chainApis[chain] || []).map(({ api }) => api);
|
|
102
119
|
}
|
|
103
120
|
|
|
104
121
|
function logApiStatus(logger = console) {
|
|
105
122
|
Object.entries(chainApis).map(([chain, apis]) => {
|
|
106
|
-
logger.info(`chain: ${chain}`);
|
|
123
|
+
logger.info(`chain: ${ chain }`);
|
|
107
124
|
for (const { endpoint, api } of apis) {
|
|
108
|
-
logger.info(`\t ${endpoint} connected: ${api.isConnected}`);
|
|
125
|
+
logger.info(`\t ${ endpoint } connected: ${ api.isConnected }`);
|
|
109
126
|
}
|
|
110
127
|
});
|
|
111
128
|
}
|
|
@@ -113,6 +130,7 @@ function logApiStatus(logger = console) {
|
|
|
113
130
|
module.exports = {
|
|
114
131
|
createApi,
|
|
115
132
|
createApiInLimitTime,
|
|
133
|
+
createApiForChain,
|
|
116
134
|
getApis,
|
|
117
135
|
logApiStatus,
|
|
118
136
|
}
|