Call.injectMetadata (align with Events) (#1462)
* Call.injectMetadata (align with Events) * Fix interface builds * Fix md builds * Fixup tests with injection
This commit is contained in:
@@ -5,8 +5,7 @@
|
||||
import { Codec } from '@polkadot/types/types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { Bytes, Compact, StorageKey, U8a } from '@polkadot/types';
|
||||
import { createType, createTypeUnsafe } from '@polkadot/types/codec';
|
||||
import { Compact, U8a, createType, createTypeUnsafe } from '@polkadot/types/codec';
|
||||
import { StorageEntryMetadata, StorageEntryType } from '@polkadot/types/Metadata/v8/Storage';
|
||||
import { StorageEntry } from '@polkadot/types/primitive/StorageKey';
|
||||
import { assert, isNull, isUndefined, stringLowerFirst, stringToU8a, u8aConcat } from '@polkadot/util';
|
||||
@@ -123,13 +122,13 @@ function extendLinkedMap ({ meta: { documentation, name, type } }: CreateItemFn,
|
||||
name,
|
||||
modifier: createType('StorageEntryModifierLatest', 1), // required
|
||||
type: new StorageEntryType(createType('PlainTypeLatest', type.asMap.key), 0),
|
||||
fallback: new Bytes(createTypeUnsafe(type.asMap.key.toString()).toHex()),
|
||||
fallback: createType('Bytes', createTypeUnsafe(type.asMap.key.toString()).toHex()),
|
||||
documentation
|
||||
});
|
||||
|
||||
// here we pass the section/method through as well - these are not on
|
||||
// the function itself, so specify these explicitly to the constructor
|
||||
storageFn.headKey = new StorageKey(headFn, {
|
||||
storageFn.headKey = createType('StorageKey', headFn, {
|
||||
method: storageFn.method,
|
||||
section: `head of ${storageFn.section}`
|
||||
});
|
||||
|
||||
@@ -5,18 +5,12 @@
|
||||
import '@polkadot/types/injector';
|
||||
|
||||
import testingPairs from '@polkadot/keyring/testingPairs';
|
||||
import { Metadata } from '@polkadot/types';
|
||||
import json from '@polkadot/types/Metadata/static';
|
||||
import { u8aToHex } from '@polkadot/util';
|
||||
|
||||
import fromMetadata from '../fromMetadata';
|
||||
import storage from '../static';
|
||||
|
||||
const keyring = testingPairs({ type: 'ed25519' });
|
||||
|
||||
// Use the pre-generated metadata
|
||||
const metadata = new Metadata(json);
|
||||
const storage = fromMetadata(metadata);
|
||||
|
||||
describe('fromMetadata', (): void => {
|
||||
it('should throw if the storage function expects an argument', (): void => {
|
||||
expect((): any => storage.balances.freeBalance()).toThrowError(/requires one argument/);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import { StorageEntryMetadata, StorageEntryType } from '@polkadot/types/Metadata/v8/Storage';
|
||||
import { StorageEntry } from '@polkadot/types/primitive/StorageKey';
|
||||
import { createType, Text, Vec } from '@polkadot/types';
|
||||
import { createType } from '@polkadot/types/codec';
|
||||
|
||||
import createFunction from './createFunction';
|
||||
|
||||
@@ -18,7 +18,7 @@ const createRuntimeFunction = (method: string, key: string, { documentation, typ
|
||||
createFunction(
|
||||
{
|
||||
meta: {
|
||||
documentation: new Vec(Text, [documentation]),
|
||||
documentation: createType('Vec<Text>', [documentation]),
|
||||
modifier: createType('StorageEntryModifierLatest', 1), // required
|
||||
type: new StorageEntryType(type, 0),
|
||||
toJSON: (): any => key
|
||||
|
||||
Reference in New Issue
Block a user