Rework uniqTypes without duplication (#1316)

* Rework uniqTypes without  duplication

* Extra info for vX -> v7 conversion

* Add vX to naming

* Rework unwrap return

* Ignore gathering unique for v0

* Fix getUniq for V0 (well, def. throw-away, but anyway...)

* compareMap cleanup

* Cleanup author extraction

* Add modules via Struct.with (Metadata)

* Revert "Add modules via Struct.with (Metadata)"

This reverts commit 0666c3014cf840fb4ab26a5231cdf67dbe977bd7.

* Consistency in injected vs defined classes (Metadata)

* Add isTrue/isFalse to Bool

* Meta PlainType/MapType in registry

* Fix wrong v6 imports

* Extract storage modifier

* Split additional Metadata classes into interfaces

* Minor cleanups in type naming

* Static json renames

* Convert most V0 classes to interfaces

* Additional meta classes to interfaces

* No classes for Metadata V0 & V1 anymore

* Rename json imports

* Base cleanups

* Add polkadot static
This commit is contained in:
Jaco Greeff
2019-08-18 15:01:21 +02:00
committed by GitHub
parent b685b29e8c
commit c7c76f6edb
75 changed files with 12231 additions and 7922 deletions
@@ -4,7 +4,7 @@
import { Calls, ModulesWithCalls } from '@polkadot/types/types';
import { ModuleMetadata } from '@polkadot/types/Metadata/v7/Metadata';
import { ModuleMetadataV7 } from '@polkadot/types/Metadata/v7/Metadata';
import Metadata from '@polkadot/types/Metadata';
import { stringCamelCase } from '@polkadot/util';
@@ -19,7 +19,7 @@ import createUnchecked from './createUnchecked';
export default function fromMetadata (metadata: Metadata): ModulesWithCalls {
return metadata.asLatest.modules
.filter(({ calls }): boolean => calls.isSome)
.reduce((result, modul: ModuleMetadata, sectionIndex): ModulesWithCalls => {
.reduce((result, modul: ModuleMetadataV7, sectionIndex): ModulesWithCalls => {
const section = stringCamelCase(modul.name.toString());
result[section] = modul.calls.unwrap().reduce((newModule, callMetadata, methodIndex): Calls => {
@@ -6,8 +6,8 @@ import { Codec } from '@polkadot/types/types';
import BN from 'bn.js';
import { Bytes, Compact, StorageKey, U8a } from '@polkadot/types';
import { createTypeUnsafe } from '@polkadot/types/codec';
import { PlainType, StorageEntryMetadata, StorageEntryModifier, StorageEntryType } from '@polkadot/types/Metadata/v6/Storage';
import { createType, createTypeUnsafe } from '@polkadot/types/codec';
import { StorageEntryMetadata, StorageEntryType } from '@polkadot/types/Metadata/v7/Storage';
import { StorageEntry } from '@polkadot/types/primitive/StorageKey';
import { assert, isNull, isUndefined, stringLowerFirst, stringToU8a, u8aConcat } from '@polkadot/util';
@@ -105,7 +105,7 @@ export default function createFunction ({ meta, method, prefix, section }: Creat
// instances (e.g. collective) will not work since it is only matched on param meta
storageFn.toJSON = (): any => ({ ...(meta.toJSON() as any), storage: { method, prefix, section } });
if (meta.type.isMap && meta.type.asMap.isLinked) {
if (meta.type.isMap && meta.type.asMap.linked.isTrue) {
const headHash = new U8a(hasher(`head of ${stringKey}`));
const headFn: any = (): U8a => headHash;
@@ -113,8 +113,8 @@ export default function createFunction ({ meta, method, prefix, section }: Creat
// meta fallback only applies to actual entry values, create one for head
headFn.meta = new StorageEntryMetadata({
name: meta.name,
modifier: new StorageEntryModifier('Required'),
type: new StorageEntryType(new PlainType(meta.type.asMap.key), 0),
modifier: createType('StorageEntryModifierV7', 1), // required
type: new StorageEntryType(createType('PlainTypeV7', meta.type.asMap.key), 0),
fallback: new Bytes(createTypeUnsafe(meta.type.asMap.key.toString()).toHex()),
documentation: meta.documentation
});
@@ -2,9 +2,9 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { StorageEntryMetadata, StorageEntryModifier, StorageEntryType } from '@polkadot/types/Metadata/v6/Storage';
import { StorageEntryMetadata, StorageEntryType } from '@polkadot/types/Metadata/v7/Storage';
import { StorageEntry } from '@polkadot/types/primitive/StorageKey';
import { Text, Vec } from '@polkadot/types';
import { createType, Text, Vec } from '@polkadot/types';
import createFunction from './createFunction';
@@ -19,7 +19,7 @@ const createRuntimeFunction = (method: string, key: string, { documentation, typ
{
meta: {
documentation: new Vec(Text, [documentation]),
modifier: new StorageEntryModifier(1), // default
modifier: createType('StorageEntryModifierV7', 1), // required
type: new StorageEntryType(type, 0),
toJSON: (): any => key
} as unknown as StorageEntryMetadata,