From 9164637c44988c8a71d25737373c75db64519099 Mon Sep 17 00:00:00 2001 From: Jaco Greeff Date: Mon, 28 Dec 2020 13:21:43 +0100 Subject: [PATCH] Fix augmented generation for RPC w/ alias (#2994) * Fix augmented generation for RPC w/ alias * Fix * Rebuild --- packages/api/src/augment/rpc.ts | 44 +++++++++++++++------------- packages/rpc-core/src/index.ts | 4 +++ packages/typegen/src/generate/rpc.ts | 37 ++++++++++++++++++++--- 3 files changed, 61 insertions(+), 24 deletions(-) diff --git a/packages/api/src/augment/rpc.ts b/packages/api/src/augment/rpc.ts index 2312814bc2..4113796b5b 100644 --- a/packages/api/src/augment/rpc.ts +++ b/packages/api/src/augment/rpc.ts @@ -152,10 +152,6 @@ declare module '@polkadot/rpc-core/types.jsonrpc' { * Returns the chain ID used for transaction signing at the current best block. None is returned if not available. **/ chainId: AugmentedRpc<() => Observable>; - /** - * Returns current client version. - **/ - clientVersion: AugmentedRpc<() => Observable>; /** * Returns block author. **/ @@ -248,18 +244,10 @@ declare module '@polkadot/rpc-core/types.jsonrpc' { * Returns the number of hashes per second that the node is mining with. **/ hashrate: AugmentedRpc<() => Observable>; - /** - * Returns true if client is actively listening for network connections. Otherwise false. - **/ - listening: AugmentedRpc<() => Observable>; /** * Returns true if client is actively mining new blocks. **/ mining: AugmentedRpc<() => Observable>; - /** - * Returns number of peers connected to node. - **/ - peerCount: AugmentedRpc<() => Observable>; /** * Returns protocol version encoded as a string (quotes are necessary). **/ @@ -272,10 +260,6 @@ declare module '@polkadot/rpc-core/types.jsonrpc' { * Sends transaction; will block waiting for signer to return the transaction hash **/ sendTransaction: AugmentedRpc<(tx: EthTransactionRequest | { from?: any; to?: any; gasPrice?: any; gas?: any; value?: any; data?: any; nonce?: any } | string | Uint8Array) => Observable>; - /** - * Returns sha3 of the given data - **/ - sha3: AugmentedRpc<(_: Bytes | string | Uint8Array) => Observable>; /** * Used for submitting mining hashrate. **/ @@ -292,10 +276,6 @@ declare module '@polkadot/rpc-core/types.jsonrpc' { * Returns an object with data about the sync status or false. **/ syncing: AugmentedRpc<() => Observable>; - /** - * Returns protocol version. - **/ - version: AugmentedRpc<() => Observable>; }; grandpa: { /** @@ -311,6 +291,20 @@ declare module '@polkadot/rpc-core/types.jsonrpc' { **/ subscribeJustifications: AugmentedRpc<() => Observable>; }; + net: { + /** + * Returns true if client is actively listening for network connections. Otherwise false. + **/ + listening: AugmentedRpc<() => Observable>; + /** + * Returns number of peers connected to node. + **/ + peerCount: AugmentedRpc<() => Observable>; + /** + * Returns protocol version. + **/ + version: AugmentedRpc<() => Observable>; + }; offchain: { /** * Get offchain local storage under given key and prefix @@ -487,5 +481,15 @@ declare module '@polkadot/rpc-core/types.jsonrpc' { **/ version: AugmentedRpc<() => Observable>; }; + web3: { + /** + * Returns current client version. + **/ + clientVersion: AugmentedRpc<() => Observable>; + /** + * Returns sha3 of the given data + **/ + sha3: AugmentedRpc<(data: Bytes | string | Uint8Array) => Observable>; + }; } } diff --git a/packages/rpc-core/src/index.ts b/packages/rpc-core/src/index.ts index 67ddcd7500..d627001913 100644 --- a/packages/rpc-core/src/index.ts +++ b/packages/rpc-core/src/index.ts @@ -110,6 +110,8 @@ export class RpcCore implements RpcInterface { public readonly grandpa!: RpcInterface['grandpa']; + public readonly net!: RpcInterface['net']; + public readonly offchain!: RpcInterface['offchain']; public readonly payment!: RpcInterface['payment']; @@ -122,6 +124,8 @@ export class RpcCore implements RpcInterface { public readonly system!: RpcInterface['system']; + public readonly web3!: RpcInterface['web3']; + /** * @constructor * Default constructor for the Api Object diff --git a/packages/typegen/src/generate/rpc.ts b/packages/typegen/src/generate/rpc.ts index d118cf026e..7501e85941 100644 --- a/packages/typegen/src/generate/rpc.ts +++ b/packages/typegen/src/generate/rpc.ts @@ -10,6 +10,19 @@ import * as defaultDefinitions from '@polkadot/types/interfaces/definitions'; import { createImports, formatType, getSimilarTypes, readTemplate, registerDefinitions, setImports, writeFile } from '../util'; +interface ItemDef { + args: string; + docs: string[]; + generic: string | undefined; + name: string; + type: string | undefined; +} + +interface ModuleDef { + items: ItemDef[]; + name: string; +} + const StorageKeyTye = 'StorageKey | string | Uint8Array | any'; const template = readTemplate('rpc'); @@ -30,6 +43,7 @@ export function generateRpcTypes (registry: TypeRegistry, importDefinitions: Rec .filter((key) => Object.keys(definitions[key].rpc || {}).length !== 0) .sort(); + const additional: Record = {}; const modules = rpcKeys.map((sectionFullName) => { const rpc = definitions[sectionFullName].rpc; const section = sectionFullName.split('/').pop(); @@ -79,20 +93,35 @@ export function generateRpcTypes (registry: TypeRegistry, importDefinitions: Rec generic = ''; } - return { + const item = { args: args.join(', '), docs: [def.description], generic, name: methodName, type }; - }); + + if (def.aliasSection) { + if (!additional[def.aliasSection]) { + additional[def.aliasSection] = { + items: [], + name: def.aliasSection + }; + } + + additional[def.aliasSection].items.push(item); + + return null; + } + + return item; + }).filter((item): item is ItemDef => !!item); return { items: allMethods, - name: section + name: section || 'unknown' }; - }); + }).concat(...Object.values(additional)).sort((a, b) => a.name.localeCompare(b.name)); imports.typesTypes.Observable = true;