@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.
- 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/ConstructorTxGen.js +1 -1
- package/cjs/sol/generator/IndexGen.js +1 -1
- package/cjs/sol/generator/QueryGen.js +1 -1
- package/cjs/sol/generator/TxGen.js +1 -1
- package/cjs/sol/templates/constructor-query.hbs +1 -1
- package/cjs/sol/templates/constructor-tx.hbs +1 -2
- package/cjs/sol/templates/events.hbs +1 -1
- package/cjs/sol/templates/index.hbs +7 -7
- package/cjs/sol/templates/query.hbs +1 -1
- package/cjs/sol/templates/tx.hbs +1 -1
- package/cjs/typink/generator/ConstructorQueryGen.js +1 -1
- package/cjs/typink/generator/ConstructorTxGen.js +1 -1
- package/cjs/typink/generator/IndexGen.js +1 -1
- package/cjs/typink/generator/QueryGen.js +1 -1
- package/cjs/typink/generator/TxGen.js +1 -1
- package/cjs/typink/templates/constructor-query.hbs +1 -1
- package/cjs/typink/templates/constructor-tx.hbs +1 -2
- package/cjs/typink/templates/events.hbs +1 -1
- package/cjs/typink/templates/index.hbs +7 -7
- package/cjs/typink/templates/query.hbs +1 -1
- package/cjs/typink/templates/tx.hbs +1 -1
- 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/ConstructorTxGen.js +1 -1
- package/sol/generator/IndexGen.js +1 -1
- package/sol/generator/QueryGen.js +1 -1
- package/sol/generator/TxGen.js +1 -1
- package/sol/templates/constructor-query.hbs +1 -1
- package/sol/templates/constructor-tx.hbs +1 -2
- package/sol/templates/events.hbs +1 -1
- package/sol/templates/index.hbs +7 -7
- package/sol/templates/query.hbs +1 -1
- package/sol/templates/tx.hbs +1 -1
- package/typink/generator/ConstructorQueryGen.js +1 -1
- package/typink/generator/ConstructorTxGen.js +1 -1
- package/typink/generator/IndexGen.js +1 -1
- package/typink/generator/QueryGen.js +1 -1
- package/typink/generator/TxGen.js +1 -1
- package/typink/templates/constructor-query.hbs +1 -1
- package/typink/templates/constructor-tx.hbs +1 -2
- package/typink/templates/events.hbs +1 -1
- package/typink/templates/index.hbs +7 -7
- package/typink/templates/query.hbs +1 -1
- package/typink/templates/tx.hbs +1 -1
- package/utils.d.ts +9 -0
- package/utils.js +25 -0
package/cjs/utils.js
CHANGED
|
@@ -26,7 +26,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.getVariantDeprecationComment = exports.getDeprecationComment = exports.isNativeType = exports.isReservedWord = exports.compileTemplate = exports.beautifySourceCode = exports.commentBlock = exports.TUPLE_TYPE_REGEX = exports.WRAPPER_TYPE_REGEX = void 0;
|
|
29
|
+
exports.resolveBlockHash = exports.getVariantDeprecationComment = exports.getDeprecationComment = exports.isNativeType = exports.isReservedWord = exports.compileTemplate = exports.beautifySourceCode = exports.commentBlock = exports.TUPLE_TYPE_REGEX = exports.WRAPPER_TYPE_REGEX = void 0;
|
|
30
|
+
const utils_1 = require("@dedot/utils");
|
|
30
31
|
const fs = __importStar(require("fs"));
|
|
31
32
|
const handlebars_1 = __importDefault(require("handlebars"));
|
|
32
33
|
const path = __importStar(require("path"));
|
|
@@ -51,6 +52,7 @@ exports.commentBlock = commentBlock;
|
|
|
51
52
|
const beautifySourceCode = async (source) => {
|
|
52
53
|
const prettierOptions = await prettier.resolveConfig(path.resolve((0, dirname_js_1.currentDirname)(), '../../../.prettierrc.cjs'));
|
|
53
54
|
return prettier.format(source, { parser: 'babel-ts', ...prettierOptions });
|
|
55
|
+
// return source;
|
|
54
56
|
};
|
|
55
57
|
exports.beautifySourceCode = beautifySourceCode;
|
|
56
58
|
const compileTemplate = (templateFile) => {
|
|
@@ -141,3 +143,27 @@ const getVariantDeprecationComment = (deprecationInfo, variantIndex) => {
|
|
|
141
143
|
}
|
|
142
144
|
};
|
|
143
145
|
exports.getVariantDeprecationComment = getVariantDeprecationComment;
|
|
146
|
+
/**
|
|
147
|
+
* Resolve block hash from either a block hash or block number
|
|
148
|
+
* @param client - The API client
|
|
149
|
+
* @param at - Block hash (0x...) or block number (number)
|
|
150
|
+
* @returns The resolved block hash
|
|
151
|
+
*/
|
|
152
|
+
async function resolveBlockHash(client, at) {
|
|
153
|
+
// Check if it's a hex string (block hash)
|
|
154
|
+
if ((0, utils_1.isHex)(at)) {
|
|
155
|
+
return at;
|
|
156
|
+
}
|
|
157
|
+
// Try to parse as a number (block height)
|
|
158
|
+
const blockNumber = parseInt(at, 10);
|
|
159
|
+
if (isNaN(blockNumber) || blockNumber < 0) {
|
|
160
|
+
throw new utils_1.DedotError(`Invalid block specifier: ${at}. Must be a block hash (0x...) or block number.`);
|
|
161
|
+
}
|
|
162
|
+
// Resolve block number to block hash
|
|
163
|
+
const blockHash = await client.rpc.chain_getBlockHash(blockNumber);
|
|
164
|
+
if (!blockHash) {
|
|
165
|
+
throw new utils_1.DedotError(`Block not found at height: ${blockNumber}`);
|
|
166
|
+
}
|
|
167
|
+
return blockHash;
|
|
168
|
+
}
|
|
169
|
+
exports.resolveBlockHash = resolveBlockHash;
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dedot/codegen",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Generate types",
|
|
5
5
|
"author": "Thang X. Vu <thang@dedot.dev>",
|
|
6
6
|
"homepage": "https://dedot.dev",
|
|
@@ -19,16 +19,16 @@
|
|
|
19
19
|
"copy": "cp -R ./src/chaintypes/templates ./dist/chaintypes && cp -R ./src/chaintypes/templates ./dist/cjs/chaintypes && cp -R ./src/typink/templates ./dist/typink && cp -R ./src/typink/templates ./dist/cjs/typink && cp -R ./src/sol/templates ./dist/sol && cp -R ./src/sol/templates ./dist/cjs/sol"
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@dedot/api": "0.
|
|
23
|
-
"@dedot/codecs": "0.
|
|
24
|
-
"@dedot/contracts": "0.
|
|
25
|
-
"@dedot/providers": "0.
|
|
26
|
-
"@dedot/runtime-specs": "0.
|
|
27
|
-
"@dedot/shape": "0.
|
|
28
|
-
"@dedot/types": "0.
|
|
29
|
-
"@dedot/utils": "0.
|
|
22
|
+
"@dedot/api": "1.0.0",
|
|
23
|
+
"@dedot/codecs": "1.0.0",
|
|
24
|
+
"@dedot/contracts": "1.0.0",
|
|
25
|
+
"@dedot/providers": "1.0.0",
|
|
26
|
+
"@dedot/runtime-specs": "1.0.0",
|
|
27
|
+
"@dedot/shape": "1.0.0",
|
|
28
|
+
"@dedot/types": "1.0.0",
|
|
29
|
+
"@dedot/utils": "1.0.0",
|
|
30
30
|
"handlebars": "^4.7.8",
|
|
31
|
-
"prettier": "^3.
|
|
31
|
+
"prettier": "^3.7.3"
|
|
32
32
|
},
|
|
33
33
|
"publishConfig": {
|
|
34
34
|
"access": "public",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"node": ">=18"
|
|
39
39
|
},
|
|
40
40
|
"license": "Apache-2.0",
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "7767062a2188b4ac90561c5ad3cc3f06ac608a24",
|
|
42
42
|
"module": "./index.js",
|
|
43
43
|
"types": "./index.d.ts",
|
|
44
44
|
"exports": {
|
|
@@ -29,7 +29,7 @@ export class ConstructorQueryGen {
|
|
|
29
29
|
}
|
|
30
30
|
generateMethodDef(abiItem, optionsParamName = 'options') {
|
|
31
31
|
const paramsOut = this.generateParamsOut(abiItem);
|
|
32
|
-
return `GenericConstructorQueryCall<
|
|
32
|
+
return `GenericConstructorQueryCall<(${paramsOut && `${paramsOut},`} ${optionsParamName}?: ConstructorCallOptions) => Promise<GenericConstructorCallResult<[], ContractInstantiateResult>>, Type>`;
|
|
33
33
|
}
|
|
34
34
|
generateParamsOut(abiItem) {
|
|
35
35
|
return abiItem.inputs
|
|
@@ -13,6 +13,6 @@ export class ConstructorTxGen extends ConstructorQueryGen {
|
|
|
13
13
|
}
|
|
14
14
|
generateMethodDef(abiItem, optionsParamName = 'options') {
|
|
15
15
|
const paramsOut = this.generateParamsOut(abiItem);
|
|
16
|
-
return `GenericConstructorTxCall<
|
|
16
|
+
return `GenericConstructorTxCall<(${paramsOut && `${paramsOut},`} ${optionsParamName}?: ConstructorTxOptions) => GenericInstantiateSubmittableExtrinsic<ContractApi>, Type>`;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
@@ -10,7 +10,7 @@ export class IndexGen {
|
|
|
10
10
|
generate(useSubPaths = false) {
|
|
11
11
|
const interfaceName = this.interfaceName;
|
|
12
12
|
const typeImports = new TypeImports();
|
|
13
|
-
typeImports.addKnownType('
|
|
13
|
+
typeImports.addKnownType('GenericSubstrateApi', 'RpcVersion', 'RpcV2');
|
|
14
14
|
typeImports.addContractType('SolGenericContractApi', 'SolRegistry');
|
|
15
15
|
typeImports.addChainType('SubstrateApi');
|
|
16
16
|
const importTypes = typeImports.toImports({ useSubPaths });
|
|
@@ -36,7 +36,7 @@ export class QueryGen {
|
|
|
36
36
|
const typeOutInner = `${outputs.map((o) => this.typesGen.generateType(o, abiItem, 1, true)).join(',')}`;
|
|
37
37
|
// If there is only one output, we don't need to wrap it in a tuple, for user-friendly
|
|
38
38
|
const typeOut = outputs.length === 1 ? typeOutInner : `[${typeOutInner}]`;
|
|
39
|
-
return `GenericContractQueryCall<
|
|
39
|
+
return `GenericContractQueryCall<(${paramsOut && `${paramsOut},`} ${optionsParamName}?: ContractCallOptions) => Promise<GenericContractCallResult<${typeOut}, ContractCallResult>>, Type>`;
|
|
40
40
|
}
|
|
41
41
|
generateParamsOut(abiItem) {
|
|
42
42
|
return abiItem.inputs
|
package/sol/generator/TxGen.js
CHANGED
|
@@ -13,6 +13,6 @@ export class TxGen extends QueryGen {
|
|
|
13
13
|
}
|
|
14
14
|
generateMethodDef(abiItem, optionsParamName = 'options') {
|
|
15
15
|
const paramsOut = this.generateParamsOut(abiItem);
|
|
16
|
-
return `GenericContractTxCall<
|
|
16
|
+
return `GenericContractTxCall<(${paramsOut && `${paramsOut},`} ${optionsParamName}?: ContractTxOptions) => ContractSubmittableExtrinsic, Type>`;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
{{{ importTypes }}}
|
|
4
4
|
|
|
5
|
-
export interface ConstructorQuery
|
|
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
|
|
8
|
+
> extends GenericConstructorTx<Type> {
|
|
10
9
|
{{{ constructorsOut }}}
|
|
11
10
|
}
|
package/sol/templates/events.hbs
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
{{{ importTypes }}}
|
|
4
4
|
|
|
5
|
-
export interface ContractEvents
|
|
5
|
+
export interface ContractEvents<Type extends MetadataType> extends GenericContractEvents<Type> {
|
|
6
6
|
{{{ eventsOut }}}
|
|
7
7
|
}
|
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<
|
|
15
|
-
tx: ContractTx<
|
|
16
|
-
constructorQuery: ConstructorQuery<
|
|
17
|
-
events: ContractEvents<
|
|
18
|
-
constructorTx: ConstructorTx<
|
|
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
|
|
21
|
+
ChainApi: ChainApi;
|
|
22
22
|
};
|
|
23
23
|
}
|
package/sol/templates/query.hbs
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
{{{ importTypes }}}
|
|
4
4
|
|
|
5
|
-
export interface ContractQuery<
|
|
5
|
+
export interface ContractQuery<Type extends MetadataType> extends GenericContractQuery<Type> {
|
|
6
6
|
{{{ queryCallsOut }}}
|
|
7
7
|
}
|
package/sol/templates/tx.hbs
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
{{{ importTypes }}}
|
|
4
4
|
|
|
5
|
-
export interface ContractTx<
|
|
5
|
+
export interface ContractTx<Type extends MetadataType> extends GenericContractTx<Type> {
|
|
6
6
|
{{{ txCallsOut }}}
|
|
7
7
|
}
|
|
@@ -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<
|
|
20
|
+
return `GenericConstructorQueryCall<(${paramsOut && `${paramsOut},`} ${optionsParamName}?: ConstructorCallOptions) => Promise<GenericConstructorCallResult<${typeOut}, ContractInstantiateResult>>, Type>`;
|
|
21
21
|
}
|
|
22
22
|
}
|
|
@@ -13,6 +13,6 @@ export class ConstructorTxGen extends QueryGen {
|
|
|
13
13
|
}
|
|
14
14
|
generateMethodDef(def, optionsParamName = 'options') {
|
|
15
15
|
const paramsOut = this.generateParamsOut(def.args);
|
|
16
|
-
return `GenericConstructorTxCall<
|
|
16
|
+
return `GenericConstructorTxCall<(${paramsOut && `${paramsOut},`} ${optionsParamName}?: ConstructorTxOptions) => GenericInstantiateSubmittableExtrinsic<ContractApi>, Type>`;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
@@ -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<
|
|
40
|
+
return `GenericContractQueryCall<(${paramsOut && `${paramsOut},`} ${optionsParamName}?: ContractCallOptions) => Promise<GenericContractCallResult<${typeOut}, ContractCallResult>>, Type>`;
|
|
41
41
|
}
|
|
42
42
|
generateParamsOut(args) {
|
|
43
43
|
return args
|
|
@@ -14,6 +14,6 @@ export class TxGen extends QueryGen {
|
|
|
14
14
|
}
|
|
15
15
|
generateMethodDef(def, optionsParamName = 'options') {
|
|
16
16
|
const paramsOut = this.generateParamsOut(def.args);
|
|
17
|
-
return `GenericContractTxCall<
|
|
17
|
+
return `GenericContractTxCall<(${paramsOut && `${paramsOut},`} ${optionsParamName}?: ContractTxOptions) => ContractSubmittableExtrinsic, Type>`;
|
|
18
18
|
}
|
|
19
19
|
}
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
{{{ importTypes }}}
|
|
4
4
|
|
|
5
|
-
export interface ConstructorQuery<
|
|
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<
|
|
8
|
+
> extends GenericConstructorTx<Type> {
|
|
10
9
|
{{{ constructorsOut }}}
|
|
11
10
|
}
|
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
{{{ importTypes }}}
|
|
4
4
|
|
|
5
|
-
export interface ContractEvents
|
|
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}}}<
|
|
12
|
+
{{{interfaceDocs}}}export interface {{{interfaceName}}}<ChainApi extends GenericSubstrateApi = SubstrateApi> extends InkGenericContractApi<ChainApi> {
|
|
13
13
|
metadataType: 'ink';
|
|
14
|
-
query: ContractQuery<
|
|
15
|
-
tx: ContractTx<
|
|
16
|
-
constructorQuery: ConstructorQuery<
|
|
17
|
-
constructorTx: ConstructorTx<
|
|
18
|
-
events: ContractEvents<
|
|
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
|
|
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<
|
|
5
|
+
export interface ContractQuery<Type extends MetadataType> extends GenericContractQuery<Type> {
|
|
6
6
|
{{{ queryCallsOut }}}
|
|
7
7
|
}
|
package/typink/templates/tx.hbs
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
{{{ importTypes }}}
|
|
4
4
|
|
|
5
|
-
export interface ContractTx<
|
|
5
|
+
export interface ContractTx<Type extends MetadataType> extends GenericContractTx<Type> {
|
|
6
6
|
{{{ txCallsOut }}}
|
|
7
7
|
}
|
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
|
+
}
|