Add a Decorated class, which will be offline decorated Metadata (#1463)

* Move Metadata to api-metadata

* Make tests in api-metadata pass

* Make tests in api-metadata pass

* Refactor fromMetadata into decorated

* Fix some linting

* Replace headers

* Fix all tests

* Small lint

* Fix tests

* Fix metadata docs scripts

* Fix import ordering

* Add line breaks

* Grumbles

* Fix forgotten import

* rpcMetadata everywhere

* Fixlint

* s/api-metadata/metadata

* Fix latest tests

* Fix lint

* Fix tests
This commit is contained in:
Amaury Martiny
2019-11-12 12:06:18 +01:00
committed by Jaco Greeff
parent c87ba33893
commit 16e0ea9315
152 changed files with 510 additions and 413 deletions
@@ -0,0 +1,25 @@
// Copyright 2017-2019 @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 polkadotJson from './static-polkadot.json';
import substrateJson from './static-substrate.json';
import polkadotData from './static.polkadot';
import substrateData from './static';
import { decodeLatestSubstrate, defaultValues, toLatest } from '../util/testUtil';
describe('MetadataV7 (substrate)', (): void => {
decodeLatestSubstrate(7, substrateData, substrateJson);
toLatest(7, substrateData);
defaultValues(substrateData);
});
describe('MetadataV7 (polkadot)', (): void => {
decodeLatestSubstrate(7, polkadotData, polkadotJson);
toLatest(7, polkadotData);
defaultValues(polkadotData);
});
@@ -0,0 +1,84 @@
// Copyright 2017-2019 @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 { EventMetadataV7, FunctionMetadataV7, ModuleConstantMetadataV7 } from '@polkadot/types/interfaces/metadata';
import { MetadataInterface } from '../types';
import Option from '@polkadot/types/codec/Option';
import Struct from '@polkadot/types/codec/Struct';
import Vec from '@polkadot/types/codec/Vec';
import Text from '@polkadot/types/primitive/Text';
import { StorageMetadata } from './Storage';
/**
* @name ModuleMetadataV7
* @description
* The definition of a module in the system
*/
export class ModuleMetadataV7 extends Struct {
constructor (value?: any) {
super({
name: 'Text',
storage: Option.with(StorageMetadata),
calls: Option.with('Vec<FunctionMetadataV7>'),
events: Option.with('Vec<EventMetadataV7>'),
constants: 'Vec<ModuleConstantMetadataV7>'
}, value);
}
/**
* @description the module calls
*/
public get calls (): Option<Vec<FunctionMetadataV7>> {
return this.get('calls') as Option<Vec<FunctionMetadataV7>>;
}
/**
* @description the module constants
*/
public get constants (): Vec<ModuleConstantMetadataV7> {
return this.get('constants') as Vec<ModuleConstantMetadataV7>;
}
/**
* @description the module events
*/
public get events (): Option<Vec<EventMetadataV7>> {
return this.get('events') as Option<Vec<EventMetadataV7>>;
}
/**
* @description the module name
*/
public get name (): Text {
return this.get('name') as Text;
}
/**
* @description the associated module storage
*/
public get storage (): Option<StorageMetadata> {
return this.get('storage') as Option<StorageMetadata>;
}
}
/**
* @name MetadataV7
* @description
* The runtime metadata as a decoded structure
*/
export default class MetadataV7 extends Struct implements MetadataInterface<ModuleMetadataV7> {
constructor (value?: any) {
super({
modules: Vec.with(ModuleMetadataV7)
}, value);
}
/**
* @description The associated modules for this structure
*/
public get modules (): Vec<ModuleMetadataV7> {
return this.get('modules') as Vec<ModuleMetadataV7>;
}
}
@@ -0,0 +1,39 @@
// Copyright 2017-2019 @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 Struct from '@polkadot/types/codec/Struct';
import Vec from '@polkadot/types/codec/Vec';
import Text from '@polkadot/types/primitive/Text';
import { StorageEntryMetadata, StorageEntryMetadataValue, StorageEntryType } from '../v6/Storage';
// Re-export classes that haven't changed between V6 and V7
export {
StorageEntryMetadata,
StorageEntryMetadataValue,
StorageEntryType
};
export class StorageMetadata extends Struct {
constructor (value?: any) {
super({
prefix: 'Text',
// NOTE renamed to items from entries (since Struct already has entries from Map)
items: Vec.with(StorageEntryMetadata)
}, value);
}
/**
* @description the storage entries
*/
public get items (): Vec<StorageEntryMetadata> {
return this.get('items') as Vec<StorageEntryMetadata>;
}
/**
* @description the prefix for this module
*/
public get prefix (): Text {
return this.get('prefix') as Text;
}
}
@@ -0,0 +1,11 @@
// Copyright 2017-2019 @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 MetadataV7, { ModuleMetadataV7 } from './Metadata';
export default MetadataV7;
export {
ModuleMetadataV7
};
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+25
View File
@@ -0,0 +1,25 @@
// Copyright 2017-2019 @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 MetadataV7 from './Metadata';
import MetadataV8 from '../v8';
import { ModuleMetadataV8 } from '../v8/Metadata';
/**
* Convert from MetadataV7 to MetadataV8
*/
export default function toV8 ({ modules }: MetadataV7): MetadataV8 {
return new MetadataV8({
modules: modules.map(({ calls, constants, events, name, storage }): ModuleMetadataV8 =>
new ModuleMetadataV8({
calls,
constants,
errors: [],
events,
name,
storage
})
)
});
}