diff --git a/packages/types/src/metadata/decorate/storage/index.ts b/packages/types/src/metadata/decorate/storage/index.ts index 6968b26928..11b1d3b3df 100644 --- a/packages/types/src/metadata/decorate/storage/index.ts +++ b/packages/types/src/metadata/decorate/storage/index.ts @@ -38,13 +38,9 @@ export function decorateStorage (registry: Registry, { pallets }: MetadataLatest return newModule; }, { palletVersion: createRuntimeFunction( - name.toString(), - 'palletVersion', + { method: 'palletVersion', prefix, section }, createKeyRaw(registry, { method: ':__STORAGE_VERSION__:', prefix: name.toString() }, [], [], []), - { - docs: 'Returns the current pallet version from storage', - type: 'u16' - } + { docs: 'Returns the current pallet version from storage', type: 'u16' } )(registry) } as ModuleStorage); diff --git a/packages/types/src/metadata/decorate/storage/substrate.ts b/packages/types/src/metadata/decorate/storage/substrate.ts index 524f8f4287..da8933894d 100644 --- a/packages/types/src/metadata/decorate/storage/substrate.ts +++ b/packages/types/src/metadata/decorate/storage/substrate.ts @@ -3,29 +3,34 @@ import type { StorageEntry } from '../../../primitive/types'; import type { Registry } from '../../../types'; +import type { ManualMetadata } from './util'; import { createRuntimeFunction } from './util'; type Creator = (registry: Registry) => StorageEntry; +function createSubstrateFn (method: string, key: string, meta: ManualMetadata): Creator { + return createRuntimeFunction({ method, prefix: 'Substrate', section: 'substrate' }, key, meta); +} + export const substrate: Record = { - changesTrieConfig: createRuntimeFunction('Substrate', 'changesTrieConfig', ':changes_trie', { + changesTrieConfig: createSubstrateFn('changesTrieConfig', ':changes_trie', { docs: ' Changes trie configuration is stored under this key.', type: 'u32' }), - childStorageKeyPrefix: createRuntimeFunction('Substrate', 'childStorageKeyPrefix', ':child_storage:', { + childStorageKeyPrefix: createSubstrateFn('childStorageKeyPrefix', ':child_storage:', { docs: ' Prefix of child storage keys.', type: 'u32' }), - code: createRuntimeFunction('Substrate', 'code', ':code', { + code: createSubstrateFn('code', ':code', { docs: ' Wasm code of the runtime.', type: 'Bytes' }), - extrinsicIndex: createRuntimeFunction('Substrate', 'extrinsicIndex', ':extrinsic_index', { + extrinsicIndex: createSubstrateFn('extrinsicIndex', ':extrinsic_index', { docs: ' Current extrinsic index (u32) is stored under this key.', type: 'u32' }), - heapPages: createRuntimeFunction('Substrate', 'heapPages', ':heappages', { + heapPages: createSubstrateFn('heapPages', ':heappages', { docs: ' Number of wasm linear memory pages required for execution of the runtime.', type: 'u64' }) diff --git a/packages/types/src/metadata/decorate/storage/util.ts b/packages/types/src/metadata/decorate/storage/util.ts index 378d52cb75..ca11a6e72e 100644 --- a/packages/types/src/metadata/decorate/storage/util.ts +++ b/packages/types/src/metadata/decorate/storage/util.ts @@ -7,11 +7,17 @@ import type { Registry } from '../../../types'; import { createFunction } from './createFunction'; -interface ManualMetadata { +export interface ManualMetadata { docs: string; type: string; } +interface ManualDefinition { + method: string; + prefix: string; + section: string; +} + function findSiPrimitive (registry: Registry, _prim: string): PortableType | undefined { const prim = _prim.toLowerCase(); @@ -56,7 +62,7 @@ function findSiType (registry: Registry, orig: string): PortableType | undefined // Small helper function to factorize code on this page. /** @internal */ -export function createRuntimeFunction (prefix: string, method: string, key: Uint8Array | string, { docs, type }: ManualMetadata): (registry: Registry) => StorageEntry { +export function createRuntimeFunction ({ method, prefix, section }: ManualDefinition, key: Uint8Array | string, { docs, type }: ManualMetadata): (registry: Registry) => StorageEntry { return (registry: Registry): StorageEntry => createFunction(registry, { meta: registry.createType('StorageEntryMetadataLatest', { @@ -68,6 +74,6 @@ export function createRuntimeFunction (prefix: string, method: string, key: Uint }), method, prefix, - section: prefix.toLowerCase() + section }, { key, skipHashing: true }); }