Correct construction of palletVersion keys (#4115)

This commit is contained in:
Jaco
2021-10-26 13:20:54 +03:00
committed by GitHub
parent bf6c7ee0c3
commit 66215890dd
3 changed files with 21 additions and 14 deletions
@@ -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);
@@ -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<string, Creator> = {
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'
})
@@ -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 });
}