diff --git a/CHANGELOG.md b/CHANGELOG.md index c66bf080a0..a64cbb7fd2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +# 0.91.0-beta.x + +- The `getRuntimeVersion` and `subscribeRuntimeVersion` RPCs are now only available on the `rpc.state.*` endpoints. This aligns with the Substrate implementation. + + # 0.90.1 If you are upgrading form an older version, use the CHANGELOG hand-in-hand with the [migration guide](UPGRADING.md). diff --git a/packages/api/src/base/Init.ts b/packages/api/src/base/Init.ts index d8492e3e0e..074ee5bc9f 100644 --- a/packages/api/src/base/Init.ts +++ b/packages/api/src/base/Init.ts @@ -91,7 +91,7 @@ export default abstract class Init extends Decorate { private async metaFromChain (optMetadata: Record): Promise { [this._genesisHash, this._runtimeVersion] = await Promise.all([ this._rpcCore.chain.getBlockHash(0).toPromise(), - this._rpcCore.chain.getRuntimeVersion().toPromise() + this._rpcCore.state.getRuntimeVersion().toPromise() ]); // based on the node, inject specific types diff --git a/packages/api/test/e2e/rpc-core/chain.spec.ts b/packages/api/test/e2e/rpc-core/chain.spec.ts index a90ed9758c..a8159b7420 100644 --- a/packages/api/test/e2e/rpc-core/chain.spec.ts +++ b/packages/api/test/e2e/rpc-core/chain.spec.ts @@ -2,7 +2,7 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { Header, RuntimeVersion } from '@polkadot/types/interfaces'; +import { Header } from '@polkadot/types/interfaces'; import { ClassOf } from '@polkadot/types'; import WsProvider from '@polkadot/rpc-provider/ws'; @@ -36,13 +36,4 @@ describeE2E({ } }); }); - - it('retrieves the runtime version', (done): void => { - rpc.chain - .getRuntimeVersion() - .subscribe((version: RuntimeVersion): void => { - expect(version).toBeInstanceOf(ClassOf('RuntimeVersion')); - done(); - }); - }); }); diff --git a/packages/api/test/e2e/rpc-core/state.spec.ts b/packages/api/test/e2e/rpc-core/state.spec.ts index 99f86a6822..bbbaa57154 100644 --- a/packages/api/test/e2e/rpc-core/state.spec.ts +++ b/packages/api/test/e2e/rpc-core/state.spec.ts @@ -2,12 +2,12 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { Balance, Moment } from '@polkadot/types/interfaces'; -import { Bytes, Metadata, StorageKey } from '@polkadot/types'; +import { Balance, Moment, RuntimeVersion } from '@polkadot/types/interfaces'; import storage from '@polkadot/api-metadata/storage/static'; import Rpc from '@polkadot/rpc-core'; import WsProvider from '@polkadot/rpc-provider/ws'; +import { Bytes, ClassOf, Metadata, StorageKey } from '@polkadot/types'; import { describeE2E } from '../../util'; @@ -46,6 +46,15 @@ describeE2E({ }); }); + it('retrieves the runtime version', (done): void => { + rpc.state + .getRuntimeVersion() + .subscribe((version: RuntimeVersion): void => { + expect(version).toBeInstanceOf(ClassOf('RuntimeVersion')); + done(); + }); + }); + describe('test-suite getStorage()', (): void => { it('retrieves code', (done): void => { rpc.state diff --git a/packages/rpc-core/src/jsonrpc.types.ts b/packages/rpc-core/src/jsonrpc.types.ts index 8f2c6f7ab5..7de10cd2d8 100644 --- a/packages/rpc-core/src/jsonrpc.types.ts +++ b/packages/rpc-core/src/jsonrpc.types.ts @@ -22,10 +22,8 @@ export interface RpcInterface { getBlockHash(blockNumber?: BlockNumber | Uint8Array | number | string): Observable; getFinalizedHead(): Observable; getHeader(hash?: Hash | Uint8Array | string): Observable
; - getRuntimeVersion(hash?: Hash | Uint8Array | string): Observable; subscribeFinalizedHeads(): Observable
; subscribeNewHeads(): Observable
; - subscribeRuntimeVersion(): Observable; }; state: { call(method: Text | string, data: Bytes | Uint8Array | string, block?: Hash | Uint8Array | string): Observable; @@ -40,6 +38,7 @@ export interface RpcInterface { getStorageHash(key: any, block?: Hash | Uint8Array | string): Observable; getStorageSize(key: any, block?: Hash | Uint8Array | string): Observable; queryStorage(keys: (any)[], startBlock: Hash | Uint8Array | string, block?: Hash | Uint8Array | string): Observable>; + subscribeRuntimeVersion(): Observable; subscribeStorage(keys: any[]): Observable; }; system: { diff --git a/packages/rpc-provider/src/mock/index.ts b/packages/rpc-provider/src/mock/index.ts index 517be3457f..ccc2106bf7 100644 --- a/packages/rpc-provider/src/mock/index.ts +++ b/packages/rpc-provider/src/mock/index.ts @@ -53,7 +53,7 @@ export default class Mock implements ProviderInterface { chain_getBlock: (hash: string): any => createType('SignedBlock', rpcSignedBlock.result).toJSON(), // eslint-disable-next-line @typescript-eslint/no-unused-vars chain_getBlockHash: (blockNumber: number): string => '0x1234', - chain_getRuntimeVersion: (): string => createType('RuntimeVersion').toHex(), + state_getRuntimeVersion: (): string => createType('RuntimeVersion').toHex(), state_getStorage: (storage: MockStateDb, params: any[]): string => { return u8aToHex( storage[(params[0] as string)] diff --git a/packages/type-jsonrpc/src/chain.ts b/packages/type-jsonrpc/src/chain.ts index 19a796a479..c2d74ae8d2 100644 --- a/packages/type-jsonrpc/src/chain.ts +++ b/packages/type-jsonrpc/src/chain.ts @@ -39,14 +39,6 @@ const getFinalizedHead: RpcMethodOpt = { type: 'Hash' }; -const getRuntimeVersion: RpcMethodOpt = { - description: 'Get the runtime version (alias of state_getRuntimeVersion)', - params: [ - createParam('hash', 'Hash', { isOptional: true }) - ], - type: 'RuntimeVersion' -}; - const subscribeNewHeads: RpcMethodOpt = { description: 'Retrieves the best header via subscription', params: [], @@ -70,17 +62,6 @@ const subscribeFinalizedHeads: RpcMethodOpt = { type: 'Header' }; -const subscribeRuntimeVersion: RpcMethodOpt = { - description: 'Retrieves the runtime version via subscription', - params: [], - pubsub: [ - 'runtimeVersion', - 'subscribeRuntimeVersion', - 'unsubscribeRuntimeVersion' - ], - type: 'RuntimeVersion' -}; - const section = 'chain'; /** @@ -96,9 +77,7 @@ export default { getBlockHash: createMethod(section, 'getBlockHash', getBlockHash), getFinalizedHead: createMethod(section, 'getFinalizedHead', getFinalizedHead), getHeader: createMethod(section, 'getHeader', getHeader), - getRuntimeVersion: createMethod(section, 'getRuntimeVersion', getRuntimeVersion), subscribeFinalizedHeads: createMethod(section, 'subscribeFinalizedHeads', subscribeFinalizedHeads), - subscribeRuntimeVersion: createMethod(section, 'subscribeRuntimeVersion', subscribeRuntimeVersion), subscribeNewHeads: createMethod(section, 'subscribeNewHeads', subscribeNewHeads) } }; diff --git a/packages/type-jsonrpc/src/state.ts b/packages/type-jsonrpc/src/state.ts index 3bff269862..c2495e7ee2 100644 --- a/packages/type-jsonrpc/src/state.ts +++ b/packages/type-jsonrpc/src/state.ts @@ -105,6 +105,17 @@ const queryStorage: RpcMethodOpt = { type: 'Vec' }; +const subscribeRuntimeVersion: RpcMethodOpt = { + description: 'Retrieves the runtime version via subscription', + params: [], + pubsub: [ + 'runtimeVersion', + 'subscribeRuntimeVersion', + 'unsubscribeRuntimeVersion' + ], + type: 'RuntimeVersion' +}; + const subscribeStorage: RpcMethodOpt = { description: 'Subscribes to storage changes for the provided keys', params: [ @@ -141,6 +152,7 @@ export default { getStorageHash: createMethod(section, 'getStorageHash', getStorageHash), getStorageSize: createMethod(section, 'getStorageSize', getStorageSize), queryStorage: createMethod(section, 'queryStorage', queryStorage), + subscribeRuntimeVersion: createMethod(section, 'subscribeRuntimeVersion', subscribeRuntimeVersion), subscribeStorage: createMethod(section, 'subscribeStorage', subscribeStorage) } };