@pezkuwi/typegen 16.5.5
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/README.md +3 -0
- package/build/augment.d.ts +2 -0
- package/build/bundle.d.ts +2 -0
- package/build/extractChain.d.ts +1 -0
- package/build/fromChain.d.ts +1 -0
- package/build/fromDefs.d.ts +1 -0
- package/build/generate/consts.d.ts +5 -0
- package/build/generate/errors.d.ts +4 -0
- package/build/generate/events.d.ts +5 -0
- package/build/generate/index.d.ts +10 -0
- package/build/generate/interfaceRegistry.d.ts +4 -0
- package/build/generate/lookup.d.ts +4 -0
- package/build/generate/query.d.ts +5 -0
- package/build/generate/rpc.d.ts +6 -0
- package/build/generate/runtime.d.ts +7 -0
- package/build/generate/tsDef.d.ts +16 -0
- package/build/generate/tx.d.ts +5 -0
- package/build/generate/types.d.ts +12 -0
- package/build/index.d.ts +2 -0
- package/build/interfacesTs.d.ts +1 -0
- package/build/metadataMd.d.ts +1 -0
- package/build/packageDetect.d.ts +1 -0
- package/build/packageInfo.d.ts +6 -0
- package/build/scripts/polkadot-types-chain-info.mjs +7 -0
- package/build/scripts/polkadot-types-from-chain.mjs +7 -0
- package/build/scripts/polkadot-types-from-defs.mjs +7 -0
- package/build/scripts/polkadot-types-internal-interfaces.mjs +7 -0
- package/build/scripts/polkadot-types-internal-metadata.mjs +7 -0
- package/build/util/assert.d.ts +2 -0
- package/build/util/derived.d.ts +4 -0
- package/build/util/docs.d.ts +1 -0
- package/build/util/file.d.ts +2 -0
- package/build/util/formatting.d.ts +11 -0
- package/build/util/imports.d.ts +23 -0
- package/build/util/index.d.ts +15 -0
- package/build/util/initMeta.d.ts +12 -0
- package/build/util/register.d.ts +4 -0
- package/build/util/wsMeta.d.ts +4 -0
- package/package.json +52 -0
- package/scripts/polkadot-types-chain-info.mjs +7 -0
- package/scripts/polkadot-types-from-chain.mjs +7 -0
- package/scripts/polkadot-types-from-defs.mjs +7 -0
- package/scripts/polkadot-types-internal-interfaces.mjs +7 -0
- package/scripts/polkadot-types-internal-metadata.mjs +7 -0
- package/src/augment.ts +5 -0
- package/src/bundle.ts +5 -0
- package/src/extractChain.ts +54 -0
- package/src/fromChain.ts +123 -0
- package/src/fromDefs.ts +106 -0
- package/src/generate/consts.ts +112 -0
- package/src/generate/errors.ts +75 -0
- package/src/generate/events.ts +165 -0
- package/src/generate/index.ts +13 -0
- package/src/generate/interfaceRegistry.ts +85 -0
- package/src/generate/lookup.ts +294 -0
- package/src/generate/query.ts +169 -0
- package/src/generate/rpc.ts +158 -0
- package/src/generate/runtime.ts +284 -0
- package/src/generate/tsDef.ts +321 -0
- package/src/generate/tx.ts +152 -0
- package/src/generate/types.ts +26 -0
- package/src/index.ts +6 -0
- package/src/interfacesTs.ts +35 -0
- package/src/metadataMd.ts +844 -0
- package/src/packageDetect.ts +14 -0
- package/src/packageInfo.ts +6 -0
- package/src/templates/calls.hbs +30 -0
- package/src/templates/consts.hbs +28 -0
- package/src/templates/docs.hbs +7 -0
- package/src/templates/errors.hbs +28 -0
- package/src/templates/events.hbs +28 -0
- package/src/templates/header.hbs +2 -0
- package/src/templates/interfaceRegistry.hbs +15 -0
- package/src/templates/lookup/defs-named.hbs +12 -0
- package/src/templates/lookup/defs.hbs +15 -0
- package/src/templates/lookup/index.hbs +3 -0
- package/src/templates/lookup/types.hbs +14 -0
- package/src/templates/query.hbs +29 -0
- package/src/templates/rpc.hbs +22 -0
- package/src/templates/tsDef/index.hbs +3 -0
- package/src/templates/tsDef/moduleTypes.hbs +10 -0
- package/src/templates/tsDef/types.hbs +7 -0
- package/src/templates/tx.hbs +30 -0
- package/src/util/assert.ts +18 -0
- package/src/util/derived.spec.ts +58 -0
- package/src/util/derived.ts +133 -0
- package/src/util/docs.ts +13 -0
- package/src/util/file.ts +42 -0
- package/src/util/formatting.spec.ts +30 -0
- package/src/util/formatting.ts +295 -0
- package/src/util/imports.ts +164 -0
- package/src/util/index.ts +18 -0
- package/src/util/initMeta.ts +37 -0
- package/src/util/register.ts +12 -0
- package/src/util/wsMeta.ts +70 -0
- package/tsconfig.build.json +28 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.scripts.json +19 -0
- package/tsconfig.spec.json +17 -0
|
@@ -0,0 +1,844 @@
|
|
|
1
|
+
// Copyright 2017-2025 @polkadot/typegen authors & contributors
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import type { MetadataLatest, RuntimeApiMethodMetadataV16, SiLookupTypeId } from '@pezkuwi/types/interfaces';
|
|
5
|
+
import type { PortableRegistry } from '@pezkuwi/types/metadata';
|
|
6
|
+
import type { Text } from '@pezkuwi/types/primitive';
|
|
7
|
+
import type { Codec, DefinitionCall, DefinitionRpcParam, DefinitionsCall, Registry } from '@pezkuwi/types/types';
|
|
8
|
+
import type { HexString } from '@pezkuwi/util/types';
|
|
9
|
+
|
|
10
|
+
import { parse, type Spec } from 'comment-parser';
|
|
11
|
+
import fs from 'node:fs';
|
|
12
|
+
import path, { dirname, resolve } from 'node:path';
|
|
13
|
+
import process from 'node:process';
|
|
14
|
+
import { fileURLToPath } from 'node:url';
|
|
15
|
+
import yargs from 'yargs';
|
|
16
|
+
import { hideBin } from 'yargs/helpers';
|
|
17
|
+
|
|
18
|
+
import { derive } from '@pezkuwi/api-derive';
|
|
19
|
+
import { Metadata, TypeRegistry, Vec } from '@pezkuwi/types';
|
|
20
|
+
import * as definitions from '@pezkuwi/types/interfaces/definitions';
|
|
21
|
+
import { getStorage as getSubstrateStorage } from '@pezkuwi/types/metadata/decorate/storage/getStorage';
|
|
22
|
+
import { unwrapStorageType } from '@pezkuwi/types/util';
|
|
23
|
+
import assetHubKusamaMeta from '@pezkuwi/types-support/metadata/v15/asset-hub-kusama-hex';
|
|
24
|
+
import assetHubKusamaRpc from '@pezkuwi/types-support/metadata/v15/asset-hub-kusama-rpc';
|
|
25
|
+
import assetHubKusamaVer from '@pezkuwi/types-support/metadata/v15/asset-hub-kusama-ver';
|
|
26
|
+
import assetHubPolkadotMeta from '@pezkuwi/types-support/metadata/v15/asset-hub-polkadot-hex';
|
|
27
|
+
import assetHubPolkadotRpc from '@pezkuwi/types-support/metadata/v15/asset-hub-polkadot-rpc';
|
|
28
|
+
import assetHubPolkadotVer from '@pezkuwi/types-support/metadata/v15/asset-hub-polkadot-ver';
|
|
29
|
+
import kusamaMeta from '@pezkuwi/types-support/metadata/v15/kusama-hex';
|
|
30
|
+
import kusamaRpc from '@pezkuwi/types-support/metadata/v15/kusama-rpc';
|
|
31
|
+
import kusamaVer from '@pezkuwi/types-support/metadata/v15/kusama-ver';
|
|
32
|
+
import polkadotMeta from '@pezkuwi/types-support/metadata/v15/polkadot-hex';
|
|
33
|
+
import polkadotRpc from '@pezkuwi/types-support/metadata/v15/polkadot-rpc';
|
|
34
|
+
import polkadotVer from '@pezkuwi/types-support/metadata/v15/polkadot-ver';
|
|
35
|
+
import substrateMeta from '@pezkuwi/types-support/metadata/v15/substrate-hex';
|
|
36
|
+
import { isHex, stringCamelCase, stringLowerFirst } from '@pezkuwi/util';
|
|
37
|
+
import { blake2AsHex } from '@pezkuwi/util-crypto';
|
|
38
|
+
|
|
39
|
+
import { assertFile, getMetadataViaWs, getRpcMethodsViaWs, getRuntimeVersionViaWs } from './util/index.js';
|
|
40
|
+
|
|
41
|
+
interface SectionItem {
|
|
42
|
+
link?: string;
|
|
43
|
+
name: string;
|
|
44
|
+
[bullet: string]: undefined | string | Vec<Text>;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
interface Section {
|
|
48
|
+
link?: string;
|
|
49
|
+
name: string;
|
|
50
|
+
description?: string;
|
|
51
|
+
items: SectionItem[];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
interface Page {
|
|
55
|
+
title: string;
|
|
56
|
+
description: string;
|
|
57
|
+
sections: Section[];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
type ApiDef = [apiHash: string, apiVersion: number];
|
|
61
|
+
|
|
62
|
+
interface StaticDef {
|
|
63
|
+
meta: HexString;
|
|
64
|
+
rpc?: { methods: string[] };
|
|
65
|
+
ver?: { apis: ApiDef[] }
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
interface Derive {
|
|
69
|
+
name: string | null;
|
|
70
|
+
description: string | null;
|
|
71
|
+
params: DeriveParam[];
|
|
72
|
+
returns: string | null;
|
|
73
|
+
example: string | null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
interface DeriveParam {
|
|
77
|
+
description: string | null;
|
|
78
|
+
name: string | null;
|
|
79
|
+
type: string | null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const headerFn = (runtimeDesc: string) => `\n\n(NOTE: These were generated from a static/snapshot view of a recent ${runtimeDesc}. Some items may not be available in older nodes, or in any customized implementations.)`;
|
|
83
|
+
|
|
84
|
+
const ALL_STATIC: Record<string, StaticDef> = {
|
|
85
|
+
'asset-hub-kusama': {
|
|
86
|
+
meta: assetHubKusamaMeta,
|
|
87
|
+
rpc: assetHubKusamaRpc,
|
|
88
|
+
ver: assetHubKusamaVer as unknown as { apis: ApiDef[] }
|
|
89
|
+
},
|
|
90
|
+
'asset-hub-polkadot': {
|
|
91
|
+
meta: assetHubPolkadotMeta,
|
|
92
|
+
rpc: assetHubPolkadotRpc,
|
|
93
|
+
ver: assetHubPolkadotVer as unknown as { apis: ApiDef[] }
|
|
94
|
+
},
|
|
95
|
+
kusama: {
|
|
96
|
+
meta: kusamaMeta,
|
|
97
|
+
rpc: kusamaRpc,
|
|
98
|
+
ver: kusamaVer as unknown as { apis: ApiDef[] }
|
|
99
|
+
},
|
|
100
|
+
polkadot: {
|
|
101
|
+
meta: polkadotMeta,
|
|
102
|
+
rpc: polkadotRpc,
|
|
103
|
+
ver: polkadotVer as unknown as { apis: ApiDef[] }
|
|
104
|
+
},
|
|
105
|
+
substrate: {
|
|
106
|
+
meta: substrateMeta
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
/** @internal */
|
|
111
|
+
function docsVecToMarkdown (docLines: Vec<Text>, indent = 0): string {
|
|
112
|
+
const md = docLines
|
|
113
|
+
.map((docLine) =>
|
|
114
|
+
docLine
|
|
115
|
+
.toString()
|
|
116
|
+
.trimStart()
|
|
117
|
+
.replace(/^r"/g, '')
|
|
118
|
+
.trimStart()
|
|
119
|
+
)
|
|
120
|
+
.reduce((md, docLine) => // generate paragraphs
|
|
121
|
+
!docLine.length
|
|
122
|
+
? `${md}\n\n` // empty line
|
|
123
|
+
: /^[*-]/.test(docLine.trimStart()) && !md.endsWith('\n\n')
|
|
124
|
+
? `${md}\n\n${docLine}` // line calling for a preceding linebreak
|
|
125
|
+
: `${md} ${docLine.replace(/^#{1,3} /, '#### ')} `
|
|
126
|
+
, '')
|
|
127
|
+
.replace(/#### <weight>/g, '<weight>')
|
|
128
|
+
.replace(/<weight>(.|\n)*?<\/weight>/g, '')
|
|
129
|
+
.replace(/#### Weight:/g, 'Weight:');
|
|
130
|
+
|
|
131
|
+
// prefix each line with indentation
|
|
132
|
+
return md?.split('\n\n').map((line) => `${' '.repeat(indent)}${line}`).join('\n\n');
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function renderPage (page: Page): string {
|
|
136
|
+
let md = `---\ntitle: ${page.title}\n---\n\n`;
|
|
137
|
+
|
|
138
|
+
if (page.description) {
|
|
139
|
+
md += `${page.description}\n\n`;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// index
|
|
143
|
+
page.sections.forEach((section) => {
|
|
144
|
+
md += `- **[${stringCamelCase(section.name)}](#${stringCamelCase(section.name).toLowerCase()})**\n\n`;
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
// contents
|
|
148
|
+
page.sections.forEach((section) => {
|
|
149
|
+
md += '\n___\n\n\n';
|
|
150
|
+
md += section.link
|
|
151
|
+
? `<h2 id="#${section.link}">${section.name}</h2>\n`
|
|
152
|
+
: `## ${section.name}\n`;
|
|
153
|
+
|
|
154
|
+
if (section.description) {
|
|
155
|
+
md += `\n_${section.description}_\n`;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
section.items.forEach((item) => {
|
|
159
|
+
md += ' \n';
|
|
160
|
+
md += item.link
|
|
161
|
+
? `<h3 id="#${item.link}">${item.name}</h3>`
|
|
162
|
+
: `### ${item.name}`;
|
|
163
|
+
|
|
164
|
+
Object
|
|
165
|
+
.keys(item)
|
|
166
|
+
.filter((key) => !['link', 'name'].includes(key))
|
|
167
|
+
.forEach((bullet) => {
|
|
168
|
+
md += `\n- **${bullet}**: ${
|
|
169
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
170
|
+
item[bullet] instanceof Vec
|
|
171
|
+
? docsVecToMarkdown(item[bullet], 2).toString()
|
|
172
|
+
: item[bullet]
|
|
173
|
+
}`;
|
|
174
|
+
});
|
|
175
|
+
|
|
176
|
+
md += '\n';
|
|
177
|
+
});
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
return md;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function sortByName<T extends { name: Codec | string }> (a: T, b: T): number {
|
|
184
|
+
// case insensitive (all-uppercase) sorting
|
|
185
|
+
return a.name.toString().toUpperCase().localeCompare(b.name.toString().toUpperCase());
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function getSiName (lookup: PortableRegistry, type: SiLookupTypeId): string {
|
|
189
|
+
const typeDef = lookup.getTypeDef(type);
|
|
190
|
+
|
|
191
|
+
return typeDef.lookupName || typeDef.type;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/** @internal */
|
|
195
|
+
function addRpc (_runtimeDesc: string, rpcMethods?: string[]): string {
|
|
196
|
+
return renderPage({
|
|
197
|
+
description: 'The following sections contain known RPC methods that may be available on specific nodes (depending on configuration and available pallets) and allow you to interact with the actual node, query, and submit.',
|
|
198
|
+
sections: Object
|
|
199
|
+
.keys(definitions)
|
|
200
|
+
.filter((key) => Object.keys(definitions[key as 'babe'].rpc || {}).length !== 0)
|
|
201
|
+
.sort()
|
|
202
|
+
.reduce((all: Section[], _sectionName): Section[] => {
|
|
203
|
+
const section = definitions[_sectionName as 'babe'];
|
|
204
|
+
|
|
205
|
+
Object
|
|
206
|
+
.keys(section.rpc || {})
|
|
207
|
+
.sort()
|
|
208
|
+
.forEach((methodName) => {
|
|
209
|
+
const method = section.rpc?.[methodName];
|
|
210
|
+
|
|
211
|
+
if (!method) {
|
|
212
|
+
throw new Error(`No ${methodName} RPC found in ${_sectionName}`);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const sectionName = method.aliasSection || _sectionName;
|
|
216
|
+
const jsonrpc = (method.endpoint || `${sectionName}_${methodName}`);
|
|
217
|
+
|
|
218
|
+
if (rpcMethods) {
|
|
219
|
+
// if we are passing the rpcMethods params and we cannot find this method, skip it
|
|
220
|
+
if (jsonrpc !== 'rpc_methods' && !rpcMethods.includes(jsonrpc)) {
|
|
221
|
+
return;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const topName = method.aliasSection ? `${_sectionName}/${method.aliasSection}` : _sectionName;
|
|
226
|
+
let container = all.find(({ name }) => name === topName);
|
|
227
|
+
|
|
228
|
+
if (!container) {
|
|
229
|
+
container = { items: [], name: topName };
|
|
230
|
+
|
|
231
|
+
all.push(container);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const args = method.params.map(({ isOptional, name, type }: DefinitionRpcParam): string => {
|
|
235
|
+
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
|
|
236
|
+
return name + (isOptional ? '?' : '') + ': `' + type + '`';
|
|
237
|
+
}).join(', ');
|
|
238
|
+
const type = '`' + method.type + '`';
|
|
239
|
+
|
|
240
|
+
container.items.push({
|
|
241
|
+
interface: '`' + `api.rpc.${sectionName}.${methodName}` + '`',
|
|
242
|
+
jsonrpc: '`' + jsonrpc + '`',
|
|
243
|
+
// link: jsonrpc,
|
|
244
|
+
name: `${methodName}(${args}): ${type}`,
|
|
245
|
+
...((method.description && { summary: method.description }) || {}),
|
|
246
|
+
...((method.deprecated && { deprecated: method.deprecated }) || {}),
|
|
247
|
+
...((method.isUnsafe && { unsafe: 'This method is only active with appropriate flags' }) || {})
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
return all;
|
|
252
|
+
}, []).sort(sortByName),
|
|
253
|
+
title: 'JSON-RPC'
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
/** @internal */
|
|
258
|
+
function getMethods (registry: Registry, methods: Vec<RuntimeApiMethodMetadataV16>) {
|
|
259
|
+
const result: Record<string, DefinitionCall> = {};
|
|
260
|
+
|
|
261
|
+
methods.forEach((m) => {
|
|
262
|
+
const { docs, inputs, name, output } = m;
|
|
263
|
+
|
|
264
|
+
result[name.toString()] = {
|
|
265
|
+
description: docs.map((d) => d.toString()).join(),
|
|
266
|
+
params: inputs.map(({ name, type }) => {
|
|
267
|
+
return { name: name.toString(), type: registry.lookup.getName(type) || registry.lookup.getTypeDef(type).type };
|
|
268
|
+
}),
|
|
269
|
+
type: registry.lookup.getName(output) || registry.lookup.getTypeDef(output).type
|
|
270
|
+
};
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
return result;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/** @internal */
|
|
277
|
+
function getRuntimeDefViaMetadata (registry: Registry) {
|
|
278
|
+
const result: DefinitionsCall = {};
|
|
279
|
+
const { apis } = registry.metadata;
|
|
280
|
+
|
|
281
|
+
for (let i = 0, count = apis.length; i < count; i++) {
|
|
282
|
+
const { methods, name } = apis[i];
|
|
283
|
+
|
|
284
|
+
result[name.toString()] = [{
|
|
285
|
+
methods: getMethods(registry, methods),
|
|
286
|
+
// We set the version to 0 here since it will not be relevant when we are grabbing the runtime apis
|
|
287
|
+
// from the Metadata.
|
|
288
|
+
version: 0
|
|
289
|
+
}];
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
return Object.entries(result);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function runtimeSections (registry: Registry) {
|
|
296
|
+
const sections = getRuntimeDefViaMetadata(registry);
|
|
297
|
+
const all = [];
|
|
298
|
+
|
|
299
|
+
for (let j = 0, jcount = sections.length; j < jcount; j++) {
|
|
300
|
+
const [_section, secs] = sections[j];
|
|
301
|
+
const sec = secs[0];
|
|
302
|
+
|
|
303
|
+
const section = stringCamelCase(_section);
|
|
304
|
+
const methods = Object.entries(sec.methods);
|
|
305
|
+
|
|
306
|
+
const container: Section = { items: [], name: section };
|
|
307
|
+
|
|
308
|
+
all.push(container);
|
|
309
|
+
|
|
310
|
+
methods
|
|
311
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
312
|
+
.forEach(([methodName, { description, params, type }]): void => {
|
|
313
|
+
const args = params.map(({ name, type }): string => {
|
|
314
|
+
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
|
|
315
|
+
return name + ': `' + type + '`';
|
|
316
|
+
}).join(', ');
|
|
317
|
+
|
|
318
|
+
container.items.push({
|
|
319
|
+
interface: '`' + `api.call.${stringCamelCase(section)}.${stringCamelCase(methodName)}` + '`',
|
|
320
|
+
name: `${stringCamelCase(methodName)}(${args}): ${'`' + type + '`'}`,
|
|
321
|
+
runtime: '`' + `${section}_${methodName}` + '`',
|
|
322
|
+
summary: description
|
|
323
|
+
});
|
|
324
|
+
});
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
return all.sort(sortByName);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
/** @internal */
|
|
331
|
+
function addRuntime (_runtimeDesc: string, registry: Registry): string {
|
|
332
|
+
return renderPage({
|
|
333
|
+
description: 'The following section contains known runtime calls that may be available on specific runtimes (depending on configuration and available pallets). These call directly into the WASM runtime for queries and operations.',
|
|
334
|
+
sections: runtimeSections(registry),
|
|
335
|
+
title: 'Runtime'
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
/** @internal */
|
|
340
|
+
function addLegacyRuntime (_runtimeDesc: string, _registry: Registry, apis?: ApiDef[]) {
|
|
341
|
+
return renderPage({
|
|
342
|
+
description: 'The following section contains known runtime calls that may be available on specific runtimes (depending on configuration and available pallets). These call directly into the WASM runtime for queries and operations.',
|
|
343
|
+
sections: Object
|
|
344
|
+
.keys(definitions)
|
|
345
|
+
.filter((key) => Object.keys(definitions[key as 'babe'].runtime || {}).length !== 0)
|
|
346
|
+
.sort()
|
|
347
|
+
.reduce((all: Section[], _sectionName): Section[] => {
|
|
348
|
+
Object
|
|
349
|
+
.entries(definitions[_sectionName as 'babe'].runtime || {})
|
|
350
|
+
.forEach(([apiName, versions]) => {
|
|
351
|
+
versions
|
|
352
|
+
.sort((a, b) => b.version - a.version)
|
|
353
|
+
.forEach(({ methods, version }, index) => {
|
|
354
|
+
if (apis) {
|
|
355
|
+
// if we are passing the api hashes and we cannot find this one, skip it
|
|
356
|
+
const apiHash = blake2AsHex(apiName, 64);
|
|
357
|
+
const api = apis.find(([hash]) => hash === apiHash);
|
|
358
|
+
|
|
359
|
+
if (!api || api[1] !== version) {
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
} else if (index) {
|
|
363
|
+
// we only want the highest version
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
const container: Section = { items: [], name: apiName };
|
|
368
|
+
|
|
369
|
+
all.push(container);
|
|
370
|
+
|
|
371
|
+
Object
|
|
372
|
+
.entries(methods)
|
|
373
|
+
.sort(([a], [b]) => a.localeCompare(b))
|
|
374
|
+
.forEach(([methodName, { description, params, type }]): void => {
|
|
375
|
+
const args = params.map(({ name, type }): string => {
|
|
376
|
+
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
|
|
377
|
+
return name + ': `' + type + '`';
|
|
378
|
+
}).join(', ');
|
|
379
|
+
|
|
380
|
+
container.items.push({
|
|
381
|
+
interface: '`' + `api.call.${stringCamelCase(apiName)}.${stringCamelCase(methodName)}` + '`',
|
|
382
|
+
name: `${stringCamelCase(methodName)}(${args}): ${'`' + type + '`'}`,
|
|
383
|
+
runtime: '`' + `${apiName}_${methodName}` + '`',
|
|
384
|
+
summary: description
|
|
385
|
+
});
|
|
386
|
+
});
|
|
387
|
+
});
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
return all;
|
|
391
|
+
}, []).sort(sortByName),
|
|
392
|
+
title: 'Runtime'
|
|
393
|
+
});
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/** @internal */
|
|
397
|
+
function addConstants (runtimeDesc: string, { lookup, pallets }: MetadataLatest): string {
|
|
398
|
+
return renderPage({
|
|
399
|
+
description: `The following sections contain the module constants, also known as parameter types. These can only be changed as part of a runtime upgrade. On the api, these are exposed via \`api.consts.<module>.<method>\`. ${headerFn(runtimeDesc)}`,
|
|
400
|
+
sections: pallets
|
|
401
|
+
.sort(sortByName)
|
|
402
|
+
.filter(({ constants }) => !constants.isEmpty)
|
|
403
|
+
.map(({ constants, name }) => {
|
|
404
|
+
const sectionName = stringLowerFirst(name);
|
|
405
|
+
|
|
406
|
+
return {
|
|
407
|
+
items: constants
|
|
408
|
+
.sort(sortByName)
|
|
409
|
+
.map(({ docs, name, type }) => {
|
|
410
|
+
const methodName = stringCamelCase(name);
|
|
411
|
+
|
|
412
|
+
return {
|
|
413
|
+
interface: '`' + `api.consts.${sectionName}.${methodName}` + '`',
|
|
414
|
+
name: `${methodName}: ` + '`' + getSiName(lookup, type) + '`',
|
|
415
|
+
...(docs.length && { summary: docs })
|
|
416
|
+
};
|
|
417
|
+
}),
|
|
418
|
+
name: sectionName
|
|
419
|
+
};
|
|
420
|
+
}),
|
|
421
|
+
title: 'Constants'
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/** @internal */
|
|
426
|
+
function addStorage (runtimeDesc: string, { lookup, pallets, registry }: MetadataLatest): string {
|
|
427
|
+
const { substrate } = getSubstrateStorage(registry);
|
|
428
|
+
const moduleSections = pallets
|
|
429
|
+
.sort(sortByName)
|
|
430
|
+
.filter((moduleMetadata) => !moduleMetadata.storage.isNone)
|
|
431
|
+
.map((moduleMetadata): Section => {
|
|
432
|
+
const sectionName = stringLowerFirst(moduleMetadata.name);
|
|
433
|
+
|
|
434
|
+
return {
|
|
435
|
+
items: moduleMetadata.storage.unwrap().items
|
|
436
|
+
.sort(sortByName)
|
|
437
|
+
.map((func) => {
|
|
438
|
+
let arg = '';
|
|
439
|
+
|
|
440
|
+
if (func.type.isMap) {
|
|
441
|
+
const { hashers, key } = func.type.asMap;
|
|
442
|
+
|
|
443
|
+
arg = '`' + (
|
|
444
|
+
hashers.length === 1
|
|
445
|
+
? getSiName(lookup, key)
|
|
446
|
+
: lookup.getSiType(key).def.asTuple.map((t) => getSiName(lookup, t)).join(', ')
|
|
447
|
+
) + '`';
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
const methodName = stringLowerFirst(func.name);
|
|
451
|
+
const outputType = unwrapStorageType(registry, func.type, func.modifier.isOptional);
|
|
452
|
+
|
|
453
|
+
return {
|
|
454
|
+
interface: '`' + `api.query.${sectionName}.${methodName}` + '`',
|
|
455
|
+
name: `${methodName}(${arg}): ` + '`' + outputType + '`',
|
|
456
|
+
...(func.docs.length && { summary: func.docs })
|
|
457
|
+
};
|
|
458
|
+
}),
|
|
459
|
+
name: sectionName
|
|
460
|
+
};
|
|
461
|
+
});
|
|
462
|
+
|
|
463
|
+
return renderPage({
|
|
464
|
+
description: `The following sections contain Storage methods are part of the ${runtimeDesc}. On the api, these are exposed via \`api.query.<module>.<method>\`. ${headerFn(runtimeDesc)}`,
|
|
465
|
+
sections: moduleSections.concat([{
|
|
466
|
+
description: 'These are well-known keys that are always available to the runtime implementation of any Substrate-based network.',
|
|
467
|
+
items: Object.entries(substrate).map(([name, { meta }]) => {
|
|
468
|
+
const arg = meta.type.isMap
|
|
469
|
+
? ('`' + getSiName(lookup, meta.type.asMap.key) + '`')
|
|
470
|
+
: '';
|
|
471
|
+
const methodName = stringLowerFirst(name);
|
|
472
|
+
const outputType = unwrapStorageType(registry, meta.type, meta.modifier.isOptional);
|
|
473
|
+
|
|
474
|
+
return {
|
|
475
|
+
interface: '`' + `api.query.substrate.${methodName}` + '`',
|
|
476
|
+
name: `${methodName}(${arg}): ` + '`' + outputType + '`',
|
|
477
|
+
summary: meta.docs
|
|
478
|
+
};
|
|
479
|
+
}),
|
|
480
|
+
name: 'substrate'
|
|
481
|
+
}]).sort(sortByName),
|
|
482
|
+
title: 'Storage'
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/** @internal */
|
|
487
|
+
function addExtrinsics (runtimeDesc: string, { lookup, pallets }: MetadataLatest): string {
|
|
488
|
+
return renderPage({
|
|
489
|
+
description: `The following sections contain Extrinsics methods are part of the ${runtimeDesc}. On the api, these are exposed via \`api.tx.<module>.<method>\`. ${headerFn(runtimeDesc)}`,
|
|
490
|
+
sections: pallets
|
|
491
|
+
.sort(sortByName)
|
|
492
|
+
.filter(({ calls }) => calls.isSome)
|
|
493
|
+
.map(({ calls, name }) => {
|
|
494
|
+
const sectionName = stringCamelCase(name);
|
|
495
|
+
|
|
496
|
+
return {
|
|
497
|
+
items: lookup.getSiType(calls.unwrap().type).def.asVariant.variants
|
|
498
|
+
.sort(sortByName)
|
|
499
|
+
.map(({ docs, fields, name }, index) => {
|
|
500
|
+
const methodName = stringCamelCase(name);
|
|
501
|
+
const args = fields.map(({ name, type }) =>
|
|
502
|
+
`${name.isSome ? name.toString() : `param${index}`}: ` + '`' + getSiName(lookup, type) + '`'
|
|
503
|
+
).join(', ');
|
|
504
|
+
|
|
505
|
+
return {
|
|
506
|
+
interface: '`' + `api.tx.${sectionName}.${methodName}` + '`',
|
|
507
|
+
name: `${methodName}(${args})`,
|
|
508
|
+
...(docs.length && { summary: docs })
|
|
509
|
+
};
|
|
510
|
+
}),
|
|
511
|
+
name: sectionName
|
|
512
|
+
};
|
|
513
|
+
}),
|
|
514
|
+
title: 'Extrinsics'
|
|
515
|
+
});
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
/** @internal */
|
|
519
|
+
function addEvents (runtimeDesc: string, { lookup, pallets }: MetadataLatest): string {
|
|
520
|
+
return renderPage({
|
|
521
|
+
description: `Events are emitted for certain operations on the runtime. The following sections describe the events that are part of the ${runtimeDesc}. ${headerFn(runtimeDesc)}`,
|
|
522
|
+
sections: pallets
|
|
523
|
+
.sort(sortByName)
|
|
524
|
+
.filter(({ events }) => events.isSome)
|
|
525
|
+
.map((meta) => ({
|
|
526
|
+
items: lookup.getSiType(meta.events.unwrap().type).def.asVariant.variants
|
|
527
|
+
.sort(sortByName)
|
|
528
|
+
.map(({ docs, fields, name }) => {
|
|
529
|
+
const methodName = name.toString();
|
|
530
|
+
const args = fields.map(({ type }) =>
|
|
531
|
+
'`' + getSiName(lookup, type) + '`'
|
|
532
|
+
).join(', ');
|
|
533
|
+
|
|
534
|
+
return {
|
|
535
|
+
interface: '`' + `api.events.${stringCamelCase(meta.name)}.${methodName}.is` + '`',
|
|
536
|
+
name: `${methodName}(${args})`,
|
|
537
|
+
...(docs.length && { summary: docs })
|
|
538
|
+
};
|
|
539
|
+
}),
|
|
540
|
+
name: stringCamelCase(meta.name)
|
|
541
|
+
})),
|
|
542
|
+
title: 'Events'
|
|
543
|
+
});
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
/** @internal */
|
|
547
|
+
function addErrors (runtimeDesc: string, { lookup, pallets }: MetadataLatest): string {
|
|
548
|
+
return renderPage({
|
|
549
|
+
description: `This page lists the errors that can be encountered in the different modules. ${headerFn(runtimeDesc)}`,
|
|
550
|
+
sections: pallets
|
|
551
|
+
.sort(sortByName)
|
|
552
|
+
.filter(({ errors }) => errors.isSome)
|
|
553
|
+
.map((moduleMetadata) => ({
|
|
554
|
+
items: lookup.getSiType(moduleMetadata.errors.unwrap().type).def.asVariant.variants
|
|
555
|
+
.sort(sortByName)
|
|
556
|
+
.map((error) => ({
|
|
557
|
+
interface: '`' + `api.errors.${stringCamelCase(moduleMetadata.name)}.${error.name.toString()}.is` + '`',
|
|
558
|
+
name: error.name.toString(),
|
|
559
|
+
...(error.docs.length && { summary: error.docs })
|
|
560
|
+
})),
|
|
561
|
+
name: stringLowerFirst(moduleMetadata.name)
|
|
562
|
+
})),
|
|
563
|
+
title: 'Errors'
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
function getDependencyBasePath (moduleName: string): string {
|
|
568
|
+
const modulePath = import.meta.resolve(moduleName);
|
|
569
|
+
|
|
570
|
+
return resolve(dirname(fileURLToPath(modulePath)));
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
const BASE_DERIVE_PATH = getDependencyBasePath('@pezkuwi/api-derive');
|
|
574
|
+
|
|
575
|
+
// It finds all typescript file paths withing a given derive module.
|
|
576
|
+
const obtainDeriveFiles = (deriveModule: string) => {
|
|
577
|
+
const filePath = `${BASE_DERIVE_PATH}/${deriveModule}`;
|
|
578
|
+
const files = fs.readdirSync(filePath);
|
|
579
|
+
|
|
580
|
+
return files
|
|
581
|
+
.filter((file) => file.endsWith('.js'))
|
|
582
|
+
.map((file) => `${deriveModule}/${file}`);
|
|
583
|
+
};
|
|
584
|
+
|
|
585
|
+
function extractDeriveDescription (tags: Spec[], name: string) {
|
|
586
|
+
const descriptionTag = tags.find((tag) => tag.tag === name);
|
|
587
|
+
|
|
588
|
+
return descriptionTag
|
|
589
|
+
? `${descriptionTag.name ?? ''} ${descriptionTag.description ?? ''}`.trim()
|
|
590
|
+
: null;
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
function extractDeriveParams (tags: Spec[]) {
|
|
594
|
+
const descriptionTag = tags
|
|
595
|
+
.filter((tag) => tag.tag === 'param')
|
|
596
|
+
.map((param) => {
|
|
597
|
+
return {
|
|
598
|
+
description: param.description ?? null,
|
|
599
|
+
name: param.name ?? null,
|
|
600
|
+
type: param.type ?? null
|
|
601
|
+
};
|
|
602
|
+
});
|
|
603
|
+
|
|
604
|
+
return descriptionTag;
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
function extractDeriveExample (tags: Spec[]) {
|
|
608
|
+
const exampleTag = tags.find((tag) => tag.tag === 'example');
|
|
609
|
+
|
|
610
|
+
if (!exampleTag) {
|
|
611
|
+
return null;
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
let example = '';
|
|
615
|
+
const inCodeBlock = { done: false, found: false };
|
|
616
|
+
|
|
617
|
+
// Obtain code block from example tag.
|
|
618
|
+
exampleTag.source.forEach((line) => {
|
|
619
|
+
if (inCodeBlock.done) {
|
|
620
|
+
return;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
if (line.source.indexOf('```') !== -1 && !inCodeBlock.found) {
|
|
624
|
+
inCodeBlock.found = true;
|
|
625
|
+
} else if (line.source.indexOf('```') !== -1 && inCodeBlock.found) {
|
|
626
|
+
inCodeBlock.done = true;
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
if (!inCodeBlock.found) {
|
|
630
|
+
return;
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
example += line.source.slice(2, line.source.length);
|
|
634
|
+
|
|
635
|
+
if (!inCodeBlock.done) {
|
|
636
|
+
example += '\n';
|
|
637
|
+
}
|
|
638
|
+
});
|
|
639
|
+
|
|
640
|
+
return example;
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
// Parses the comments of a given derive file and adds the
|
|
644
|
+
// relevant information (name, description, params, returns, example).
|
|
645
|
+
const getDeriveDocs = (
|
|
646
|
+
metadata: Record<string, Derive[]>,
|
|
647
|
+
file: string
|
|
648
|
+
) => {
|
|
649
|
+
const filePath = `${BASE_DERIVE_PATH}/${file}`;
|
|
650
|
+
const deriveModule = file.split('/')[0];
|
|
651
|
+
const fileContent = fs.readFileSync(filePath, 'utf8');
|
|
652
|
+
const comments = parse(fileContent);
|
|
653
|
+
|
|
654
|
+
const docs: Derive[] = comments
|
|
655
|
+
.filter((comment) => comment.tags)
|
|
656
|
+
.map((comment) => {
|
|
657
|
+
return {
|
|
658
|
+
description: extractDeriveDescription(comment.tags, 'description'),
|
|
659
|
+
example: extractDeriveExample(comment.tags),
|
|
660
|
+
name: comment.tags.find((tag) => tag.tag === 'name')?.name || null,
|
|
661
|
+
params: extractDeriveParams(comment.tags),
|
|
662
|
+
returns: extractDeriveDescription(comment.tags, 'returns')
|
|
663
|
+
};
|
|
664
|
+
});
|
|
665
|
+
|
|
666
|
+
metadata[deriveModule]
|
|
667
|
+
? (metadata[deriveModule] = [...metadata[deriveModule], ...docs])
|
|
668
|
+
: (metadata[deriveModule] = [...docs]);
|
|
669
|
+
};
|
|
670
|
+
|
|
671
|
+
function renderDerives (metadata: Record<string, Derive[]>) {
|
|
672
|
+
let md = '---\ntitle: Derives\n---\n\nThis page lists the derives that can be encountered in the different modules. Designed to simplify the process of querying complex on-chain data by combining multiple RPC calls, storage queries, and runtime logic into a single, callable function. \n\nInstead of manually fetching and processing blockchain data, developers can use `api.derive.<module>.<method>()` to retrieve information.\n\n';
|
|
673
|
+
const deriveModules = Object.keys(metadata).filter(
|
|
674
|
+
(d) => metadata[d].length !== 0
|
|
675
|
+
);
|
|
676
|
+
|
|
677
|
+
// index
|
|
678
|
+
deriveModules.forEach((deriveModule) => {
|
|
679
|
+
md += `- **[${deriveModule}](#${deriveModule})**\n\n`;
|
|
680
|
+
});
|
|
681
|
+
|
|
682
|
+
// contents
|
|
683
|
+
deriveModules.forEach((deriveModule) => {
|
|
684
|
+
md += `\n___\n## ${deriveModule}\n`;
|
|
685
|
+
|
|
686
|
+
metadata[deriveModule]
|
|
687
|
+
.filter((item) => item.name)
|
|
688
|
+
.forEach((item) => {
|
|
689
|
+
const { description, example, name, params, returns } = item;
|
|
690
|
+
|
|
691
|
+
md += ` \n### [${name}](#${name})`;
|
|
692
|
+
|
|
693
|
+
if (description) {
|
|
694
|
+
md += `\n${description}`;
|
|
695
|
+
}
|
|
696
|
+
|
|
697
|
+
md += `\n- **interface**: \`api.derive.${deriveModule}.${name}\``;
|
|
698
|
+
|
|
699
|
+
if (params.length) {
|
|
700
|
+
md += '\n- **params**:\n';
|
|
701
|
+
params.forEach(
|
|
702
|
+
(param) =>
|
|
703
|
+
(md += ` - ${param.name} \`${param.type}\`: ${param.description}\n`)
|
|
704
|
+
);
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
if (returns) {
|
|
708
|
+
md += `\n- **returns**: ${returns}`;
|
|
709
|
+
}
|
|
710
|
+
|
|
711
|
+
if (example) {
|
|
712
|
+
md += `\n- **example**: \n${example}`;
|
|
713
|
+
}
|
|
714
|
+
});
|
|
715
|
+
});
|
|
716
|
+
|
|
717
|
+
return md;
|
|
718
|
+
}
|
|
719
|
+
|
|
720
|
+
function generateDerives () {
|
|
721
|
+
let fileList: string[] = [];
|
|
722
|
+
|
|
723
|
+
Object.keys(derive).forEach((deriveModule) => {
|
|
724
|
+
fileList = [...fileList, ...obtainDeriveFiles(deriveModule)];
|
|
725
|
+
});
|
|
726
|
+
|
|
727
|
+
const metadata = {};
|
|
728
|
+
|
|
729
|
+
fileList.forEach((file) => {
|
|
730
|
+
getDeriveDocs(metadata, file);
|
|
731
|
+
});
|
|
732
|
+
|
|
733
|
+
return renderDerives(metadata);
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
/** @internal */
|
|
737
|
+
function writeFile (name: string, ...chunks: any[]): void {
|
|
738
|
+
const writeStream = fs.createWriteStream(name, { encoding: 'utf8', flags: 'w' });
|
|
739
|
+
|
|
740
|
+
writeStream.on('finish', (): void => {
|
|
741
|
+
console.log(`Completed writing ${name}`);
|
|
742
|
+
});
|
|
743
|
+
|
|
744
|
+
chunks.forEach((chunk): void => {
|
|
745
|
+
writeStream.write(chunk);
|
|
746
|
+
});
|
|
747
|
+
|
|
748
|
+
writeStream.end();
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
interface ArgV { chain?: string; endpoint?: string; metadataVer?: number; }
|
|
752
|
+
|
|
753
|
+
async function mainPromise (): Promise<void> {
|
|
754
|
+
const { chain, endpoint, metadataVer } = yargs(hideBin(process.argv)).strict().options({
|
|
755
|
+
chain: {
|
|
756
|
+
description: 'The chain name to use for the output (defaults to "Substrate")',
|
|
757
|
+
type: 'string'
|
|
758
|
+
},
|
|
759
|
+
endpoint: {
|
|
760
|
+
description: 'The endpoint to connect to (e.g. wss://kusama-rpc.polkadot.io) or relative path to a file containing the JSON output of an RPC state_getMetadata call',
|
|
761
|
+
type: 'string'
|
|
762
|
+
},
|
|
763
|
+
metadataVer: {
|
|
764
|
+
description: 'The metadata version to use for generating type information. This will use state_call::Metadata_metadata_at_version to query metadata',
|
|
765
|
+
type: 'number'
|
|
766
|
+
}
|
|
767
|
+
}).argv as ArgV;
|
|
768
|
+
|
|
769
|
+
/**
|
|
770
|
+
* This is unique to when the endpoint arg is used. Since the endpoint requires us to query the chain, it may query the chains
|
|
771
|
+
* rpc state_getMetadata method to get metadata, but this restricts us to v14 only. Therefore we must also check if the `metadataVer` is passed
|
|
772
|
+
* in as well. These checks will help us decide if we are using v14 or newer.
|
|
773
|
+
*/
|
|
774
|
+
const useV14Metadata = endpoint && ((metadataVer && metadataVer < 15) || !metadataVer);
|
|
775
|
+
const chainName = chain || 'Substrate';
|
|
776
|
+
let metaHex: HexString;
|
|
777
|
+
let rpcMethods: string[] | undefined;
|
|
778
|
+
let runtimeApis: ApiDef[] | undefined;
|
|
779
|
+
|
|
780
|
+
if (endpoint) {
|
|
781
|
+
if (endpoint.startsWith('wss://') || endpoint.startsWith('ws://')) {
|
|
782
|
+
metaHex = await getMetadataViaWs(endpoint, metadataVer);
|
|
783
|
+
rpcMethods = await getRpcMethodsViaWs(endpoint);
|
|
784
|
+
runtimeApis = await getRuntimeVersionViaWs(endpoint);
|
|
785
|
+
} else {
|
|
786
|
+
metaHex = (
|
|
787
|
+
JSON.parse(
|
|
788
|
+
fs.readFileSync(assertFile(path.join(process.cwd(), endpoint)), 'utf-8')
|
|
789
|
+
) as { result: HexString }
|
|
790
|
+
).result;
|
|
791
|
+
|
|
792
|
+
if (!isHex(metaHex)) {
|
|
793
|
+
throw new Error('Invalid metadata file');
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
} else if (ALL_STATIC[chainName.toLowerCase()]) {
|
|
797
|
+
metaHex = ALL_STATIC[chainName.toLowerCase()].meta;
|
|
798
|
+
rpcMethods = ALL_STATIC[chainName.toLowerCase()].rpc?.methods;
|
|
799
|
+
} else {
|
|
800
|
+
metaHex = substrateMeta;
|
|
801
|
+
}
|
|
802
|
+
|
|
803
|
+
let metadata: Metadata;
|
|
804
|
+
const registry = new TypeRegistry();
|
|
805
|
+
|
|
806
|
+
if (useV14Metadata) {
|
|
807
|
+
metadata = new Metadata(registry, metaHex);
|
|
808
|
+
} else {
|
|
809
|
+
const opaqueMetadata = registry.createType('Option<OpaqueMetadata>', registry.createType('Raw', metaHex).toU8a()).unwrap();
|
|
810
|
+
|
|
811
|
+
metadata = new Metadata(registry, opaqueMetadata.toHex());
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
registry.setMetadata(metadata);
|
|
815
|
+
|
|
816
|
+
const latest = metadata.asLatest;
|
|
817
|
+
const runtimeDesc = `default ${chainName} runtime`;
|
|
818
|
+
const docRoot = `docs/${chainName.toLowerCase()}`;
|
|
819
|
+
|
|
820
|
+
writeFile(`${docRoot}/rpc.md`, addRpc(runtimeDesc, rpcMethods));
|
|
821
|
+
|
|
822
|
+
useV14Metadata
|
|
823
|
+
? writeFile(`${docRoot}/runtime.md`, addLegacyRuntime(runtimeDesc, registry, runtimeApis))
|
|
824
|
+
: writeFile(`${docRoot}/runtime.md`, addRuntime(runtimeDesc, registry));
|
|
825
|
+
|
|
826
|
+
writeFile(`${docRoot}/constants.md`, addConstants(runtimeDesc, latest));
|
|
827
|
+
writeFile(`${docRoot}/storage.md`, addStorage(runtimeDesc, latest));
|
|
828
|
+
writeFile(`${docRoot}/extrinsics.md`, addExtrinsics(runtimeDesc, latest));
|
|
829
|
+
writeFile(`${docRoot}/events.md`, addEvents(runtimeDesc, latest));
|
|
830
|
+
writeFile(`${docRoot}/errors.md`, addErrors(runtimeDesc, latest));
|
|
831
|
+
|
|
832
|
+
if (chainName === 'Substrate') {
|
|
833
|
+
writeFile('docs/derives/derives.md', generateDerives());
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
export function main (): void {
|
|
838
|
+
mainPromise().catch((error) => {
|
|
839
|
+
console.error();
|
|
840
|
+
console.error(error);
|
|
841
|
+
console.error();
|
|
842
|
+
process.exit(1);
|
|
843
|
+
});
|
|
844
|
+
}
|