Don't export constants as ConstantCodec (TS casting) (#1140)
* Don't export constants as ConstantCodec (TS casting) * Import ConstantCodec from types
This commit is contained in:
@@ -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 { Constants, ConstantCodec, ModuleConstants } from './types';
|
||||
import { Constants, ConstantCodec, ModuleConstants } from '../types';
|
||||
|
||||
import { createType } from '@polkadot/types';
|
||||
import Metadata from '@polkadot/types/Metadata';
|
||||
@@ -24,14 +24,13 @@ export default function fromMetadata (metadata: Metadata): Constants {
|
||||
// For access, we change the index names, i.e. Democracy.EnactmentPeriod -> democracy.enactmentPeriod
|
||||
result[stringCamelCase(name.toString())] = moduleMetadata.constants.reduce((newModule, meta): ModuleConstants => {
|
||||
const codec = createType(meta.type, meta.value);
|
||||
const ccodec = codec as ConstantCodec;
|
||||
|
||||
// This is not a perfect idea, however as it stands with number-only constants on the metadata
|
||||
// does not have any effect. However, this could become problematic in cases where items are
|
||||
// exposed that contain their own metadata. As of now, the compatibility with current, e.g.
|
||||
// storage is the driving factor, one consistent way of handling interfaces
|
||||
ccodec.meta = meta;
|
||||
newModule[stringCamelCase(meta.name.toString())] = ccodec;
|
||||
(codec as ConstantCodec).meta = meta;
|
||||
newModule[stringCamelCase(meta.name.toString())] = codec;
|
||||
|
||||
return newModule;
|
||||
}, {} as unknown as ModuleConstants);
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
// Copyright 2017-2019 @polkadot/api-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 { Codec } from '@polkadot/types/types';
|
||||
import { ModuleConstantMetadata as MetaV6 } from '@polkadot/types/Metadata/v6/Constants';
|
||||
|
||||
export interface ConstantCodec extends Codec {
|
||||
meta: MetaV6;
|
||||
}
|
||||
|
||||
export type ModuleConstants = Record<string, ConstantCodec>;
|
||||
|
||||
export type Constants = Record<string, ModuleConstants>;
|
||||
Reference in New Issue
Block a user