@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
|
@@ -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'
|
|
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<
|
|
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<
|
|
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
|
|
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'
|
|
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
|
|
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
|
|
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<
|
|
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<
|
|
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', '
|
|
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<
|
|
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<
|
|
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<
|
|
64
|
-
Extrinsic<${addressTypeIn}, T, ${signatureTypeIn},
|
|
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<
|
|
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'
|
|
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<
|
|
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
|
|
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 });
|
package/cjs/chaintypes/index.js
CHANGED
|
@@ -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(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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(
|
|
44
|
-
const
|
|
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
|
-
|
|
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);
|
|
@@ -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
|
|
23
|
-
rpc: ChainJsonRpcApis
|
|
24
|
-
consts: ChainConsts
|
|
25
|
-
query: ChainStorage
|
|
26
|
-
errors: ChainErrors
|
|
27
|
-
events: ChainEvents
|
|
28
|
-
call: RuntimeApis
|
|
29
|
-
view: ChainViewFunctions
|
|
30
|
-
tx: ChainTx<
|
|
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
|
|
5
|
+
export type ChainJsonRpcApis =
|
|
6
6
|
{{#if jsonRpcMethods.length}}
|
|
7
|
-
Pick<JsonRpcApis, {{{jsonRpcMethods}}}> & GenericJsonRpcApis
|
|
7
|
+
Pick<JsonRpcApis, {{{jsonRpcMethods}}}> & GenericJsonRpcApis;
|
|
8
8
|
{{else}}
|
|
9
|
-
JsonRpcApis & GenericJsonRpcApis
|
|
9
|
+
JsonRpcApis & GenericJsonRpcApis;
|
|
10
10
|
{{/if}}
|
|
@@ -4,6 +4,6 @@
|
|
|
4
4
|
|
|
5
5
|
{{{ defTypes }}}
|
|
6
6
|
|
|
7
|
-
export interface ChainTx<
|
|
7
|
+
export interface ChainTx<ChainKnownTypes extends GenericChainKnownTypes = GenericChainKnownTypes> extends GenericChainTx<TxCall<ChainKnownTypes>> {
|
|
8
8
|
{{{ txDefsOut }}}
|
|
9
9
|
}
|
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<
|
|
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<
|
|
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('
|
|
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<
|
|
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<
|
|
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
|
|
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
|
}
|
|
@@ -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,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
|
}
|
|
@@ -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/cjs/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
|
}
|
|
@@ -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<
|
|
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<
|
|
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('
|
|
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<
|
|
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<
|
|
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<
|
|
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
|
}
|
|
@@ -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
|
}
|