@dedot/codegen 0.0.1-next.ce93b605.2 → 0.0.1-next.d9aff57d.57
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/cjs/generator/ConstsGen.js +12 -13
- package/cjs/generator/ErrorsGen.js +15 -16
- package/cjs/generator/EventsGen.js +16 -17
- package/cjs/generator/IndexGen.js +13 -10
- package/cjs/generator/JsonRpcGen.js +59 -0
- package/cjs/generator/QueryGen.js +26 -18
- package/cjs/generator/RuntimeApisGen.js +107 -33
- package/cjs/generator/TxGen.js +23 -21
- package/cjs/generator/TypeImports.js +13 -3
- package/cjs/generator/TypesGen.js +22 -29
- package/cjs/generator/index.js +10 -10
- package/cjs/generator/known-codecs.js +1 -1
- package/cjs/generator/utils.js +30 -1
- package/cjs/index.js +42 -41
- package/cjs/templates/consts.hbs +1 -1
- package/cjs/templates/errors.hbs +1 -1
- package/cjs/templates/events.hbs +1 -1
- package/cjs/templates/index.hbs +15 -10
- package/cjs/templates/json-rpc.hbs +5 -0
- package/cjs/templates/query.hbs +1 -1
- package/cjs/templates/runtime.hbs +1 -1
- package/cjs/templates/tx.hbs +1 -1
- package/generator/ApiGen.d.ts +1 -1
- package/generator/ConstsGen.d.ts +2 -2
- package/generator/ConstsGen.js +7 -8
- package/generator/ErrorsGen.d.ts +2 -2
- package/generator/ErrorsGen.js +8 -9
- package/generator/EventsGen.d.ts +2 -2
- package/generator/EventsGen.js +8 -9
- package/generator/IndexGen.d.ts +3 -4
- package/generator/IndexGen.js +12 -9
- package/generator/JsonRpcGen.d.ts +8 -0
- package/generator/JsonRpcGen.js +55 -0
- package/generator/QueryGen.d.ts +2 -2
- package/generator/QueryGen.js +23 -15
- package/generator/RuntimeApisGen.d.ts +6 -6
- package/generator/RuntimeApisGen.js +97 -23
- package/generator/TxGen.d.ts +2 -2
- package/generator/TxGen.js +13 -11
- package/generator/TypeImports.d.ts +8 -1
- package/generator/TypeImports.js +13 -3
- package/generator/TypesGen.d.ts +3 -3
- package/generator/TypesGen.js +7 -14
- package/generator/index.d.ts +10 -10
- package/generator/index.js +10 -10
- package/generator/known-codecs.d.ts +1 -1
- package/generator/known-codecs.js +1 -1
- package/generator/utils.d.ts +5 -0
- package/generator/utils.js +28 -0
- package/index.d.ts +2 -3
- package/index.js +33 -32
- package/package.json +15 -18
- package/templates/consts.hbs +1 -1
- package/templates/errors.hbs +1 -1
- package/templates/events.hbs +1 -1
- package/templates/index.hbs +15 -10
- package/templates/json-rpc.hbs +5 -0
- package/templates/query.hbs +1 -1
- package/templates/runtime.hbs +1 -1
- package/templates/tx.hbs +1 -1
- package/cjs/genSupportedChainTypes.js +0 -83
- package/cjs/generator/RpcGen.js +0 -176
- package/cjs/generator/known-types.js +0 -33
- package/cjs/packageInfo.js +0 -5
- package/cjs/templates/rpc.hbs +0 -7
- package/cjs/types.js +0 -2
- package/genSupportedChainTypes.d.ts +0 -1
- package/genSupportedChainTypes.js +0 -78
- package/generator/RpcGen.d.ts +0 -10
- package/generator/RpcGen.js +0 -172
- package/generator/known-types.d.ts +0 -6
- package/generator/known-types.js +0 -30
- package/packageInfo.d.ts +0 -4
- package/packageInfo.js +0 -2
- package/templates/rpc.hbs +0 -7
- package/types.d.ts +0 -6
- package/types.js +0 -1
package/generator/TypesGen.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
import { stringPascalCase } from '@polkadot/util';
|
|
2
1
|
import { PortableRegistry } from '@dedot/codecs';
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { findKnownCodec, findKnownCodecType, isKnownCodecType } from './known-codecs';
|
|
2
|
+
import { normalizeName, stringPascalCase } from '@dedot/utils';
|
|
3
|
+
import { TypeImports } from './TypeImports.js';
|
|
4
|
+
import { findKnownCodec, findKnownCodecType, isKnownCodecType } from './known-codecs.js';
|
|
5
|
+
import { beautifySourceCode, commentBlock, compileTemplate, isNativeType } from './utils.js';
|
|
8
6
|
// Skip generate types for these
|
|
9
7
|
// as we do have native types for them
|
|
10
8
|
const SKIP_TYPES = [
|
|
@@ -42,7 +40,7 @@ export class TypesGen {
|
|
|
42
40
|
this.includedTypes = this.#includedTypes();
|
|
43
41
|
this.typeImports = new TypeImports();
|
|
44
42
|
}
|
|
45
|
-
generate() {
|
|
43
|
+
generate(useSubPaths = false) {
|
|
46
44
|
this.clearCache();
|
|
47
45
|
let defTypeOut = '';
|
|
48
46
|
Object.values(this.includedTypes)
|
|
@@ -53,7 +51,7 @@ export class TypesGen {
|
|
|
53
51
|
defTypeOut += `export type ${name} = ${this.generateType(id)};\n\n`;
|
|
54
52
|
}
|
|
55
53
|
});
|
|
56
|
-
const importTypes = this.typeImports.toImports('./types');
|
|
54
|
+
const importTypes = this.typeImports.toImports({ useSubPaths, excludeModules: ['./types'] });
|
|
57
55
|
const template = compileTemplate('types.hbs');
|
|
58
56
|
return beautifySourceCode(template({ importTypes, defTypeOut }));
|
|
59
57
|
}
|
|
@@ -423,11 +421,6 @@ export class TypesGen {
|
|
|
423
421
|
this.typeImports.addCodecType(typeName);
|
|
424
422
|
return;
|
|
425
423
|
}
|
|
426
|
-
|
|
427
|
-
this.typeImports.addKnownType(typeName);
|
|
428
|
-
}
|
|
429
|
-
else {
|
|
430
|
-
this.typeImports.addOutType(typeName);
|
|
431
|
-
}
|
|
424
|
+
this.typeImports.addOutType(typeName);
|
|
432
425
|
}
|
|
433
426
|
}
|
package/generator/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export * from './TypesGen';
|
|
2
|
-
export * from './ApiGen';
|
|
3
|
-
export * from './ConstsGen';
|
|
4
|
-
export * from './QueryGen';
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './IndexGen';
|
|
7
|
-
export * from './ErrorsGen';
|
|
8
|
-
export * from './EventsGen';
|
|
9
|
-
export * from './TxGen';
|
|
10
|
-
export * from './RuntimeApisGen';
|
|
1
|
+
export * from './TypesGen.js';
|
|
2
|
+
export * from './ApiGen.js';
|
|
3
|
+
export * from './ConstsGen.js';
|
|
4
|
+
export * from './QueryGen.js';
|
|
5
|
+
export * from './JsonRpcGen.js';
|
|
6
|
+
export * from './IndexGen.js';
|
|
7
|
+
export * from './ErrorsGen.js';
|
|
8
|
+
export * from './EventsGen.js';
|
|
9
|
+
export * from './TxGen.js';
|
|
10
|
+
export * from './RuntimeApisGen.js';
|
package/generator/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
export * from './TypesGen';
|
|
2
|
-
export * from './ApiGen';
|
|
3
|
-
export * from './ConstsGen';
|
|
4
|
-
export * from './QueryGen';
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './IndexGen';
|
|
7
|
-
export * from './ErrorsGen';
|
|
8
|
-
export * from './EventsGen';
|
|
9
|
-
export * from './TxGen';
|
|
10
|
-
export * from './RuntimeApisGen';
|
|
1
|
+
export * from './TypesGen.js';
|
|
2
|
+
export * from './ApiGen.js';
|
|
3
|
+
export * from './ConstsGen.js';
|
|
4
|
+
export * from './QueryGen.js';
|
|
5
|
+
export * from './JsonRpcGen.js';
|
|
6
|
+
export * from './IndexGen.js';
|
|
7
|
+
export * from './ErrorsGen.js';
|
|
8
|
+
export * from './EventsGen.js';
|
|
9
|
+
export * from './TxGen.js';
|
|
10
|
+
export * from './RuntimeApisGen.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import * as $ from '@dedot/shape';
|
|
2
1
|
import * as Codecs from '@dedot/codecs';
|
|
3
2
|
import { $AccountId20, $AccountId32, $Bytes, $ConsensusEngineId, $Era, $EthereumAddress, $MultiAddress, $OpaqueExtrinsic, $PrefixedStorageKey, $RawBytes, $StorageData, $StorageKey, $UncheckedExtrinsic, } from '@dedot/codecs';
|
|
3
|
+
import * as $ from '@dedot/shape';
|
|
4
4
|
import { assert } from '@dedot/utils';
|
|
5
5
|
export const normalizeCodecName = (name) => {
|
|
6
6
|
return name.startsWith('$') ? name : `$${name}`;
|
package/generator/utils.d.ts
CHANGED
|
@@ -8,3 +8,8 @@ export declare const compileTemplate: (templateFileName: string) => HandlebarsTe
|
|
|
8
8
|
* @param word
|
|
9
9
|
*/
|
|
10
10
|
export declare const isReservedWord: (word: string) => boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Check if a type is native JS/TS type
|
|
13
|
+
* @param type
|
|
14
|
+
*/
|
|
15
|
+
export declare const isNativeType: (type: string) => boolean;
|
package/generator/utils.js
CHANGED
|
@@ -33,3 +33,31 @@ const TS_RESERVED_WORDS = ['new', 'class'];
|
|
|
33
33
|
* @param word
|
|
34
34
|
*/
|
|
35
35
|
export const isReservedWord = (word) => TS_RESERVED_WORDS.includes(word);
|
|
36
|
+
const TS_PRIMITIVE_TYPES = [
|
|
37
|
+
'void',
|
|
38
|
+
'undefined',
|
|
39
|
+
'null',
|
|
40
|
+
'number',
|
|
41
|
+
'boolean',
|
|
42
|
+
'bigint',
|
|
43
|
+
'Map',
|
|
44
|
+
'Set',
|
|
45
|
+
'string',
|
|
46
|
+
'any',
|
|
47
|
+
'Array',
|
|
48
|
+
'Record',
|
|
49
|
+
];
|
|
50
|
+
/**
|
|
51
|
+
* Check if a type is native JS/TS type
|
|
52
|
+
* @param type
|
|
53
|
+
*/
|
|
54
|
+
export const isNativeType = (type) => {
|
|
55
|
+
return TS_PRIMITIVE_TYPES.some((one) => {
|
|
56
|
+
if (typeof one === 'string') {
|
|
57
|
+
return one === type;
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
return type.match(one);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
};
|
package/index.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
1
|
import { MetadataLatest } from '@dedot/codecs';
|
|
2
|
-
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function generateTypes(network: NetworkInfo, metadata: MetadataLatest, rpcMethods: string[], runtimeApis: any[], outDir?: string): Promise<void>;
|
|
2
|
+
export declare function generateTypesFromEndpoint(chain: string, endpoint: string, outDir?: string, extension?: string, useSubPaths?: boolean): Promise<void>;
|
|
3
|
+
export declare function generateTypes(chain: string, metadata: MetadataLatest, rpcMethods: string[], runtimeApis: Record<string, number>, outDir?: string, extension?: string, useSubPaths?: boolean): Promise<void>;
|
package/index.js
CHANGED
|
@@ -1,48 +1,49 @@
|
|
|
1
|
-
import { Dedot } from 'dedot';
|
|
1
|
+
import { Dedot } from '@dedot/api';
|
|
2
|
+
import { WsProvider } from '@dedot/providers';
|
|
3
|
+
import { stringCamelCase } from '@dedot/utils';
|
|
2
4
|
import * as fs from 'fs';
|
|
3
5
|
import * as path from 'path';
|
|
4
|
-
import { ConstsGen, ErrorsGen, EventsGen, IndexGen,
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
network.chain = stringCamelCase(api.runtimeVersion?.specName || api.runtimeChain || 'local');
|
|
6
|
+
import { ConstsGen, ErrorsGen, EventsGen, IndexGen, JsonRpcGen, QueryGen, RuntimeApisGen, TxGen, TypesGen, } from './generator/index.js';
|
|
7
|
+
export async function generateTypesFromEndpoint(chain, endpoint, outDir, extension = 'd.ts', useSubPaths = false) {
|
|
8
|
+
const api = await Dedot.new(new WsProvider(endpoint));
|
|
9
|
+
const { methods } = await api.rpc.rpc_methods();
|
|
10
|
+
const apis = api.runtimeVersion.apis || {};
|
|
11
|
+
if (!chain) {
|
|
12
|
+
chain = stringCamelCase(api.runtimeVersion.specName || 'local');
|
|
12
13
|
}
|
|
13
|
-
await generateTypes(
|
|
14
|
+
await generateTypes(chain, api.metadata.latest, methods, apis, outDir, extension, useSubPaths);
|
|
14
15
|
await api.disconnect();
|
|
15
16
|
}
|
|
16
|
-
export async function generateTypes(
|
|
17
|
-
const dirPath = path.resolve(outDir,
|
|
18
|
-
const defTypesFileName = path.join(dirPath, `types
|
|
19
|
-
const constsTypesFileName = path.join(dirPath, `consts
|
|
20
|
-
const queryTypesFileName = path.join(dirPath, `query
|
|
21
|
-
const
|
|
22
|
-
const indexFileName = path.join(dirPath, `index
|
|
23
|
-
const errorsFileName = path.join(dirPath, `errors
|
|
24
|
-
const eventsFileName = path.join(dirPath, `events
|
|
25
|
-
const runtimeApisFileName = path.join(dirPath, `runtime
|
|
26
|
-
const txFileName = path.join(dirPath, `tx
|
|
17
|
+
export async function generateTypes(chain, metadata, rpcMethods, runtimeApis, outDir = '.', extension = 'd.ts', useSubPaths = false) {
|
|
18
|
+
const dirPath = path.resolve(outDir, chain);
|
|
19
|
+
const defTypesFileName = path.join(dirPath, `types.${extension}`);
|
|
20
|
+
const constsTypesFileName = path.join(dirPath, `consts.${extension}`);
|
|
21
|
+
const queryTypesFileName = path.join(dirPath, `query.${extension}`);
|
|
22
|
+
const jsonRpcFileName = path.join(dirPath, `json-rpc.${extension}`);
|
|
23
|
+
const indexFileName = path.join(dirPath, `index.${extension}`);
|
|
24
|
+
const errorsFileName = path.join(dirPath, `errors.${extension}`);
|
|
25
|
+
const eventsFileName = path.join(dirPath, `events.${extension}`);
|
|
26
|
+
const runtimeApisFileName = path.join(dirPath, `runtime.${extension}`);
|
|
27
|
+
const txFileName = path.join(dirPath, `tx.${extension}`);
|
|
27
28
|
if (!fs.existsSync(dirPath)) {
|
|
28
29
|
fs.mkdirSync(dirPath, { recursive: true });
|
|
29
30
|
}
|
|
30
31
|
const typesGen = new TypesGen(metadata);
|
|
31
32
|
const constsGen = new ConstsGen(typesGen);
|
|
32
33
|
const queryGen = new QueryGen(typesGen);
|
|
33
|
-
const
|
|
34
|
-
const indexGen = new IndexGen(
|
|
34
|
+
const jsonRpcGen = new JsonRpcGen(typesGen, rpcMethods);
|
|
35
|
+
const indexGen = new IndexGen(chain);
|
|
35
36
|
const errorsGen = new ErrorsGen(typesGen);
|
|
36
37
|
const eventsGen = new EventsGen(typesGen);
|
|
37
38
|
const runtimeApisGen = new RuntimeApisGen(typesGen, runtimeApis);
|
|
38
39
|
const txGen = new TxGen(typesGen);
|
|
39
|
-
fs.writeFileSync(defTypesFileName, await typesGen.generate());
|
|
40
|
-
fs.writeFileSync(errorsFileName, await errorsGen.generate());
|
|
41
|
-
fs.writeFileSync(eventsFileName, await eventsGen.generate());
|
|
42
|
-
fs.writeFileSync(
|
|
43
|
-
fs.writeFileSync(queryTypesFileName, await queryGen.generate());
|
|
44
|
-
fs.writeFileSync(constsTypesFileName, await constsGen.generate());
|
|
45
|
-
fs.writeFileSync(txFileName, await txGen.generate());
|
|
46
|
-
fs.writeFileSync(indexFileName, await indexGen.generate());
|
|
47
|
-
fs.writeFileSync(runtimeApisFileName, await runtimeApisGen.generate());
|
|
40
|
+
fs.writeFileSync(defTypesFileName, await typesGen.generate(useSubPaths));
|
|
41
|
+
fs.writeFileSync(errorsFileName, await errorsGen.generate(useSubPaths));
|
|
42
|
+
fs.writeFileSync(eventsFileName, await eventsGen.generate(useSubPaths));
|
|
43
|
+
fs.writeFileSync(jsonRpcFileName, await jsonRpcGen.generate(useSubPaths));
|
|
44
|
+
fs.writeFileSync(queryTypesFileName, await queryGen.generate(useSubPaths));
|
|
45
|
+
fs.writeFileSync(constsTypesFileName, await constsGen.generate(useSubPaths));
|
|
46
|
+
fs.writeFileSync(txFileName, await txGen.generate(useSubPaths));
|
|
47
|
+
fs.writeFileSync(indexFileName, await indexGen.generate(useSubPaths));
|
|
48
|
+
fs.writeFileSync(runtimeApisFileName, await runtimeApisGen.generate(useSubPaths));
|
|
48
49
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dedot/codegen",
|
|
3
|
-
"version": "0.0.1-next.
|
|
3
|
+
"version": "0.0.1-next.d9aff57d.57+d9aff57",
|
|
4
4
|
"description": "Generate types",
|
|
5
5
|
"author": "Thang X. Vu <thang@coongcrafts.io>",
|
|
6
6
|
"homepage": "https://github.com/dedotdev/dedot/tree/main/packages/codegen",
|
|
@@ -18,33 +18,30 @@
|
|
|
18
18
|
"copy": "cp -R ./src/templates ./dist && cp -R ./src/templates ./dist/cjs"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@dedot/
|
|
22
|
-
"@dedot/
|
|
23
|
-
"@dedot/
|
|
24
|
-
"@dedot/
|
|
25
|
-
"@
|
|
26
|
-
"dedot": "0.0.1-next.
|
|
27
|
-
"
|
|
28
|
-
"
|
|
21
|
+
"@dedot/api": "0.0.1-next.d9aff57d.57+d9aff57",
|
|
22
|
+
"@dedot/codecs": "0.0.1-next.d9aff57d.57+d9aff57",
|
|
23
|
+
"@dedot/providers": "0.0.1-next.d9aff57d.57+d9aff57",
|
|
24
|
+
"@dedot/runtime-specs": "0.0.1-next.d9aff57d.57+d9aff57",
|
|
25
|
+
"@dedot/shape": "0.0.1-next.d9aff57d.57+d9aff57",
|
|
26
|
+
"@dedot/types": "0.0.1-next.d9aff57d.57+d9aff57",
|
|
27
|
+
"@dedot/utils": "0.0.1-next.d9aff57d.57+d9aff57",
|
|
28
|
+
"handlebars": "^4.7.7",
|
|
29
|
+
"prettier": "^3.2.5"
|
|
29
30
|
},
|
|
30
31
|
"publishConfig": {
|
|
31
32
|
"access": "public",
|
|
32
33
|
"directory": "dist"
|
|
33
34
|
},
|
|
34
35
|
"license": "Apache-2.0",
|
|
35
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "d9aff57dcbd8e15455da9627cbc43f07cb6c0afc",
|
|
36
37
|
"module": "./index.js",
|
|
37
38
|
"types": "./index.d.ts",
|
|
38
39
|
"exports": {
|
|
39
40
|
".": {
|
|
40
|
-
"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
"require": {
|
|
45
|
-
"types": "./index.d.ts",
|
|
46
|
-
"default": "./cjs/index.js"
|
|
47
|
-
}
|
|
41
|
+
"types": "./index.d.ts",
|
|
42
|
+
"import": "./index.js",
|
|
43
|
+
"require": "./cjs/index.js",
|
|
44
|
+
"default": "./index.js"
|
|
48
45
|
}
|
|
49
46
|
}
|
|
50
47
|
}
|
package/templates/consts.hbs
CHANGED
package/templates/errors.hbs
CHANGED
package/templates/events.hbs
CHANGED
package/templates/index.hbs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// Generated by @dedot/codegen
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
{{{importTypes}}}
|
|
4
4
|
import { ChainConsts } from './consts';
|
|
5
5
|
import { ChainStorage } from './query';
|
|
6
|
-
import {
|
|
6
|
+
import { ChainJsonRpcApis } from './json-rpc';
|
|
7
7
|
import { ChainErrors } from './errors';
|
|
8
8
|
import { ChainEvents } from './events';
|
|
9
9
|
import { RuntimeApis } from './runtime';
|
|
@@ -11,12 +11,17 @@ import { ChainTx } from './tx';
|
|
|
11
11
|
|
|
12
12
|
export * from './types';
|
|
13
13
|
|
|
14
|
-
export interface {{{interfaceName}}}Api extends GenericSubstrateApi {
|
|
15
|
-
rpc:
|
|
16
|
-
consts: ChainConsts
|
|
17
|
-
query: ChainStorage
|
|
18
|
-
errors: ChainErrors
|
|
19
|
-
events: ChainEvents
|
|
20
|
-
call: RuntimeApis
|
|
21
|
-
tx: ChainTx
|
|
14
|
+
export interface Versioned{{{interfaceName}}}Api<Rv extends RpcVersion> extends GenericSubstrateApi<Rv> {
|
|
15
|
+
rpc: ChainJsonRpcApis<Rv>;
|
|
16
|
+
consts: ChainConsts<Rv>;
|
|
17
|
+
query: ChainStorage<Rv>;
|
|
18
|
+
errors: ChainErrors<Rv>;
|
|
19
|
+
events: ChainEvents<Rv>;
|
|
20
|
+
call: RuntimeApis<Rv>;
|
|
21
|
+
tx: ChainTx<Rv>;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface {{{interfaceName}}}Api {
|
|
25
|
+
legacy: Versioned{{{interfaceName}}}Api<RpcLegacy>;
|
|
26
|
+
v2: Versioned{{{interfaceName}}}Api<RpcV2>;
|
|
22
27
|
}
|
package/templates/query.hbs
CHANGED
package/templates/runtime.hbs
CHANGED
package/templates/tx.hbs
CHANGED
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const index_1 = require("./index");
|
|
7
|
-
const static_substrate_1 = require("@polkadot/types-support/metadata/static-substrate");
|
|
8
|
-
const substrate_hex_1 = __importDefault(require("@polkadot/types-support/metadata/v15/substrate-hex"));
|
|
9
|
-
const codecs_1 = require("@dedot/codecs");
|
|
10
|
-
const dedot_1 = require("dedot");
|
|
11
|
-
const NETWORKS = [
|
|
12
|
-
{
|
|
13
|
-
chain: 'substrate',
|
|
14
|
-
metadataHex: substrate_hex_1.default,
|
|
15
|
-
rpcMethods: static_substrate_1.rpc.methods,
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
chain: 'polkadot',
|
|
19
|
-
endpoint: 'wss://rpc.polkadot.io',
|
|
20
|
-
},
|
|
21
|
-
{
|
|
22
|
-
chain: 'kusama',
|
|
23
|
-
endpoint: 'wss://kusama-rpc.polkadot.io',
|
|
24
|
-
},
|
|
25
|
-
{
|
|
26
|
-
chain: 'astar',
|
|
27
|
-
endpoint: 'wss://rpc.astar.network',
|
|
28
|
-
},
|
|
29
|
-
{
|
|
30
|
-
chain: 'moonbeam',
|
|
31
|
-
endpoint: 'wss://moonbeam.api.onfinality.io/public-ws',
|
|
32
|
-
},
|
|
33
|
-
{
|
|
34
|
-
chain: 'polkadotAssetHub',
|
|
35
|
-
endpoint: 'wss://polkadot-asset-hub-rpc.polkadot.io/',
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
chain: 'kusamaAssetHub',
|
|
39
|
-
endpoint: 'wss://kusama-asset-hub-rpc.polkadot.io/',
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
chain: 'rococo',
|
|
43
|
-
endpoint: 'wss://rococo-rpc.polkadot.io/',
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
chain: 'rococoAssetHub',
|
|
47
|
-
endpoint: 'wss://rococo-asset-hub-rpc.polkadot.io/',
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
chain: 'aleph',
|
|
51
|
-
endpoint: 'wss://aleph-zero.api.onfinality.io/public-ws',
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
chain: 'westendAssetHub',
|
|
55
|
-
endpoint: 'wss://westend-asset-hub-rpc.polkadot.io',
|
|
56
|
-
},
|
|
57
|
-
];
|
|
58
|
-
const OUT_DIR = 'packages/chaintypes/src';
|
|
59
|
-
async function run() {
|
|
60
|
-
for (const network of NETWORKS) {
|
|
61
|
-
const { chain, endpoint, metadataHex, rpcMethods } = network;
|
|
62
|
-
if (endpoint) {
|
|
63
|
-
console.log(`Generate types for ${chain} via endpoint ${endpoint}`);
|
|
64
|
-
await (0, index_1.generateTypesFromChain)(network, endpoint, OUT_DIR);
|
|
65
|
-
}
|
|
66
|
-
else if (metadataHex && rpcMethods) {
|
|
67
|
-
console.log(`Generate types for ${chain} via raw data`);
|
|
68
|
-
const metadata = codecs_1.$Metadata.tryDecode(metadataHex);
|
|
69
|
-
const runtimeVersion = getRuntimeVersion(metadata);
|
|
70
|
-
await (0, index_1.generateTypes)(network, metadata.latest, rpcMethods, runtimeVersion.apis, OUT_DIR);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
console.log('DONE!');
|
|
74
|
-
}
|
|
75
|
-
const getRuntimeVersion = (metadata) => {
|
|
76
|
-
const registry = new codecs_1.PortableRegistry(metadata.latest);
|
|
77
|
-
const executor = new dedot_1.ConstantExecutor({
|
|
78
|
-
registry,
|
|
79
|
-
metadataLatest: metadata.latest,
|
|
80
|
-
});
|
|
81
|
-
return executor.execute('system', 'version');
|
|
82
|
-
};
|
|
83
|
-
run().catch(console.log);
|