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,85 @@
// 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 { EventMetadataV2, FunctionMetadataV2 } 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 { StorageFunctionMetadata } from './Storage';
/**
* @name ModuleMetadataV2
* @description
* The definition of a module in the system
*/
export class ModuleMetadataV2 extends Struct {
constructor (value?: any) {
super({
name: 'Text',
prefix: 'Text',
storage: Option.with(Vec.with(StorageFunctionMetadata)),
calls: Option.with('Vec<FunctionMetadataV2>'),
events: Option.with('Vec<EventMetadataV2>')
}, value);
}
/**
* @description the module calls
*/
public get calls (): Option<Vec<FunctionMetadataV2>> {
return this.get('calls') as Option<Vec<FunctionMetadataV2>>;
}
/**
* @description the module events
*/
public get events (): Option<Vec<EventMetadataV2>> {
return this.get('events') as Option<Vec<EventMetadataV2>>;
}
/**
* @description the module name
*/
public get name (): Text {
return this.get('name') as Text;
}
/**
* @description the module prefix
*/
public get prefix (): Text {
return this.get('prefix') as Text;
}
/**
* @description the associated module storage
*/
public get storage (): Option<Vec<StorageFunctionMetadata>> {
return this.get('storage') as Option<Vec<StorageFunctionMetadata>>;
}
}
/**
* @name MetadataV2
* @description
* The runtime metadata as a decoded structure
*/
export default class MetadataV2 extends Struct implements MetadataInterface<ModuleMetadataV2> {
constructor (value?: any) {
super({
modules: Vec.with(ModuleMetadataV2)
}, value);
}
/**
* @description The associated modules for this structure
*/
public get modules (): Vec<ModuleMetadataV2> {
return this.get('modules') as Vec<ModuleMetadataV2>;
}
}