* adds definitions and types according to ink v5 changes
* adds toV5 boilerplate code draft
* adds v5 flipper test contract code
* fix license dates
* adds test v5 toLatest test
* implements new scheme to determine event
* apply linter changes
* adds test result outputs
* change `EventRecord['topics'][0]` type to plain `Hash`
* adds testcases for decoding payload data of a ink!v4 and ink!v5 event
* changes `Abi.decodeEvent(data:Bytes)` method interface to `Abi.decodeEvent(record:EventRecord)` which includes the event and the topic for decoding.
* draft implementation with version metadata
* cleaner implementation of versioned Metadata by actually leveraging the `version` field included since v2 contract metadata
* trying to make linter happy
* makes `ContractMetadataSupported` in internal to `Abi` type and not exposing it externally.
* properly types unused parameter for tsc 🤷
* adds `@polkadot/types-support` dev dependency
* Update yarn.lock
* references `types-support` in `api-contract
* resolving change requests
* resolves linter warnings
* changes ContractMetadataV5 field to `u64` from `Text`
* adds contracts and contract metadata compiled with the most recent ink version
* implements decoding of anonymous events if possible
* removes done todo comments
59 lines
2.2 KiB
JavaScript
59 lines
2.2 KiB
JavaScript
// Copyright 2017-2024 @polkadot/typegen authors & contributors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
import fs from 'node:fs';
|
|
|
|
import { fetch } from '@polkadot/x-fetch';
|
|
|
|
const PREAMBLE = '// Copyright 2017-2024 @polkadot/types-support authors & contributors\n// SPDX-License-Identifier: Apache-2.0\n\n/* eslint-disable */\n\n';
|
|
const CMD = {
|
|
kusama: `${PREAMBLE}// cargo run --release -- purge-chain -y --chain kusama-dev && cargo run --release -- --chain kusama-dev --alice --force-authoring\n\nexport default`,
|
|
polkadot: `${PREAMBLE}// cargo run --release -- purge-chain -y --dev && cargo run --release -- --dev\n\nexport default`,
|
|
substrate: `${PREAMBLE}// cargo run --release -- purge-chain -y --dev && cargo run --release -- --dev\n\nexport default`,
|
|
'substrate-contracts-node': `${PREAMBLE}// cargo run --release -- purge-chain -y --dev && cargo run --release -- --dev\n\nexport default`
|
|
};
|
|
|
|
let requestId = 0;
|
|
|
|
/**
|
|
*
|
|
* @param {'rpc_methods' | 'state_getMetadata' | 'state_getRuntimeVersion'} method
|
|
* @returns {Promise<any>}
|
|
*/
|
|
async function get (method) {
|
|
const res = await fetch('http://127.0.0.1:9944', {
|
|
body: JSON.stringify({
|
|
id: ++requestId,
|
|
jsonrpc: '2.0',
|
|
method,
|
|
params: []
|
|
}),
|
|
headers: {
|
|
Accept: 'application/json',
|
|
'Content-Type': 'application/json'
|
|
},
|
|
method: 'post'
|
|
});
|
|
const body = await res.json();
|
|
|
|
return body.result;
|
|
}
|
|
|
|
/** @type {[string[], string, { specName: 'polkadot' | 'kusama' | 'node'; specVersion: string; }]} */
|
|
const [methods, metadata, version] = await Promise.all([
|
|
get('rpc_methods'),
|
|
get('state_getMetadata'),
|
|
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}`;
|
|
|
|
fs.writeFileSync(`${path}-hex.ts`, `${CMD[chain]} '${metadata}';\n`);
|
|
fs.writeFileSync(`${path}-rpc.ts`, `${CMD[chain]} ${JSON.stringify(methods, null, 2)};\n`);
|
|
fs.writeFileSync(`${path}-ver.ts`, `${CMD[chain]} ${JSON.stringify(version, null, 2)};\n`);
|
|
|
|
console.log(`Retrieved ${chain}/${version.specVersion}, metadata v${metaVer}`);
|