@dedot/codegen 0.18.7 → 1.0.0-next.a0f8d41e.25

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 (63) 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/IndexGen.js +1 -1
  44. package/cjs/sol/generator/QueryGen.js +1 -1
  45. package/cjs/sol/templates/index.hbs +7 -7
  46. package/cjs/typink/generator/ConstructorQueryGen.js +1 -1
  47. package/cjs/typink/generator/IndexGen.js +1 -1
  48. package/cjs/typink/generator/QueryGen.js +1 -1
  49. package/cjs/typink/templates/index.hbs +7 -7
  50. package/cjs/utils.js +27 -1
  51. package/index.d.ts +1 -0
  52. package/index.js +1 -0
  53. package/package.json +11 -11
  54. package/sol/generator/ConstructorQueryGen.js +1 -1
  55. package/sol/generator/IndexGen.js +1 -1
  56. package/sol/generator/QueryGen.js +1 -1
  57. package/sol/templates/index.hbs +7 -7
  58. package/typink/generator/ConstructorQueryGen.js +1 -1
  59. package/typink/generator/IndexGen.js +1 -1
  60. package/typink/generator/QueryGen.js +1 -1
  61. package/typink/templates/index.hbs +7 -7
  62. package/utils.d.ts +9 -0
  63. package/utils.js +25 -0
@@ -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<ChainApi, 'sol'>;
15
+ tx: ContractTx<ChainApi, 'sol'>;
16
+ constructorQuery: ConstructorQuery<ChainApi, 'sol'>;
17
+ events: ContractEvents<ChainApi, 'sol'>;
18
+ constructorTx: ConstructorTx<ChainApi, {{{interfaceName}}}, 'sol'>;
19
19
 
20
20
  types: {
21
- ChainApi: ChainApi[Rv];
21
+ ChainApi: ChainApi;
22
22
  };
23
23
  }
@@ -17,6 +17,6 @@ export class ConstructorQueryGen extends QueryGen {
17
17
  const typeOutRaw = this.typesGen.generateType(returnType.type, 0, true);
18
18
  // Unwrap langError result
19
19
  const typeOut = typeOutRaw.match(/^(\w+)<(.*), (.*)>$/).at(2);
20
- return `GenericConstructorQueryCall<ChainApi, (${paramsOut && `${paramsOut},`} ${optionsParamName}?: ConstructorCallOptions) => Promise<GenericConstructorCallResult<${typeOut}, ContractInstantiateResult<ChainApi>>>, Type>`;
20
+ return `GenericConstructorQueryCall<ChainApi, (${paramsOut && `${paramsOut},`} ${optionsParamName}?: ConstructorCallOptions) => Promise<GenericConstructorCallResult<${typeOut}, ContractInstantiateResult>>, Type>`;
21
21
  }
22
22
  }
