Remove v11 metadata (#1748)

* Remove v11 metadata

* Linting
This commit is contained in:
Jaco Greeff
2020-01-27 12:37:01 +01:00
committed by GitHub
parent 693cf855f0
commit 7adad82786
13 changed files with 96 additions and 4964 deletions
@@ -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 { MetadataAll, MetadataLatest, MetadataV0, MetadataV1, MetadataV2, MetadataV3, MetadataV4, MetadataV5, MetadataV6, MetadataV7, MetadataV8, MetadataV9, MetadataV10, MetadataV11 } from '@polkadot/types/interfaces/metadata';
import { MetadataAll, MetadataLatest, MetadataV0, MetadataV1, MetadataV2, MetadataV3, MetadataV4, MetadataV5, MetadataV6, MetadataV7, MetadataV8, MetadataV9, MetadataV10 } from '@polkadot/types/interfaces/metadata';
import { Registry } from '@polkadot/types/types';
import { createType } from '@polkadot/types/codec/create/createType';
@@ -20,12 +20,12 @@ import v6ToV7 from './v6/toV7';
import v7ToV8 from './v7/toV8';
import v8ToV9 from './v8/toV9';
import v9ToV10 from './v9/toV10';
import v10ToV11 from './v10/toV11';
import v10ToLatest from './v10/toLatest';
import { getUniqTypes, toCallsOnly } from './util';
type MetaMapped = MetadataV0 | MetadataV1 | MetadataV2 | MetadataV3 | MetadataV4 | MetadataV5 | MetadataV6 | MetadataV7 | MetadataV8 | MetadataV9 | MetadataV10 | MetadataV11;
type MetaMapped = MetadataV0 | MetadataV1 | MetadataV2 | MetadataV3 | MetadataV4 | MetadataV5 | MetadataV6 | MetadataV7 | MetadataV8 | MetadataV9 | MetadataV10;
type MetaVersions = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11;
type MetaAsX = 'asV0' | 'asV1' | 'asV2' | 'asV3' | 'asV4' | 'asV5' | 'asV6' | 'asV7' | 'asV8' | 'asV9' | 'asV10' | 'asV11';
type MetaAsX = 'asV0' | 'asV1' | 'asV2' | 'asV3' | 'asV4' | 'asV5' | 'asV6' | 'asV7' | 'asV8' | 'asV9' | 'asV10';
/**
* @name MetadataVersioned
@@ -154,18 +154,12 @@ export default class MetadataVersioned extends Struct {
return this.getVersion(10, v9ToV10);
}
/**
* @description Returns the wrapped values as a V10 object
*/
public get asV11 (): MetadataV11 {
return this.getVersion(11, v10ToV11);
}
/**
* @description Returns the wrapped values as a latest version object
*/
public get asLatest (): MetadataLatest {
return this.asV11;
// 11 is non-existent & latest - applied here to do to the type conversions
return this.getVersion(11, v10ToLatest);
}
/**
+1 -1
View File
@@ -2,6 +2,6 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import metadata from './v9/static';
import metadata from './v10/static';
export default metadata;
@@ -0,0 +1,47 @@
// Copyright 2017-2020 @polkadot/metadata authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { OverrideModuleType } from '@polkadot/types/known/types';
import { FunctionMetadataV10, FunctionMetadataLatest, MetadataV10, MetadataLatest, ModuleMetadataV10, ModuleMetadataLatest } from '@polkadot/types/interfaces/metadata';
import { Registry } from '@polkadot/types/types';
import { getModuleTypes } from '@polkadot/types/known';
import { createType } from '@polkadot/types';
import { stringCamelCase } from '@polkadot/util';
// apply module-specific type overrides - this should always be done as part of toLatest
/** @internal */
function convertCalls (registry: Registry, calls: FunctionMetadataV10[], sectionTypes: OverrideModuleType[]): FunctionMetadataLatest[] {
return calls.map(({ args, documentation, name }): FunctionMetadataLatest => {
args.forEach(({ type }): void => {
const queued = sectionTypes.find(({ name }): boolean => type.eq(name));
if (queued) {
type.setOverride(queued.override);
}
});
return createType(registry, 'FunctionMetadataLatest', { args, name, documentation });
});
}
/** @internal */
function convertModule (registry: Registry, mod: ModuleMetadataV10): ModuleMetadataLatest {
const calls = mod.calls.unwrapOr(null);
const sectionTypes = getModuleTypes(stringCamelCase(mod.name.toString())) || [];
return createType(registry, 'ModuleMetadataLatest', {
...mod,
calls: calls
? convertCalls(registry, calls, sectionTypes)
: null
});
}
/** @internal */
export default function toLatest (registry: Registry, { modules }: MetadataV10): MetadataLatest {
return createType(registry, 'MetadataLatest', {
modules: modules.map((mod): ModuleMetadataLatest => convertModule(registry, mod))
});
}
@@ -1,76 +0,0 @@
// Copyright 2017-2020 @polkadot/metadata authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { OverrideModuleType } from '@polkadot/types/known/types';
import { FunctionMetadataV10, FunctionMetadataV11, MetadataV10, MetadataV11, ModuleMetadataV10, ModuleMetadataV11, StorageEntryTypeV10 } from '@polkadot/types/interfaces/metadata';
import { Registry } from '@polkadot/types/types';
import { getModuleTypes } from '@polkadot/types/known';
import { createType } from '@polkadot/types';
import { stringCamelCase } from '@polkadot/util';
// migrate a storage entry type - only map types are different (with a kind enum)
// all return the actual value for the enum, followed by the numeric index
/** @internal */
function createStorageType (registry: Registry, entryType: StorageEntryTypeV10): [any, number] {
if (entryType.isPlain) {
return [entryType.asPlain, 0];
} else if (entryType.isDoubleMap) {
return [entryType.asDoubleMap, 2];
}
const map = entryType.asMap;
// map needs a migration, removing linked and adding an explicit kind
return [{
...map,
kind: createType(registry, 'MapKindV11', null, map.linked.isTrue ? 1 : 0)
}, 1];
}
// apply module-specific type overrides
/** @internal */
function convertCalls (registry: Registry, calls: FunctionMetadataV10[], sectionTypes: OverrideModuleType[]): FunctionMetadataV11[] {
return calls.map(({ args, documentation, name }): FunctionMetadataV11 => {
args.forEach(({ type }): void => {
const queued = sectionTypes.find(({ name }): boolean => type.eq(name));
if (queued) {
type.setOverride(queued.override);
}
});
return createType(registry, 'FunctionMetadataV11', { args, name, documentation });
});
}
/** @internal */
function convertModule (registry: Registry, mod: ModuleMetadataV10): ModuleMetadataV11 {
const calls = mod.calls.unwrapOr(null);
const storage = mod.storage.unwrapOr(null);
const sectionTypes = getModuleTypes(stringCamelCase(mod.name.toString())) || [];
return createType(registry, 'ModuleMetadataV11', {
...mod,
calls: calls
? convertCalls(registry, calls, sectionTypes)
: null,
storage: storage
? {
...storage,
items: storage.items.map((item): any => ({
...item,
type: createType(registry, 'StorageEntryTypeV11', ...createStorageType(registry, item.type))
}))
}
: null
});
}
/** @internal */
export default function toV11 (registry: Registry, { modules }: MetadataV10): MetadataV11 {
return createType(registry, 'MetadataV11', {
modules: modules.map((mod): ModuleMetadataV11 => convertModule(registry, mod))
});
}
@@ -1,19 +0,0 @@
// Copyright 2017-2020 @polkadot/metadata authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { TypeRegistry } from '@polkadot/types';
import substrateJson from './static-substrate.json';
import substrateData from './static';
import { decodeLatestSubstrate, defaultValues, toLatest } from '../util/testUtil';
describe('MetadataV11 (substrate)', (): void => {
const registry = new TypeRegistry();
decodeLatestSubstrate(registry, 11, substrateData, substrateJson);
toLatest(registry, 11, substrateData);
defaultValues(registry, substrateData);
});
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long