Skip to content

Commit 8062572

Browse files
jacogrian.he
authored andcommitted
Remove deprecated Metadata getters (polkadot-js#1315)
* Remove deprecated Metadata getters * Start metadata with som injected types * Cleanup V0 somewhat with injected types * Re-generate interfaces * Extract some Storage type definitions * Remove unneeded Calls & Constants files in metadata
1 parent 7dafa17 commit 8062572

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+560
-833
lines changed

packages/api-metadata/src/consts/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
// of the Apache-2.0 license. See the LICENSE file for details.
44

55
import { Codec } from '@plugnet/types/types';
6-
import { ModuleConstantMetadata as MetaV7 } from '@plugnet/types/Metadata/v6/Constants';
6+
import { ModuleConstantMetadataV7 } from '@plugnet/types/interfaces';
77

88
export interface ConstantCodec extends Codec {
9-
meta: MetaV7;
9+
meta: ModuleConstantMetadataV7;
1010
}
1111

1212
export type ModuleConstants = Record<string, Codec>;

packages/api-metadata/src/extrinsics/fromMetadata/createUnchecked.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
// This software may be modified and distributed under the terms
33
// of the Apache-2.0 license. See the LICENSE file for details.
44

5-
import { Call } from '@plugnet/types/interfaces';
5+
import { Call, FunctionMetadataV7 } from '@plugnet/types/interfaces';
66
import { CallFunction } from '@plugnet/types/types';
77

8-
import { FunctionMetadata } from '@plugnet/types/Metadata/v7/Calls';
98
import { createType } from '@plugnet/types';
109
import { assert, stringCamelCase } from '@plugnet/util';
1110

@@ -22,7 +21,7 @@ export default function createDescriptor (
2221
section: string,
2322
sectionIndex: number,
2423
methodIndex: number,
25-
callMetadata: FunctionMetadata
24+
callMetadata: FunctionMetadataV7
2625
): CallFunction {
2726
const callIndex = new Uint8Array([sectionIndex, methodIndex]);
2827
const expectedArgs = callMetadata.args;

packages/types/src/Metadata/v0/Calls.ts

Lines changed: 0 additions & 62 deletions
This file was deleted.

packages/types/src/Metadata/v0/Events.ts

Lines changed: 5 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -2,72 +2,23 @@
22
// This software may be modified and distributed under the terms
33
// of the Apache-2.0 license. See the LICENSE file for details.
44

5+
import { EventMetadataV0 } from '../../interfaces/metadata/types';
6+
57
import Struct from '../../codec/Struct';
68
import Tuple from '../../codec/Tuple';
79
import Vec from '../../codec/Vec';
810
import Text from '../../primitive/Text';
9-
import Type from '../../primitive/Type';
10-
11-
export class EventMetadata extends Struct {
12-
public constructor (value?: any) {
13-
super({
14-
name: Text,
15-
args: Vec.with(Type),
16-
documentation: Vec.with(Text)
17-
}, value);
18-
}
19-
20-
/**
21-
* @description The arguments of [[Type]]
22-
*/
23-
public get args (): Vec<Type> {
24-
return this.get('args') as Vec<Type>;
25-
}
26-
27-
/**
28-
* @description The arguments of [[Type]]
29-
* @deprecated Use `.args` instead
30-
*/
31-
public get arguments (): Vec<Type> {
32-
return this.args;
33-
}
34-
35-
/**
36-
* @description The [[Text]] documentation
37-
*/
38-
public get documentation (): Vec<Text> {
39-
return this.get('documentation') as Vec<Text>;
40-
}
41-
42-
/**
43-
* @description The [[Text]] documentation
44-
* @deprecated Use `.documentation` instead.
45-
*/
46-
public get docs (): Vec<Text> {
47-
return this.documentation;
48-
}
49-
50-
/**
51-
* @description The name for the event
52-
*/
53-
public get name (): Text {
54-
return this.get('name') as Text;
55-
}
56-
}
5711

5812
export class OuterEventEventMetadata extends Tuple {
5913
public constructor (value?: any) {
60-
super({
61-
Text,
62-
'Vec<EventMetadata>': Vec.with(EventMetadata)
63-
}, value);
14+
super(['Text', 'Vec<EventMetadataV0>'], value);
6415
}
6516

6617
/**
6718
* @description The [[EventMetadata]]
6819
*/
69-
public get events (): Vec<EventMetadata> {
70-
return this[1] as Vec<EventMetadata>;
20+
public get events (): Vec<EventMetadataV0> {
21+
return this[1] as Vec<EventMetadataV0>;
7122
}
7223

7324
/**

packages/types/src/Metadata/v0/Metadata.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// This software may be modified and distributed under the terms
33
// of the Apache-2.0 license. See the LICENSE file for details.
44

5+
import { OuterDispatchMetadataV0, OuterDispatchCallV0 } from '../../interfaces/metadata/types';
56
import { MetadataInterface } from '../types';
67

78
import { hexToU8a, isHex, isU8a } from '@plugnet/util';
@@ -10,9 +11,8 @@ import Compact from '../../codec/Compact';
1011
import Struct from '../../codec/Struct';
1112
import Vec from '../../codec/Vec';
1213
import { flattenUniq, validateTypes } from '../util';
13-
import { OuterDispatchMetadata, OuterDispatchCall } from './Calls';
1414
import { OuterEventMetadata, OuterEventEventMetadata } from './Events';
15-
import { RuntimeModuleMetadata } from './Modules';
15+
import { RuntimeModuleMetadataV0 } from './Modules';
1616

1717
// Decodes the runtime metadata as passed through from the `state_getMetadata` call.
1818

@@ -21,12 +21,12 @@ import { RuntimeModuleMetadata } from './Modules';
2121
* @description
2222
* The runtime metadata as a decoded structure
2323
*/
24-
export default class MetadataV0 extends Struct implements MetadataInterface<RuntimeModuleMetadata> {
24+
export default class MetadataV0 extends Struct implements MetadataInterface<RuntimeModuleMetadataV0> {
2525
public constructor (value?: any) {
2626
super({
2727
outerEvent: OuterEventMetadata,
28-
modules: Vec.with(RuntimeModuleMetadata),
29-
outerDispatch: OuterDispatchMetadata
28+
modules: Vec.with(RuntimeModuleMetadataV0),
29+
outerDispatch: 'OuterDispatchMetadataV0'
3030
}, MetadataV0.decodeMetadata(value));
3131
}
3232

@@ -55,8 +55,8 @@ export default class MetadataV0 extends Struct implements MetadataInterface<Runt
5555
/**
5656
* @description Wrapped [[OuterDispatchCall]]
5757
*/
58-
public get calls (): Vec<OuterDispatchCall> {
59-
return (this.get('outerDispatch') as OuterDispatchMetadata).calls;
58+
public get calls (): Vec<OuterDispatchCallV0> {
59+
return (this.get('outerDispatch') as OuterDispatchMetadataV0).calls;
6060
}
6161

6262
/**
@@ -69,14 +69,14 @@ export default class MetadataV0 extends Struct implements MetadataInterface<Runt
6969
/**
7070
* @description Wrapped [[RuntimeModuleMetadata]]
7171
*/
72-
public get modules (): Vec<RuntimeModuleMetadata> {
73-
return this.get('modules') as Vec<RuntimeModuleMetadata>;
72+
public get modules (): Vec<RuntimeModuleMetadataV0> {
73+
return this.get('modules') as Vec<RuntimeModuleMetadataV0>;
7474
}
7575

7676
private get argNames (): string[][][] {
77-
return this.modules.map((modul): string[][] =>
78-
modul.module.call.functions.map((fn): string[] =>
79-
fn.args.map((argument): string => argument.type.toString())
77+
return this.modules.map(({ module: { call: { functions } } }): string[][] =>
78+
functions.map(({ args }): string[] =>
79+
args.map((arg): string => arg.type.toString())
8080
)
8181
);
8282
}
@@ -92,10 +92,10 @@ export default class MetadataV0 extends Struct implements MetadataInterface<Runt
9292
private get storageNames (): string[][][] {
9393
return this.modules.map((modul): string[][] =>
9494
modul.storage.isSome
95-
? modul.storage.unwrap().functions.map((fn): string[] =>
96-
fn.type.isMap
97-
? [fn.type.asMap.key.toString(), fn.type.asMap.value.toString()]
98-
: [fn.type.asType.toString()]
95+
? modul.storage.unwrap().functions.map(({ type }): string[] =>
96+
type.isMap
97+
? [type.asMap.key.toString(), type.asMap.value.toString()]
98+
: [type.asType.toString()]
9999
)
100100
: []
101101
);

0 commit comments

Comments
 (0)