Metadata v7 (#1182)
* Make a start... static is in, code copied as a start. * Get exports (more-or-less) right * Well, the v7/* tests pass... now just to tweak storage generation * Linting is happy, it doesn't mean it will work... * It compiles... ship it.
This commit is contained in:
@@ -14,7 +14,7 @@ import { stringCamelCase } from '@polkadot/util';
|
||||
* @param metadata - The metadata
|
||||
*/
|
||||
export default function fromMetadata (metadata: Metadata): Constants {
|
||||
return metadata.asV6.modules.reduce((result, moduleMetadata): Constants => {
|
||||
return metadata.asV7.modules.reduce((result, moduleMetadata): Constants => {
|
||||
if (moduleMetadata.constants.isEmpty) {
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Codec } from '@polkadot/types/types';
|
||||
import { ModuleConstantMetadata as MetaV6 } from '@polkadot/types/Metadata/v6/Constants';
|
||||
import { ModuleConstantMetadata as MetaV7 } from '@polkadot/types/Metadata/v6/Constants';
|
||||
|
||||
export interface ConstantCodec extends Codec {
|
||||
meta: MetaV6;
|
||||
meta: MetaV7;
|
||||
}
|
||||
|
||||
export type ModuleConstants = Record<string, Codec>;
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Extrinsic, Metadata } from '@polkadot/types';
|
||||
import json from '@polkadot/types/Metadata/v6/static';
|
||||
import json from '@polkadot/types/Metadata/v7/static';
|
||||
|
||||
import fromV6 from '.';
|
||||
import fromMetadata from '.';
|
||||
|
||||
// Use the pre-generated metadata
|
||||
const metadata = new Metadata(json);
|
||||
const newExtrinsics = fromV6(metadata);
|
||||
const newExtrinsics = fromMetadata(metadata);
|
||||
|
||||
describe('fromMetadata', (): void => {
|
||||
it('should throw if an incorrect number of args is supplied', (): void => {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { ModuleMetadata } from '@polkadot/types/Metadata/v6/Metadata';
|
||||
import { ModuleMetadata } from '@polkadot/types/Metadata/v7/Metadata';
|
||||
import { Methods, ModulesWithMethods } from '@polkadot/types/primitive/Method';
|
||||
import Metadata from '@polkadot/types/Metadata';
|
||||
import { stringCamelCase } from '@polkadot/util';
|
||||
@@ -16,7 +16,7 @@ import createUnchecked from './createUnchecked';
|
||||
* @param metadata - The metadata
|
||||
*/
|
||||
export default function fromMetadata (metadata: Metadata): ModulesWithMethods {
|
||||
return metadata.asV6.modules
|
||||
return metadata.asV7.modules
|
||||
.filter((modul): boolean => modul.calls.isSome)
|
||||
.reduce((result, modul: ModuleMetadata, sectionIndex): ModulesWithMethods => {
|
||||
const section = stringCamelCase(modul.name.toString());
|
||||
|
||||
@@ -16,22 +16,24 @@ import { storage } from './storage';
|
||||
* @param metadata - The metadata
|
||||
*/
|
||||
export default function fromMetadata (metadata: Metadata): Storage {
|
||||
return metadata.asV6.modules.reduce((result, moduleMetadata): Storage => {
|
||||
return metadata.asV7.modules.reduce((result, moduleMetadata): Storage => {
|
||||
if (moduleMetadata.storage.isNone) {
|
||||
return result;
|
||||
}
|
||||
|
||||
const { name, prefix } = moduleMetadata;
|
||||
const { name } = moduleMetadata;
|
||||
const section = stringCamelCase(name.toString());
|
||||
const unwrapped = moduleMetadata.storage.unwrap();
|
||||
const prefix = unwrapped.prefix.toString();
|
||||
|
||||
// For access, we change the index names, i.e. Balances.FreeBalance -> balances.freeBalance
|
||||
result[section] = moduleMetadata.storage.unwrap().reduce((newModule, meta): ModuleStorage => {
|
||||
result[section] = unwrapped.items.reduce((newModule, meta): ModuleStorage => {
|
||||
const method = meta.name.toString();
|
||||
|
||||
newModule[stringLowerFirst(method)] = createFunction({
|
||||
meta,
|
||||
method,
|
||||
prefix: prefix.toString(),
|
||||
prefix,
|
||||
section
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user