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:
@@ -28,10 +28,10 @@
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.5.4",
|
||||
"@polkadot/types": "^0.82.0-beta.66",
|
||||
"@polkadot/util": "^0.94.0-beta.11",
|
||||
"@polkadot/util-crypto": "^0.94.0-beta.11"
|
||||
"@polkadot/util": "^0.94.0-beta.12",
|
||||
"@polkadot/util-crypto": "^0.94.0-beta.12"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^0.94.0-beta.11"
|
||||
"@polkadot/keyring": "^0.94.0-beta.12"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
-1
@@ -9,6 +9,6 @@ export interface ConstantCodec extends Codec {
|
||||
meta: MetaV6;
|
||||
}
|
||||
|
||||
export type ModuleConstants = Record<string, ConstantCodec>;
|
||||
export type ModuleConstants = Record<string, Codec>;
|
||||
|
||||
export type Constants = Record<string, ModuleConstants>;
|
||||
Reference in New Issue
Block a user