Skip to content

Commit 3b4c2ac

Browse files
authored
Extract getSiName conversion (#3974)
1 parent d0ecfda commit 3b4c2ac

File tree

6 files changed

+17
-5
lines changed

6 files changed

+17
-5
lines changed

packages/types/src/interfaces/metadata/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export interface FunctionMetadataV14 extends Struct {
132132
readonly fields: Vec<SiField>;
133133
readonly index: u8;
134134
readonly docs: Vec<Text>;
135-
readonly args: Vec<FunctionArgumentMetadataLatest>;
135+
readonly args: Vec<FunctionArgumentMetadataV14>;
136136
}
137137

138138
/** @name FunctionMetadataV9 */

packages/types/src/interfaces/metadata/v14.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const v14: DefinitionsTypes = {
2828
FunctionArgumentMetadataV14: 'FunctionArgumentMetadataV13',
2929
FunctionMetadataV14: {
3030
...SiVariant,
31-
args: 'Vec<FunctionArgumentMetadataLatest>'
31+
args: 'Vec<FunctionArgumentMetadataV14>'
3232
},
3333

3434
// V14

packages/types/src/metadata/decorate/extrinsics/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import type { Extrinsics, ModuleExtrinsics } from '../types';
77

88
import { stringCamelCase } from '@polkadot/util';
99

10+
import { getSiName } from '../../util';
1011
import { createUnchecked } from './createUnchecked';
1112

1213
/** @internal */
@@ -25,7 +26,7 @@ export function decorateExtrinsics (registry: Registry, { lookup, pallets }: Met
2526
...variant,
2627
args: variant.fields.map(({ name, type }, index) => ({
2728
name: stringCamelCase(name.unwrapOr(`param${index}`)),
28-
type: lookup.getTypeDef(type).type
29+
type: getSiName(lookup, type)
2930
}))
3031
});
3132

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// Copyright 2017-2021 @polkadot/types authors & contributors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
import type { PortableRegistry, SiLookupTypeId } from '../../interfaces';
5+
6+
export function getSiName (lookup: PortableRegistry, type: SiLookupTypeId): string {
7+
const typeDef = lookup.getTypeDef(type);
8+
9+
return typeDef.lookupName || typeDef.type;
10+
}

packages/types/src/metadata/util/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33

44
export { flattenUniq } from './flattenUniq';
5+
export { getSiName } from './getSiName';
56
export { getUniqTypes } from './getUniqTypes';
67
export { toCallsOnly } from './toCallsOnly';
78
export { validateTypes } from './validateTypes';

packages/types/src/primitive/StorageKey.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import type { StorageEntry } from './types';
99

1010
import { assert, isFunction, isString, isU8a } from '@polkadot/util';
1111

12+
import { getSiName } from '../metadata/util';
1213
import { Bytes } from './Bytes';
1314

1415
interface Decoded {
@@ -42,8 +43,7 @@ export function unwrapStorageSi (type: StorageEntryTypeLatest): SiLookupTypeId {
4243

4344
/** @internal */
4445
export function unwrapStorageType (registry: Registry, type: StorageEntryTypeLatest, isOptional?: boolean): keyof InterfaceTypes {
45-
const typeDef = registry.lookup.getTypeDef(unwrapStorageSi(type));
46-
const outputType = typeDef.lookupName || typeDef.type;
46+
const outputType = getSiName(registry.lookup, unwrapStorageSi(type));
4747

4848
return isOptional
4949
? `Option<${outputType}>` as keyof InterfaceTypes

0 commit comments

Comments
 (0)