Extract getSiName conversion (#3974)
This commit is contained in:
@@ -132,7 +132,7 @@ export interface FunctionMetadataV14 extends Struct {
|
||||
readonly fields: Vec<SiField>;
|
||||
readonly index: u8;
|
||||
readonly docs: Vec<Text>;
|
||||
readonly args: Vec<FunctionArgumentMetadataLatest>;
|
||||
readonly args: Vec<FunctionArgumentMetadataV14>;
|
||||
}
|
||||
|
||||
/** @name FunctionMetadataV9 */
|
||||
|
||||
@@ -28,7 +28,7 @@ export const v14: DefinitionsTypes = {
|
||||
FunctionArgumentMetadataV14: 'FunctionArgumentMetadataV13',
|
||||
FunctionMetadataV14: {
|
||||
...SiVariant,
|
||||
args: 'Vec<FunctionArgumentMetadataLatest>'
|
||||
args: 'Vec<FunctionArgumentMetadataV14>'
|
||||
},
|
||||
|
||||
// V14
|
||||
|
||||
@@ -7,6 +7,7 @@ import type { Extrinsics, ModuleExtrinsics } from '../types';
|
||||
|
||||
import { stringCamelCase } from '@polkadot/util';
|
||||
|
||||
import { getSiName } from '../../util';
|
||||
import { createUnchecked } from './createUnchecked';
|
||||
|
||||
/** @internal */
|
||||
@@ -25,7 +26,7 @@ export function decorateExtrinsics (registry: Registry, { lookup, pallets }: Met
|
||||
...variant,
|
||||
args: variant.fields.map(({ name, type }, index) => ({
|
||||
name: stringCamelCase(name.unwrapOr(`param${index}`)),
|
||||
type: lookup.getTypeDef(type).type
|
||||
type: getSiName(lookup, type)
|
||||
}))
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// Copyright 2017-2021 @polkadot/types authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { PortableRegistry, SiLookupTypeId } from '../../interfaces';
|
||||
|
||||
export function getSiName (lookup: PortableRegistry, type: SiLookupTypeId): string {
|
||||
const typeDef = lookup.getTypeDef(type);
|
||||
|
||||
return typeDef.lookupName || typeDef.type;
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export { flattenUniq } from './flattenUniq';
|
||||
export { getSiName } from './getSiName';
|
||||
export { getUniqTypes } from './getUniqTypes';
|
||||
export { toCallsOnly } from './toCallsOnly';
|
||||
export { validateTypes } from './validateTypes';
|
||||
|
||||
@@ -9,6 +9,7 @@ import type { StorageEntry } from './types';
|
||||
|
||||
import { assert, isFunction, isString, isU8a } from '@polkadot/util';
|
||||
|
||||
import { getSiName } from '../metadata/util';
|
||||
import { Bytes } from './Bytes';
|
||||
|
||||
interface Decoded {
|
||||
@@ -42,8 +43,7 @@ export function unwrapStorageSi (type: StorageEntryTypeLatest): SiLookupTypeId {
|
||||
|
||||
/** @internal */
|
||||
export function unwrapStorageType (registry: Registry, type: StorageEntryTypeLatest, isOptional?: boolean): keyof InterfaceTypes {
|
||||
const typeDef = registry.lookup.getTypeDef(unwrapStorageSi(type));
|
||||
const outputType = typeDef.lookupName || typeDef.type;
|
||||
const outputType = getSiName(registry.lookup, unwrapStorageSi(type));
|
||||
|
||||
return isOptional
|
||||
? `Option<${outputType}>` as keyof InterfaceTypes
|
||||
|
||||
Reference in New Issue
Block a user