diff --git a/packages/typegen/src/metadataMd.ts b/packages/typegen/src/metadataMd.ts index 556e0d50fe..ec68528d05 100644 --- a/packages/typegen/src/metadataMd.ts +++ b/packages/typegen/src/metadataMd.ts @@ -161,19 +161,16 @@ function addRpc (_runtimeDesc: string, rpcMethods?: string[]): string { return name + (isOptional ? '?' : '') + ': `' + type + '`'; }).join(', '); const type = '`' + method.type + '`'; - const item: SectionItem = { + + container.items.push({ interface: '`' + `api.rpc.${sectionName}.${methodName}` + '`', jsonrpc: '`' + jsonrpc + '`', // link: jsonrpc, name: `${methodName}(${args}): ${type}`, - ...(method.description && { summary: method.description }) - }; - - if (method.deprecated) { - item.deprecated = method.deprecated; - } - - container.items.push(item); + ...((method.description && { summary: method.description }) || {}), + ...((method.deprecated && { deprecated: method.deprecated }) || {}), + ...((method.isUnsafe && { unsafe: 'This method is only active with appropriate flags' }) || {}) + }); }); return all; diff --git a/packages/types/src/interfaces/author/rpc.ts b/packages/types/src/interfaces/author/rpc.ts index 2bbf6fc093..702423b52e 100644 --- a/packages/types/src/interfaces/author/rpc.ts +++ b/packages/types/src/interfaces/author/rpc.ts @@ -6,6 +6,7 @@ import type { DefinitionsRpc } from '../../types/index.js'; export const rpc: DefinitionsRpc = { hasKey: { description: 'Returns true if the keystore has private keys for the given public key and key type.', + isUnsafe: true, params: [ { name: 'publicKey', @@ -20,6 +21,7 @@ export const rpc: DefinitionsRpc = { }, hasSessionKeys: { description: 'Returns true if the keystore has private keys for the given session public keys.', + isUnsafe: true, params: [ { name: 'sessionKeys', @@ -30,6 +32,7 @@ export const rpc: DefinitionsRpc = { }, insertKey: { description: 'Insert a key into the keystore.', + isUnsafe: true, params: [ { name: 'keyType', @@ -53,6 +56,7 @@ export const rpc: DefinitionsRpc = { }, removeExtrinsic: { description: 'Remove given extrinsic from the pool and temporarily ban it to prevent reimporting', + isUnsafe: true, params: [ { name: 'bytesOrHash', @@ -63,6 +67,7 @@ export const rpc: DefinitionsRpc = { }, rotateKeys: { description: 'Generate new session keys and returns the corresponding public keys', + isUnsafe: true, params: [], type: 'Bytes' }, diff --git a/packages/types/src/interfaces/babe/rpc.ts b/packages/types/src/interfaces/babe/rpc.ts index 57bf009481..288c57d457 100644 --- a/packages/types/src/interfaces/babe/rpc.ts +++ b/packages/types/src/interfaces/babe/rpc.ts @@ -6,6 +6,7 @@ import type { DefinitionsRpc } from '../../types/index.js'; export const rpc: DefinitionsRpc = { epochAuthorship: { description: 'Returns data about which slots (primary or secondary) can be claimed in the current epoch with the keys in the keystore', + isUnsafe: true, params: [], type: 'HashMap' } diff --git a/packages/types/src/interfaces/dev/rpc.ts b/packages/types/src/interfaces/dev/rpc.ts index 34bf3ea132..867eb44b16 100644 --- a/packages/types/src/interfaces/dev/rpc.ts +++ b/packages/types/src/interfaces/dev/rpc.ts @@ -6,6 +6,7 @@ import type { DefinitionsRpc } from '../../types/index.js'; export const rpc: DefinitionsRpc = { getBlockStats: { description: 'Reexecute the specified `block_hash` and gather statistics while doing so', + isUnsafe: true, params: [ { isHistoric: true, diff --git a/packages/types/src/interfaces/offchain/rpc.ts b/packages/types/src/interfaces/offchain/rpc.ts index e44b0eaadb..004a069f48 100644 --- a/packages/types/src/interfaces/offchain/rpc.ts +++ b/packages/types/src/interfaces/offchain/rpc.ts @@ -6,6 +6,7 @@ import type { DefinitionsRpc } from '../../types/index.js'; export const rpc: DefinitionsRpc = { localStorageGet: { description: 'Get offchain local storage under given key and prefix', + isUnsafe: true, params: [ { name: 'kind', @@ -20,6 +21,7 @@ export const rpc: DefinitionsRpc = { }, localStorageSet: { description: 'Set offchain local storage under given key and prefix', + isUnsafe: true, params: [ { name: 'kind', diff --git a/packages/types/src/interfaces/state/rpc.ts b/packages/types/src/interfaces/state/rpc.ts index 152eb4ed90..fb423b38f5 100644 --- a/packages/types/src/interfaces/state/rpc.ts +++ b/packages/types/src/interfaces/state/rpc.ts @@ -215,6 +215,7 @@ export const rpc: DefinitionsRpc = { getPairs: { deprecated: 'Use `api.rpc.state.getKeysPaged` to retrieve keys', description: 'Returns the keys with prefix, leave empty to get all the keys (deprecated: Use getKeysPaged)', + isUnsafe: true, params: [ { name: 'prefix', @@ -311,6 +312,7 @@ export const rpc: DefinitionsRpc = { }, queryStorage: { description: 'Query historical storage entries (by key) starting from a start block', + isUnsafe: true, params: [ { name: 'keys', @@ -357,6 +359,10 @@ export const rpc: DefinitionsRpc = { }, subscribeStorage: { description: 'Subscribes to storage changes for the provided keys', + // NOTE Just marking it here to follow the logic - this is unsafe when no + // keys are provided (i.e. subscribing to all), generally this is used + // extensively with normal subscriptions + // isUnsafe: true, params: [ { isOptional: true, @@ -373,6 +379,7 @@ export const rpc: DefinitionsRpc = { }, traceBlock: { description: 'Provides a way to trace the re-execution of a single block', + isUnsafe: true, params: [ { name: 'block', @@ -395,6 +402,7 @@ export const rpc: DefinitionsRpc = { }, trieMigrationStatus: { description: 'Check current migration state', + isUnsafe: true, params: [ { isHistoric: true, diff --git a/packages/types/src/interfaces/system/rpc.ts b/packages/types/src/interfaces/system/rpc.ts index a650c79f31..3a02d3d616 100644 --- a/packages/types/src/interfaces/system/rpc.ts +++ b/packages/types/src/interfaces/system/rpc.ts @@ -17,6 +17,7 @@ export const rpc: DefinitionsRpc = { }, addLogFilter: { description: 'Adds the supplied directives to the current log filter', + isUnsafe: true, params: [ { name: 'directives', @@ -27,6 +28,7 @@ export const rpc: DefinitionsRpc = { }, addReservedPeer: { description: 'Adds a reserved peer', + isUnsafe: true, params: [ { name: 'peer', @@ -48,6 +50,7 @@ export const rpc: DefinitionsRpc = { dryRun: { alias: ['system_dryRunAt'], description: 'Dry run an extrinsic at a given block', + isUnsafe: true, params: [ { name: 'extrinsic', @@ -86,6 +89,7 @@ export const rpc: DefinitionsRpc = { networkState: { alias: ['system_unstable_networkState'], description: 'Returns current state of the network', + isUnsafe: true, params: [], type: 'NetworkState' }, @@ -96,6 +100,7 @@ export const rpc: DefinitionsRpc = { }, peers: { description: 'Returns the currently connected peers', + isUnsafe: true, params: [], type: 'Vec' }, @@ -106,6 +111,7 @@ export const rpc: DefinitionsRpc = { }, removeReservedPeer: { description: 'Remove a reserved peer', + isUnsafe: true, params: [ { name: 'peerId', @@ -121,6 +127,7 @@ export const rpc: DefinitionsRpc = { }, resetLogFilter: { description: 'Resets the log filter to Substrate defaults', + isUnsafe: true, params: [], type: 'Null' }, diff --git a/packages/types/src/types/definitions.ts b/packages/types/src/types/definitions.ts index 7d1b0e71c4..a67db16218 100644 --- a/packages/types/src/types/definitions.ts +++ b/packages/types/src/types/definitions.ts @@ -42,6 +42,8 @@ export interface DefinitionRpc { endpoint?: string; /** true if this needs a signed submission, e.g. when submitting extrinsics */ isSigned?: boolean; + /** true if this is an RPC call that has been marked unsafe */ + isUnsafe?: boolean; /** Don't log any errors if they occur (should be used sparingly for exceptions only) */ noErrorLog?: boolean; /** The applicable parameters for the call */