@dedot/codegen 0.18.8 → 1.0.0

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.
Files changed (91) hide show
  1. package/chaintypes/generator/ConstsGen.js +1 -1
  2. package/chaintypes/generator/ErrorsGen.js +3 -3
  3. package/chaintypes/generator/EventsGen.js +3 -3
  4. package/chaintypes/generator/IndexGen.d.ts +1 -0
  5. package/chaintypes/generator/IndexGen.js +34 -2
  6. package/chaintypes/generator/JsonRpcGen.js +1 -1
  7. package/chaintypes/generator/QueryGen.js +4 -4
  8. package/chaintypes/generator/RuntimeApisGen.js +5 -5
  9. package/chaintypes/generator/TxGen.js +6 -10
  10. package/chaintypes/generator/ViewFunctionsGen.js +3 -3
  11. package/chaintypes/index.d.ts +22 -3
  12. package/chaintypes/index.js +63 -13
  13. package/chaintypes/templates/consts.hbs +1 -1
  14. package/chaintypes/templates/errors.hbs +1 -1
  15. package/chaintypes/templates/events.hbs +1 -1
  16. package/chaintypes/templates/index.hbs +10 -14
  17. package/chaintypes/templates/json-rpc.hbs +3 -3
  18. package/chaintypes/templates/query.hbs +1 -1
  19. package/chaintypes/templates/runtime.hbs +1 -1
  20. package/chaintypes/templates/tx.hbs +1 -1
  21. package/chaintypes/templates/view-functions.hbs +1 -1
  22. package/cjs/chaintypes/generator/ConstsGen.js +1 -1
  23. package/cjs/chaintypes/generator/ErrorsGen.js +3 -3
  24. package/cjs/chaintypes/generator/EventsGen.js +3 -3
  25. package/cjs/chaintypes/generator/IndexGen.js +34 -2
  26. package/cjs/chaintypes/generator/JsonRpcGen.js +1 -1
  27. package/cjs/chaintypes/generator/QueryGen.js +4 -4
  28. package/cjs/chaintypes/generator/RuntimeApisGen.js +5 -5
  29. package/cjs/chaintypes/generator/TxGen.js +6 -10
  30. package/cjs/chaintypes/generator/ViewFunctionsGen.js +3 -3
  31. package/cjs/chaintypes/index.js +61 -11
  32. package/cjs/chaintypes/templates/consts.hbs +1 -1
  33. package/cjs/chaintypes/templates/errors.hbs +1 -1
  34. package/cjs/chaintypes/templates/events.hbs +1 -1
  35. package/cjs/chaintypes/templates/index.hbs +10 -14
  36. package/cjs/chaintypes/templates/json-rpc.hbs +3 -3
  37. package/cjs/chaintypes/templates/query.hbs +1 -1
  38. package/cjs/chaintypes/templates/runtime.hbs +1 -1
  39. package/cjs/chaintypes/templates/tx.hbs +1 -1
  40. package/cjs/chaintypes/templates/view-functions.hbs +1 -1
  41. package/cjs/index.js +3 -0
  42. package/cjs/sol/generator/ConstructorQueryGen.js +1 -1
  43. package/cjs/sol/generator/ConstructorTxGen.js +1 -1
  44. package/cjs/sol/generator/IndexGen.js +1 -1
  45. package/cjs/sol/generator/QueryGen.js +1 -1
  46. package/cjs/sol/generator/TxGen.js +1 -1
  47. package/cjs/sol/templates/constructor-query.hbs +1 -1
  48. package/cjs/sol/templates/constructor-tx.hbs +1 -2
  49. package/cjs/sol/templates/events.hbs +1 -1
  50. package/cjs/sol/templates/index.hbs +7 -7
  51. package/cjs/sol/templates/query.hbs +1 -1
  52. package/cjs/sol/templates/tx.hbs +1 -1
  53. package/cjs/typink/generator/ConstructorQueryGen.js +1 -1
  54. package/cjs/typink/generator/ConstructorTxGen.js +1 -1
  55. package/cjs/typink/generator/IndexGen.js +1 -1
  56. package/cjs/typink/generator/QueryGen.js +1 -1
  57. package/cjs/typink/generator/TxGen.js +1 -1
  58. package/cjs/typink/templates/constructor-query.hbs +1 -1
  59. package/cjs/typink/templates/constructor-tx.hbs +1 -2
  60. package/cjs/typink/templates/events.hbs +1 -1
  61. package/cjs/typink/templates/index.hbs +7 -7
  62. package/cjs/typink/templates/query.hbs +1 -1
  63. package/cjs/typink/templates/tx.hbs +1 -1
  64. package/cjs/utils.js +27 -1
  65. package/index.d.ts +1 -0
  66. package/index.js +1 -0
  67. package/package.json +11 -11
  68. package/sol/generator/ConstructorQueryGen.js +1 -1
  69. package/sol/generator/ConstructorTxGen.js +1 -1
  70. package/sol/generator/IndexGen.js +1 -1
  71. package/sol/generator/QueryGen.js +1 -1
  72. package/sol/generator/TxGen.js +1 -1
  73. package/sol/templates/constructor-query.hbs +1 -1
  74. package/sol/templates/constructor-tx.hbs +1 -2
  75. package/sol/templates/events.hbs +1 -1
  76. package/sol/templates/index.hbs +7 -7
  77. package/sol/templates/query.hbs +1 -1
  78. package/sol/templates/tx.hbs +1 -1
  79. package/typink/generator/ConstructorQueryGen.js +1 -1
  80. package/typink/generator/ConstructorTxGen.js +1 -1
  81. package/typink/generator/IndexGen.js +1 -1
  82. package/typink/generator/QueryGen.js +1 -1
  83. package/typink/generator/TxGen.js +1 -1
  84. package/typink/templates/constructor-query.hbs +1 -1
  85. package/typink/templates/constructor-tx.hbs +1 -2
  86. package/typink/templates/events.hbs +1 -1
  87. package/typink/templates/index.hbs +7 -7
  88. package/typink/templates/query.hbs +1 -1
  89. package/typink/templates/tx.hbs +1 -1
  90. package/utils.d.ts +9 -0
  91. package/utils.js +25 -0
