feat: Metadata V6 with module constants (#1059)
* feat: metadata v6, minus static and test * fix: update v5 to v6 everywhere * fix: lint and testUtil * fix typo * fix: match final metadata. constants no longer optional, StorageFunctionMetadata renamed to StorageEntryMetadata. * fix: constants constructor * fix: unit tests pass * fix: linting and renaming, make tests pass * fix: skip e2e remove console log * fix: formatting test * fix api e2e tests * fix: put the skip back * feat: yarn test:skip-e2e * fix: grumbles, add fresh flipper wasm * fix: grumbles, add fresh flipper wasm * fix: changelog * fix ci
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { StorageHasher, Text } from '@polkadot/types';
|
||||
import { StorageFunction } from '@polkadot/types/primitive/StorageKey';
|
||||
import { StorageEntry } from '@polkadot/types/primitive/StorageKey';
|
||||
import { stringToU8a, u8aConcat, u8aToHex } from '@polkadot/util';
|
||||
|
||||
import createFunction from './createFunction';
|
||||
@@ -57,7 +57,7 @@ describe('createFunction', () => {
|
||||
});
|
||||
|
||||
describe('the created double map function', () => {
|
||||
let storageFn: StorageFunction;
|
||||
let storageFn: StorageEntry;
|
||||
beforeAll(() => {
|
||||
storageFn = createFunction(
|
||||
'GenericAsset',
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { createType, Bytes, Compact, StorageKey, Text, U8a } from '@polkadot/types';
|
||||
import { PlainType, StorageFunctionMetadata, StorageFunctionModifier, StorageFunctionType } from '@polkadot/types/Metadata/v5/Storage';
|
||||
import { StorageFunction } from '@polkadot/types/primitive/StorageKey';
|
||||
import { PlainType, StorageEntryMetadata, StorageEntryModifier, StorageEntryType } from '@polkadot/types/Metadata/v6/Storage';
|
||||
import { StorageEntry } from '@polkadot/types/primitive/StorageKey';
|
||||
import { assert, isNull, isUndefined, stringLowerFirst, stringToU8a, u8aConcat } from '@polkadot/util';
|
||||
|
||||
import getHasher, { HasherFunction } from './getHasher';
|
||||
@@ -24,7 +24,7 @@ export interface CreateItemOptions {
|
||||
* are not known at runtime (from state_getMetadata), they need to be supplied
|
||||
* by us manually at compile time.
|
||||
*/
|
||||
export default function createFunction (section: Text | string, method: Text | string, meta: StorageFunctionMetadata, options: CreateItemOptions = {}): StorageFunction {
|
||||
export default function createFunction (section: Text | string, method: Text | string, meta: StorageEntryMetadata, options: CreateItemOptions = {}): StorageEntry {
|
||||
const stringKey = options.key
|
||||
? options.key
|
||||
: `${section.toString()} ${method.toString()}`;
|
||||
@@ -81,10 +81,10 @@ export default function createFunction (section: Text | string, method: Text | s
|
||||
if (meta.type.isMap && meta.type.asMap.isLinked) {
|
||||
const keyHash = new U8a(hasher(`head of ${stringKey}`));
|
||||
const keyFn: any = () => keyHash;
|
||||
keyFn.meta = new StorageFunctionMetadata({
|
||||
keyFn.meta = new StorageEntryMetadata({
|
||||
name: meta.name,
|
||||
modifier: new StorageFunctionModifier('Required'),
|
||||
type: new StorageFunctionType(new PlainType(meta.type.asMap.key), 0),
|
||||
modifier: new StorageEntryModifier('Required'),
|
||||
type: new StorageEntryType(new PlainType(meta.type.asMap.key), 0),
|
||||
fallback: new Bytes(),
|
||||
documentation: meta.documentation
|
||||
});
|
||||
@@ -96,5 +96,5 @@ export default function createFunction (section: Text | string, method: Text | s
|
||||
storageFn.section = stringLowerFirst(section.toString());
|
||||
storageFn.toJSON = (): any => meta.toJSON();
|
||||
|
||||
return storageFn as StorageFunction;
|
||||
return storageFn as StorageEntry;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import testingPairs from '@polkadot/keyring/testingPairs';
|
||||
import { Metadata } from '@polkadot/types';
|
||||
import json from '@polkadot/types/Metadata/v5/static';
|
||||
import json from '@polkadot/types/Metadata/v6/static';
|
||||
import { u8aToHex } from '@polkadot/util';
|
||||
|
||||
import fromMetadata from './';
|
||||
|
||||
@@ -18,7 +18,7 @@ import { storage } from './storage';
|
||||
* @param metadata - The metadata to extend the storage object against.
|
||||
*/
|
||||
export default function fromMetadata (metadata: Metadata): Storage {
|
||||
return metadata.asV5.modules.reduce((result, moduleMetadata) => {
|
||||
return metadata.asV6.modules.reduce((result, moduleMetadata) => {
|
||||
if (moduleMetadata.storage.isNone) {
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { StorageFunctionMetadata, StorageFunctionModifier, StorageFunctionType } from '@polkadot/types/Metadata/v5/Storage';
|
||||
import { StorageFunction } from '@polkadot/types/primitive/StorageKey';
|
||||
import { StorageEntryMetadata, StorageEntryModifier, StorageEntryType } from '@polkadot/types/Metadata/v6/Storage';
|
||||
import { StorageEntry } from '@polkadot/types/primitive/StorageKey';
|
||||
import { Text, Vector } from '@polkadot/types';
|
||||
|
||||
import createFunction from './createFunction';
|
||||
@@ -14,16 +14,16 @@ interface SubstrateMetadata {
|
||||
}
|
||||
|
||||
// Small helper function to factorize code on this page.
|
||||
const createRuntimeFunction = (method: string, key: string, { documentation, type }: SubstrateMetadata): StorageFunction =>
|
||||
const createRuntimeFunction = (method: string, key: string, { documentation, type }: SubstrateMetadata): StorageEntry =>
|
||||
createFunction(
|
||||
new Text('Substrate'),
|
||||
new Text(method),
|
||||
{
|
||||
documentation: new Vector(Text, [documentation]),
|
||||
modifier: new StorageFunctionModifier(1), // default
|
||||
type: new StorageFunctionType(type, 0),
|
||||
modifier: new StorageEntryModifier(1), // default
|
||||
type: new StorageEntryType(type, 0),
|
||||
toJSON: (): any => key
|
||||
} as StorageFunctionMetadata,
|
||||
} as StorageEntryMetadata,
|
||||
{
|
||||
key,
|
||||
skipHashing: true
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Metadata } from '@polkadot/types';
|
||||
import metadataRpc from '@polkadot/types/Metadata/v5/static';
|
||||
import metadataRpc from '@polkadot/types/Metadata/v6/static';
|
||||
|
||||
import fromMetadata from './fromMetadata';
|
||||
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { StorageFunction } from '@polkadot/types/primitive/StorageKey';
|
||||
import { StorageEntry } from '@polkadot/types/primitive/StorageKey';
|
||||
|
||||
export interface ModuleStorage {
|
||||
[key: string]: StorageFunction;
|
||||
[key: string]: StorageEntry;
|
||||
}
|
||||
|
||||
export interface Storage {
|
||||
[key: string]: ModuleStorage; // Will hold modules returned by state_getMetadata
|
||||
substrate: { [key: string]: StorageFunction };
|
||||
substrate: { [key: string]: StorageEntry };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user