Set static metadata to v15 and update typegen to generate runtime apis and use v15 metadata (#5987)

* Set static metadata to v15

* Fix testUtil

* Fix metadata spec

* support metadata files

* lint and fix commented tests

* Fix test

* Add augment static runtime types by metadata

* Fix alias typing for runtime def types

* Cleanup and add remaining generated files

* lint

* Fix typegen for edgecase

* Update polkadot to 1003003

* Fix tests

* Set correct rpc
This commit is contained in:
Tarik Gul
2024-10-18 05:01:08 +03:00
committed by GitHub
parent 1772458304
commit bc199956f3
42 changed files with 160378 additions and 12515 deletions
+11 -6
View File
@@ -13,26 +13,31 @@ const CMD = {
'substrate-contracts-node': `${PREAMBLE}// cargo run --release -- purge-chain -y --dev && cargo run --release -- --dev\n\nexport default`
};
// V15
const META_VERSION_HEX = '0x0f000000';
const META_VERSION = 15;
let requestId = 0;
/**
*
* @param {'rpc_methods' | 'state_getMetadata' | 'state_getRuntimeVersion'} method
* @param {'rpc_methods' | 'state_getMetadata' | 'state_getRuntimeVersion' | 'state_call'} method
* @param {string[]} params
* @returns {Promise<any>}
*/
async function get (method) {
async function get (method, params = []) {
const res = await fetch('http://127.0.0.1:9944', {
body: JSON.stringify({
id: ++requestId,
jsonrpc: '2.0',
method,
params: []
params
}),
headers: {
Accept: 'application/json',
'Content-Type': 'application/json'
},
method: 'post'
method: 'POST'
});
const body = await res.json();
@@ -42,14 +47,14 @@ async function get (method) {
/** @type {[string[], string, { specName: 'polkadot' | 'kusama' | 'node'; specVersion: string; }]} */
const [methods, metadata, version] = await Promise.all([
get('rpc_methods'),
get('state_getMetadata'),
get('state_call', ['Metadata_metadata_at_version', META_VERSION_HEX]),
get('state_getRuntimeVersion')
]);
const chain = version.specName === 'node'
? 'substrate'
: version.specName;
const metaVer = parseInt(metadata.substring(10, 12), 16);
const path = `packages/types-support/src/metadata/v${metaVer}/${chain}`;
const path = `packages/types-support/src/metadata/v${META_VERSION}/${chain}`;
fs.writeFileSync(`${path}-hex.ts`, `${CMD[chain]} '${metadata}';\n`);
fs.writeFileSync(`${path}-rpc.ts`, `${CMD[chain]} ${JSON.stringify(methods, null, 2)};\n`);