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('MetadataV6 (substrate)', (): void => {
decodeLatestSubstrate(6, substrateData, substrateJson);
toLatest(6, substrateData);
defaultValues(substrateData);
});
describe('MetadataV6 (polkadot)', (): void => {
decodeLatestSubstrate(6, polkadotData, polkadotJson);
toLatest(6, polkadotData);
defaultValues(polkadotData);
});
@@ -0,0 +1,92 @@
// 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 { EventMetadataV6, FunctionMetadataV6, ModuleConstantMetadataV6 } 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 { StorageEntryMetadata } from './Storage';
/**
* @name ModuleMetadataV6
* @description
* The definition of a module in the system
*/
export class ModuleMetadataV6 extends Struct {
constructor (value?: any) {
super({
name: 'Text',
prefix: 'Text',
storage: Option.with(Vec.with(StorageEntryMetadata)),
calls: Option.with('Vec<FunctionMetadataV6>'),
events: Option.with('Vec<EventMetadataV6>'),
constants: 'Vec<ModuleConstantMetadataV6>'
}, value);
}
/**
* @description the module calls
*/
public get calls (): Option<Vec<FunctionMetadataV6>> {
return this.get('calls') as Option<Vec<FunctionMetadataV6>>;
}
/**
* @description the module constants
*/
public get constants (): Vec<ModuleConstantMetadataV6> {
return this.get('constants') as Vec<ModuleConstantMetadataV6>;
}
/**
* @description the module events
*/
public get events (): Option<Vec<EventMetadataV6>> {
return this.get('events') as Option<Vec<EventMetadataV6>>;
}
/**
* @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<StorageEntryMetadata>> {
return this.get('storage') as Option<Vec<StorageEntryMetadata>>;
}
}
/**
* @name MetadataV6
* @description
* The runtime metadata as a decoded structure
*/
export default class MetadataV6 extends Struct implements MetadataInterface<ModuleMetadataV6> {
constructor (value?: any) {
super({
modules: Vec.with(ModuleMetadataV6)
}, value);
}
/**
* @description The associated modules for this structure
*/
public get modules (): Vec<ModuleMetadataV6> {
return this.get('modules') as Vec<ModuleMetadataV6>;
}
}
@@ -0,0 +1,12 @@
// 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 { StorageFunctionMetadata, StorageFunctionMetadataValue, StorageFunctionType } from '../v5/Storage';
// Re-export classes that haven't changed between V5 and V6
export {
StorageFunctionMetadata as StorageEntryMetadata,
StorageFunctionMetadataValue as StorageEntryMetadataValue,
StorageFunctionType as StorageEntryType
};
@@ -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 MetadataV6, { ModuleMetadataV6 } from './Metadata';
export default MetadataV6;
export {
ModuleMetadataV6
};
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
+27
View File
@@ -0,0 +1,27 @@
// 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 MetadataV6 from './Metadata';
import MetadataV7 from '../v7';
import { ModuleMetadataV7 } from '../v7/Metadata';
import { StorageMetadata as StorageV7 } from '../v7/Storage';
/**
* Convert from MetadataV6 to MetadataV7
*/
export default function toV7 ({ modules }: MetadataV6): MetadataV7 {
return new MetadataV7({
modules: modules.map(({ calls, constants, events, name, prefix, storage }): ModuleMetadataV7 =>
new ModuleMetadataV7({
calls,
constants,
events,
name,
storage: storage.isSome
? new StorageV7({ prefix, items: storage.unwrap() })
: null
})
)
});
}