@@ -9,7 +9,7 @@ class QueryGen extends ApiGen_js_1.ApiGen {
9
9
  generate(useSubPaths = false) {
10
10
  const { pallets } = this.metadata;
11
11
  this.typesGen.clearCache();
12
- this.typesGen.typeImports.addKnownType('GenericChainStorage', 'GenericStorageQuery', 'Callback', 'RpcVersion');
12
+ this.typesGen.typeImports.addKnownType('GenericChainStorage', 'GenericStorageQuery', 'Callback');
13
13
  let defTypeOut = '';
14
14
  for (let pallet of pallets) {
15
15
  const storage = pallet.storage;
@@ -18,17 +18,17 @@ class QueryGen extends ApiGen_js_1.ApiGen {
18
18
  const queries = storage.entries.map((one) => this.#generateEntry(one));
19
19
  const queryDefs = queries.map(({ name, valueType, keyType, docs, keyTypeOut }) => {
20
20
  if (keyTypeOut) {
21
- return `${(0, utils_js_1.commentBlock)(docs)}${name}: GenericStorageQuery<Rv, (${keyType}) => ${valueType}, ${keyTypeOut}>`;
21
+ return `${(0, utils_js_1.commentBlock)(docs)}${name}: GenericStorageQuery<(${keyType}) => ${valueType}, ${keyTypeOut}>`;
22
22
  }
23
23
  else {
24
- return `${(0, utils_js_1.commentBlock)(docs)}${name}: GenericStorageQuery<Rv, (${keyType}) => ${valueType}>`;
24
+ return `${(0, utils_js_1.commentBlock)(docs)}${name}: GenericStorageQuery<(${keyType}) => ${valueType}>`;
25
25
  }
26
26
  });
27
27
  defTypeOut += (0, utils_js_1.commentBlock)(`Pallet \`${pallet.name}\`'s storage queries`);
28
28
  defTypeOut += `${(0, utils_1.stringCamelCase)(pallet.name)}: {
29
29
  ${queryDefs.join(',\n')}
30
30
 
31
- ${(0, utils_js_1.commentBlock)('Generic pallet storage query')}[storage: string]: GenericStorageQuery<Rv>;
31
+ ${(0, utils_js_1.commentBlock)('Generic pallet storage query')}[storage: string]: GenericStorageQuery;
32
32
  },`;
33
33
  }
34
34
  const importTypes = this.typesGen.typeImports.toImports({ useSubPaths });
@@ -17,7 +17,7 @@ class RuntimeApisGen extends ApiGen_js_1.ApiGen {
17
17
  }
18
18
  generate(useSubPaths = false) {
19
19
  this.typesGen.clearCache();
20
- this.typesGen.typeImports.addKnownType('GenericRuntimeApis', 'GenericRuntimeApiMethod', 'RpcVersion');
20
+ this.typesGen.typeImports.addKnownType('GenericRuntimeApis', 'GenericRuntimeApiMethod');
21
21
  let runtimeCallsOut = '';
22
22
  if (this.metadata.apis.length > 0) {
23
23
  this.metadata.apis.forEach((runtimeApi) => {
@@ -26,7 +26,7 @@ class RuntimeApisGen extends ApiGen_js_1.ApiGen {
26
26
  runtimeCallsOut += `${(0, utils_1.stringCamelCase)(runtimeApiName)}: {
27
27
  ${methods.map((method) => this.#generateMethodDef(runtimeApiName, method)).join('\n')}
28
28
 
29
- ${(0, utils_js_1.commentBlock)('Generic runtime api call')}[method: string]: GenericRuntimeApiMethod<Rv>
29
+ ${(0, utils_js_1.commentBlock)('Generic runtime api call')}[method: string]: GenericRuntimeApiMethod
30
30
  }`;
31
31
  });
32
32
  }
@@ -43,7 +43,7 @@ class RuntimeApisGen extends ApiGen_js_1.ApiGen {
43
43
  }))
44
44
  .join('\n')}
45
45
 
46
- ${(0, utils_js_1.commentBlock)('Generic runtime api call')}[method: string]: GenericRuntimeApiMethod<Rv>
46
+ ${(0, utils_js_1.commentBlock)('Generic runtime api call')}[method: string]: GenericRuntimeApiMethod
47
47
  }`;
48
48
  });
49
49
  }
@@ -72,7 +72,7 @@ class RuntimeApisGen extends ApiGen_js_1.ApiGen {
72
72
  .map(({ name, isOptional, plainType }) => `${(0, utils_1.stringCamelCase)(name)}${isOptional ? '?' : ''}: ${plainType}`)
73
73
  .join(', ');
74
74
  const typeOut = this.#getGeneratedTypeName(type, false);
75
- return `${(0, utils_js_1.commentBlock)(docs, '\n', defaultDocs, typedParams.map(({ plainType, name }) => `@param {${plainType}} ${name}`))}${methodName}: GenericRuntimeApiMethod<Rv, (${paramsOut}) => Promise<${typeOut}>>`;
75
+ return `${(0, utils_js_1.commentBlock)(docs, '\n', defaultDocs, typedParams.map(({ plainType, name }) => `@param {${plainType}} ${name}`))}${methodName}: GenericRuntimeApiMethod<(${paramsOut}) => Promise<${typeOut}>>`;
76
76
  }
77
77
  #generateMethodDef(runtimeApiName, methodDef) {
78
78
  const { name: methodName, inputs, output, docs, deprecationInfo } = methodDef;
@@ -97,7 +97,7 @@ class RuntimeApisGen extends ApiGen_js_1.ApiGen {
97
97
  const paramsOut = typedInputs
98
98
  .map(({ name, type, isOptional }) => `${(0, utils_1.stringCamelCase)(name)}${isOptional ? '?' : ''}: ${type}`)
99
99
  .join(', ');
100
- return `${(0, utils_js_1.commentBlock)(docs, '\n', defaultDocs, typedInputs.map(({ type, name }) => `@param {${type}} ${name}`), deprecationComments)}${(0, utils_1.stringCamelCase)(methodName)}: GenericRuntimeApiMethod<Rv, (${paramsOut}) => Promise<${typeOut}>>`;
100
+ return `${(0, utils_js_1.commentBlock)(docs, '\n', defaultDocs, typedInputs.map(({ type, name }) => `@param {${type}} ${name}`), deprecationComments)}${(0, utils_1.stringCamelCase)(methodName)}: GenericRuntimeApiMethod<(${paramsOut}) => Promise<${typeOut}>>`;
101
101
  }
102
102
  #targetRuntimeApiSpecs() {
103
103
  const specs = Object.entries(this.runtimeApis).map(([runtimeApiHash, version]) => {
@@ -8,7 +8,7 @@ class TxGen extends index_js_1.ApiGen {
8
8
  generate(useSubPaths = false) {
9
9
  const { pallets, types } = this.metadata;
10
10
  this.typesGen.clearCache();
11
- this.typesGen.typeImports.addKnownType('GenericChainTx', 'GenericTxCall', 'ISubmittableExtrinsic', 'ISubmittableResult', 'IRuntimeTxCall', 'RpcVersion', 'RpcV2', 'ISubmittableExtrinsicLegacy');
11
+ this.typesGen.typeImports.addKnownType('GenericChainTx', 'GenericTxCall', 'GenericChainKnownTypes', 'ISubmittableExtrinsic', 'ISubmittableResult', 'IRuntimeTxCall');
12
12
  const { callTypeId, addressTypeId, signatureTypeId } = this.metadata.extrinsic;
13
13
  const callTypeIn = this.typesGen.generateType(callTypeId, 1);
14
14
  const addressTypeIn = this.typesGen.generateType(addressTypeId, 1);
@@ -50,23 +50,19 @@ class TxGen extends index_js_1.ApiGen {
50
50
  if (deprecationComments.length > 0) {
51
51
  deprecationComments.unshift('\n');
52
52
  }
53
- return `${(0, utils_js_1.commentBlock)(docs, '\n', params.map((p) => `@param {${p.type}} ${p.normalizedName} ${p.docs}`), deprecationComments)}${functionName}: GenericTxCall<Rv, (${params.map((p) => `${p.normalizedName}: ${p.type}`).join(', ')}) => ChainSubmittableExtrinsic<Rv, ${callInput}>>`;
53
+ return `${(0, utils_js_1.commentBlock)(docs, '\n', params.map((p) => `@param {${p.type}} ${p.normalizedName} ${p.docs}`), deprecationComments)}${functionName}: GenericTxCall<(${params.map((p) => `${p.normalizedName}: ${p.type}`).join(', ')}) => ChainSubmittableExtrinsic<${callInput}, ChainKnownTypes>>`;
54
54
  })
55
55
  .join(',\n')}
56
56
 
57
- ${(0, utils_js_1.commentBlock)('Generic pallet tx call')}[callName: string]: GenericTxCall<Rv, TxCall<Rv>>,
57
+ ${(0, utils_js_1.commentBlock)('Generic pallet tx call')}[callName: string]: GenericTxCall<TxCall<ChainKnownTypes>>,
58
58
  },`;
59
59
  }
60
60
  const importTypes = this.typesGen.typeImports.toImports({ useSubPaths });
61
- // TODO make explicit separate type for Extra
62
61
  const defTypes = `
63
- export type ChainSubmittableExtrinsic<Rv extends RpcVersion, T extends IRuntimeTxCall = ${callTypeIn}> =
64
- Extrinsic<${addressTypeIn}, T, ${signatureTypeIn}, any[]> &
65
- (Rv extends RpcV2
66
- ? ISubmittableExtrinsic<ISubmittableResult<FrameSystemEventRecord>>
67
- : ISubmittableExtrinsicLegacy<ISubmittableResult<FrameSystemEventRecord>>)
62
+ export type ChainSubmittableExtrinsic<T extends IRuntimeTxCall = ${callTypeIn}, ChainKnownTypes extends GenericChainKnownTypes = GenericChainKnownTypes> =
63
+ Extrinsic<${addressTypeIn}, T, ${signatureTypeIn}, ChainKnownTypes['Extra']> & ISubmittableExtrinsic<ISubmittableResult<FrameSystemEventRecord>, ChainKnownTypes['AssetId']>
68
64
 
69
- export type TxCall<Rv extends RpcVersion> = (...args: any[]) => ChainSubmittableExtrinsic<Rv>;
65
+ export type TxCall<ChainKnownTypes extends GenericChainKnownTypes = GenericChainKnownTypes> = (...args: any[]) => ChainSubmittableExtrinsic<${callTypeIn}, ChainKnownTypes>;
70
66
  `;
71
67
  const template = (0, utils_js_1.compileTemplate)('chaintypes/templates/tx.hbs');
72
68
  return (0, utils_js_1.beautifySourceCode)(template({ importTypes, defTypes, txDefsOut }));
@@ -10,7 +10,7 @@ class ViewFunctionsGen extends ApiGen_js_1.ApiGen {
10
10
  const { pallets } = this.metadata;
11
11
  this.typesGen.clearCache();
12
12
  this.typesGen.typeImports.addKnownType('GenericChainViewFunctions', // --
13
- 'GenericViewFunction', 'RpcVersion');
13
+ 'GenericViewFunction');
14
14
  let defTypeOut = '';
15
15
  for (let pallet of pallets) {
16
16
  if (!pallet.viewFunctions || pallet.viewFunctions.length === 0)
@@ -27,13 +27,13 @@ class ViewFunctionsGen extends ApiGen_js_1.ApiGen {
27
27
  }
28
28
  const params = vf.inputs.map((input) => `${(0, utils_1.stringCamelCase)(input.name)}: ${this.typesGen.generateType(input.typeId, 1)}`);
29
29
  const outputType = this.typesGen.generateType(vf.output, 1, true);
30
- return `${(0, utils_js_1.commentBlock)(docs)}${(0, utils_1.stringCamelCase)(vf.name)}: GenericViewFunction<Rv, (${params.join(', ')}) => Promise<${outputType}>>`;
30
+ return `${(0, utils_js_1.commentBlock)(docs)}${(0, utils_1.stringCamelCase)(vf.name)}: GenericViewFunction<(${params.join(', ')}) => Promise<${outputType}>>`;
31
31
  });
