CreateType is typed, add createTypeUnsafe just in case (#1199)

* Use unsafe internally

* Add comments

* Remove <> in createType

* Fix lint

* Fix classOf

* Remove createType from Text

* Fix lint

* Fix Fallback type

* Fix fallback in createType
This commit is contained in:
Amaury Martiny
2019-07-26 14:00:25 +02:00
committed by Jaco Greeff
parent ec0b9a84a3
commit 441148889d
24 changed files with 112 additions and 104 deletions
@@ -4,7 +4,7 @@
import { Constants, ConstantCodec, ModuleConstants } from '../types';
import { createType } from '@polkadot/types';
import { createTypeUnsafe } from '@polkadot/types/codec/createType';
import Metadata from '@polkadot/types/Metadata';
import { stringCamelCase } from '@polkadot/util';
@@ -23,7 +23,7 @@ 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 codec = createTypeUnsafe(meta.type.toString(), meta.value);
// 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