@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.
- package/chaintypes/generator/ConstsGen.js +1 -1
- package/chaintypes/generator/ErrorsGen.js +3 -3
- package/chaintypes/generator/EventsGen.js +3 -3
- package/chaintypes/generator/IndexGen.d.ts +1 -0
- package/chaintypes/generator/IndexGen.js +34 -2
- package/chaintypes/generator/JsonRpcGen.js +1 -1
- package/chaintypes/generator/QueryGen.js +4 -4
- package/chaintypes/generator/RuntimeApisGen.js +5 -5
- package/chaintypes/generator/TxGen.js +6 -10
- package/chaintypes/generator/ViewFunctionsGen.js +3 -3
- package/chaintypes/index.d.ts +22 -3
- package/chaintypes/index.js +63 -13
- package/chaintypes/templates/consts.hbs +1 -1
- package/chaintypes/templates/errors.hbs +1 -1
- package/chaintypes/templates/events.hbs +1 -1
- package/chaintypes/templates/index.hbs +10 -14
- package/chaintypes/templates/json-rpc.hbs +3 -3
- package/chaintypes/templates/query.hbs +1 -1
- package/chaintypes/templates/runtime.hbs +1 -1
- package/chaintypes/templates/tx.hbs +1 -1
- package/chaintypes/templates/view-functions.hbs +1 -1
- package/cjs/chaintypes/generator/ConstsGen.js +1 -1
- package/cjs/chaintypes/generator/ErrorsGen.js +3 -3
- package/cjs/chaintypes/generator/EventsGen.js +3 -3
- package/cjs/chaintypes/generator/IndexGen.js +34 -2
- package/cjs/chaintypes/generator/JsonRpcGen.js +1 -1
- package/cjs/chaintypes/generator/QueryGen.js +4 -4
- package/cjs/chaintypes/generator/RuntimeApisGen.js +5 -5
- package/cjs/chaintypes/generator/TxGen.js +6 -10
- package/cjs/chaintypes/generator/ViewFunctionsGen.js +3 -3
- package/cjs/chaintypes/index.js +61 -11
- package/cjs/chaintypes/templates/consts.hbs +1 -1
- package/cjs/chaintypes/templates/errors.hbs +1 -1
- package/cjs/chaintypes/templates/events.hbs +1 -1
- package/cjs/chaintypes/templates/index.hbs +10 -14
- package/cjs/chaintypes/templates/json-rpc.hbs +3 -3
- package/cjs/chaintypes/templates/query.hbs +1 -1
- package/cjs/chaintypes/templates/runtime.hbs +1 -1
- package/cjs/chaintypes/templates/tx.hbs +1 -1
- package/cjs/chaintypes/templates/view-functions.hbs +1 -1
- package/cjs/index.js +3 -0
- package/cjs/sol/generator/ConstructorQueryGen.js +1 -1
- package/cjs/sol/generator/IndexGen.js +1 -1
- package/cjs/sol/generator/QueryGen.js +1 -1
- package/cjs/sol/templates/index.hbs +7 -7
- package/cjs/typink/generator/ConstructorQueryGen.js +1 -1
- package/cjs/typink/generator/IndexGen.js +1 -1
- package/cjs/typink/generator/QueryGen.js +1 -1
- package/cjs/typink/templates/index.hbs +7 -7
- package/cjs/utils.js +27 -1
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/package.json +11 -11
- package/sol/generator/ConstructorQueryGen.js +1 -1
- package/sol/generator/IndexGen.js +1 -1
- package/sol/generator/QueryGen.js +1 -1
- package/sol/templates/index.hbs +7 -7
- package/typink/generator/ConstructorQueryGen.js +1 -1
- package/typink/generator/IndexGen.js +1 -1
- package/typink/generator/QueryGen.js +1 -1
- package/typink/templates/index.hbs +7 -7
- package/utils.d.ts +9 -0
- package/utils.js +25 -0
package/sol/templates/index.hbs
CHANGED
|
@@ -9,15 +9,15 @@ import { ContractEvents } from './events.js';
|
|
|
9
9
|
|
|
10
10
|
export * from './types.js';
|
|
11
11
|
|
|
12
|
-
{{{interfaceDocs}}}export interface {{{interfaceName}}}<
|
|
12
|
+
{{{interfaceDocs}}}export interface {{{interfaceName}}}< ChainApi extends GenericSubstrateApi = SubstrateApi> extends SolGenericContractApi<ChainApi> {
|
|
13
13
|
metadataType: 'sol';
|
|
14
|
-
query: ContractQuery<ChainApi
|
|
15
|
-
tx: ContractTx<ChainApi
|
|
16
|
-
constructorQuery: ConstructorQuery<ChainApi
|
|
17
|
-
events: ContractEvents<ChainApi
|
|
18
|
-
constructorTx: ConstructorTx<ChainApi
|
|
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
|
|
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
|
|
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('
|
|
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
|
|
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}}}<
|
|
12
|
+
{{{interfaceDocs}}}export interface {{{interfaceName}}}< ChainApi extends GenericSubstrateApi = SubstrateApi> extends InkGenericContractApi<ChainApi> {
|
|
13
13
|
metadataType: 'ink';
|
|
14
|
-
query: ContractQuery<ChainApi
|
|
15
|
-
tx: ContractTx<ChainApi
|
|
16
|
-
constructorQuery: ConstructorQuery<ChainApi
|
|
17
|
-
constructorTx: ConstructorTx<ChainApi
|
|
18
|
-
events: ContractEvents<ChainApi
|
|
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
|
|
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
|
+
}
|