32
32
  defTypeOut += (0, utils_js_1.commentBlock)(`Pallet \`${pallet.name}\`'s view functions`);
33
33
  defTypeOut += `${(0, utils_1.stringCamelCase)(pallet.name)}: {
34
34
  ${viewFns.join(',\n')}
35
35
 
36
- ${(0, utils_js_1.commentBlock)('Generic pallet view function')}[name: string]: GenericViewFunction<Rv>;
36
+ ${(0, utils_js_1.commentBlock)('Generic pallet view function')}[name: string]: GenericViewFunction;
37
37
  },`;
38
38
  }
39
39
  const importTypes = this.typesGen.typeImports.toImports({ useSubPaths });
@@ -29,19 +29,67 @@ const providers_1 = require("@dedot/providers");
29
29
  const utils_1 = require("@dedot/utils");
30
30
  const fs = __importStar(require("fs"));
31
31
  const path = __importStar(require("path"));
32
+ const utils_js_1 = require("../utils.js");
32
33
  const index_js_1 = require("./generator/index.js");
33
- async function generateTypesFromEndpoint(chain, endpoint, outDir, extension = 'd.ts', useSubPaths = false) {
34
- // Immediately throw error if cannot connect to provider for the first time.
35
- const client = await api_1.LegacyClient.new(new providers_1.WsProvider({ endpoint, retryDelayMs: 0, timeout: 0 }));
36
- const { methods } = await client.rpc.rpc_methods();
37
- chain = chain || client.runtimeVersion.specName || 'local';
38
- const result = await generateTypes(chain, client.metadata.latest, methods, client.runtimeVersion, outDir, extension, useSubPaths);
39
- await client.disconnect();
40
- return result;
34
+ async function generateTypesFromEndpoint(options) {
35
+ const { chain, endpoint, client: providedClient, outDir, extension = 'd.ts', useSubPaths = false, at } = options;
36
+ // Validate that either endpoint or client is provided
37
+ if (!endpoint && !providedClient) {
38
+ throw new Error('Either "endpoint" or "client" must be provided');
39
+ }
40
+ if (endpoint && providedClient) {
41
+ throw new Error('Cannot provide both "endpoint" and "client"');
42
+ }
43
+ // Create client if not provided
44
+ const client = providedClient || (await api_1.DedotClient.legacy(new providers_1.WsProvider({ endpoint: endpoint, retryDelayMs: 0, timeout: 0 })));
45
+ const shouldDisconnect = !providedClient;
46
+ try {
47
+ const { methods } = await client.rpc.rpc_methods();
48
+ // Resolve block hash if `at` is provided
49
+ let blockHash;
50
+ if (at) {
51
+ blockHash = await (0, utils_js_1.resolveBlockHash)(client, at);
52
+ }
53
+ // Get runtime version and metadata at the specified block
54
+ let runtimeVersion;
55
+ let metadata;
56
+ if (blockHash) {
57
+ // Get the header of the target block
58
+ const header = await client.block.header(blockHash);
59
+ (0, utils_1.assert)(`Header not found for block hash: ${blockHash}`);
60
+ const childBlockHash = await client.rpc.chain_getBlockHash(header.number + 1);
61
+ const clientAt = await client.at(childBlockHash);
62
+ runtimeVersion = clientAt.runtimeVersion;
63
+ metadata = clientAt.metadata;
64
+ }
65
+ else {
66
+ runtimeVersion = client.runtimeVersion;
67
+ metadata = client.metadata;
68
+ }
69
+ const resolvedChain = chain || runtimeVersion.specName || 'local';
70
+ return await generateTypes({
71
+ chain: resolvedChain,
72
+ metadata: metadata.latest,
73
+ rpcMethods: methods,
74
+ runtimeVersion,
75
+ outDir,
76
+ extension,
77
+ useSubPaths,
78
+ appendSpecVersion: !!blockHash,
79
+ });
80
+ }
81
+ finally {
82
+ if (shouldDisconnect) {
83
+ await client.disconnect();
84
+ }
85
+ }
41
86
  }
42
87
  exports.generateTypesFromEndpoint = generateTypesFromEndpoint;
43
- async function generateTypes(chain, metadata, rpcMethods, runtimeVersion, outDir = '.', extension = 'd.ts', useSubPaths = false) {
44
- const dirPath = path.resolve(outDir, (0, utils_1.stringDashCase)(chain));
88
+ async function generateTypes(options) {
89
+ const { chain, metadata, rpcMethods, runtimeVersion, outDir = '.', extension = 'd.ts', useSubPaths = false, appendSpecVersion = false, } = options;
90
+ // Build folder suffix with spec version if requested
91
+ const folderSuffix = appendSpecVersion ? `-${runtimeVersion.specVersion}` : '';
92
+ const dirPath = path.resolve(outDir, (0, utils_1.stringDashCase)(chain) + folderSuffix);
45
93
  const defTypesFileName = path.join(dirPath, `types.${extension}`);
46
94
  const constsTypesFileName = path.join(dirPath, `consts.${extension}`);
47
95
  const queryTypesFileName = path.join(dirPath, `query.${extension}`);
@@ -55,7 +103,9 @@ async function generateTypes(chain, metadata, rpcMethods, runtimeVersion, outDir
55
103
  if (!fs.existsSync(dirPath)) {
56
104
  fs.mkdirSync(dirPath, { recursive: true });
57
105
  }
58
- const interfaceName = `${(0, utils_1.stringPascalCase)(chain)}Api`;
106
+ // Build interface suffix with spec version if requested
107
+ const interfaceSuffix = appendSpecVersion ? runtimeVersion.specVersion : '';
108
+ const interfaceName = `${(0, utils_1.stringPascalCase)(chain)}Api${interfaceSuffix}`;
59
109
  const typesGen = new index_js_1.TypesGen(metadata);
60
110
  const constsGen = new index_js_1.ConstsGen(typesGen);
61
111
  const queryGen = new index_js_1.QueryGen(typesGen);
@@ -2,6 +2,6 @@
2
2
 
3
3
  {{{ importTypes }}}
4
4
 
5
- export interface ChainConsts<Rv extends RpcVersion> extends GenericChainConsts<Rv> {
5
+ export interface ChainConsts extends GenericChainConsts {
6
6
  {{{ defTypeOut }}}
7
7
  }
@@ -2,6 +2,6 @@
2
2
 
3
3
  {{{ importTypes }}}
4
4
 
5
- export interface ChainErrors<Rv extends RpcVersion> extends GenericChainErrors<Rv> {
5
+ export interface ChainErrors extends GenericChainErrors {
6
6
  {{{ defTypeOut }}}
7
7
  }
@@ -2,6 +2,6 @@
2
2
 
3
3
  {{{ importTypes }}}
4
4
 
5
- export interface ChainEvents<Rv extends RpcVersion> extends GenericChainEvents<Rv> {
5
+ export interface ChainEvents extends GenericChainEvents {
6
6
  {{{ defTypeOut }}}
7
7
  }
@@ -17,22 +17,18 @@ interface ChainKnownTypes extends GenericChainKnownTypes {
17
17
  Signature: {{{signatureType}}};
18
18
  RuntimeCall: {{{runtimeCallType}}};
19
19
  Extra: {{{extraType}}};
20
+ AssetId: {{{assetIdType}}};
20
21
  }
21
22
 
22
- export interface Versioned{{{interfaceName}}}<Rv extends RpcVersion> extends GenericSubstrateApi<Rv> {
23
- rpc: ChainJsonRpcApis<Rv>;
24
- consts: ChainConsts<Rv>;
25
- query: ChainStorage<Rv>;
26
- errors: ChainErrors<Rv>;
27
- events: ChainEvents<Rv>;
28
- call: RuntimeApis<Rv>;
29
- view: ChainViewFunctions<Rv>;
30
- tx: ChainTx<Rv>;
23
+ {{interfaceDocs}}export interface {{{interfaceName}}} extends GenericSubstrateApi {
24
+ rpc: ChainJsonRpcApis;
25
+ consts: ChainConsts;
26
+ query: ChainStorage;
27
+ errors: ChainErrors;
28
+ events: ChainEvents;
29
+ call: RuntimeApis;
30
+ view: ChainViewFunctions;
31
+ tx: ChainTx<ChainKnownTypes>;
31
32
 
32
33
  types: ChainKnownTypes;
33
34
  }
34
-
35
- {{interfaceDocs}}export interface {{{interfaceName}}} {
36
- legacy: Versioned{{{interfaceName}}}<RpcLegacy>;
37
- v2: Versioned{{{interfaceName}}}<RpcV2>;
38
- }
@@ -2,9 +2,9 @@
2
2
 
3
3
  {{{ importTypes }}}
4
4
 
5
- export type ChainJsonRpcApis<Rv extends RpcVersion> =
5
+ export type ChainJsonRpcApis =
6
6
  {{#if jsonRpcMethods.length}}
7
- Pick<JsonRpcApis, {{{jsonRpcMethods}}}> & GenericJsonRpcApis<Rv>;
7
+ Pick<JsonRpcApis, {{{jsonRpcMethods}}}> & GenericJsonRpcApis;
8
8
  {{else}}
9
- JsonRpcApis & GenericJsonRpcApis<Rv>;
9
+ JsonRpcApis & GenericJsonRpcApis;
10
10
  {{/if}}
@@ -2,6 +2,6 @@
2
2
 
3
3
  {{{ importTypes }}}
4
4
 
5
- export interface ChainStorage<Rv extends RpcVersion> extends GenericChainStorage<Rv> {
5
+ export interface ChainStorage extends GenericChainStorage {
6
6
  {{{ defTypeOut }}}
7
7
  }
@@ -2,7 +2,7 @@
2
2
 
3
3
  {{{ importTypes }}}
4
4
 
5
- export interface RuntimeApis<Rv extends RpcVersion> extends GenericRuntimeApis<Rv> {
5
+ export interface RuntimeApis extends GenericRuntimeApis {
6
6
  {{{ runtimeCallsOut }}}
7
7
  }
8
8
 
@@ -4,6 +4,6 @@
4
4
 
5
5
  {{{ defTypes }}}
6
6
 
7
- export interface ChainTx<Rv extends RpcVersion> extends GenericChainTx<Rv, TxCall<Rv>> {
7
+ export interface ChainTx<ChainKnownTypes extends GenericChainKnownTypes = GenericChainKnownTypes> extends GenericChainTx<TxCall<ChainKnownTypes>> {
8
8
  {{{ txDefsOut }}}
9
9
  }
@@ -2,6 +2,6 @@
2
2
 
3
3
  {{{ importTypes }}}
4
4
 
5
- export interface ChainViewFunctions<Rv extends RpcVersion> extends GenericChainViewFunctions<Rv> {
5
+ export interface ChainViewFunctions extends GenericChainViewFunctions {
6
6
  {{{ defTypeOut }}}
7
7
  }
package/cjs/index.js CHANGED
@@ -14,7 +14,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.resolveBlockHash = void 0;
17
18
  __exportStar(require("./types.js"), exports);
18
19
  __exportStar(require("./chaintypes/index.js"), exports);
19
20
  __exportStar(require("./typink/index.js"), exports);
20
21
  __exportStar(require("./sol/index.js"), exports);
22
+ var utils_js_1 = require("./utils.js");
23
+ Object.defineProperty(exports, "resolveBlockHash", { enumerable: true, get: function () { return utils_js_1.resolveBlockHash; } });
@@ -32,7 +32,7 @@ class ConstructorQueryGen {
32
32
  }
33
33
  generateMethodDef(abiItem, optionsParamName = 'options') {
34
34
  const paramsOut = this.generateParamsOut(abiItem);
35
- return `GenericConstructorQueryCall<ChainApi, (${paramsOut && `${paramsOut},`} ${optionsParamName}?: ConstructorCallOptions) => Promise<GenericConstructorCallResult<[], ContractInstantiateResult<ChainApi>>>, Type>`;
35
+ return `GenericConstructorQueryCall<(${paramsOut && `${paramsOut},`} ${optionsParamName}?: ConstructorCallOptions) => Promise<GenericConstructorCallResult<[], ContractInstantiateResult>>, Type>`;
36
36
  }
37
37
  generateParamsOut(abiItem) {
38
38
  return abiItem.inputs
@@ -16,7 +16,7 @@ class ConstructorTxGen extends ConstructorQueryGen_js_1.ConstructorQueryGen {
16
16
  }
17
17
  generateMethodDef(abiItem, optionsParamName = 'options') {
18
18
  const paramsOut = this.generateParamsOut(abiItem);
19
- return `GenericConstructorTxCall<ChainApi, (${paramsOut && `${paramsOut},`} ${optionsParamName}?: ConstructorTxOptions) => GenericInstantiateSubmittableExtrinsic<ChainApi, ContractApi>, Type>`;
19
+ return `GenericConstructorTxCall<(${paramsOut && `${paramsOut},`} ${optionsParamName}?: ConstructorTxOptions) => GenericInstantiateSubmittableExtrinsic<ContractApi>, Type>`;
20
20
  }
21
21
  }
22
22
  exports.ConstructorTxGen = ConstructorTxGen;
@@ -13,7 +13,7 @@ class IndexGen {
13
13
  generate(useSubPaths = false) {
14
14
  const interfaceName = this.interfaceName;
15
15
  const typeImports = new index_js_1.TypeImports();
16
- typeImports.addKnownType('VersionedGenericSubstrateApi', 'RpcVersion', 'RpcV2');
16
+ typeImports.addKnownType('GenericSubstrateApi', 'RpcVersion', 'RpcV2');
17
17
  typeImports.addContractType('SolGenericContractApi', 'SolRegistry');
18
18
  typeImports.addChainType('SubstrateApi');
19
19
  const importTypes = typeImports.toImports({ useSubPaths });
@@ -39,7 +39,7 @@ class QueryGen {
39
39
  const typeOutInner = `${outputs.map((o) => this.typesGen.generateType(o, abiItem, 1, true)).join(',')}`;
40
40
  // If there is only one output, we don't need to wrap it in a tuple, for user-friendly
41
41
  const typeOut = outputs.length === 1 ? typeOutInner : `[${typeOutInner}]`;
42
- return `GenericContractQueryCall<ChainApi, (${paramsOut && `${paramsOut},`} ${optionsParamName}?: ContractCallOptions) => Promise<GenericContractCallResult<${typeOut}, ContractCallResult<ChainApi>>>, Type>`;
42
+ return `GenericContractQueryCall<(${paramsOut && `${paramsOut},`} ${optionsParamName}?: ContractCallOptions) => Promise<GenericContractCallResult<${typeOut}, ContractCallResult>>, Type>`;
43
43
  }
44
44
  generateParamsOut(abiItem) {
45
45
  return abiItem.inputs
@@ -16,7 +16,7 @@ class TxGen extends QueryGen_js_1.QueryGen {
16
16
  }
17
17
  generateMethodDef(abiItem, optionsParamName = 'options') {
18
18
  const paramsOut = this.generateParamsOut(abiItem);
19
- return `GenericContractTxCall<ChainApi, (${paramsOut && `${paramsOut},`} ${optionsParamName}?: ContractTxOptions) => ContractSubmittableExtrinsic<ChainApi>, Type>`;
19
+ return `GenericContractTxCall<(${paramsOut && `${paramsOut},`} ${optionsParamName}?: ContractTxOptions) => ContractSubmittableExtrinsic, Type>`;
20
20
  }
21
21
  }
22
22
  exports.TxGen = TxGen;
@@ -2,6 +2,6 @@
2
2
 
3
3
  {{{ importTypes }}}
4
4
 
5
- export interface ConstructorQuery <ChainApi extends GenericSubstrateApi, Type extends MetadataType> extends GenericConstructorQuery <ChainApi, Type> {
5
+ export interface ConstructorQuery<Type extends MetadataType> extends GenericConstructorQuery<Type> {
6
6
  {{{ constructorsOut }}}
7
7
  }
@@ -3,9 +3,8 @@
3
3
  {{{ importTypes }}}
4
4
 
5
5
  export interface ConstructorTx<
6
- ChainApi extends GenericSubstrateApi,
7
6
  ContractApi extends SolGenericContractApi,
8
7
  Type extends MetadataType
9
- > extends GenericConstructorTx <ChainApi, Type> {
8
+ > extends GenericConstructorTx<Type> {
10
9
  {{{ constructorsOut }}}
11
10
  }
@@ -2,6 +2,6 @@
2
2
 
3
3
  {{{ importTypes }}}
4
4
 
5
- export interface ContractEvents <ChainApi extends GenericSubstrateApi, Type extends MetadataType> extends GenericContractEvents <ChainApi, Type> {
5
+ export interface ContractEvents<Type extends MetadataType> extends GenericContractEvents<Type> {
6
6
  {{{ eventsOut }}}
7
7
  }
@@ -9,15 +9,15 @@ import { ContractEvents } from './events.js';
9
9
 
10
10
  export * from './types.js';
11
11
 
12
- {{{interfaceDocs}}}export interface {{{interfaceName}}}<Rv extends RpcVersion = RpcVersion, ChainApi extends VersionedGenericSubstrateApi = SubstrateApi> extends SolGenericContractApi<Rv, ChainApi> {
12
+ {{{interfaceDocs}}}export interface {{{interfaceName}}}<ChainApi extends GenericSubstrateApi = SubstrateApi> extends SolGenericContractApi<ChainApi> {
13
13
  metadataType: 'sol';
14
- query: ContractQuery<ChainApi[Rv], 'sol'>;
15
- tx: ContractTx<ChainApi[Rv], 'sol'>;
16
- constructorQuery: ConstructorQuery<ChainApi[Rv], 'sol'>;
17
- events: ContractEvents<ChainApi[Rv], 'sol'>;
18
- constructorTx: ConstructorTx<ChainApi[Rv], {{{interfaceName}}}, 'sol'>;
14
+ query: ContractQuery<'sol'>;
15
+ tx: ContractTx<'sol'>;
16
+ constructorQuery: ConstructorQuery<'sol'>;
17
+ events: ContractEvents<'sol'>;
18
+ constructorTx: ConstructorTx<{{{interfaceName}}}, 'sol'>;
19
19
 
20
20
  types: {
21
- ChainApi: ChainApi[Rv];
21
+ ChainApi: ChainApi;
22
22
  };
23
23
  }
@@ -2,6 +2,6 @@
2
2
 
3
3
  {{{ importTypes }}}
4
4
 
5
- export interface ContractQuery<ChainApi extends GenericSubstrateApi, Type extends MetadataType> extends GenericContractQuery<ChainApi, Type> {
5
+ export interface ContractQuery<Type extends MetadataType> extends GenericContractQuery<Type> {
6
6
  {{{ queryCallsOut }}}
7
7
  }
@@ -2,6 +2,6 @@
2
2
 
3
3
  {{{ importTypes }}}
4
4
 
5
- export interface ContractTx<ChainApi extends GenericSubstrateApi, Type extends MetadataType> extends GenericContractTx<ChainApi, Type> {
5
+ export interface ContractTx<Type extends MetadataType> extends GenericContractTx<Type> {
6
6
  {{{ txCallsOut }}}
7
7
  }
@@ -20,7 +20,7 @@ class ConstructorQueryGen extends QueryGen_js_1.QueryGen {
20
20
  const typeOutRaw = this.typesGen.generateType(returnType.type, 0, true);
21
21
  // Unwrap langError result
22
22
  const typeOut = typeOutRaw.match(/^(\w+)<(.*), (.*)>$/).at(2);
23
- return `GenericConstructorQueryCall<ChainApi, (${paramsOut && `${paramsOut},`} ${optionsParamName}?: ConstructorCallOptions) => Promise<GenericConstructorCallResult<${typeOut}, ContractInstantiateResult<ChainApi>>>, Type>`;
23
+ return `GenericConstructorQueryCall<(${paramsOut && `${paramsOut},`} ${optionsParamName}?: ConstructorCallOptions) => Promise<GenericConstructorCallResult<${typeOut}, ContractInstantiateResult>>, Type>`;
24
24
  }
25
25
  }
26
26
  exports.ConstructorQueryGen = ConstructorQueryGen;
@@ -16,7 +16,7 @@ class ConstructorTxGen extends QueryGen_js_1.QueryGen {
16
16
  }
17
17
  generateMethodDef(def, optionsParamName = 'options') {
18
18
  const paramsOut = this.generateParamsOut(def.args);
19
- return `GenericConstructorTxCall<ChainApi, (${paramsOut && `${paramsOut},`} ${optionsParamName}?: ConstructorTxOptions) => GenericInstantiateSubmittableExtrinsic<ChainApi, ContractApi>, Type>`;
19
+ return `GenericConstructorTxCall<(${paramsOut && `${paramsOut},`} ${optionsParamName}?: ConstructorTxOptions) => GenericInstantiateSubmittableExtrinsic<ContractApi>, Type>`;
20
20
  }
21
21
  }
22
22
  exports.ConstructorTxGen = ConstructorTxGen;
@@ -18,7 +18,7 @@ class IndexGen {
18
18
  const langErrorId = this.contractMetadata.spec.lang_error.type;
19
19
  const langErrorName = this.typesGen.cleanPath(this.contractMetadata.types[langErrorId].type.path);
20
20
  const typeImports = new index_js_1.TypeImports();
21
- typeImports.addKnownType('VersionedGenericSubstrateApi', 'RpcVersion', 'RpcV2');
21
+ typeImports.addKnownType('GenericSubstrateApi', 'RpcVersion', 'RpcV2');
22
22
  typeImports.addContractType('InkGenericContractApi', 'WithLazyStorage');
23
23
  typeImports.addChainType('SubstrateApi');
24
24
  typeImports.addPortableType(langErrorName);
@@ -40,7 +40,7 @@ class QueryGen {
40
40
  const typeOutRaw = this.typesGen.generateType(returnType.type, 0, true);
41
41
  // Unwrap langError result
42
42
  const typeOut = typeOutRaw.match(/^(\w+)<(.*), (.*)>$/).at(2);
43
- return `GenericContractQueryCall<ChainApi, (${paramsOut && `${paramsOut},`} ${optionsParamName}?: ContractCallOptions) => Promise<GenericContractCallResult<${typeOut}, ContractCallResult<ChainApi>>>, Type>`;
43
+ return `GenericContractQueryCall<(${paramsOut && `${paramsOut},`} ${optionsParamName}?: ContractCallOptions) => Promise<GenericContractCallResult<${typeOut}, ContractCallResult>>, Type>`;
44
44
  }
45
45
  generateParamsOut(args) {
46
46
  return args
@@ -17,7 +17,7 @@ class TxGen extends QueryGen_js_1.QueryGen {
17
17
  }
18
18
  generateMethodDef(def, optionsParamName = 'options') {
19
19
  const paramsOut = this.generateParamsOut(def.args);
20
- return `GenericContractTxCall<ChainApi, (${paramsOut && `${paramsOut},`} ${optionsParamName}?: ContractTxOptions) => ContractSubmittableExtrinsic<ChainApi>, Type>`;
20
+ return `GenericContractTxCall<(${paramsOut && `${paramsOut},`} ${optionsParamName}?: ContractTxOptions) => ContractSubmittableExtrinsic, Type>`;
21
21
  }
22
22
  }
23
23
  exports.TxGen = TxGen;
@@ -2,6 +2,6 @@
2
2
 
3
3
  {{{ importTypes }}}
4
4
 
5
- export interface ConstructorQuery<ChainApi extends GenericSubstrateApi, Type extends MetadataType> extends GenericConstructorQuery<ChainApi, Type> {
5
+ export interface ConstructorQuery<Type extends MetadataType> extends GenericConstructorQuery<Type> {
6
6
  {{{ constructorsOut }}}
7
7
  }
@@ -3,9 +3,8 @@
3
3
  {{{ importTypes }}}
4
4
 
5
5
  export interface ConstructorTx<
6
- ChainApi extends GenericSubstrateApi,
7
6
  ContractApi extends InkGenericContractApi,
8
7
  Type extends MetadataType
9
- > extends GenericConstructorTx<ChainApi, Type> {
8
+ > extends GenericConstructorTx<Type> {
10
9
  {{{ constructorsOut }}}
11
10
  }
@@ -2,6 +2,6 @@
2
2
 
3
3
  {{{ importTypes }}}
4
4
 
5
- export interface ContractEvents <ChainApi extends GenericSubstrateApi, Type extends MetadataType> extends GenericContractEvents <ChainApi, Type> {
5
+ export interface ContractEvents<Type extends MetadataType> extends GenericContractEvents <Type> {
6
6
  {{{ eventsOut }}}
7
7
  }
@@ -9,20 +9,20 @@ import { ContractEvents } from './events.js';
9
9
 
10
10
  export * from './types.js';
11
11
 
12
- {{{interfaceDocs}}}export interface {{{interfaceName}}}<Rv extends RpcVersion = RpcVersion, ChainApi extends VersionedGenericSubstrateApi = SubstrateApi> extends InkGenericContractApi<Rv, ChainApi> {
12
+ {{{interfaceDocs}}}export interface {{{interfaceName}}}<ChainApi extends GenericSubstrateApi = SubstrateApi> extends InkGenericContractApi<ChainApi> {
13
13
  metadataType: 'ink';
14
- query: ContractQuery<ChainApi[Rv], 'ink'>;
15
- tx: ContractTx<ChainApi[Rv], 'ink'>;
16
- constructorQuery: ConstructorQuery<ChainApi[Rv], 'ink'>;
17
- constructorTx: ConstructorTx<ChainApi[Rv], {{{interfaceName}}}, 'ink'>;
18
- events: ContractEvents<ChainApi[Rv], 'ink'>;
14
+ query: ContractQuery<'ink'>;
15
+ tx: ContractTx<'ink'>;
16
+ constructorQuery: ConstructorQuery<'ink'>;
17
+ constructorTx: ConstructorTx<{{{interfaceName}}}, 'ink'>;
18
+ events: ContractEvents<'ink'>;
19
19
  storage: {
20
20
  root(): Promise<{{{rootStorageName}}}>;
21
21
  lazy(): {{{lazyStorageName}}};
22
22
  };
23
23
 
24
24
  types: {
25
- ChainApi: ChainApi[Rv];
25
+ ChainApi: ChainApi;
26
26
  RootStorage: {{{rootStorageName}}};
27
27
  LazyStorage: {{{lazyStorageName}}};
28
28
  LangError: {{{langErrorName}}};
@@ -2,6 +2,6 @@
2
2
 
3
3
  {{{ importTypes }}}
4
4
 
5
- export interface ContractQuery<ChainApi extends GenericSubstrateApi, Type extends MetadataType> extends GenericContractQuery<ChainApi, Type> {
5
+ export interface ContractQuery<Type extends MetadataType> extends GenericContractQuery<Type> {
6
6
  {{{ queryCallsOut }}}
7
7
  }
@@ -2,6 +2,6 @@
2
2
 
3
3
  {{{ importTypes }}}
4
4
 
5
- export interface ContractTx<ChainApi extends GenericSubstrateApi, Type extends MetadataType> extends GenericContractTx<ChainApi, Type> {
5
+ export interface ContractTx<Type extends MetadataType> extends GenericContractTx<Type> {
6
6
  {{{ txCallsOut }}}
7
7
  }