diff --git a/packages/api-augment/src/kusama/runtime.ts b/packages/api-augment/src/kusama/runtime.ts index a8654bf50f..9514d45999 100644 --- a/packages/api-augment/src/kusama/runtime.ts +++ b/packages/api-augment/src/kusama/runtime.ts @@ -2,8 +2,11 @@ /* eslint-disable */ import type { ApiTypes } from '@polkadot/api-base/types'; +import type { Bytes, u32 } from '@polkadot/types-codec'; +import type { AnyNumber } from '@polkadot/types-codec/types'; import type { AuthorityList, SetId } from '@polkadot/types/interfaces/grandpa'; import type { OpaqueMetadata } from '@polkadot/types/interfaces/metadata'; +import type { FeeDetails, RuntimeDispatchInfo } from '@polkadot/types/interfaces/payment'; import type { AccountId, Index } from '@polkadot/types/interfaces/runtime'; import type { Observable } from '@polkadot/types/types'; @@ -43,5 +46,19 @@ declare module '@polkadot/api-base/types/calls' { **/ [key: string]: DecoratedCallBase; }; + transactionPaymentApi: { + /** + * The transaction fee details + **/ + queryFeeDetails: AugmentedCall Observable>; + /** + * The transaction info + **/ + queryInfo: AugmentedCall Observable>; + /** + * Generic call + **/ + [key: string]: DecoratedCallBase; + }; } // AugmentedCalls } // declare module diff --git a/packages/api-augment/src/polkadot/runtime.ts b/packages/api-augment/src/polkadot/runtime.ts index a8654bf50f..9514d45999 100644 --- a/packages/api-augment/src/polkadot/runtime.ts +++ b/packages/api-augment/src/polkadot/runtime.ts @@ -2,8 +2,11 @@ /* eslint-disable */ import type { ApiTypes } from '@polkadot/api-base/types'; +import type { Bytes, u32 } from '@polkadot/types-codec'; +import type { AnyNumber } from '@polkadot/types-codec/types'; import type { AuthorityList, SetId } from '@polkadot/types/interfaces/grandpa'; import type { OpaqueMetadata } from '@polkadot/types/interfaces/metadata'; +import type { FeeDetails, RuntimeDispatchInfo } from '@polkadot/types/interfaces/payment'; import type { AccountId, Index } from '@polkadot/types/interfaces/runtime'; import type { Observable } from '@polkadot/types/types'; @@ -43,5 +46,19 @@ declare module '@polkadot/api-base/types/calls' { **/ [key: string]: DecoratedCallBase; }; + transactionPaymentApi: { + /** + * The transaction fee details + **/ + queryFeeDetails: AugmentedCall Observable>; + /** + * The transaction info + **/ + queryInfo: AugmentedCall Observable>; + /** + * Generic call + **/ + [key: string]: DecoratedCallBase; + }; } // AugmentedCalls } // declare module diff --git a/packages/api-augment/src/substrate/runtime.ts b/packages/api-augment/src/substrate/runtime.ts index a8654bf50f..3465f5fe90 100644 --- a/packages/api-augment/src/substrate/runtime.ts +++ b/packages/api-augment/src/substrate/runtime.ts @@ -2,9 +2,13 @@ /* eslint-disable */ import type { ApiTypes } from '@polkadot/api-base/types'; +import type { Bytes, Option, u32, u64 } from '@polkadot/types-codec'; +import type { AnyNumber } from '@polkadot/types-codec/types'; +import type { CodeUploadResult, ContractExecResult, ContractInstantiateResult } from '@polkadot/types/interfaces/contracts'; import type { AuthorityList, SetId } from '@polkadot/types/interfaces/grandpa'; import type { OpaqueMetadata } from '@polkadot/types/interfaces/metadata'; -import type { AccountId, Index } from '@polkadot/types/interfaces/runtime'; +import type { FeeDetails, RuntimeDispatchInfo } from '@polkadot/types/interfaces/payment'; +import type { AccountId, Balance, Index } from '@polkadot/types/interfaces/runtime'; import type { Observable } from '@polkadot/types/types'; declare module '@polkadot/api-base/types/calls' { @@ -19,6 +23,28 @@ declare module '@polkadot/api-base/types/calls' { **/ [key: string]: DecoratedCallBase; }; + contractsApi: { + /** + * Perform a call from a specified account to a given contract. + **/ + call: AugmentedCall | null | object | string | Uint8Array, inputData: Bytes | string | Uint8Array) => Observable>; + /** + * Query a given storage key in a given contract. + **/ + getStorage: AugmentedCall Observable>>; + /** + * Instantiate a new contract. + **/ + instantiate: AugmentedCall | null | object | string | Uint8Array, code: Bytes | string | Uint8Array, data: Bytes | string | Uint8Array, salt: Bytes | string | Uint8Array) => Observable>; + /** + * Upload new code without instantiating a contract from it. + **/ + uploadCode: AugmentedCall | null | object | string | Uint8Array) => Observable>; + /** + * Generic call + **/ + [key: string]: DecoratedCallBase; + }; grandpaApi: { /** * Get current GRANDPA authority set id. @@ -43,5 +69,19 @@ declare module '@polkadot/api-base/types/calls' { **/ [key: string]: DecoratedCallBase; }; + transactionPaymentApi: { + /** + * The transaction fee details + **/ + queryFeeDetails: AugmentedCall Observable>; + /** + * The transaction info + **/ + queryInfo: AugmentedCall Observable>; + /** + * Generic call + **/ + [key: string]: DecoratedCallBase; + }; } // AugmentedCalls } // declare module diff --git a/packages/typegen/package.json b/packages/typegen/package.json index 8905dc4da5..88889759d5 100644 --- a/packages/typegen/package.json +++ b/packages/typegen/package.json @@ -44,6 +44,7 @@ "@polkadot/types-create": "8.10.2-1-x", "@polkadot/types-support": "8.10.2-1-x", "@polkadot/util": "^9.6.2", + "@polkadot/util-crypto": "^9.6.2", "@polkadot/x-ws": "^9.6.2", "handlebars": "^4.7.7", "websocket": "^1.0.34", diff --git a/packages/typegen/src/fromChain.ts b/packages/typegen/src/fromChain.ts index 6ca333a3d6..4e5846cebf 100644 --- a/packages/typegen/src/fromChain.ts +++ b/packages/typegen/src/fromChain.ts @@ -12,7 +12,9 @@ import { formatNumber } from '@polkadot/util'; import { generateDefaultCalls, generateDefaultConsts, generateDefaultErrors, generateDefaultEvents, generateDefaultQuery, generateDefaultRpc, generateDefaultTx } from './generate'; import { assertDir, assertFile, getMetadataViaWs, HEADER, writeFile } from './util'; -function generate (metaHex: HexString, pkg: string | undefined, output: string, isStrict?: boolean): void { +type Version = { apis: [HexString, number][] }; + +function generate (metaHex: HexString, version: Version | null, pkg: string | undefined, output: string, isStrict?: boolean): void { console.log(`Generating from metadata, ${formatNumber((metaHex.length - 2) / 2)} bytes`); const outputPath = assertDir(path.join(process.cwd(), output)); @@ -46,7 +48,7 @@ function generate (metaHex: HexString, pkg: string | undefined, output: string, generateDefaultQuery(path.join(outputPath, 'augment-api-query.ts'), metaHex, extraTypes, isStrict, customLookupDefinitions); generateDefaultRpc(path.join(outputPath, 'augment-api-rpc.ts'), extraTypes); generateDefaultTx(path.join(outputPath, 'augment-api-tx.ts'), metaHex, extraTypes, isStrict, customLookupDefinitions); - generateDefaultCalls(path.join(outputPath, 'augment-api-runtime.ts'), metaHex, extraTypes, isStrict, customLookupDefinitions); + generateDefaultCalls(path.join(outputPath, 'augment-api-runtime.ts'), metaHex, version, extraTypes, isStrict, customLookupDefinitions); writeFile(path.join(outputPath, 'augment-api.ts'), (): string => [ @@ -62,10 +64,10 @@ function generate (metaHex: HexString, pkg: string | undefined, output: string, process.exit(0); } -type ArgV = { endpoint: string; output: string; package?: string; strict?: boolean }; +type ArgV = { endpoint: string; output: string; package?: string; strict?: boolean, version?: string }; export function main (): void { - const { endpoint, output, package: pkg, strict: isStrict } = yargs.strict().options({ + const { endpoint, output, package: pkg, strict: isStrict, version } = yargs.strict().options({ endpoint: { description: 'The endpoint to connect to (e.g. wss://kusama-rpc.polkadot.io) or relative path to a file containing the JSON output of an RPC state_getMetadata call', required: true, @@ -83,15 +85,28 @@ export function main (): void { strict: { description: 'Turns on strict mode, no output of catch-all generic versions', type: 'boolean' + }, + version: { + description: 'Pass through a version JSON (if endpoint is non-wss)', + type: 'string' } }).argv as ArgV; if (endpoint.startsWith('wss://') || endpoint.startsWith('ws://')) { getMetadataViaWs(endpoint) - .then((metadata) => generate(metadata, pkg, output, isStrict)) + .then(({ metadata, version }) => generate(metadata, version, pkg, output, isStrict)) .catch(() => process.exit(1)); } else { + let rtv: Version | null = null; + + if (version) { + // eslint-disable-next-line @typescript-eslint/no-var-requires + rtv = (require(assertFile(path.join(process.cwd(), version))) as Record).result; + } + // eslint-disable-next-line @typescript-eslint/no-var-requires - generate((require(assertFile(path.join(process.cwd(), endpoint))) as Record).result, pkg, output, isStrict); + const metadata = (require(assertFile(path.join(process.cwd(), endpoint))) as Record).result; + + generate(metadata, rtv, pkg, output, isStrict); } } diff --git a/packages/typegen/src/fromDefs.ts b/packages/typegen/src/fromDefs.ts index 0796dfd120..bcf8c2884b 100644 --- a/packages/typegen/src/fromDefs.ts +++ b/packages/typegen/src/fromDefs.ts @@ -72,7 +72,7 @@ export function main (): void { if (endpoint) { if (endpoint.startsWith('wss://') || endpoint.startsWith('ws://')) { getMetadataViaWs(endpoint) - .then((metadata) => generateDefaultLookup(inputPath, metadata)) + .then(({ metadata }) => generateDefaultLookup(inputPath, metadata)) .catch(() => process.exit(1)); } else { // eslint-disable-next-line @typescript-eslint/no-var-requires diff --git a/packages/typegen/src/generate/runtime.ts b/packages/typegen/src/generate/runtime.ts index 82136e4760..868230fe68 100644 --- a/packages/typegen/src/generate/runtime.ts +++ b/packages/typegen/src/generate/runtime.ts @@ -12,13 +12,16 @@ import Handlebars from 'handlebars'; import * as defaultDefs from '@polkadot/types/interfaces/definitions'; import lookupDefinitions from '@polkadot/types-augment/lookup/definitions'; import { objectSpread, stringCamelCase } from '@polkadot/util'; +import { blake2AsHex } from '@polkadot/util-crypto'; import { createImports, formatType, getSimilarTypes, initMeta, readTemplate, setImports, writeFile } from '../util'; +type Apis = [HexString, number][]; + const generateCallsTypesTemplate = Handlebars.compile(readTemplate('calls')); /** @internal */ -function getDefs (defs: Record): Record> { +function getDefs (apis: Apis | null, defs: Record): Record> { const named: Record> = {}; const all = Object.values(defs); @@ -30,20 +33,31 @@ function getDefs (defs: Record): Record h === apiHash); - if (methods.length) { - const section = stringCamelCase(_section); + if (api) { + const ver = sec.find(({ version = 1 }) => version === api[1]); - if (!named[section]) { - named[section] = {}; - } + if (ver) { + const methods = Object.entries(ver.methods); - for (let m = 0; m < methods.length; m++) { - const [_method, def] = methods[m]; - const method = stringCamelCase(_method); + if (methods.length) { + const section = stringCamelCase(_section); - named[section][method] = objectSpread({ method, name: `${_section}_${method}`, section }, def); + if (!named[section]) { + named[section] = {}; + } + + for (let m = 0; m < methods.length; m++) { + const [_method, def] = methods[m]; + const method = stringCamelCase(_method); + + named[section][method] = objectSpread({ method, name: `${_section}_${method}`, section }, def); + } + } + } else { + console.warn(`Unable to find matching version for runtime ${_section}, expected ${api[1]}`); } } } @@ -54,7 +68,7 @@ function getDefs (defs: Record): Record { const allTypes: ExtraTypes = { '@polkadot/types-augment': { @@ -70,7 +84,7 @@ export function generateCallTypes (registry: TypeRegistry, dest: string, extraTy const allDefs = Object.entries(allTypes).reduce((defs, [path, obj]) => { return Object.entries(obj).reduce((defs, [key, value]) => ({ ...defs, [`${path}/${key}`]: value }), defs); }, {}); - const definitions = getDefs(imports.definitions as Record); + const definitions = getDefs(apis, imports.definitions as Record); const callKeys = Object.keys(definitions); const modules = callKeys.map((section) => { @@ -103,7 +117,9 @@ export function generateCallTypes (registry: TypeRegistry, dest: string, extraTy }; }).sort((a, b) => a.name.localeCompare(b.name)); - imports.typesTypes.Observable = true; + if (modules.length) { + imports.typesTypes.Observable = true; + } return generateCallsTypesTemplate({ headerType: 'chain', @@ -124,12 +140,13 @@ export function generateCallTypes (registry: TypeRegistry, dest: string, extraTy }); } -export function generateDefaultCalls (dest: string, data: HexString, extraTypes: ExtraTypes = {}, isStrict = false, customLookupDefinitions?: Definitions): void { +export function generateDefaultCalls (dest: string, data: HexString, rtVersion: { apis: Apis } | null = null, extraTypes: ExtraTypes = {}, isStrict = false, customLookupDefinitions?: Definitions): void { const { registry } = initMeta(data, extraTypes); generateCallTypes( registry, dest, + rtVersion && rtVersion.apis, extraTypes, isStrict, customLookupDefinitions diff --git a/packages/typegen/src/interfacesTs.ts b/packages/typegen/src/interfacesTs.ts index b411b199f2..6a5b12ee93 100644 --- a/packages/typegen/src/interfacesTs.ts +++ b/packages/typegen/src/interfacesTs.ts @@ -6,11 +6,15 @@ import type { HexString } from '@polkadot/util/types'; import kusama from '@polkadot/types-support/metadata/static-kusama'; import polkadot from '@polkadot/types-support/metadata/static-polkadot'; import substrate from '@polkadot/types-support/metadata/static-substrate'; +import kusamaVer from '@polkadot/types-support/versions/kusama'; +import polkadotVer from '@polkadot/types-support/versions/polkadot'; +import substrateVer from '@polkadot/types-support/versions/substrate'; import { generateDefaultCalls, generateDefaultConsts, generateDefaultErrors, generateDefaultEvents, generateDefaultInterface, generateDefaultLookup, generateDefaultQuery, generateDefaultRpc, generateDefaultTsDef, generateDefaultTx } from './generate'; const BASE = 'packages/api-augment/src'; const METAS = Object.entries({ kusama, polkadot, substrate }) as [string, HexString][]; +const VERS = { kusama: kusamaVer, polkadot: polkadotVer, substrate: substrateVer }; export function main (): void { generateDefaultInterface(); @@ -27,6 +31,6 @@ export function main (): void { generateDefaultEvents(`${BASE}/${name}/events.ts`, staticMeta); generateDefaultQuery(`${BASE}/${name}/query.ts`, staticMeta); generateDefaultTx(`${BASE}/${name}/tx.ts`, staticMeta); - generateDefaultCalls(`${BASE}/${name}/runtime.ts`, staticMeta); + generateDefaultCalls(`${BASE}/${name}/runtime.ts`, staticMeta, VERS[name as keyof typeof VERS] as unknown as { apis: [HexString, number][] }); } } diff --git a/packages/typegen/src/util/wsMeta.ts b/packages/typegen/src/util/wsMeta.ts index 7a9d03d600..d8fb25786d 100644 --- a/packages/typegen/src/util/wsMeta.ts +++ b/packages/typegen/src/util/wsMeta.ts @@ -5,7 +5,7 @@ import type { HexString } from '@polkadot/util/types'; import { WebSocket } from '@polkadot/x-ws'; -export async function getMetadataViaWs (endpoint: string): Promise { +async function getWsData (endpoint: string, method: 'state_getMetadata' | 'state_getRuntimeVersion'): Promise { return new Promise((resolve): void => { try { const websocket = new WebSocket(endpoint); @@ -28,11 +28,11 @@ export async function getMetadataViaWs (endpoint: string): Promise { websocket.onopen = (): void => { console.log('connected'); - websocket.send('{"id":"1","jsonrpc":"2.0","method":"state_getMetadata","params":[]}'); + websocket.send(`{"id":"1","jsonrpc":"2.0","method":"${method}","params":[]}`); }; websocket.onmessage = (message: { data: string }): void => { - resolve((JSON.parse(message.data) as { result: HexString }).result); + resolve((JSON.parse(message.data) as { result: T }).result); websocket.close(); }; } catch (error) { @@ -40,3 +40,15 @@ export async function getMetadataViaWs (endpoint: string): Promise { } }); } + +export async function getMetadataViaWs (endpoint: string): Promise<{ metadata: HexString, version: { apis: [HexString, number][] } }> { + return Promise + .all([ + getWsData(endpoint, 'state_getMetadata'), + getWsData<{ apis: [HexString, number][] }>(endpoint, 'state_getRuntimeVersion') + ]) + .then(([metadata, version]) => ({ + metadata, + version + })); +} diff --git a/packages/types-augment/src/registry/interfaces.ts b/packages/types-augment/src/registry/interfaces.ts index efd83898f8..409a78d21d 100644 --- a/packages/types-augment/src/registry/interfaces.ts +++ b/packages/types-augment/src/registry/interfaces.ts @@ -10,7 +10,7 @@ import type { ExtrinsicOrHash, ExtrinsicStatus } from '@polkadot/types/interface import type { UncleEntryItem } from '@polkadot/types/interfaces/authorship'; import type { AllowedSlots, BabeAuthorityWeight, BabeBlockWeight, BabeEpochConfiguration, BabeEquivocationProof, BabeWeight, EpochAuthorship, MaybeRandomness, MaybeVrf, NextConfigDescriptor, NextConfigDescriptorV1, Randomness, RawBabePreDigest, RawBabePreDigestCompat, RawBabePreDigestPrimary, RawBabePreDigestPrimaryTo159, RawBabePreDigestSecondaryPlain, RawBabePreDigestSecondaryTo159, RawBabePreDigestSecondaryVRF, RawBabePreDigestTo159, SlotNumber, VrfData, VrfOutput, VrfProof } from '@polkadot/types/interfaces/babe'; import type { AccountData, BalanceLock, BalanceLockTo212, BalanceStatus, Reasons, ReserveData, ReserveIdentifier, VestingSchedule, WithdrawReasons } from '@polkadot/types/interfaces/balances'; -import type { BeefyCommitment, BeefyId, BeefyNextAuthoritySet, BeefyPayload, BeefyPayloadId, BeefySignedCommitment, MmrRootHash, ValidatorSetId } from '@polkadot/types/interfaces/beefy'; +import type { BeefyAuthoritySet, BeefyCommitment, BeefyId, BeefyNextAuthoritySet, BeefyPayload, BeefyPayloadId, BeefySignedCommitment, MmrRootHash, ValidatorSetId } from '@polkadot/types/interfaces/beefy'; import type { BridgeMessageId, BridgedBlockHash, BridgedBlockNumber, BridgedHeader, CallOrigin, ChainId, DeliveredMessages, DispatchFeePayment, InboundLaneData, InboundRelayer, InitializationData, LaneId, MessageData, MessageKey, MessageNonce, MessagesDeliveryProofOf, MessagesProofOf, OperatingMode, OutboundLaneData, OutboundMessageFee, OutboundPayload, Parameter, RelayerId, UnrewardedRelayer, UnrewardedRelayersState } from '@polkadot/types/interfaces/bridges'; import type { BlockHash } from '@polkadot/types/interfaces/chain'; import type { PrefixedStorageKey } from '@polkadot/types/interfaces/childstate'; @@ -136,6 +136,7 @@ declare module '@polkadot/types/types/registry' { BalanceLockTo212: BalanceLockTo212; BalanceOf: BalanceOf; BalanceStatus: BalanceStatus; + BeefyAuthoritySet: BeefyAuthoritySet; BeefyCommitment: BeefyCommitment; BeefyId: BeefyId; BeefyKey: BeefyKey; diff --git a/packages/types-support/src/versions/kusama.ts b/packages/types-support/src/versions/kusama.ts new file mode 100644 index 0000000000..129c368a71 --- /dev/null +++ b/packages/types-support/src/versions/kusama.ts @@ -0,0 +1,72 @@ +// Copyright 2017-2022 @polkadot/types-support authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +/* eslint-disable sort-keys */ + +export default { + specName: 'kusama', + implName: 'parity-kusama', + authoringVersion: 2, + specVersion: 9230, + implVersion: 0, + apis: [ + [ + '0xdf6acb689907609b', + 4 + ], + [ + '0x37e397fc7c91f5e4', + 1 + ], + [ + '0x40fe3ad401f8959a', + 6 + ], + [ + '0xd2bc9897eed08f15', + 3 + ], + [ + '0xf78b278be53f454c', + 2 + ], + [ + '0xaf2c0297a23e6d3d', + 2 + ], + [ + '0x49eaaf1b548a0cb0', + 1 + ], + [ + '0x91d5df18b0d2cf58', + 1 + ], + [ + '0xed99c5acb25eedf5', + 3 + ], + [ + '0xcbca25e39f142387', + 2 + ], + [ + '0x687ad44ad37f03c2', + 1 + ], + [ + '0xab3c0572291feb8b', + 1 + ], + [ + '0xbc9d89904f5b923f', + 1 + ], + [ + '0x37c8bb1350a9a2a8', + 1 + ] + ], + transactionVersion: 11, + stateVersion: 0 +}; diff --git a/packages/types-support/src/versions/polkadot.ts b/packages/types-support/src/versions/polkadot.ts new file mode 100644 index 0000000000..19e085b25f --- /dev/null +++ b/packages/types-support/src/versions/polkadot.ts @@ -0,0 +1,72 @@ +// Copyright 2017-2022 @polkadot/types-support authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +/* eslint-disable sort-keys */ + +export default { + specName: 'polkadot', + implName: 'parity-polkadot', + authoringVersion: 0, + specVersion: 9230, + implVersion: 0, + apis: [ + [ + '0xdf6acb689907609b', + 4 + ], + [ + '0x37e397fc7c91f5e4', + 1 + ], + [ + '0x40fe3ad401f8959a', + 6 + ], + [ + '0xd2bc9897eed08f15', + 3 + ], + [ + '0xf78b278be53f454c', + 2 + ], + [ + '0xaf2c0297a23e6d3d', + 2 + ], + [ + '0x49eaaf1b548a0cb0', + 1 + ], + [ + '0x91d5df18b0d2cf58', + 1 + ], + [ + '0xed99c5acb25eedf5', + 3 + ], + [ + '0xcbca25e39f142387', + 2 + ], + [ + '0x687ad44ad37f03c2', + 1 + ], + [ + '0xab3c0572291feb8b', + 1 + ], + [ + '0xbc9d89904f5b923f', + 1 + ], + [ + '0x37c8bb1350a9a2a8', + 1 + ] + ], + transactionVersion: 12, + stateVersion: 0 +}; diff --git a/packages/types-support/src/versions/substrate.ts b/packages/types-support/src/versions/substrate.ts new file mode 100644 index 0000000000..16f5b92127 --- /dev/null +++ b/packages/types-support/src/versions/substrate.ts @@ -0,0 +1,68 @@ +// Copyright 2017-2022 @polkadot/types-support authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +/* eslint-disable sort-keys */ + +export default { + specName: 'node', + implName: 'substrate-node', + authoringVersion: 10, + specVersion: 268, + implVersion: 0, + apis: [ + [ + '0xdf6acb689907609b', + 4 + ], + [ + '0x37e397fc7c91f5e4', + 1 + ], + [ + '0x40fe3ad401f8959a', + 6 + ], + [ + '0xd2bc9897eed08f15', + 3 + ], + [ + '0xf78b278be53f454c', + 2 + ], + [ + '0xed99c5acb25eedf5', + 3 + ], + [ + '0xcbca25e39f142387', + 2 + ], + [ + '0x687ad44ad37f03c2', + 1 + ], + [ + '0xbc9d89904f5b923f', + 1 + ], + [ + '0x68b66ba122c93fa7', + 1 + ], + [ + '0x37c8bb1350a9a2a8', + 1 + ], + [ + '0x91d5df18b0d2cf58', + 1 + ], + [ + '0xab3c0572291feb8b', + 1 + ] + ], + transactionVersion: 2, + stateVersion: 1 +}; diff --git a/packages/types/src/interfaces/beefy/definitions.ts b/packages/types/src/interfaces/beefy/definitions.ts index f8961657b6..b6ad09e108 100644 --- a/packages/types/src/interfaces/beefy/definitions.ts +++ b/packages/types/src/interfaces/beefy/definitions.ts @@ -7,10 +7,17 @@ import type { Definitions } from '../../types'; import { rpc } from './rpc'; +import { runtime } from './runtime'; export default { rpc, + runtime, types: { + BeefyAuthoritySet: { + id: 'u64', + len: 'u32', + root: 'H256' + }, BeefyCommitment: { payload: 'BeefyPayload', blockNumber: 'BlockNumber', diff --git a/packages/types/src/interfaces/beefy/runtime.ts b/packages/types/src/interfaces/beefy/runtime.ts new file mode 100644 index 0000000000..eea1689104 --- /dev/null +++ b/packages/types/src/interfaces/beefy/runtime.ts @@ -0,0 +1,23 @@ +// Copyright 2017-2022 @polkadot/types authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import type { DefinitionsCall } from '../../types'; + +export const runtime: DefinitionsCall = { + BeefyMmrApi: [ + { + methods: { + authority_set_proof: { + description: 'Return the currently active BEEFY authority set proof.', + params: [], + type: 'BeefyAuthoritySet' + }, + next_authority_set_proof: { + description: 'Return the next/queued BEEFY authority set proof.', + params: [], + type: 'BeefyNextAuthoritySet' + } + } + } + ] +}; diff --git a/packages/types/src/interfaces/beefy/types.ts b/packages/types/src/interfaces/beefy/types.ts index a32af6ee9d..d96da2465e 100644 --- a/packages/types/src/interfaces/beefy/types.ts +++ b/packages/types/src/interfaces/beefy/types.ts @@ -6,6 +6,13 @@ import type { ITuple } from '@polkadot/types-codec/types'; import type { EcdsaSignature } from '@polkadot/types/interfaces/extrinsics'; import type { BlockNumber, H256 } from '@polkadot/types/interfaces/runtime'; +/** @name BeefyAuthoritySet */ +export interface BeefyAuthoritySet extends Struct { + readonly id: u64; + readonly len: u32; + readonly root: H256; +} + /** @name BeefyCommitment */ export interface BeefyCommitment extends Struct { readonly payload: BeefyPayload; diff --git a/packages/types/src/interfaces/contracts/definitions.ts b/packages/types/src/interfaces/contracts/definitions.ts index 064bf53b2b..f0faafdb9e 100644 --- a/packages/types/src/interfaces/contracts/definitions.ts +++ b/packages/types/src/interfaces/contracts/definitions.ts @@ -6,10 +6,12 @@ import type { Definitions } from '../../types'; -import rpc from './rpc'; +import { rpc } from './rpc'; +import { runtime } from './runtime'; export default { rpc, + runtime, types: { AliveContractInfo: { trieId: 'TrieId', diff --git a/packages/types/src/interfaces/contracts/rpc.ts b/packages/types/src/interfaces/contracts/rpc.ts index 095b5b6f0a..fd6b9eafd8 100644 --- a/packages/types/src/interfaces/contracts/rpc.ts +++ b/packages/types/src/interfaces/contracts/rpc.ts @@ -1,12 +1,9 @@ // Copyright 2017-2022 @polkadot/types authors & contributors // SPDX-License-Identifier: Apache-2.0 -// order important in structs... :) -/* eslint-disable sort-keys */ - import type { DefinitionsRpc } from '../../types'; -export default { +export const rpc: DefinitionsRpc = { call: { description: 'Executes a call to a contract', params: [ @@ -15,49 +12,14 @@ export default { type: 'ContractCallRequest' }, { - name: 'at', - type: 'BlockHash', isHistoric: true, - isOptional: true + isOptional: true, + name: 'at', + type: 'BlockHash' } ], type: 'ContractExecResult' }, - instantiate: { - description: 'Instantiate a new contract', - params: [ - { - name: 'request', - type: 'InstantiateRequest' - }, - { - name: 'at', - type: 'BlockHash', - isHstoric: true, - isOptional: true - } - ], - type: 'ContractInstantiateResult' - }, - uploadCode: { - // The RPC here is terribly misnamed - somebody forgot how the RPCs - // are actually done, ie. _ - endpoint: 'contracts_upload_code', - description: 'Upload new code without instantiating a contract from it', - params: [ - { - name: 'uploadRequest', - type: 'CodeUploadRequest' - }, - { - name: 'at', - type: 'BlockHash', - isHstoric: true, - isOptional: true - } - ], - type: 'CodeUploadResult' - }, getStorage: { description: 'Returns the value under a specified storage key in a contract', params: [ @@ -70,14 +32,30 @@ export default { type: 'H256' }, { - name: 'at', - type: 'BlockHash', isHistoric: true, - isOptional: true + isOptional: true, + name: 'at', + type: 'BlockHash' } ], type: 'Option' }, + instantiate: { + description: 'Instantiate a new contract', + params: [ + { + name: 'request', + type: 'InstantiateRequest' + }, + { + isHistoric: true, + isOptional: true, + name: 'at', + type: 'BlockHash' + } + ], + type: 'ContractInstantiateResult' + }, rentProjection: { description: 'Returns the projected time a given contract will be able to sustain paying its rent', params: [ @@ -86,12 +64,31 @@ export default { type: 'AccountId' }, { - name: 'at', - type: 'BlockHash', isHistoric: true, - isOptional: true + isOptional: true, + name: 'at', + type: 'BlockHash' } ], type: 'Option' + }, + uploadCode: { + description: 'Upload new code without instantiating a contract from it', + // The RPC here is terribly misnamed - somebody forgot how the RPCs + // are actually done, ie. _ + endpoint: 'contracts_upload_code', + params: [ + { + name: 'uploadRequest', + type: 'CodeUploadRequest' + }, + { + isHistoric: true, + isOptional: true, + name: 'at', + type: 'BlockHash' + } + ], + type: 'CodeUploadResult' } -} as DefinitionsRpc; +}; diff --git a/packages/types/src/interfaces/contracts/runtime.ts b/packages/types/src/interfaces/contracts/runtime.ts new file mode 100644 index 0000000000..b711b19e4f --- /dev/null +++ b/packages/types/src/interfaces/contracts/runtime.ts @@ -0,0 +1,109 @@ +// Copyright 2017-2022 @polkadot/types authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import type { DefinitionsCall } from '../../types'; + +export const runtime: DefinitionsCall = { + ContractsApi: [ + { + methods: { + call: { + description: 'Perform a call from a specified account to a given contract.', + params: [ + { + name: 'origin', + type: 'AccountId' + }, + { + name: 'dest', + type: 'AccountId' + }, + { + name: 'value', + type: 'Balance' + }, + { + name: 'gasLimit', + type: 'u64' + }, + { + name: 'storageDepositLimit', + type: 'Option' + }, + { + name: 'inputData', + type: 'Vec' + } + ], + type: 'ContractExecResult' + }, + get_storage: { + description: 'Query a given storage key in a given contract.', + params: [ + { + name: 'address', + type: 'AccountId' + }, + { + name: 'key', + type: 'Bytes' + } + ], + type: 'Option' + }, + instantiate: { + description: 'Instantiate a new contract.', + params: [ + { + name: 'origin', + type: 'AccountId' + }, + { + name: 'value', + type: 'Balance' + }, + { + name: 'gasLimit', + type: 'u64' + }, + { + name: 'storageDepositLimit', + type: 'Option' + }, + { + name: 'code', + type: 'Bytes' + }, + { + name: 'data', + type: 'Bytes' + }, + { + name: 'salt', + type: 'Bytes' + } + ], + type: 'ContractInstantiateResult' + }, + upload_code: { + description: 'Upload new code without instantiating a contract from it.', + params: [ + { + name: 'origin', + type: 'AccountId' + }, + { + name: 'code', + type: 'Bytes' + }, + { + name: 'storageDepositLimit', + type: 'Option' + } + ], + type: 'CodeUploadResult' + } + } + } + ] +}; diff --git a/packages/types/src/interfaces/payment/definitions.ts b/packages/types/src/interfaces/payment/definitions.ts index 4c4b31ab1a..2965808019 100644 --- a/packages/types/src/interfaces/payment/definitions.ts +++ b/packages/types/src/interfaces/payment/definitions.ts @@ -7,9 +7,11 @@ import type { Definitions } from '../../types'; import { rpc } from './rpc'; +import { runtime } from './runtime'; export default { rpc, + runtime, types: { FeeDetails: { inclusionFee: 'Option' diff --git a/packages/types/src/interfaces/payment/runtime.ts b/packages/types/src/interfaces/payment/runtime.ts new file mode 100644 index 0000000000..eb4fd47a02 --- /dev/null +++ b/packages/types/src/interfaces/payment/runtime.ts @@ -0,0 +1,41 @@ +// Copyright 2017-2022 @polkadot/types authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +import type { DefinitionsCall } from '../../types'; + +export const runtime: DefinitionsCall = { + TransactionPaymentApi: [ + { + methods: { + query_fee_details: { + description: 'The transaction fee details', + params: [ + { + name: 'uxt', + type: 'Bytes' + }, + { + name: 'len', + type: 'u32' + } + ], + type: 'FeeDetails' + }, + query_info: { + description: 'The transaction info', + params: [ + { + name: 'uxt', + type: 'Bytes' + }, + { + name: 'len', + type: 'u32' + } + ], + type: 'RuntimeDispatchInfo' + } + } + } + ] +}; diff --git a/yarn.lock b/yarn.lock index 36599b56d3..d43b7256f6 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2222,6 +2222,7 @@ __metadata: "@polkadot/types-create": 8.10.2-1-x "@polkadot/types-support": 8.10.2-1-x "@polkadot/util": ^9.6.2 + "@polkadot/util-crypto": ^9.6.2 "@polkadot/x-ws": ^9.6.2 "@types/websocket": ^1.0.5 "@types/yargs": ^17.0.10