@@ -15,7 +15,7 @@ export class IndexGen {
15
15
  const langErrorId = this.contractMetadata.spec.lang_error.type;
16
16
  const langErrorName = this.typesGen.cleanPath(this.contractMetadata.types[langErrorId].type.path);
17
17
  const typeImports = new TypeImports();
18
- typeImports.addKnownType('VersionedGenericSubstrateApi', 'RpcVersion', 'RpcV2');
18
+ typeImports.addKnownType('GenericSubstrateApi', 'RpcVersion', 'RpcV2');
19
19
  typeImports.addContractType('InkGenericContractApi', 'WithLazyStorage');
20
20
  typeImports.addChainType('SubstrateApi');
21
21
  typeImports.addPortableType(langErrorName);
@@ -37,7 +37,7 @@ export class QueryGen {
37
37
  const typeOutRaw = this.typesGen.generateType(returnType.type, 0, true);
38
38
  // Unwrap langError result
39
39
  const typeOut = typeOutRaw.match(/^(\w+)<(.*), (.*)>$/).at(2);
40
- return `GenericContractQueryCall<ChainApi, (${paramsOut && `${paramsOut},`} ${optionsParamName}?: ContractCallOptions) => Promise<GenericContractCallResult<${typeOut}, ContractCallResult<ChainApi>>>, Type>`;
40
+ return `GenericContractQueryCall<ChainApi, (${paramsOut && `${paramsOut},`} ${optionsParamName}?: ContractCallOptions) => Promise<GenericContractCallResult<${typeOut}, ContractCallResult>>, Type>`;
41
41
  }
42
42
  generateParamsOut(args) {
43
43
  return args
@@ -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<ChainApi, 'ink'>;
15
+ tx: ContractTx<ChainApi, 'ink'>;
16
+ constructorQuery: ConstructorQuery<ChainApi, 'ink'>;
17
+ constructorTx: ConstructorTx<ChainApi, {{{interfaceName}}}, 'ink'>;
18
+ events: ContractEvents<ChainApi, '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}}};
package/utils.d.ts CHANGED
@@ -1,4 +1,6 @@
1
+ import { DedotClient } from '@dedot/api';
1
2
  import { ItemDeprecationInfoDefV16, EnumDeprecationInfoDefV16 } from '@dedot/codecs';
3
+ import { HexString } from '@dedot/utils';
2
4
  export declare const WRAPPER_TYPE_REGEX: RegExp;
3
5
  export declare const TUPLE_TYPE_REGEX: RegExp;
4
6
  export declare const commentBlock: (...docs: (string | string[])[]) => string;
@@ -27,3 +29,10 @@ export declare const getDeprecationComment: (deprecationInfo: ItemDeprecationInf
27
29
  * @param variantIndex
28
30
  */
29
31
  export declare const getVariantDeprecationComment: (deprecationInfo: EnumDeprecationInfoDefV16 | undefined, variantIndex: number) => string[];
32
+ /**
33
+ * Resolve block hash from either a block hash or block number
34
+ * @param client - The API client
35
+ * @param at - Block hash (0x...) or block number (number)
36
+ * @returns The resolved block hash
37
+ */
38
+ export declare function resolveBlockHash(client: DedotClient, at: string): Promise<HexString>;
package/utils.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { DedotError, isHex } from '@dedot/utils';
1
2
  import * as fs from 'fs';
2
3
  import handlebars from 'handlebars';
3
4
  import * as path from 'path';
@@ -21,6 +22,7 @@ ${flatLines.map((line) => `* ${line.replaceAll(/\s+/g, ' ').trim()}`).join('\n')
21
22
  export const beautifySourceCode = async (source) => {
22
23
  const prettierOptions = await prettier.resolveConfig(path.resolve(currentDirname(), '../../../.prettierrc.cjs'));
23
24
  return prettier.format(source, { parser: 'babel-ts', ...prettierOptions });
25
+ // return source;
24
26
  };
25
27
  export const compileTemplate = (templateFile) => {
26
28
  const templateFilePath = path.resolve(currentDirname(), templateFile);
@@ -105,3 +107,26 @@ export const getVariantDeprecationComment = (deprecationInfo, variantIndex) => {
105
107
  return [];
106
108
  }
107
109
  };
110
+ /**
111
+ * Resolve block hash from either a block hash or block number
112
+ * @param client - The API client
113
+ * @param at - Block hash (0x...) or block number (number)
114
+ * @returns The resolved block hash
115
+ */
116
+ export async function resolveBlockHash(client, at) {
117
+ // Check if it's a hex string (block hash)
118
+ if (isHex(at)) {
119
+ return at;
120
+ }
121
+ // Try to parse as a number (block height)
122
+ const blockNumber = parseInt(at, 10);
123
+ if (isNaN(blockNumber) || blockNumber < 0) {
124
+ throw new DedotError(`Invalid block specifier: ${at}. Must be a block hash (0x...) or block number.`);
125
+ }
126
+ // Resolve block number to block hash
127
+ const blockHash = await client.rpc.chain_getBlockHash(blockNumber);
128
+ if (!blockHash) {
129
+ throw new DedotError(`Block not found at height: ${blockNumber}`);
130
+ }
131
+ return blockHash;
132
+ }