Add toJSON function for substrate meta (#188)

This commit is contained in:
Jaco Greeff
2018-10-02 15:56:11 +02:00
committed by GitHub
parent 69f712006c
commit 51d4c45c48
+5 -7
View File
@@ -2,7 +2,7 @@
// This software may be modified and distributed under the terms
// of the ISC license. See the LICENSE file for details.
import { StorageFunctionModifier, StorageFunctionType } from '@polkadot/types/Metadata';
import { StorageFunctionMetadata, StorageFunctionModifier, StorageFunctionType } from '@polkadot/types/Metadata';
import Text from '@polkadot/types/Text';
import Vector from '@polkadot/types/codec/Vector';
@@ -15,18 +15,16 @@ interface SubstrateMetadata {
// Small helper function to factorize code on this page.
const createRuntimeFunction = (method: string, key: string, { documentation, type }: SubstrateMetadata) =>
// TODO The expected 2nd argument is a StorageFunctionMetadata, but we
// actually only need the fields `documentation` and `type` of it, so in
// order to not input other fields (byteLength, fromJSON...) we lazily cast
// as any.
createFunction(
new Text('Substrate'),
new Text(key),
{
documentation: new Vector(Text, [documentation]),
modifier: new StorageFunctionModifier().fromJSON(0),
type: new StorageFunctionType(0, type)
} as any,
type: new StorageFunctionType(0, type),
toJSON: (): any =>
key
} as StorageFunctionMetadata,
{
isUnhashed: true,
method