diff --git a/packages/api/src/Base.ts b/packages/api/src/Base.ts index 40f6687f65..b65faaadd7 100644 --- a/packages/api/src/Base.ts +++ b/packages/api/src/Base.ts @@ -424,7 +424,7 @@ export default abstract class ApiBase implement injectNodeCompat(this._runtimeVersion as RuntimeVersion); - const extrinsics = extrinsicsFromMeta(this.runtimeMetadata.asV0); + const extrinsics = extrinsicsFromMeta(this.runtimeMetadata); const storage = storageFromMeta(this.runtimeMetadata); this._extrinsics = this.decorateExtrinsics(extrinsics, this.onCall); diff --git a/packages/rpc-core/src/formatting.spec.ts b/packages/rpc-core/src/formatting.spec.ts index 095d9e35f1..157cb37111 100644 --- a/packages/rpc-core/src/formatting.spec.ts +++ b/packages/rpc-core/src/formatting.spec.ts @@ -3,78 +3,94 @@ // of the Apache-2.0 license. See the LICENSE file for details. import BN from 'bn.js'; -import storage from '@plugnet/storage/static'; +import fromMetadata from '@plugnet/storage/fromMetadata'; +import { Storage } from '@plugnet/storage/types'; +import Metadata from '@plugnet/types/Metadata'; +import rpcMetadataV3 from '@plugnet/types/Metadata/v3/static'; +import rpcMetadataV4 from '@plugnet/types/Metadata/v4/static'; import Api from '.'; const ADDR_ONE = '5DkQbYAExs3M2sZgT1Ec3mKfZnAQCL4Dt9beTCknkCUn5jzo'; const ADDR_TWO = '5C62W7ELLAAfix9LYrcx5smtcffbhvThkM5x7xfMeYXCtGwF'; -const ENC_ONE = '0x4af2c53fce3ec33c6ccccf22e926f1a7'; -const ENC_TWO = '0x3e62f7ed6e788e1337bce2a97b68a12a'; +function formattingTests (version: string, storage: Storage, encodedValues: [String, String]) { + const [ENC_ONE, ENC_TWO] = encodedValues; -describe('formatting', () => { - let api: Api; - let provider: any; + describe(`formatting with Metadata ${version}`, () => { + let api: Api; + let provider: any; - beforeEach(() => { - provider = { - send: jest.fn((method, params) => - Promise.resolve('0x0102') - ), - subscribe: jest.fn((type, method, params, subscription) => - subscription(null, { - block: '0x1234', - changes: [ - [ENC_ONE, '0x0102'], - [ENC_TWO, '0x0201'] - ] - }) - ) - }; - api = new Api(provider); + beforeEach(() => { + provider = { + send: jest.fn((method, params) => + Promise.resolve('0x0102') + ), + subscribe: jest.fn((type, method, params, subscription) => + subscription(null, { + block: '0x1234', + changes: [ + [ENC_ONE, '0x0102'], + [ENC_TWO, '0x0201'] + ] + }) + ) + }; + api = new Api(provider); + }); + + it('encodes key (with params), decoding response', () => { + return api.state + .getStorage( + [storage.balances.freeBalance, ADDR_ONE] + ) + .then((value) => { + expect( + provider.send + ).toHaveBeenCalledWith( + 'state_getStorage', + [ENC_ONE] + ); + expect(value.toNumber()).toEqual(513); + }); + }); + + it('encodes multiple keys, decoding multiple results', (done) => { + return api.state.subscribeStorage( + [ + [storage.balances.freeBalance, ADDR_ONE], + [storage.balances.freeBalance, ADDR_TWO] + ], + (value: any) => { + console.error(value); + + expect( + provider.subscribe + ).toHaveBeenCalledWith( + 'state_storage', + 'state_subscribeStorage', + [[ENC_ONE, ENC_TWO]], + expect.anything() + ); + expect( + value.map((balance: BN) => + balance.toNumber() + ) + ).toEqual([513, 258]); + + done(); + }); + }); }); +} - it('encodes key (with params), decoding response', () => { - return api.state - .getStorage( - [storage.balances.freeBalance, ADDR_ONE] - ) - .then((value) => { - expect( - provider.send - ).toHaveBeenCalledWith( - 'state_getStorage', - [ENC_ONE] - ); - expect(value.toNumber()).toEqual(513); - }); - }); - - it('encodes multiple keys, decoding multiple results', (done) => { - return api.state.subscribeStorage( - [ - [storage.balances.freeBalance, ADDR_ONE], - [storage.balances.freeBalance, ADDR_TWO] - ], - (value: any) => { - console.error(value); - - expect( - provider.subscribe - ).toHaveBeenCalledWith( - 'state_storage', - 'state_subscribeStorage', - [[ENC_ONE, ENC_TWO]], - expect.anything() - ); - expect( - value.map((balance: BN) => - balance.toNumber() - ) - ).toEqual([513, 258]); - - done(); - }); - }); -}); +formattingTests( + 'v3', + fromMetadata(new Metadata(rpcMetadataV3)), + ['0x4af2c53fce3ec33c6ccccf22e926f1a7', '0x3e62f7ed6e788e1337bce2a97b68a12a'] +); +formattingTests( + 'v4', + fromMetadata(new Metadata(rpcMetadataV4)), + ['0xec8f96437274a883afcac82d01a9defeb68209cd4f2c084632813692aa5e65ad', '0x1dbb0224910f42a14e7f1406b24c6fe8157296691b02a78756e01946038fffab'] +); diff --git a/packages/rpc-provider/src/mock/index.ts b/packages/rpc-provider/src/mock/index.ts index 9d4cf2351e..e935b42b1a 100644 --- a/packages/rpc-provider/src/mock/index.ts +++ b/packages/rpc-provider/src/mock/index.ts @@ -11,7 +11,7 @@ import interfaces from '@plugnet/jsonrpc'; import testKeyring from '@plugnet/keyring/testing'; import storage from '@plugnet/storage/static'; import { Codec } from '@plugnet/types/types'; -import metadata from '@plugnet/types/Metadata/v0/static'; +import rpcMetadataV4 from '@plugnet/types/Metadata/v4/static'; import { Header, RuntimeVersion } from '@plugnet/types'; import { bnToU8a, logger, u8aToHex } from '@plugnet/util'; import { randomAsU8a } from '@plugnet/util-crypto'; @@ -50,7 +50,7 @@ export default class Mock implements ProviderInterface { ); }, 'system_chain': (): string => 'mockChain', - 'state_getMetadata': (): string => metadata, + 'state_getMetadata': (): string => rpcMetadataV4, 'system_name': (): string => 'mockClient', 'system_version': (): string => '9.8.7' }; diff --git a/packages/type-extrinsics/src/fromMetadata.ts b/packages/type-extrinsics/src/fromMetadata.ts deleted file mode 100644 index 2723a95201..0000000000 --- a/packages/type-extrinsics/src/fromMetadata.ts +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2017-2019 @polkadot/extrinsics 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 { RuntimeModuleMetadata } from '@plugnet/types/Metadata/v0/Modules'; -import { Methods, ModulesWithMethods } from '@plugnet/types/primitive/Method'; -import MetadataV0 from '@plugnet/types/Metadata/v0'; - -import { stringCamelCase } from '@plugnet/util'; - -import createUnchecked from './utils/createUnchecked'; -import extrinsics from '.'; - -/** - * Extend a storage object with the storage modules & module functions present - * in the metadata. - * - * @param extrinsics - An extrinsics object to be extended. - * @param metadata - The metadata to extend the storage object against. - */ -export default function fromMetadata (metadata: MetadataV0): ModulesWithMethods { - let indexCount = -1; - - const findIndex = (prefix: string): number => { - indexCount++; - - const mod = metadata.calls.find((item) => item.prefix.toString() === prefix); - - if (!mod) { - console.error(`Unable to find module index for '${prefix}'`); - - // compatible with old versions - return indexCount; - } - - return mod.index.toNumber(); - }; - - return metadata.modules.reduce((result, meta: RuntimeModuleMetadata) => { - if (!meta.module.call || !meta.module.call.functions.length) { - return result; - } - - const prefix = stringCamelCase(meta.prefix.toString()); - const index = findIndex(meta.prefix.toString()); - - result[prefix] = meta.module.call.functions.reduce((newModule, funcMeta) => { - // extrinsics.balances.set_balance -> extrinsics.balances.setBalance - const funcName = stringCamelCase(funcMeta.name.toString()); - - newModule[funcName] = createUnchecked(prefix, funcName, index, funcMeta); - - return newModule; - }, {} as Methods); - - return result; - }, { ...extrinsics }); -} diff --git a/packages/type-extrinsics/src/fromMetadata/createUnchecked.ts b/packages/type-extrinsics/src/fromMetadata/createUnchecked.ts new file mode 100644 index 0000000000..2e8e26752b --- /dev/null +++ b/packages/type-extrinsics/src/fromMetadata/createUnchecked.ts @@ -0,0 +1,48 @@ +// Copyright 2017-2019 @polkadot/extrinsics 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 { FunctionMetadata } from '@polkadot/types/Metadata/v4/Calls'; +import { MethodFunction } from '@polkadot/types/primitive/Method'; +import { Method } from '@polkadot/types'; +import { assert, stringCamelCase } from '@polkadot/util'; + +/** + * From the metadata of a function in the module's storage, generate the function + * that will return the an [[MethodFunction]]. + * + * @param section - Name of the module section. + * @param sectionIndex - Index of the module section in the modules array. + * @param methodIndex - Index of the method inside the section. + * @param callMetadata - Metadata of the call function. + */ +export default function createDescriptor ( + section: string, + sectionIndex: number, + methodIndex: number, + callMetadata: FunctionMetadata +): MethodFunction { + const callIndex = new Uint8Array([sectionIndex, methodIndex]); + const expectedArgs = callMetadata.args; + const funcName = stringCamelCase(callMetadata.name.toString()); + const extrinsicFn = (...args: any[]): Method => { + assert( + expectedArgs.length.valueOf() === args.length, + `Extrinsic ${section}.${funcName} expects ${expectedArgs.length.valueOf()} arguments, got ${args.length}.` + ); + + return new Method({ + args, + callIndex + }, callMetadata); + }; + + extrinsicFn.callIndex = callIndex; + extrinsicFn.meta = callMetadata; + extrinsicFn.method = funcName; + extrinsicFn.section = section; + extrinsicFn.toJSON = (): any => + callMetadata.toJSON(); + + return extrinsicFn as MethodFunction; +} diff --git a/packages/type-extrinsics/src/fromMetadata.spec.ts b/packages/type-extrinsics/src/fromMetadata/fromMetadata.spec.ts similarity index 85% rename from packages/type-extrinsics/src/fromMetadata.spec.ts rename to packages/type-extrinsics/src/fromMetadata/fromMetadata.spec.ts index d3c40c3a80..bd6c802ce0 100644 --- a/packages/type-extrinsics/src/fromMetadata.spec.ts +++ b/packages/type-extrinsics/src/fromMetadata/fromMetadata.spec.ts @@ -3,13 +3,13 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { Extrinsic, Metadata } from '@plugnet/types'; -import json from '@plugnet/types/Metadata/v0/static'; +import json from '@plugnet/types/Metadata/v4/static'; -import fromMetadata from './fromMetadata'; +import fromV4 from '.'; // Use the pre-generated metadata -const metadata = new Metadata(json).asV0; -const newExtrinsics = fromMetadata(metadata); +const metadata = new Metadata(json); +const newExtrinsics = fromV4(metadata); describe('fromMetadata', () => { it('should throw if an incorrect number of args is supplied', () => { diff --git a/packages/type-extrinsics/src/fromMetadata/index.ts b/packages/type-extrinsics/src/fromMetadata/index.ts new file mode 100644 index 0000000000..8ac113ff97 --- /dev/null +++ b/packages/type-extrinsics/src/fromMetadata/index.ts @@ -0,0 +1,36 @@ +// Copyright 2017-2019 @polkadot/extrinsics 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 { ModuleMetadata } from '@polkadot/types/Metadata/v4/Metadata'; +import { Methods, ModulesWithMethods } from '@polkadot/types/primitive/Method'; +import Metadata from '@polkadot/types/Metadata'; +import { stringCamelCase } from '@polkadot/util'; + +import extrinsics from '../'; +import createUnchecked from './createUnchecked'; + +/** + * Extend a storage object with the storage modules & module functions present + * in the metadata. + * + * @param extrinsics - An extrinsics object to be extended. + * @param metadata - The metadata to extend the storage object against. + */ +export default function fromMetadata (metadata: Metadata): ModulesWithMethods { + return metadata.asV4.modules + .filter((modul) => modul.calls.isSome) + .reduce((result, modul: ModuleMetadata, sectionIndex) => { + const prefix = stringCamelCase(modul.prefix.toString()); + + result[prefix] = modul.calls.unwrap().reduce((newModule, callMetadata, methodIndex) => { + const funcName = stringCamelCase(callMetadata.name.toString()); + + newModule[funcName] = createUnchecked(prefix, sectionIndex, methodIndex, callMetadata); + + return newModule; + }, {} as Methods); + + return result; + }, { ...extrinsics }); +} diff --git a/packages/type-extrinsics/src/static.ts b/packages/type-extrinsics/src/static.ts index 23889bf286..8e061cf0ae 100644 --- a/packages/type-extrinsics/src/static.ts +++ b/packages/type-extrinsics/src/static.ts @@ -3,12 +3,12 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { Metadata } from '@plugnet/types'; -import metadataRpc from '@plugnet/types/Metadata/v0/static'; +import metadataRpc from '@plugnet/types/Metadata/v4/static'; import { ModulesWithMethods } from '@plugnet/types/primitive/Method'; import fromMetadata from './fromMetadata'; const staticMetadata: ModulesWithMethods = fromMetadata( - new Metadata(metadataRpc).asV0 + new Metadata(metadataRpc) ); export default staticMetadata; diff --git a/packages/type-extrinsics/src/utils/createUnchecked.ts b/packages/type-extrinsics/src/utils/createUnchecked.ts deleted file mode 100644 index d6888b09c9..0000000000 --- a/packages/type-extrinsics/src/utils/createUnchecked.ts +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2017-2019 @polkadot/extrinsics 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 { FunctionMetadata } from '@plugnet/types/Metadata/v0/Modules'; -import { MethodFunction } from '@plugnet/types/primitive/Method'; -import { Method } from '@plugnet/types'; -import { assert } from '@plugnet/util'; - -/** - * From the metadata of a function in the module's storage, generate the function - * that will return the an UncheckExtrinsic. - * - * @param index - Index of the module section in the modules array. - */ -export default function createDescriptor ( - section: string, - method: string, - index: number, - meta: FunctionMetadata -): MethodFunction { - const callIndex = new Uint8Array([index, meta.id.toNumber()]); - let extrinsicFn: any; - - const expectedArgs = Method.filterOrigin(meta); - - extrinsicFn = (...args: any[]): Method => { - assert(expectedArgs.length.valueOf() === args.length, `Extrinsic ${section}.${method} expects ${expectedArgs.length.valueOf()} arguments, got ${args.length}.`); - - return new Method({ - args, - callIndex - }, meta); - }; - - extrinsicFn.callIndex = callIndex; - extrinsicFn.meta = meta; - extrinsicFn.method = method; - extrinsicFn.section = section; - extrinsicFn.toJSON = (): any => - meta.toJSON(); - - return extrinsicFn as MethodFunction; -} diff --git a/packages/type-storage/src/fromMetadata/v0/createFunction.spec.ts b/packages/type-storage/src/fromMetadata/createFunction.spec.ts similarity index 92% rename from packages/type-storage/src/fromMetadata/v0/createFunction.spec.ts rename to packages/type-storage/src/fromMetadata/createFunction.spec.ts index d74de23fc3..4e2d2ac012 100644 --- a/packages/type-storage/src/fromMetadata/v0/createFunction.spec.ts +++ b/packages/type-storage/src/fromMetadata/createFunction.spec.ts @@ -26,8 +26,8 @@ describe('createFunction', () => { 'authorityCount', { type: {} } as any, { - isUnhashed: true, - key: ':auth:len' + key: ':auth:len', + skipHashing: true } ).method ).toEqual('authorityCount'); @@ -42,8 +42,8 @@ describe('createFunction', () => { 'authorityCount', { type: {} } as any, { - isUnhashed: true, - key + key, + skipHashing: true } )() ).toEqual( diff --git a/packages/type-storage/src/fromMetadata/v4/createFunction.ts b/packages/type-storage/src/fromMetadata/createFunction.ts similarity index 96% rename from packages/type-storage/src/fromMetadata/v4/createFunction.ts rename to packages/type-storage/src/fromMetadata/createFunction.ts index 5d6cd4aeda..7ba24f9bd8 100644 --- a/packages/type-storage/src/fromMetadata/v4/createFunction.ts +++ b/packages/type-storage/src/fromMetadata/createFunction.ts @@ -10,8 +10,8 @@ import { assert, isNull, isUndefined, stringLowerFirst, stringToU8a, u8aConcat } import getHasher from './getHasher'; export interface CreateItemOptions { - isUnhashed?: boolean; key?: string; + skipHashing?: boolean; // We don't hash the keys defined in ./substrate.ts } /** @@ -52,14 +52,13 @@ export default function createFunction (section: Text | string, method: Text | s // StorageKey is a Bytes, so is length-prefixed return Compact.addLengthPrefix( - options.isUnhashed + options.skipHashing ? key : hasher(key) ); }; if (meta.type.isMap && meta.type.asMap.isLinked) { - // TODO: there needs some better way to do this const keyHash = new U8a(hasher(`head of ${stringKey}`)); const keyFn: any = () => keyHash; keyFn.meta = new StorageFunctionMetadata({ diff --git a/packages/type-storage/src/fromMetadata/v4/v4.spec.ts b/packages/type-storage/src/fromMetadata/fromMetadata.spec.ts similarity index 71% rename from packages/type-storage/src/fromMetadata/v4/v4.spec.ts rename to packages/type-storage/src/fromMetadata/fromMetadata.spec.ts index 7cba7080a0..fb6e55395b 100644 --- a/packages/type-storage/src/fromMetadata/v4/v4.spec.ts +++ b/packages/type-storage/src/fromMetadata/fromMetadata.spec.ts @@ -7,26 +7,26 @@ import { Metadata } from '@plugnet/types'; import json from '@plugnet/types/Metadata/v4/static'; import { u8aToHex } from '@plugnet/util'; -import fromv4 from '.'; +import fromMetadata from '.'; const keyring = testingPairs({ type: 'ed25519' }); // Use the pre-generated metadata -const metadata = new Metadata(json).asV4; -const newStorage = fromv4(metadata); +const metadata = new Metadata(json); +const storage = fromMetadata(metadata); -describe('fromv4', () => { +describe('fromMetadata', () => { it('should throw if the storage function expects an argument', () => { - expect(() => newStorage.balances.freeBalance()).toThrowError(/expects one argument/); + expect(() => storage.balances.freeBalance()).toThrowError(/expects one argument/); }); it('should return a value if the storage function does not expect an argument', () => { - expect(() => newStorage.timestamp.now()).not.toThrow(); + expect(() => storage.timestamp.now()).not.toThrow(); }); it('should return the correct length-prefixed storage key', () => { expect( u8aToHex( - newStorage.balances.freeBalance(keyring.alice.address()) + storage.balances.freeBalance(keyring.alice.address()) ) ).toEqual( '0x807f864e18e3dd8b58386310d2fe0919eef27c6e558564b7f67f22d99d20f587bb' diff --git a/packages/type-storage/src/fromMetadata/fromMetadata.ts b/packages/type-storage/src/fromMetadata/fromMetadata.ts deleted file mode 100644 index 55cc2db0fd..0000000000 --- a/packages/type-storage/src/fromMetadata/fromMetadata.ts +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2017-2019 @polkadot/storage 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 { Storage } from '../types'; - -import Metadata from '@plugnet/types/Metadata'; - -import fromV0 from './v0'; -import fromV4 from './v4'; - -/** - * Extend a storage object with the storage modules & module functions present - * in the metadata. - * - * @param storage - A storage object to be extended. - * @param metadata - The metadata to extend the storage object against. - */ -export default function fromMetadata (metadata: Metadata): Storage { - // For v0-v3 we convert to v0, and use the fromV0 function to parse - if ([0, 1, 2, 3].includes(metadata.version)) { - return fromV0(metadata.asV0); - } - - // For v4, we use fromV4 function - return fromV4(metadata.asV4); -} diff --git a/packages/type-storage/src/fromMetadata/v4/getHasher.ts b/packages/type-storage/src/fromMetadata/getHasher.ts similarity index 100% rename from packages/type-storage/src/fromMetadata/v4/getHasher.ts rename to packages/type-storage/src/fromMetadata/getHasher.ts diff --git a/packages/type-storage/src/fromMetadata/index.ts b/packages/type-storage/src/fromMetadata/index.ts index 1cda4fcf49..a5e742e878 100644 --- a/packages/type-storage/src/fromMetadata/index.ts +++ b/packages/type-storage/src/fromMetadata/index.ts @@ -2,6 +2,36 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import fromMetadata from './fromMetadata'; +import { ModuleStorage, Storage } from '../types'; -export default fromMetadata; +import Metadata from '@polkadot/types/Metadata'; +import { stringLowerFirst } from '@polkadot/util'; + +import createFunction from './createFunction'; +import { storage } from './storage'; + +/** + * Extend a storage object with the storage modules & module functions present + * in the metadata. + * + * @param storage - A storage object to be extended. + * @param metadata - The metadata to extend the storage object against. + */ +export default function fromMetadata (metadata: Metadata): Storage { + return metadata.asV4.modules.reduce((result, moduleMetadata) => { + if (moduleMetadata.storage.isNone) { + return result; + } + + const prefix = moduleMetadata.prefix; + + // For access, we change the index names, i.e. Balances.FreeBalance -> balances.freeBalance + result[stringLowerFirst(prefix.toString())] = moduleMetadata.storage.unwrap().reduce((newModule, storageFnMeta) => { + newModule[stringLowerFirst(storageFnMeta.name.toString())] = createFunction(prefix, storageFnMeta.name, storageFnMeta); + + return newModule; + }, {} as ModuleStorage); + + return result; + }, { ...storage }); +} diff --git a/packages/type-storage/src/fromMetadata/v0/storage.spec.ts b/packages/type-storage/src/fromMetadata/storage.spec.ts similarity index 100% rename from packages/type-storage/src/fromMetadata/v0/storage.spec.ts rename to packages/type-storage/src/fromMetadata/storage.spec.ts diff --git a/packages/type-storage/src/fromMetadata/v0/storage.ts b/packages/type-storage/src/fromMetadata/storage.ts similarity index 90% rename from packages/type-storage/src/fromMetadata/v0/storage.ts rename to packages/type-storage/src/fromMetadata/storage.ts index c40c05d6f8..a81b703a9f 100644 --- a/packages/type-storage/src/fromMetadata/v0/storage.ts +++ b/packages/type-storage/src/fromMetadata/storage.ts @@ -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 { Storage } from '../../types'; +import { Storage } from '../types'; import * as substrate from './substrate'; export const storage: Storage = { diff --git a/packages/type-storage/src/fromMetadata/v0/substrate.spec.ts b/packages/type-storage/src/fromMetadata/substrate.spec.ts similarity index 100% rename from packages/type-storage/src/fromMetadata/v0/substrate.spec.ts rename to packages/type-storage/src/fromMetadata/substrate.spec.ts diff --git a/packages/type-storage/src/fromMetadata/v4/substrate.ts b/packages/type-storage/src/fromMetadata/substrate.ts similarity index 98% rename from packages/type-storage/src/fromMetadata/v4/substrate.ts rename to packages/type-storage/src/fromMetadata/substrate.ts index 4d34210243..0ce7e26e29 100644 --- a/packages/type-storage/src/fromMetadata/v4/substrate.ts +++ b/packages/type-storage/src/fromMetadata/substrate.ts @@ -25,8 +25,8 @@ const createRuntimeFunction = (method: string, key: string, { documentation, typ toJSON: (): any => key } as StorageFunctionMetadata, { - isUnhashed: true, - key + key, + skipHashing: true } ); diff --git a/packages/type-storage/src/fromMetadata/v0/createFunction.ts b/packages/type-storage/src/fromMetadata/v0/createFunction.ts deleted file mode 100644 index adcc9dbcd0..0000000000 --- a/packages/type-storage/src/fromMetadata/v0/createFunction.ts +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright 2017-2019 @polkadot/storage 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 { PlainType, StorageFunctionMetadata, StorageFunctionModifier, StorageFunctionType } from '@plugnet/types/Metadata/v0/Storage'; -import { StorageFunction } from '@plugnet/types/primitive/StorageKey'; -import { Compact, Text, createType, StorageKey, Bytes, U8a } from '@plugnet/types'; -import { assert, isNull, isUndefined, stringLowerFirst, stringToU8a, u8aConcat } from '@plugnet/util'; -import { xxhashAsU8a } from '@plugnet/util-crypto'; - -export interface CreateItemOptions { - isUnhashed?: boolean; - key?: string; -} - -/** - * From the schema of a function in the module's storage, generate the function - * that will return the correct storage key. - * - * @param schema - The function's definition schema to create the function from. - * The schema is taken from state_getMetadata. - * @param options - Additional options when creating the function. These options - * are not known at runtime (from state_getMetadata), they need to be supplied - * by us manually at compile time. - */ -export default function createFunction (section: Text | string, method: Text | string, meta: StorageFunctionMetadata, options: CreateItemOptions = {}): StorageFunction { - const stringKey = options.key - ? options.key - : `${section.toString()} ${method.toString()}`; - const rawKey = stringToU8a(stringKey); - - // Can only have zero or one argument: - // - storage.balances.freeBalance(address) - // - storage.timestamp.blockPeriod() - const storageFn = (arg?: any): Uint8Array => { - let key = rawKey; - if (meta.type.isMap) { - assert(!isUndefined(arg) && !isNull(arg), `${meta.name} expects one argument`); - - const type = meta.type.asMap.key.toString(); - const param = createType(type, arg).toU8a(false); - - key = u8aConcat(key, param); - } - - // StorageKey is a Bytes, so is length-prefixed - return Compact.addLengthPrefix( - options.isUnhashed - ? key - : xxhashAsU8a(key, 128) - ); - }; - - if (meta.type.isMap && meta.type.asMap.isLinked) { - // TODO: there needs some better way to do this - const keyHash = new U8a(xxhashAsU8a(`head of ${stringKey}`, 128)); - const keyFn: any = () => keyHash; - keyFn.meta = new StorageFunctionMetadata({ - name: meta.name, - modifier: new StorageFunctionModifier('Required'), - type: new StorageFunctionType(new PlainType(meta.type.asMap.key), 0), - fallback: new Bytes(), - documentation: meta.documentation - }); - storageFn.headKey = new StorageKey(keyFn); - } - - storageFn.meta = meta; - storageFn.method = stringLowerFirst(method.toString()); - storageFn.section = stringLowerFirst(section.toString()); - storageFn.toJSON = (): any => meta.toJSON(); - - return storageFn as StorageFunction; -} diff --git a/packages/type-storage/src/fromMetadata/v0/index.ts b/packages/type-storage/src/fromMetadata/v0/index.ts deleted file mode 100644 index c2caa7d246..0000000000 --- a/packages/type-storage/src/fromMetadata/v0/index.ts +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2017-2019 @polkadot/storage 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 { ModuleStorage, Storage } from '../../types'; - -import MetadataV0 from '@plugnet/types/Metadata/v0'; -import { stringLowerFirst } from '@plugnet/util'; - -import createFunction from './createFunction'; -import { storage } from './storage'; - -/** - * Extend a storage object with the storage modules & module functions present - * in the metadata. - * - * @param storage - A storage object to be extended. - * @param metadata - The metadata to extend the storage object against. - */ -export default function fromV0 (metadata: MetadataV0): Storage { - return metadata.modules.reduce((result, moduleMetadata) => { - if (moduleMetadata.storage.isNone) { - return result; - } - - const prefix = moduleMetadata.storage.unwrap().prefix; - - // For access, we change the index names, i.e. Balances.FreeBalance -> balances.freeBalance - result[stringLowerFirst(prefix.toString())] = moduleMetadata.storage.unwrap().functions.reduce((newModule, func) => { - newModule[stringLowerFirst(func.name.toString())] = createFunction(prefix, func.name, func); - - return newModule; - }, {} as ModuleStorage); - - return result; - }, { ...storage }); -} diff --git a/packages/type-storage/src/fromMetadata/v0/substrate.ts b/packages/type-storage/src/fromMetadata/v0/substrate.ts deleted file mode 100644 index f8b9052c75..0000000000 --- a/packages/type-storage/src/fromMetadata/v0/substrate.ts +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2017-2019 @polkadot/storage 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 { StorageFunctionMetadata, StorageFunctionModifier, StorageFunctionType } from '@plugnet/types/Metadata/v0/Storage'; -import { StorageFunction } from '@plugnet/types/primitive/StorageKey'; -import { Text, Vector } from '@plugnet/types'; - -import createFunction from './createFunction'; - -interface SubstrateMetadata { - documentation: string; - type: string; -} - -// Small helper function to factorize code on this page. -const createRuntimeFunction = (method: string, key: string, { documentation, type }: SubstrateMetadata): StorageFunction => - createFunction( - new Text('Substrate'), - new Text(method), - { - documentation: new Vector(Text, [documentation]), - modifier: new StorageFunctionModifier(1), // default - type: new StorageFunctionType(type, 0), - toJSON: (): any => key - } as StorageFunctionMetadata, - { - isUnhashed: true, - key - } - ); - -export const code = createRuntimeFunction('code', ':code', { - documentation: 'Wasm code of the runtime.', - type: 'Bytes' -}); - -export const heapPages = createRuntimeFunction('heapPages', ':heappages', { - documentation: 'Number of wasm linear memory pages required for execution of the runtime.', - type: 'u64' -}); - -export const authorityCount = createRuntimeFunction('authorityCount', ':auth:len', { - documentation: 'Number of authorities.', - type: 'u32' -}); - -export const authorityPrefix = createRuntimeFunction('authorityPrefix', ':auth:', { - documentation: 'Prefix under which authorities are stored.', - type: 'u32' -}); - -export const extrinsicIndex = createRuntimeFunction('extrinsicIndex', ':extrinsic_index', { - documentation: 'Current extrinsic index (u32) is stored under this key.', - type: 'u32' -}); - -export const changesTrieConfig = createRuntimeFunction('changesTrieConfig', ':changes_trie', { - documentation: 'Changes trie configuration is stored under this key.', - type: 'u32' -}); diff --git a/packages/type-storage/src/fromMetadata/v0/v0.spec.ts b/packages/type-storage/src/fromMetadata/v0/v0.spec.ts deleted file mode 100644 index 6a206401ae..0000000000 --- a/packages/type-storage/src/fromMetadata/v0/v0.spec.ts +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2017-2019 @polkadot/storage 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 { u8aToHex } from '@plugnet/util'; -import { Metadata } from '@plugnet/types'; -import json from '@plugnet/types/Metadata/v0/static'; - -import fromv0 from '.'; - -// Use the pre-generated metadata -const metadata = new Metadata(json).asV0; -const newStorage = fromv0(metadata); - -describe('fromv0', () => { - it('should throw if the storage function expects an argument', () => { - expect(() => newStorage.balances.freeBalance()).toThrowError(/expects one argument/); - }); - - it('should return a value if the storage function does not expect an argument', () => { - expect(() => newStorage.timestamp.now()).not.toThrow(); - }); - - it('should return the correct length-prefixed storage key', () => { - expect( - u8aToHex( - newStorage.balances.freeBalance('5DkQbYAExs3M2sZgT1Ec3mKfZnAQCL4Dt9beTCknkCUn5jzo') - ) - ).toEqual( - '0x404af2c53fce3ec33c6ccccf22e926f1a7' - ); - }); -}); diff --git a/packages/type-storage/src/fromMetadata/v4/createFunction.spec.ts b/packages/type-storage/src/fromMetadata/v4/createFunction.spec.ts deleted file mode 100644 index d74de23fc3..0000000000 --- a/packages/type-storage/src/fromMetadata/v4/createFunction.spec.ts +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2017-2019 @polkadot/storage 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 { stringToU8a, u8aConcat } from '@plugnet/util'; - -import createFunction from './createFunction'; - -describe('createFunction', () => { - it('should create timestamp.now correctly', () => { - expect( - createFunction( - 'Timestamp', - 'Now', - { type: {} } as any - )() - ).toEqual( - Uint8Array.from([64, 14, 73, 68, 207, 217, 141, 111, 76, 195, 116, 209, 111, 90, 78, 63, 156]) // Length-prefixed - ); - }); - - it('allows overrides on key (keeping name)', () => { - expect( - createFunction( - 'Substrate', - 'authorityCount', - { type: {} } as any, - { - isUnhashed: true, - key: ':auth:len' - } - ).method - ).toEqual('authorityCount'); - }); - - it('allows overrides on key (unhashed)', () => { - const key = ':auth:len'; - - expect( - createFunction( - 'Substrate', - 'authorityCount', - { type: {} } as any, - { - isUnhashed: true, - key - } - )() - ).toEqual( - u8aConcat( - Uint8Array.from([key.length << 2]), - stringToU8a(':auth:len') - ) - ); - }); -}); diff --git a/packages/type-storage/src/fromMetadata/v4/index.ts b/packages/type-storage/src/fromMetadata/v4/index.ts deleted file mode 100644 index 1cc7e2657d..0000000000 --- a/packages/type-storage/src/fromMetadata/v4/index.ts +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2017-2019 @polkadot/storage 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 { ModuleStorage, Storage } from '../../types'; - -import MetadataV4 from '@plugnet/types/Metadata/v4'; -import { stringLowerFirst } from '@plugnet/util'; - -import createFunction from './createFunction'; -import { storage } from './storage'; - -/** - * Extend a storage object with the storage modules & module functions present - * in the metadata. - * - * @param storage - A storage object to be extended. - * @param metadata - The metadata to extend the storage object against. - */ -export default function fromV4 (metadata: MetadataV4): Storage { - return metadata.modules.reduce((result, moduleMetadata) => { - if (moduleMetadata.storage.isNone) { - return result; - } - - const prefix = moduleMetadata.prefix; - - // For access, we change the index names, i.e. Balances.FreeBalance -> balances.freeBalance - result[stringLowerFirst(prefix.toString())] = moduleMetadata.storage.unwrap().reduce((newModule, storageFnMeta) => { - newModule[stringLowerFirst(storageFnMeta.name.toString())] = createFunction(prefix, storageFnMeta.name, storageFnMeta); - - return newModule; - }, {} as ModuleStorage); - - return result; - }, { ...storage }); -} diff --git a/packages/type-storage/src/fromMetadata/v4/storage.spec.ts b/packages/type-storage/src/fromMetadata/v4/storage.spec.ts deleted file mode 100644 index e842262079..0000000000 --- a/packages/type-storage/src/fromMetadata/v4/storage.spec.ts +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2017-2019 @polkadot/storage 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 { storage } from './storage'; - -describe('storage', () => { - it('should return well known keys', () => { - expect(typeof storage.substrate).toBe('object'); - expect(storage.substrate.authorityCount).toBeTruthy(); - expect(storage.substrate.authorityPrefix).toBeTruthy(); - expect(storage.substrate.changesTrieConfig).toBeTruthy(); - expect(storage.substrate.code).toBeTruthy(); - expect(storage.substrate.extrinsicIndex).toBeTruthy(); - expect(storage.substrate.heapPages).toBeTruthy(); - }); -}); diff --git a/packages/type-storage/src/fromMetadata/v4/storage.ts b/packages/type-storage/src/fromMetadata/v4/storage.ts deleted file mode 100644 index c40c05d6f8..0000000000 --- a/packages/type-storage/src/fromMetadata/v4/storage.ts +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright 2017-2019 @polkadot/storage 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 { Storage } from '../../types'; -import * as substrate from './substrate'; - -export const storage: Storage = { - substrate // Prefill storage with well known keys, as not returned by state_getMetadata -}; diff --git a/packages/type-storage/src/fromMetadata/v4/substrate.spec.ts b/packages/type-storage/src/fromMetadata/v4/substrate.spec.ts deleted file mode 100644 index c442e3d58e..0000000000 --- a/packages/type-storage/src/fromMetadata/v4/substrate.spec.ts +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2017-2019 @polkadot/storage 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 { authorityCount, authorityPrefix, changesTrieConfig, code, extrinsicIndex, heapPages } from './substrate'; - -describe('substrate', () => { - it('authorityCount should return the correct storage key', () => { - expect(authorityCount()).toEqual(Uint8Array.from([36, 58, 97, 117, 116, 104, 58, 108, 101, 110])); // Length-prefixed - }); - - it('authorityPrefix should return the correct storage key', () => { - expect(authorityPrefix()).toEqual(Uint8Array.from([24, 58, 97, 117, 116, 104, 58])); // Length-prefixed - }); - - it('changesTrieConfig should return the correct storage key', () => { - expect(changesTrieConfig()).toEqual(Uint8Array.from([52, 58, 99, 104, 97, 110, 103, 101, 115, 95, 116, 114, 105, 101])); // Length-prefixed - }); - - it('code should return the correct storage key', () => { - expect(code()).toEqual(Uint8Array.from([20, 58, 99, 111, 100, 101])); // Length-prefixed - }); - - it('extrinsicIndex should return the correct storage key', () => { - expect(extrinsicIndex()).toEqual( - Uint8Array.from([64, 58, 101, 120, 116, 114, 105, 110, 115, 105, 99, 95, 105, 110, 100, 101, 120]) // Length-prefixed - ); - }); - - it('heapPages should return the correct storage key', () => { - expect(heapPages()).toEqual(Uint8Array.from([40, 58, 104, 101, 97, 112, 112, 97, 103, 101, 115])); // Length-prefixed - }); -}); diff --git a/packages/type-storage/src/index.ts b/packages/type-storage/src/index.ts index 27f79886a0..eadcbca96f 100644 --- a/packages/type-storage/src/index.ts +++ b/packages/type-storage/src/index.ts @@ -2,6 +2,6 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { storage } from './fromMetadata/v0/storage'; +import { storage } from './fromMetadata/storage'; export default storage; diff --git a/packages/type-storage/src/static.ts b/packages/type-storage/src/static.ts index 3c2bc0cd7f..ab1a3dc0e5 100644 --- a/packages/type-storage/src/static.ts +++ b/packages/type-storage/src/static.ts @@ -3,7 +3,7 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { Metadata } from '@plugnet/types'; -import metadataRpc from '@plugnet/types/Metadata/v0/static'; +import metadataRpc from '@plugnet/types/Metadata/v4/static'; import fromMetadata from './fromMetadata'; diff --git a/packages/types/src/Metadata/MetadataVersioned.ts b/packages/types/src/Metadata/MetadataVersioned.ts index 56a417f8b6..048c7cc8fc 100644 --- a/packages/types/src/Metadata/MetadataVersioned.ts +++ b/packages/types/src/Metadata/MetadataVersioned.ts @@ -2,8 +2,6 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { MetadataInterface } from './types'; - import { assert, isUndefined } from '@plugnet/util'; import EnumType from '../codec/EnumType'; @@ -15,10 +13,10 @@ import MetadataV1 from './v1'; import MetadataV2 from './v2'; import MetadataV3 from './v3'; import MetadataV4 from './v4'; -import v1ToV0 from './v1/toV0'; -import v2ToV1 from './v2/toV1'; -import v3ToV2 from './v3/toV2'; -import v4ToV3 from './v4/toV3'; +import v0ToV1 from './v0/toV1'; +import v1ToV2 from './v1/toV2'; +import v2ToV3 from './v2/toV3'; +import v3ToV4 from './v3/toV4'; class MetadataDeprecated extends Null { } @@ -134,11 +132,11 @@ class MetadataEnum extends EnumType { - return (this.metadata.value as any as MetadataInterface).getUniqTypes(throwError); + return this.asV4.getUniqTypes(throwError); } /** - * @description Returns the wrapped values as a V3 object + * @description Returns the wrapped values as a V4 object */ get asV4 (): MetadataV4 { - assert(this.metadata.version === 4, `Cannot convert metadata from v${this.metadata.version} to v4`); + assert(this.metadata.version <= 4, `Cannot convert metadata from v${this.metadata.version} to v3`); - return this.metadata.asV4; + if (this.metadata.version === 4) { + return this.metadata.asV4; + } + + if (isUndefined(this._convertedV4)) { + this._convertedV4 = v3ToV4(this.asV3); + } + + return this._convertedV4; } } diff --git a/packages/types/src/Metadata/static.ts b/packages/types/src/Metadata/static.ts index 7cd53b6261..3b4aacce6f 100644 --- a/packages/types/src/Metadata/static.ts +++ b/packages/types/src/Metadata/static.ts @@ -2,6 +2,6 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import metadata from './v3/static'; +import metadata from './v4/static'; export default metadata; diff --git a/packages/types/src/Metadata/types.ts b/packages/types/src/Metadata/types.ts index 57b2fa65df..a0a99b928b 100644 --- a/packages/types/src/Metadata/types.ts +++ b/packages/types/src/Metadata/types.ts @@ -2,6 +2,10 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -export interface MetadataInterface { +import { Vector } from '../codec'; +import { Codec } from '../types'; + +export interface MetadataInterface extends Codec { + modules: Vector; getUniqTypes (throwError: boolean): Array; } diff --git a/packages/types/src/Metadata/util/testUtil.ts b/packages/types/src/Metadata/util/testUtil.ts new file mode 100644 index 0000000000..43b985a7bd --- /dev/null +++ b/packages/types/src/Metadata/util/testUtil.ts @@ -0,0 +1,68 @@ +// Copyright 2017-2019 @polkadot/types 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 extrinsicsFromMeta from '@polkadot/extrinsics/fromMetadata'; + +import createType from '../../codec/createType'; +import Metadata from '../Metadata'; +import Method from '../../primitive/Method'; +import { MetadataInterface } from '../types'; +import { Codec } from '../../types'; + +/** + * Given the static `rpcData` and the `latestSubstrate` JSON file, Metadata + * should decode `rpcData` and output `latestSubstrate`. + */ +export function decodeLatestSubstrate ( + version: number, + rpcData: string, + latestSubstrate: object +) { + it('decodes latest substrate properly', () => { + const metadata = new Metadata(rpcData); + + console.error(JSON.stringify(metadata.toJSON())); + + expect(metadata.version).toBe(version); + expect((metadata[`asV${version}` as keyof Metadata] as unknown as MetadataInterface).modules.length).not.toBe(0); + expect(metadata.toJSON()).toEqual(latestSubstrate); + }); +} + +/** + * Given a `version`, MetadataV4 and MetadataV{version} should output the same + * unique types. + */ +export function toV4 (version: number, rpcData: string) { + it('converts to V4', () => { + const metadata = new Metadata(rpcData)[`asV${version}` as keyof Metadata]; + const metadataV4 = new Metadata(rpcData).asV4; + + expect( + (metadata as unknown as MetadataInterface).getUniqTypes(true) + ).toEqual(metadataV4.getUniqTypes(true)); + }); +} + +/** + * Given a Metadata, no type should throw when given its fallback value. + */ +export function defaultValues (rpcData: string) { + describe('storage with default values', () => { + const metadata = new Metadata(rpcData); + Method.injectMethods(extrinsicsFromMeta(metadata)); + + metadata.asV4.modules + .filter(({ storage }) => storage.isSome) + .map((mod) => + mod.storage.unwrap().forEach(({ fallback, name, type }) => { + it(`creates default types for ${mod.prefix}.${name}, type ${type}`, () => { + expect( + () => createType(type.toString(), fallback) + ).not.toThrow(); + }); + }) + ); + }); +} diff --git a/packages/types/src/Metadata/v0/Events.ts b/packages/types/src/Metadata/v0/Events.ts index c23bf30ba3..98f492dd07 100644 --- a/packages/types/src/Metadata/v0/Events.ts +++ b/packages/types/src/Metadata/v0/Events.ts @@ -12,7 +12,7 @@ export class EventMetadata extends Struct { constructor (value?: any) { super({ name: Text, - arguments: Vector.with(Type), + args: Vector.with(Type), documentation: Vector.with(Text) }, value); } @@ -20,8 +20,16 @@ export class EventMetadata extends Struct { /** * @description The arguments of [[Type]] */ + get args (): Vector { + return this.get('args') as Vector; + } + + /** + * @description The arguments of [[Type]] + * @deprecated Use `.args` instead + */ get arguments (): Vector { - return this.get('arguments') as Vector; + return this.args; } /** @@ -47,7 +55,7 @@ export class EventMetadata extends Struct { } } -export class OuterEventMetadataEvent extends Tuple { +export class OuterEventEventMetadata extends Tuple { constructor (value?: any) { super({ Text, @@ -74,15 +82,15 @@ export class OuterEventMetadata extends Struct { constructor (value?: any) { super({ name: Text, - events: Vector.with(OuterEventMetadataEvent) + events: Vector.with(OuterEventEventMetadata) }, value); } /** - * @description The [[OuterEventMetadataEvent]] + * @description The [[OuterEventEventMetadata]] */ - get events (): Vector { - return this.get('events') as Vector; + get events (): Vector { + return this.get('events') as Vector; } /** diff --git a/packages/types/src/Metadata/v0/Metadata.spec.ts b/packages/types/src/Metadata/v0/Metadata.spec.ts index d57dbb4022..f75c0c6d53 100644 --- a/packages/types/src/Metadata/v0/Metadata.spec.ts +++ b/packages/types/src/Metadata/v0/Metadata.spec.ts @@ -2,41 +2,32 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import extrinsicsFromMeta from '@plugnet/extrinsics/fromMetadata'; - -import createType from '../../codec/createType'; -import Method from '../../primitive/Method'; - -import Metadata from './Metadata'; -import latestParsed from './latest.substrate.json'; +import MetadataV0 from './'; +import Metadata from '../'; +import latestSubstrateV0 from './latest.substrate.v0.json'; import rpcData from './static'; +import { defaultValues, toV4 } from '../util/testUtil'; describe('Metadata', () => { - it('decodes latest properly', () => { + it('works with fallback', () => { const metadata = new Metadata(rpcData); - const str = JSON.stringify(metadata.toJSON()); + const metadataV0 = new MetadataV0(rpcData); - expect(metadata.events.length).not.toBe(0); - expect(str).toEqual(JSON.stringify(latestParsed)); + expect(metadata.asV0.toString()).toEqual(metadataV0.toString()); }); - describe('storage with default values', () => { + it('decodes latest substrate properly', () => { const metadata = new Metadata(rpcData); + const json = metadata.asV0.toJSON(); - Method.injectMethods(extrinsicsFromMeta(metadata)); + console.error(JSON.stringify(json)); - metadata.modules.forEach((mod) => { - if (mod.storage.isNone) { - return; - } - - mod.storage.unwrap().functions.forEach((fn) => { - it(`creates default types for ${mod.prefix}.${fn.name}, type ${fn.type}`, () => { - expect( - () => createType(fn.type.toString(), fn.fallback) - ).not.toThrow(); - }); - }); - }); + expect(metadata.version).toBe(0); + expect(metadata.asV0.modules.length).not.toBe(0); + expect(json).toEqual(latestSubstrateV0); }); + + toV4(0, rpcData); + + defaultValues(rpcData); }); diff --git a/packages/types/src/Metadata/v0/Metadata.ts b/packages/types/src/Metadata/v0/Metadata.ts index a61fdd0488..1ded6634de 100644 --- a/packages/types/src/Metadata/v0/Metadata.ts +++ b/packages/types/src/Metadata/v0/Metadata.ts @@ -11,19 +11,17 @@ import Struct from '../../codec/Struct'; import Vector from '../../codec/Vector'; import { flattenUniq, validateTypes } from '../util'; import { OuterDispatchMetadata, OuterDispatchCall } from './Calls'; -import { OuterEventMetadata, OuterEventMetadataEvent } from './Events'; +import { OuterEventMetadata, OuterEventEventMetadata } from './Events'; import { RuntimeModuleMetadata } from './Modules'; -// Decodes the runtime metadata as passed through from the `state_getMetadata` call. This -// file is probably best understood from the bottom-up, i.e. start reading right at the -// end and work up. (Just so we don't use before definition) +// Decodes the runtime metadata as passed through from the `state_getMetadata` call. /** * @name MetadataV0 * @description * The runtime metadata as a decoded structure */ -export default class MetadataV0 extends Struct implements MetadataInterface { +export default class MetadataV0 extends Struct implements MetadataInterface { constructor (value?: any) { super({ outerEvent: OuterEventMetadata, @@ -62,9 +60,9 @@ export default class MetadataV0 extends Struct implements MetadataInterface { } /** - * @description Wrapped [[OuterEventMetadataEvent]] + * @description Wrapped [[OuterEventEventMetadata]] */ - get events (): Vector { + get events (): Vector { return (this.get('outerEvent') as OuterEventMetadata).events; } @@ -76,25 +74,25 @@ export default class MetadataV0 extends Struct implements MetadataInterface { } private get argNames () { - return this.modules.map((module) => - module.module.call.functions.map((fn) => - fn.arguments.map((argument) => argument.type.toString()) + return this.modules.map((modul) => + modul.module.call.functions.map((fn) => + fn.args.map((argument) => argument.type.toString()) ) ); } private get eventNames () { - return this.events.map((module) => - module.events.map((event) => - event.arguments.map((argument) => argument.toString()) + return this.events.map((modul) => + modul.events.map((event) => + event.args.map((argument) => argument.toString()) ) ); } private get storageNames () { - return this.modules.map((module) => - module.storage.isSome - ? module.storage.unwrap().functions.map((fn) => + return this.modules.map((modul) => + modul.storage.isSome + ? modul.storage.unwrap().functions.map((fn) => fn.type.isMap ? [fn.type.asMap.key.toString(), fn.type.asMap.value.toString()] : [fn.type.asType.toString()] diff --git a/packages/types/src/Metadata/v0/Modules.ts b/packages/types/src/Metadata/v0/Modules.ts index 9781768226..3559605592 100644 --- a/packages/types/src/Metadata/v0/Modules.ts +++ b/packages/types/src/Metadata/v0/Modules.ts @@ -39,13 +39,21 @@ export class FunctionMetadata extends Struct { super({ id: U16, name: Text, - arguments: Vector.with(FunctionArgumentMetadata), + args: Vector.with(FunctionArgumentMetadata), documentation: Vector.with(Text) }, value); } + /** + * @description The arguments of [[Type]] + */ + get args (): Vector { + return this.get('args') as Vector; + } + /** * @description The [[FunctionArgumentMetadata]] for arguments + * @deprecated Use `.args` instead */ get arguments (): Vector { return this.get('arguments') as Vector; @@ -103,7 +111,6 @@ export class CallMetadata extends Struct { return this.get('name') as Text; } } - export class ModuleMetadata extends Struct { constructor (value?: any) { super({ @@ -113,7 +120,7 @@ export class ModuleMetadata extends Struct { } /** - * @description The calls as [[CallMetadata]] + * @description The calls as [[FunctionMetadata]] */ get call (): CallMetadata { return this.get('call') as CallMetadata; diff --git a/packages/types/src/Metadata/v0/Storage.ts b/packages/types/src/Metadata/v0/Storage.ts index 291dfdb317..6945779bfd 100644 --- a/packages/types/src/Metadata/v0/Storage.ts +++ b/packages/types/src/Metadata/v0/Storage.ts @@ -11,7 +11,6 @@ import EnumType from '../../codec/EnumType'; import Struct from '../../codec/Struct'; import Vector from '../../codec/Vector'; import Bytes from '../../primitive/Bytes'; -import Null from '../../primitive/Null'; import Text from '../../primitive/Text'; import Type from '../../primitive/Type'; @@ -33,8 +32,6 @@ export class StorageFunctionModifier extends Enum { } } -export class DoubleMapType extends Null {} - export class MapType extends Struct { private _isLinked = false; @@ -78,20 +75,10 @@ export class StorageFunctionType extends EnumType { constructor (value?: any, index?: number) { super({ PlainType, - MapType, - DoubleMapType + MapType }, value, index); } - /** - * @description The value as a mapped value - */ - get asDoubleMap (): DoubleMapType { - assert(this.isDoubleMap, `Cannot convert '${this.type}' via asDoubleMap`); - - return this.value as DoubleMapType; - } - /** * @description The value as a mapped value */ @@ -110,13 +97,6 @@ export class StorageFunctionType extends EnumType { return this.value as PlainType; } - /** - * @description `true` if the storage entry is a double map - */ - get isDoubleMap (): boolean { - return this.toNumber() === 2; - } - /** * @description `true` if the storage entry is a map */ @@ -135,9 +115,7 @@ export class StorageFunctionType extends EnumType { * @description Returns the string representation of the value */ toString (): string { - if (this.isDoubleMap) { - return `DoubleMap<${this.asDoubleMap.toString()}>`; - } else if (this.isMap) { + if (this.isMap) { if (this.asMap.isLinked) { return `(${this.asMap.value.toString()}, Linkage<${this.asMap.key.toString()}>)`; } diff --git a/packages/types/src/Metadata/v0/latest.polkadot.json b/packages/types/src/Metadata/v0/latest.polkadot.v0.json similarity index 96% rename from packages/types/src/Metadata/v0/latest.polkadot.json rename to packages/types/src/Metadata/v0/latest.polkadot.v0.json index 6c98d99a8e..a48a62f659 100644 --- a/packages/types/src/Metadata/v0/latest.polkadot.json +++ b/packages/types/src/Metadata/v0/latest.polkadot.v0.json @@ -7,14 +7,14 @@ [ { "name": "ExtrinsicSuccess", - "arguments": [], + "args": [], "documentation": [ " An extrinsic completed successfully." ] }, { "name": "ExtrinsicFailed", - "arguments": [], + "args": [], "documentation": [ " An extrinsic failed." ] @@ -26,7 +26,7 @@ [ { "name": "NewAccount", - "arguments": [ + "args": [ "AccountId", "AccountIndex", "NewAccountOutcome" @@ -37,7 +37,7 @@ }, { "name": "ReapedAccount", - "arguments": [ + "args": [ "AccountId" ], "documentation": [ @@ -46,7 +46,7 @@ }, { "name": "Transfer", - "arguments": [ + "args": [ "AccountId", "AccountId", "Balance", @@ -63,7 +63,7 @@ [ { "name": "NewSession", - "arguments": [ + "args": [ "BlockNumber" ], "documentation": [ @@ -78,7 +78,7 @@ [ { "name": "Reward", - "arguments": [ + "args": [ "Balance" ], "documentation": [ @@ -87,7 +87,7 @@ }, { "name": "OfflineWarning", - "arguments": [ + "args": [ "AccountId", "u32" ], @@ -98,7 +98,7 @@ }, { "name": "OfflineSlash", - "arguments": [ + "args": [ "AccountId", "Balance" ], @@ -113,7 +113,7 @@ [ { "name": "Tabled", - "arguments": [ + "args": [ "PropIndex", "Balance", "Vec" @@ -122,7 +122,7 @@ }, { "name": "Started", - "arguments": [ + "args": [ "ReferendumIndex", "VoteThreshold" ], @@ -130,28 +130,28 @@ }, { "name": "Passed", - "arguments": [ + "args": [ "ReferendumIndex" ], "documentation": [] }, { "name": "NotPassed", - "arguments": [ + "args": [ "ReferendumIndex" ], "documentation": [] }, { "name": "Cancelled", - "arguments": [ + "args": [ "ReferendumIndex" ], "documentation": [] }, { "name": "Executed", - "arguments": [ + "args": [ "ReferendumIndex", "bool" ], @@ -164,7 +164,7 @@ [ { "name": "NewAuthorities", - "arguments": [ + "args": [ "Vec<(SessionKey,u64)>" ], "documentation": [ @@ -178,7 +178,7 @@ [ { "name": "VoterReaped", - "arguments": [ + "args": [ "AccountId", "AccountId" ], @@ -188,7 +188,7 @@ }, { "name": "BadReaperSlashed", - "arguments": [ + "args": [ "AccountId" ], "documentation": [ @@ -197,7 +197,7 @@ }, { "name": "TallyStarted", - "arguments": [ + "args": [ "u32" ], "documentation": [ @@ -206,7 +206,7 @@ }, { "name": "TallyFinalised", - "arguments": [ + "args": [ "Vec", "Vec" ], @@ -221,7 +221,7 @@ [ { "name": "TallyCancelation", - "arguments": [ + "args": [ "Hash", "u32", "u32", @@ -234,7 +234,7 @@ }, { "name": "TallyReferendum", - "arguments": [ + "args": [ "Hash", "u32", "u32", @@ -252,7 +252,7 @@ [ { "name": "Proposed", - "arguments": [ + "args": [ "AccountId", "ProposalIndex", "Hash", @@ -264,7 +264,7 @@ }, { "name": "Voted", - "arguments": [ + "args": [ "AccountId", "Hash", "bool", @@ -278,7 +278,7 @@ }, { "name": "Approved", - "arguments": [ + "args": [ "Hash" ], "documentation": [ @@ -287,7 +287,7 @@ }, { "name": "Disapproved", - "arguments": [ + "args": [ "Hash" ], "documentation": [ @@ -296,7 +296,7 @@ }, { "name": "Executed", - "arguments": [ + "args": [ "Hash", "bool" ], @@ -311,7 +311,7 @@ [ { "name": "Proposed", - "arguments": [ + "args": [ "ProposalIndex" ], "documentation": [ @@ -320,7 +320,7 @@ }, { "name": "Spending", - "arguments": [ + "args": [ "Balance" ], "documentation": [ @@ -329,7 +329,7 @@ }, { "name": "Awarded", - "arguments": [ + "args": [ "ProposalIndex", "Balance", "AccountId" @@ -340,7 +340,7 @@ }, { "name": "Burnt", - "arguments": [ + "args": [ "Balance" ], "documentation": [ @@ -349,7 +349,7 @@ }, { "name": "Rollover", - "arguments": [ + "args": [ "Balance" ], "documentation": [ @@ -468,7 +468,7 @@ { "id": 0, "name": "set", - "arguments": [ + "args": [ { "name": "now", "type": "Compact" @@ -528,7 +528,7 @@ { "id": 0, "name": "report_misbehavior", - "arguments": [ + "args": [ { "name": "_report", "type": "Bytes" @@ -541,7 +541,7 @@ { "id": 1, "name": "note_offline", - "arguments": [ + "args": [ { "name": "offline", "type": "InherentOfflineReport" @@ -554,7 +554,7 @@ { "id": 2, "name": "remark", - "arguments": [ + "args": [ { "name": "_remark", "type": "Bytes" @@ -567,7 +567,7 @@ { "id": 3, "name": "set_heap_pages", - "arguments": [ + "args": [ { "name": "pages", "type": "u64" @@ -580,7 +580,7 @@ { "id": 4, "name": "set_code", - "arguments": [ + "args": [ { "name": "new", "type": "Bytes" @@ -593,7 +593,7 @@ { "id": 5, "name": "set_storage", - "arguments": [ + "args": [ { "name": "items", "type": "Vec" @@ -628,7 +628,7 @@ { "id": 0, "name": "transfer", - "arguments": [ + "args": [ { "name": "dest", "type": "Address" @@ -645,7 +645,7 @@ { "id": 1, "name": "set_balance", - "arguments": [ + "args": [ { "name": "who", "type": "Address" @@ -800,7 +800,7 @@ { "id": 0, "name": "set_key", - "arguments": [ + "args": [ { "name": "key", "type": "SessionKey" @@ -814,7 +814,7 @@ { "id": 1, "name": "set_length", - "arguments": [ + "args": [ { "name": "new", "type": "Compact" @@ -827,7 +827,7 @@ { "id": 2, "name": "force_new_session", - "arguments": [ + "args": [ { "name": "apply_rewards", "type": "bool" @@ -924,7 +924,7 @@ { "id": 0, "name": "stake", - "arguments": [], + "args": [], "documentation": [ " Declare the desire to stake for the transactor.", "", @@ -934,7 +934,7 @@ { "id": 1, "name": "unstake", - "arguments": [ + "args": [ { "name": "intentions_index", "type": "Compact" @@ -949,7 +949,7 @@ { "id": 2, "name": "nominate", - "arguments": [ + "args": [ { "name": "target", "type": "Address" @@ -960,7 +960,7 @@ { "id": 3, "name": "unnominate", - "arguments": [ + "args": [ { "name": "target_index", "type": "Compact" @@ -974,7 +974,7 @@ { "id": 4, "name": "register_preferences", - "arguments": [ + "args": [ { "name": "intentions_index", "type": "Compact" @@ -993,7 +993,7 @@ { "id": 5, "name": "set_sessions_per_era", - "arguments": [ + "args": [ { "name": "new", "type": "Compact" @@ -1006,7 +1006,7 @@ { "id": 6, "name": "set_bonding_duration", - "arguments": [ + "args": [ { "name": "new", "type": "Compact" @@ -1019,7 +1019,7 @@ { "id": 7, "name": "set_validator_count", - "arguments": [ + "args": [ { "name": "new", "type": "Compact" @@ -1032,7 +1032,7 @@ { "id": 8, "name": "force_new_era", - "arguments": [ + "args": [ { "name": "apply_rewards", "type": "bool" @@ -1046,7 +1046,7 @@ { "id": 9, "name": "set_offline_slash_grace", - "arguments": [ + "args": [ { "name": "new", "type": "Compact" @@ -1261,7 +1261,7 @@ { "id": 0, "name": "propose", - "arguments": [ + "args": [ { "name": "proposal", "type": "Proposal" @@ -1278,7 +1278,7 @@ { "id": 1, "name": "second", - "arguments": [ + "args": [ { "name": "proposal", "type": "Compact" @@ -1291,7 +1291,7 @@ { "id": 2, "name": "vote", - "arguments": [ + "args": [ { "name": "ref_index", "type": "Compact" @@ -1309,7 +1309,7 @@ { "id": 3, "name": "start_referendum", - "arguments": [ + "args": [ { "name": "proposal", "type": "Proposal" @@ -1330,7 +1330,7 @@ { "id": 4, "name": "cancel_referendum", - "arguments": [ + "args": [ { "name": "ref_index", "type": "Compact" @@ -1343,7 +1343,7 @@ { "id": 5, "name": "cancel_queued", - "arguments": [ + "args": [ { "name": "when", "type": "BlockNumber" @@ -1506,7 +1506,7 @@ { "id": 0, "name": "report_misbehavior", - "arguments": [ + "args": [ { "name": "_report", "type": "Bytes" @@ -1541,7 +1541,7 @@ { "id": 0, "name": "set_approvals", - "arguments": [ + "args": [ { "name": "votes", "type": "Vec" @@ -1559,7 +1559,7 @@ { "id": 1, "name": "reap_inactive_voter", - "arguments": [ + "args": [ { "name": "reporter_index", "type": "Compact" @@ -1588,7 +1588,7 @@ { "id": 2, "name": "retract_voter", - "arguments": [ + "args": [ { "name": "index", "type": "Compact" @@ -1601,7 +1601,7 @@ { "id": 3, "name": "submit_candidacy", - "arguments": [ + "args": [ { "name": "slot", "type": "Compact" @@ -1616,7 +1616,7 @@ { "id": 4, "name": "present_winner", - "arguments": [ + "args": [ { "name": "candidate", "type": "Address" @@ -1639,7 +1639,7 @@ { "id": 5, "name": "set_desired_seats", - "arguments": [ + "args": [ { "name": "count", "type": "Compact" @@ -1654,7 +1654,7 @@ { "id": 6, "name": "remove_member", - "arguments": [ + "args": [ { "name": "who", "type": "Address" @@ -1669,7 +1669,7 @@ { "id": 7, "name": "set_presentation_duration", - "arguments": [ + "args": [ { "name": "count", "type": "Compact" @@ -1683,7 +1683,7 @@ { "id": 8, "name": "set_term_duration", - "arguments": [ + "args": [ { "name": "count", "type": "Compact" @@ -1883,7 +1883,7 @@ { "id": 0, "name": "propose", - "arguments": [ + "args": [ { "name": "proposal", "type": "Proposal" @@ -1894,7 +1894,7 @@ { "id": 1, "name": "vote", - "arguments": [ + "args": [ { "name": "proposal", "type": "Hash" @@ -1909,7 +1909,7 @@ { "id": 2, "name": "veto", - "arguments": [ + "args": [ { "name": "proposal_hash", "type": "Hash" @@ -1920,7 +1920,7 @@ { "id": 3, "name": "set_cooloff_period", - "arguments": [ + "args": [ { "name": "blocks", "type": "Compact" @@ -1931,7 +1931,7 @@ { "id": 4, "name": "set_voting_period", - "arguments": [ + "args": [ { "name": "blocks", "type": "Compact" @@ -2020,7 +2020,7 @@ { "id": 0, "name": "propose", - "arguments": [ + "args": [ { "name": "threshold", "type": "Compact" @@ -2035,7 +2035,7 @@ { "id": 1, "name": "vote", - "arguments": [ + "args": [ { "name": "proposal", "type": "Hash" @@ -2108,7 +2108,7 @@ { "id": 0, "name": "propose_spend", - "arguments": [ + "args": [ { "name": "value", "type": "Compact" @@ -2127,7 +2127,7 @@ { "id": 1, "name": "set_pot", - "arguments": [ + "args": [ { "name": "new_pot", "type": "Compact" @@ -2140,7 +2140,7 @@ { "id": 2, "name": "configure", - "arguments": [ + "args": [ { "name": "proposal_bond", "type": "Permill" @@ -2165,7 +2165,7 @@ { "id": 3, "name": "reject_proposal", - "arguments": [ + "args": [ { "name": "proposal_id", "type": "Compact" @@ -2178,7 +2178,7 @@ { "id": 4, "name": "approve_proposal", - "arguments": [ + "args": [ { "name": "proposal_id", "type": "Compact" @@ -2276,7 +2276,7 @@ { "id": 0, "name": "set_heads", - "arguments": [ + "args": [ { "name": "heads", "type": "Vec" @@ -2289,7 +2289,7 @@ { "id": 1, "name": "register_parachain", - "arguments": [ + "args": [ { "name": "id", "type": "Id" @@ -2311,7 +2311,7 @@ { "id": 2, "name": "deregister_parachain", - "arguments": [ + "args": [ { "name": "id", "type": "Id" diff --git a/packages/types/src/Metadata/v0/latest.substrate.json b/packages/types/src/Metadata/v0/latest.substrate.json deleted file mode 100644 index b2e677ee13..0000000000 --- a/packages/types/src/Metadata/v0/latest.substrate.json +++ /dev/null @@ -1,2898 +0,0 @@ -{ - "outerEvent": { - "name": "Event", - "events": [ - [ - "system", - [ - { - "name": "ExtrinsicSuccess", - "arguments": [], - "documentation": [ - " An extrinsic completed successfully." - ] - }, - { - "name": "ExtrinsicFailed", - "arguments": [], - "documentation": [ - " An extrinsic failed." - ] - } - ] - ], - [ - "indices", - [ - { - "name": "NewAccountIndex", - "arguments": [ - "AccountId", - "AccountIndex" - ], - "documentation": [ - " A new account was created." - ] - } - ] - ], - [ - "balances", - [ - { - "name": "NewAccount", - "arguments": [ - "AccountId", - "Balance" - ], - "documentation": [ - " A new account was created." - ] - }, - { - "name": "ReapedAccount", - "arguments": [ - "AccountId" - ], - "documentation": [ - " An account was reaped." - ] - }, - { - "name": "Transfer", - "arguments": [ - "AccountId", - "AccountId", - "Balance", - "Balance" - ], - "documentation": [ - " Transfer succeeded (from, to, value, fees)." - ] - } - ] - ], - [ - "session", - [ - { - "name": "NewSession", - "arguments": [ - "BlockNumber" - ], - "documentation": [ - " New session has happened. Note that the argument is the session index, not the block", - " number as the type might suggest." - ] - } - ] - ], - [ - "staking", - [ - { - "name": "Reward", - "arguments": [ - "Balance" - ], - "documentation": [ - " All validators have been rewarded by the given balance." - ] - }, - { - "name": "OfflineWarning", - "arguments": [ - "AccountId", - "u32" - ], - "documentation": [ - " One validator (and their nominators) has been given a offline-warning (they're still", - " within their grace). The accrued number of slashes is recorded, too." - ] - }, - { - "name": "OfflineSlash", - "arguments": [ - "AccountId", - "Balance" - ], - "documentation": [ - " One validator (and their nominators) has been slashed by the given amount." - ] - } - ] - ], - [ - "democracy", - [ - { - "name": "Tabled", - "arguments": [ - "PropIndex", - "Balance", - "Vec" - ], - "documentation": [] - }, - { - "name": "Started", - "arguments": [ - "ReferendumIndex", - "VoteThreshold" - ], - "documentation": [] - }, - { - "name": "Passed", - "arguments": [ - "ReferendumIndex" - ], - "documentation": [] - }, - { - "name": "NotPassed", - "arguments": [ - "ReferendumIndex" - ], - "documentation": [] - }, - { - "name": "Cancelled", - "arguments": [ - "ReferendumIndex" - ], - "documentation": [] - }, - { - "name": "Executed", - "arguments": [ - "ReferendumIndex", - "bool" - ], - "documentation": [] - } - ] - ], - [ - "council", - [ - { - "name": "VoterReaped", - "arguments": [ - "AccountId", - "AccountId" - ], - "documentation": [ - " reaped voter, reaper" - ] - }, - { - "name": "BadReaperSlashed", - "arguments": [ - "AccountId" - ], - "documentation": [ - " slashed reaper" - ] - }, - { - "name": "TallyStarted", - "arguments": [ - "u32" - ], - "documentation": [ - " A tally (for approval votes of council seat(s)) has started." - ] - }, - { - "name": "TallyFinalised", - "arguments": [ - "Vec", - "Vec" - ], - "documentation": [ - " A tally (for approval votes of council seat(s)) has ended (with one or more new members)." - ] - } - ] - ], - [ - "council_voting", - [ - { - "name": "TallyCancelation", - "arguments": [ - "Hash", - "u32", - "u32", - "u32" - ], - "documentation": [ - " A voting tally has happened for a referendum cancellation vote.", - " Last three are yes, no, abstain counts." - ] - }, - { - "name": "TallyReferendum", - "arguments": [ - "Hash", - "u32", - "u32", - "u32" - ], - "documentation": [ - " A voting tally has happened for a referendum vote.", - " Last three are yes, no, abstain counts." - ] - } - ] - ], - [ - "council_motions", - [ - { - "name": "Proposed", - "arguments": [ - "AccountId", - "ProposalIndex", - "Hash", - "u32" - ], - "documentation": [ - " A motion (given hash) has been proposed (by given account) with a threshold (given u32)." - ] - }, - { - "name": "Voted", - "arguments": [ - "AccountId", - "Hash", - "bool", - "u32", - "u32" - ], - "documentation": [ - " A motion (given hash) has been voted on by given account, leaving", - " a tally (yes votes and no votes given as u32s respectively)." - ] - }, - { - "name": "Approved", - "arguments": [ - "Hash" - ], - "documentation": [ - " A motion was approved by the required threshold." - ] - }, - { - "name": "Disapproved", - "arguments": [ - "Hash" - ], - "documentation": [ - " A motion was not approved by the required threshold." - ] - }, - { - "name": "Executed", - "arguments": [ - "Hash", - "bool" - ], - "documentation": [ - " A motion was executed; `bool` is true if returned without error." - ] - } - ] - ], - [ - "grandpa", - [ - { - "name": "NewAuthorities", - "arguments": [ - "Vec<(SessionKey,u64)>" - ], - "documentation": [ - " New authority set has been applied." - ] - } - ] - ], - [ - "treasury", - [ - { - "name": "Proposed", - "arguments": [ - "ProposalIndex" - ], - "documentation": [ - " New proposal." - ] - }, - { - "name": "Spending", - "arguments": [ - "Balance" - ], - "documentation": [ - " We have ended a spend period and will now allocate funds." - ] - }, - { - "name": "Awarded", - "arguments": [ - "ProposalIndex", - "Balance", - "AccountId" - ], - "documentation": [ - " Some funds have been allocated." - ] - }, - { - "name": "Burnt", - "arguments": [ - "Balance" - ], - "documentation": [ - " Some of our funds have been burnt." - ] - }, - { - "name": "Rollover", - "arguments": [ - "Balance" - ], - "documentation": [ - " Spending has finished; this is the amount that rolls over until next spend." - ] - } - ] - ], - [ - "contract", - [ - { - "name": "Transfer", - "arguments": [ - "AccountId", - "AccountId", - "Balance" - ], - "documentation": [ - " Transfer happened `from` -> `to` with given `value` as part of a `message-call` or `create`." - ] - }, - { - "name": "Created", - "arguments": [ - "AccountId", - "AccountId" - ], - "documentation": [ - " Contract deployed by address at the specified address." - ] - } - ] - ], - [ - "sudo", - [ - { - "name": "Sudid", - "arguments": [ - "bool" - ], - "documentation": [ - " A sudo just took place." - ] - }, - { - "name": "KeyChanged", - "arguments": [ - "AccountId" - ], - "documentation": [ - " The sudoer just switched identity; the old key is supplied." - ] - } - ] - ] - ] - }, - "modules": [ - { - "prefix": "system", - "module": { - "name": "Module", - "call": { - "name": "Call", - "functions": [] - } - }, - "storage": { - "prefix": "System", - "functions": [ - { - "name": "AccountNonce", - "modifier": "Default", - "type": { - "MapType": { - "key": "AccountId", - "value": "Index" - } - }, - "fallback": "0x0000000000000000", - "documentation": [] - }, - { - "name": "ExtrinsicCount", - "modifier": "Optional", - "type": { - "PlainType": "u32" - }, - "fallback": "0x00", - "documentation": [] - }, - { - "name": "BlockHash", - "modifier": "Default", - "type": { - "MapType": { - "key": "BlockNumber", - "value": "Hash" - } - }, - "fallback": "0x0000000000000000000000000000000000000000000000000000000000000000", - "documentation": [] - }, - { - "name": "ExtrinsicData", - "modifier": "Default", - "type": { - "MapType": { - "key": "u32", - "value": "Bytes" - } - }, - "fallback": "0x00", - "documentation": [] - }, - { - "name": "RandomSeed", - "modifier": "Default", - "type": { - "PlainType": "Hash" - }, - "fallback": "0x0000000000000000000000000000000000000000000000000000000000000000", - "documentation": [] - }, - { - "name": "Number", - "modifier": "Default", - "type": { - "PlainType": "BlockNumber" - }, - "fallback": "0x0000000000000000", - "documentation": [ - " The current block number being processed. Set by `execute_block`." - ] - }, - { - "name": "ParentHash", - "modifier": "Default", - "type": { - "PlainType": "Hash" - }, - "fallback": "0x0000000000000000000000000000000000000000000000000000000000000000", - "documentation": [] - }, - { - "name": "ExtrinsicsRoot", - "modifier": "Default", - "type": { - "PlainType": "Hash" - }, - "fallback": "0x0000000000000000000000000000000000000000000000000000000000000000", - "documentation": [] - }, - { - "name": "Digest", - "modifier": "Default", - "type": { - "PlainType": "Digest" - }, - "fallback": "0x00", - "documentation": [] - }, - { - "name": "Events", - "modifier": "Default", - "type": { - "PlainType": "Vec" - }, - "fallback": "0x00", - "documentation": [] - } - ] - } - }, - { - "prefix": "aura", - "module": { - "name": "Module", - "call": { - "name": "Call", - "functions": [] - } - }, - "storage": null - }, - { - "prefix": "timestamp", - "module": { - "name": "Module", - "call": { - "name": "Call", - "functions": [ - { - "id": 0, - "name": "set", - "arguments": [ - { - "name": "now", - "type": "Compact" - } - ], - "documentation": [ - " Set the current time.", - "", - " Extrinsic with this call should be placed at the specific position in the each block", - " (specified by the Trait::TIMESTAMP_SET_POSITION) typically at the start of the each block.", - " This call should be invoked exactly once per block. It will panic at the finalization phase,", - " if this call hasn't been invoked by that time.", - "", - " The timestamp should be greater than the previous one by the amount specified by `block_period`." - ] - } - ] - } - }, - "storage": { - "prefix": "Timestamp", - "functions": [ - { - "name": "Now", - "modifier": "Default", - "type": { - "PlainType": "Moment" - }, - "fallback": "0x0000000000000000", - "documentation": [ - " Current time for the current block." - ] - }, - { - "name": "BlockPeriod", - "modifier": "Default", - "type": { - "PlainType": "Moment" - }, - "fallback": "0x0500000000000000", - "documentation": [ - " The minimum (and advised) period between blocks." - ] - }, - { - "name": "DidUpdate", - "modifier": "Default", - "type": { - "PlainType": "bool" - }, - "fallback": "0x00", - "documentation": [ - " Did the timestamp get updated in this block?" - ] - } - ] - } - }, - { - "prefix": "consensus", - "module": { - "name": "Module", - "call": { - "name": "Call", - "functions": [ - { - "id": 0, - "name": "report_misbehavior", - "arguments": [ - { - "name": "_report", - "type": "Bytes" - } - ], - "documentation": [ - " Report some misbehaviour." - ] - }, - { - "id": 1, - "name": "note_offline", - "arguments": [ - { - "name": "offline", - "type": "InherentOfflineReport" - } - ], - "documentation": [ - " Note the previous block's validator missed their opportunity to propose a block." - ] - }, - { - "id": 2, - "name": "remark", - "arguments": [ - { - "name": "_remark", - "type": "Bytes" - } - ], - "documentation": [ - " Make some on-chain remark." - ] - }, - { - "id": 3, - "name": "set_heap_pages", - "arguments": [ - { - "name": "pages", - "type": "u64" - } - ], - "documentation": [ - " Set the number of pages in the WebAssembly environment's heap." - ] - }, - { - "id": 4, - "name": "set_code", - "arguments": [ - { - "name": "new", - "type": "Bytes" - } - ], - "documentation": [ - " Set the new code." - ] - }, - { - "id": 5, - "name": "set_storage", - "arguments": [ - { - "name": "items", - "type": "Vec" - } - ], - "documentation": [ - " Set some items of storage." - ] - } - ] - } - }, - "storage": { - "prefix": "Consensus", - "functions": [ - { - "name": "OriginalAuthorities", - "modifier": "Optional", - "type": { - "PlainType": "Vec" - }, - "fallback": "0x00", - "documentation": [] - } - ] - } - }, - { - "prefix": "indices", - "module": { - "name": "Module", - "call": { - "name": "Call", - "functions": [] - } - }, - "storage": { - "prefix": "Indices", - "functions": [ - { - "name": "NextEnumSet", - "modifier": "Default", - "type": { - "PlainType": "AccountIndex" - }, - "fallback": "0x00000000", - "documentation": [ - " The next free enumeration set." - ] - }, - { - "name": "EnumSet", - "modifier": "Default", - "type": { - "MapType": { - "key": "AccountIndex", - "value": "Vec" - } - }, - "fallback": "0x00", - "documentation": [ - " The enumeration sets." - ] - } - ] - } - }, - { - "prefix": "balances", - "module": { - "name": "Module", - "call": { - "name": "Call", - "functions": [ - { - "id": 0, - "name": "transfer", - "arguments": [ - { - "name": "dest", - "type": "Address" - }, - { - "name": "value", - "type": "Compact" - } - ], - "documentation": [ - " Transfer some liquid free balance to another staker." - ] - }, - { - "id": 1, - "name": "set_balance", - "arguments": [ - { - "name": "who", - "type": "Address" - }, - { - "name": "free", - "type": "Compact" - }, - { - "name": "reserved", - "type": "Compact" - } - ], - "documentation": [ - " Set the balances of a given account." - ] - } - ] - } - }, - "storage": { - "prefix": "Balances", - "functions": [ - { - "name": "TotalIssuance", - "modifier": "Default", - "type": { - "PlainType": "Balance" - }, - "fallback": "0x00000000000000000000000000000000", - "documentation": [ - " The total amount of stake on the system." - ] - }, - { - "name": "ExistentialDeposit", - "modifier": "Default", - "type": { - "PlainType": "Balance" - }, - "fallback": "0x00000000000000000000000000000000", - "documentation": [ - " The minimum amount allowed to keep an account open." - ] - }, - { - "name": "TransferFee", - "modifier": "Default", - "type": { - "PlainType": "Balance" - }, - "fallback": "0x00000000000000000000000000000000", - "documentation": [ - " The fee required to make a transfer." - ] - }, - { - "name": "CreationFee", - "modifier": "Default", - "type": { - "PlainType": "Balance" - }, - "fallback": "0x00000000000000000000000000000000", - "documentation": [ - " The fee required to create an account. At least as big as ReclaimRebate." - ] - }, - { - "name": "FreeBalance", - "modifier": "Default", - "type": { - "MapType": { - "key": "AccountId", - "value": "Balance" - } - }, - "fallback": "0x00000000000000000000000000000000", - "documentation": [ - " The 'free' balance of a given account.", - "", - " This is the only balance that matters in terms of most operations on tokens. It is", - " alone used to determine the balance when in the contract execution environment. When this", - " balance falls below the value of `ExistentialDeposit`, then the 'current account' is", - " deleted: specifically `FreeBalance`. Furthermore, `OnFreeBalanceZero` callback", - " is invoked, giving a chance to external modules to cleanup data associated with", - " the deleted account.", - "", - " `system::AccountNonce` is also deleted if `ReservedBalance` is also zero (it also gets", - " collapsed to zero if it ever becomes less than `ExistentialDeposit`." - ] - }, - { - "name": "ReservedBalance", - "modifier": "Default", - "type": { - "MapType": { - "key": "AccountId", - "value": "Balance" - } - }, - "fallback": "0x00000000000000000000000000000000", - "documentation": [ - " The amount of the balance of a given account that is externally reserved; this can still get", - " slashed, but gets slashed last of all.", - "", - " This balance is a 'reserve' balance that other subsystems use in order to set aside tokens", - " that are still 'owned' by the account holder, but which are suspendable. (This is different", - " and wholly unrelated to the `Bondage` system used in the staking module.)", - "", - " When this balance falls below the value of `ExistentialDeposit`, then this 'reserve account'", - " is deleted: specifically, `ReservedBalance`.", - "", - " `system::AccountNonce` is also deleted if `FreeBalance` is also zero (it also gets", - " collapsed to zero if it ever becomes less than `ExistentialDeposit`." - ] - }, - { - "name": "TransactionBaseFee", - "modifier": "Default", - "type": { - "PlainType": "Balance" - }, - "fallback": "0x00000000000000000000000000000000", - "documentation": [ - " The fee to be paid for making a transaction; the base." - ] - }, - { - "name": "TransactionByteFee", - "modifier": "Default", - "type": { - "PlainType": "Balance" - }, - "fallback": "0x00000000000000000000000000000000", - "documentation": [ - " The fee to be paid for making a transaction; the per-byte portion." - ] - } - ] - } - }, - { - "prefix": "session", - "module": { - "name": "Module", - "call": { - "name": "Call", - "functions": [ - { - "id": 0, - "name": "set_key", - "arguments": [ - { - "name": "key", - "type": "SessionKey" - } - ], - "documentation": [ - " Sets the session key of `_validator` to `_key`. This doesn't take effect until the next", - " session." - ] - }, - { - "id": 1, - "name": "set_length", - "arguments": [ - { - "name": "new", - "type": "Compact" - } - ], - "documentation": [ - " Set a new session length. Won't kick in until the next session change (at current length)." - ] - }, - { - "id": 2, - "name": "force_new_session", - "arguments": [ - { - "name": "apply_rewards", - "type": "bool" - } - ], - "documentation": [ - " Forces a new session." - ] - } - ] - } - }, - "storage": { - "prefix": "Session", - "functions": [ - { - "name": "Validators", - "modifier": "Default", - "type": { - "PlainType": "Vec" - }, - "fallback": "0x00", - "documentation": [ - " The current set of validators." - ] - }, - { - "name": "SessionLength", - "modifier": "Default", - "type": { - "PlainType": "BlockNumber" - }, - "fallback": "0xe803000000000000", - "documentation": [ - " Current length of the session." - ] - }, - { - "name": "CurrentIndex", - "modifier": "Default", - "type": { - "PlainType": "BlockNumber" - }, - "fallback": "0x0000000000000000", - "documentation": [ - " Current index of the session." - ] - }, - { - "name": "CurrentStart", - "modifier": "Default", - "type": { - "PlainType": "Moment" - }, - "fallback": "0x0000000000000000", - "documentation": [ - " Timestamp when current session started." - ] - }, - { - "name": "ForcingNewSession", - "modifier": "Optional", - "type": { - "PlainType": "bool" - }, - "fallback": "0x00", - "documentation": [ - " New session is being forced is this entry exists; in which case, the boolean value is whether", - " the new session should be considered a normal rotation (rewardable) or exceptional (slashable)." - ] - }, - { - "name": "LastLengthChange", - "modifier": "Optional", - "type": { - "PlainType": "BlockNumber" - }, - "fallback": "0x00", - "documentation": [ - " Block at which the session length last changed." - ] - }, - { - "name": "NextKeyFor", - "modifier": "Optional", - "type": { - "MapType": { - "key": "AccountId", - "value": "SessionKey" - } - }, - "fallback": "0x00", - "documentation": [ - " The next key for a given validator." - ] - }, - { - "name": "NextSessionLength", - "modifier": "Optional", - "type": { - "PlainType": "BlockNumber" - }, - "fallback": "0x00", - "documentation": [ - " The next session length." - ] - } - ] - } - }, - { - "prefix": "staking", - "module": { - "name": "Module", - "call": { - "name": "Call", - "functions": [ - { - "id": 0, - "name": "stake", - "arguments": [], - "documentation": [ - " Declare the desire to stake for the transactor.", - "", - " Effects will be felt at the beginning of the next era." - ] - }, - { - "id": 1, - "name": "unstake", - "arguments": [ - { - "name": "intentions_index", - "type": "Compact" - } - ], - "documentation": [ - " Retract the desire to stake for the transactor.", - "", - " Effects will be felt at the beginning of the next era." - ] - }, - { - "id": 2, - "name": "nominate", - "arguments": [ - { - "name": "target", - "type": "Address" - } - ], - "documentation": [] - }, - { - "id": 3, - "name": "unnominate", - "arguments": [ - { - "name": "target_index", - "type": "Compact" - } - ], - "documentation": [ - " Will panic if called when source isn't currently nominating target.", - " Updates Nominating, NominatorsFor and NominationBalance." - ] - }, - { - "id": 4, - "name": "register_preferences", - "arguments": [ - { - "name": "intentions_index", - "type": "Compact" - }, - { - "name": "prefs", - "type": "ValidatorPrefs" - } - ], - "documentation": [ - " Set the given account's preference for slashing behaviour should they be a validator.", - "", - " An error (no-op) if `Self::intentions()[intentions_index] != origin`." - ] - }, - { - "id": 5, - "name": "set_sessions_per_era", - "arguments": [ - { - "name": "new", - "type": "Compact" - } - ], - "documentation": [ - " Set the number of sessions in an era." - ] - }, - { - "id": 6, - "name": "set_bonding_duration", - "arguments": [ - { - "name": "new", - "type": "Compact" - } - ], - "documentation": [ - " The length of the bonding duration in eras." - ] - }, - { - "id": 7, - "name": "set_validator_count", - "arguments": [ - { - "name": "new", - "type": "Compact" - } - ], - "documentation": [ - " The ideal number of validators." - ] - }, - { - "id": 8, - "name": "force_new_era", - "arguments": [ - { - "name": "apply_rewards", - "type": "bool" - } - ], - "documentation": [ - " Force there to be a new era. This also forces a new session immediately after.", - " `apply_rewards` should be true for validators to get the session reward." - ] - }, - { - "id": 9, - "name": "set_offline_slash_grace", - "arguments": [ - { - "name": "new", - "type": "Compact" - } - ], - "documentation": [ - " Set the offline slash grace period." - ] - }, - { - "id": 10, - "name": "set_invulnerables", - "arguments": [ - { - "name": "validators", - "type": "Vec" - } - ], - "documentation": [ - " Set the validators who cannot be slashed (if any)." - ] - } - ] - } - }, - "storage": { - "prefix": "Staking", - "functions": [ - { - "name": "ValidatorCount", - "modifier": "Default", - "type": { - "PlainType": "u32" - }, - "fallback": "0x00000000", - "documentation": [ - " The ideal number of staking participants." - ] - }, - { - "name": "MinimumValidatorCount", - "modifier": "Default", - "type": { - "PlainType": "u32" - }, - "fallback": "0x04000000", - "documentation": [ - " Minimum number of staking participants before emergency conditions are imposed." - ] - }, - { - "name": "SessionsPerEra", - "modifier": "Default", - "type": { - "PlainType": "BlockNumber" - }, - "fallback": "0xe803000000000000", - "documentation": [ - " The length of a staking era in sessions." - ] - }, - { - "name": "SessionReward", - "modifier": "Default", - "type": { - "PlainType": "Perbill" - }, - "fallback": "0x3c000000", - "documentation": [ - " Maximum reward, per validator, that is provided per acceptable session." - ] - }, - { - "name": "OfflineSlash", - "modifier": "Default", - "type": { - "PlainType": "Perbill" - }, - "fallback": "0x40420f00", - "documentation": [ - " Slash, per validator that is taken for the first time they are found to be offline." - ] - }, - { - "name": "OfflineSlashGrace", - "modifier": "Default", - "type": { - "PlainType": "u32" - }, - "fallback": "0x00000000", - "documentation": [ - " Number of instances of offline reports before slashing begins for validators." - ] - }, - { - "name": "BondingDuration", - "modifier": "Default", - "type": { - "PlainType": "BlockNumber" - }, - "fallback": "0xe803000000000000", - "documentation": [ - " The length of the bonding duration in blocks." - ] - }, - { - "name": "Invulerables", - "modifier": "Default", - "type": { - "PlainType": "Vec" - }, - "fallback": "0x00", - "documentation": [ - " Any validators that may never be slashed or forcible kicked. It's a Vec since they're easy to initialise", - " and the performance hit is minimal (we expect no more than four invulnerables) and restricted to testnets." - ] - }, - { - "name": "CurrentEra", - "modifier": "Default", - "type": { - "PlainType": "BlockNumber" - }, - "fallback": "0x0000000000000000", - "documentation": [ - " The current era index." - ] - }, - { - "name": "ValidatorPreferences", - "modifier": "Default", - "type": { - "MapType": { - "key": "AccountId", - "value": "ValidatorPrefs" - } - }, - "fallback": "0x0c00", - "documentation": [ - " Preferences that a validator has." - ] - }, - { - "name": "Intentions", - "modifier": "Default", - "type": { - "PlainType": "Vec" - }, - "fallback": "0x00", - "documentation": [ - " All the accounts with a desire to stake." - ] - }, - { - "name": "Nominating", - "modifier": "Optional", - "type": { - "MapType": { - "key": "AccountId", - "value": "AccountId" - } - }, - "fallback": "0x00", - "documentation": [ - " All nominator -> nominee relationships." - ] - }, - { - "name": "NominatorsFor", - "modifier": "Default", - "type": { - "MapType": { - "key": "AccountId", - "value": "Vec" - } - }, - "fallback": "0x00", - "documentation": [ - " Nominators for a particular account." - ] - }, - { - "name": "CurrentNominatorsFor", - "modifier": "Default", - "type": { - "MapType": { - "key": "AccountId", - "value": "Vec" - } - }, - "fallback": "0x00", - "documentation": [ - " Nominators for a particular account that is in action right now." - ] - }, - { - "name": "CurrentSessionReward", - "modifier": "Default", - "type": { - "PlainType": "Balance" - }, - "fallback": "0x00000000000000000000000000000000", - "documentation": [ - " Maximum reward, per validator, that is provided per acceptable session." - ] - }, - { - "name": "CurrentOfflineSlash", - "modifier": "Default", - "type": { - "PlainType": "Balance" - }, - "fallback": "0x00000000000000000000000000000000", - "documentation": [ - " Slash, per validator that is taken for the first time they are found to be offline." - ] - }, - { - "name": "NextSessionsPerEra", - "modifier": "Optional", - "type": { - "PlainType": "BlockNumber" - }, - "fallback": "0x00", - "documentation": [ - " The next value of sessions per era." - ] - }, - { - "name": "LastEraLengthChange", - "modifier": "Default", - "type": { - "PlainType": "BlockNumber" - }, - "fallback": "0x0000000000000000", - "documentation": [ - " The session index at which the era length last changed." - ] - }, - { - "name": "StakeRange", - "modifier": "Default", - "type": { - "PlainType": "(Balance,Balance)" - }, - "fallback": "0x0000000000000000000000000000000000000000000000000000000000000000", - "documentation": [ - " The highest and lowest staked validator slashable balances." - ] - }, - { - "name": "Bondage", - "modifier": "Default", - "type": { - "MapType": { - "key": "AccountId", - "value": "BlockNumber" - } - }, - "fallback": "0x0000000000000000", - "documentation": [ - " The block at which the `who`'s funds become entirely liquid." - ] - }, - { - "name": "SlashCount", - "modifier": "Default", - "type": { - "MapType": { - "key": "AccountId", - "value": "u32" - } - }, - "fallback": "0x00000000", - "documentation": [ - " The number of times a given validator has been reported offline. This gets decremented by one each era that passes." - ] - }, - { - "name": "ForcingNewEra", - "modifier": "Optional", - "type": { - "PlainType": "Null" - }, - "fallback": "0x00", - "documentation": [ - " We are forcing a new era." - ] - } - ] - } - }, - { - "prefix": "democracy", - "module": { - "name": "Module", - "call": { - "name": "Call", - "functions": [ - { - "id": 0, - "name": "propose", - "arguments": [ - { - "name": "proposal", - "type": "Proposal" - }, - { - "name": "value", - "type": "Compact" - } - ], - "documentation": [ - " Propose a sensitive action to be taken." - ] - }, - { - "id": 1, - "name": "second", - "arguments": [ - { - "name": "proposal", - "type": "Compact" - } - ], - "documentation": [ - " Propose a sensitive action to be taken." - ] - }, - { - "id": 2, - "name": "vote", - "arguments": [ - { - "name": "ref_index", - "type": "Compact" - }, - { - "name": "vote", - "type": "Vote" - } - ], - "documentation": [ - " Vote in a referendum. If `vote.is_aye()`, the vote is to enact the proposal;", - " otherwise it is a vote to keep the status quo." - ] - }, - { - "id": 3, - "name": "start_referendum", - "arguments": [ - { - "name": "proposal", - "type": "Proposal" - }, - { - "name": "threshold", - "type": "VoteThreshold" - }, - { - "name": "delay", - "type": "BlockNumber" - } - ], - "documentation": [ - " Start a referendum." - ] - }, - { - "id": 4, - "name": "cancel_referendum", - "arguments": [ - { - "name": "ref_index", - "type": "Compact" - } - ], - "documentation": [ - " Remove a referendum." - ] - }, - { - "id": 5, - "name": "cancel_queued", - "arguments": [ - { - "name": "when", - "type": "Compact" - }, - { - "name": "which", - "type": "Compact" - } - ], - "documentation": [ - " Cancel a proposal queued for enactment." - ] - } - ] - } - }, - "storage": { - "prefix": "Democracy", - "functions": [ - { - "name": "PublicPropCount", - "modifier": "Default", - "type": { - "PlainType": "PropIndex" - }, - "fallback": "0x00000000", - "documentation": [ - " The number of (public) proposals that have been made so far." - ] - }, - { - "name": "PublicProps", - "modifier": "Default", - "type": { - "PlainType": "Vec<(PropIndex,Proposal,AccountId)>" - }, - "fallback": "0x00", - "documentation": [ - " The public proposals. Unsorted." - ] - }, - { - "name": "DepositOf", - "modifier": "Optional", - "type": { - "MapType": { - "key": "PropIndex", - "value": "(Balance,Vec)" - } - }, - "fallback": "0x00", - "documentation": [ - " Those who have locked a deposit." - ] - }, - { - "name": "LaunchPeriod", - "modifier": "Default", - "type": { - "PlainType": "BlockNumber" - }, - "fallback": "0xe803000000000000", - "documentation": [ - " How often (in blocks) new public referenda are launched." - ] - }, - { - "name": "MinimumDeposit", - "modifier": "Default", - "type": { - "PlainType": "Balance" - }, - "fallback": "0x00000000000000000000000000000000", - "documentation": [ - " The minimum amount to be used as a deposit for a public referendum proposal." - ] - }, - { - "name": "PublicDelay", - "modifier": "Default", - "type": { - "PlainType": "BlockNumber" - }, - "fallback": "0x0000000000000000", - "documentation": [ - " The delay before enactment for all public referenda." - ] - }, - { - "name": "MaxLockPeriods", - "modifier": "Default", - "type": { - "PlainType": "LockPeriods" - }, - "fallback": "0x00", - "documentation": [ - " The maximum number of additional lock periods a voter may offer to strengthen their vote. Multiples of `PublicDelay`." - ] - }, - { - "name": "VotingPeriod", - "modifier": "Default", - "type": { - "PlainType": "BlockNumber" - }, - "fallback": "0xe803000000000000", - "documentation": [ - " How often (in blocks) to check for new votes." - ] - }, - { - "name": "ReferendumCount", - "modifier": "Default", - "type": { - "PlainType": "ReferendumIndex" - }, - "fallback": "0x00000000", - "documentation": [ - " The next free referendum index, aka the number of referendums started so far." - ] - }, - { - "name": "NextTally", - "modifier": "Default", - "type": { - "PlainType": "ReferendumIndex" - }, - "fallback": "0x00000000", - "documentation": [ - " The next referendum index that should be tallied." - ] - }, - { - "name": "ReferendumInfoOf", - "modifier": "Optional", - "type": { - "MapType": { - "key": "ReferendumIndex", - "value": "ReferendumInfo" - } - }, - "fallback": "0x00", - "documentation": [ - " Information concerning any given referendum." - ] - }, - { - "name": "DispatchQueue", - "modifier": "Default", - "type": { - "MapType": { - "key": "BlockNumber", - "value": "Vec>" - } - }, - "fallback": "0x00", - "documentation": [ - " Queue of successful referenda to be dispatched." - ] - }, - { - "name": "Bondage", - "modifier": "Default", - "type": { - "MapType": { - "key": "AccountId", - "value": "BlockNumber" - } - }, - "fallback": "0x0000000000000000", - "documentation": [ - " The block at which the `who`'s funds become liquid." - ] - }, - { - "name": "VotersFor", - "modifier": "Default", - "type": { - "MapType": { - "key": "ReferendumIndex", - "value": "Vec" - } - }, - "fallback": "0x00", - "documentation": [ - " Get the voters for the current proposal." - ] - }, - { - "name": "VoteOf", - "modifier": "Default", - "type": { - "MapType": { - "key": "(ReferendumIndex,AccountId)", - "value": "Vote" - } - }, - "fallback": "0x00", - "documentation": [ - " Get the vote in a given referendum of a particular voter. The result is meaningful only if `voters_for` includes the", - " voter when called with the referendum (you'll get the default `Vote` value otherwise). If you don't want to check", - " `voters_for`, then you can also check for simple existence with `VoteOf::exists` first." - ] - } - ] - } - }, - { - "prefix": "council", - "module": { - "name": "Module", - "call": { - "name": "Call", - "functions": [ - { - "id": 0, - "name": "set_approvals", - "arguments": [ - { - "name": "votes", - "type": "Vec" - }, - { - "name": "index", - "type": "Compact" - } - ], - "documentation": [ - " Set candidate approvals. Approval slots stay valid as long as candidates in those slots", - " are registered." - ] - }, - { - "id": 1, - "name": "reap_inactive_voter", - "arguments": [ - { - "name": "reporter_index", - "type": "Compact" - }, - { - "name": "who", - "type": "Address" - }, - { - "name": "who_index", - "type": "Compact" - }, - { - "name": "assumed_vote_index", - "type": "Compact" - } - ], - "documentation": [ - " Remove a voter. For it not to be a bond-consuming no-op, all approved candidate indices", - " must now be either unregistered or registered to a candidate that registered the slot after", - " the voter gave their last approval set.", - "", - " May be called by anyone. Returns the voter deposit to `signed`." - ] - }, - { - "id": 2, - "name": "retract_voter", - "arguments": [ - { - "name": "index", - "type": "Compact" - } - ], - "documentation": [ - " Remove a voter. All votes are cancelled and the voter deposit is returned." - ] - }, - { - "id": 3, - "name": "submit_candidacy", - "arguments": [ - { - "name": "slot", - "type": "Compact" - } - ], - "documentation": [ - " Submit oneself for candidacy.", - "", - " Account must have enough transferrable funds in it to pay the bond." - ] - }, - { - "id": 4, - "name": "present_winner", - "arguments": [ - { - "name": "candidate", - "type": "Address" - }, - { - "name": "total", - "type": "Compact" - }, - { - "name": "index", - "type": "Compact" - } - ], - "documentation": [ - " Claim that `signed` is one of the top Self::carry_count() + current_vote().1 candidates.", - " Only works if the `block_number >= current_vote().0` and `< current_vote().0 + presentation_duration()``", - " `signed` should have at least" - ] - }, - { - "id": 5, - "name": "set_desired_seats", - "arguments": [ - { - "name": "count", - "type": "Compact" - } - ], - "documentation": [ - " Set the desired member count; if lower than the current count, then seats will not be up", - " election when they expire. If more, then a new vote will be started if one is not already", - " in progress." - ] - }, - { - "id": 6, - "name": "remove_member", - "arguments": [ - { - "name": "who", - "type": "Address" - } - ], - "documentation": [ - " Remove a particular member. A tally will happen instantly (if not already in a presentation", - " period) to fill the seat if removal means that the desired members are not met.", - " This is effective immediately." - ] - }, - { - "id": 7, - "name": "set_presentation_duration", - "arguments": [ - { - "name": "count", - "type": "Compact" - } - ], - "documentation": [ - " Set the presentation duration. If there is currently a vote being presented for, will", - " invoke `finalise_vote`." - ] - }, - { - "id": 8, - "name": "set_term_duration", - "arguments": [ - { - "name": "count", - "type": "Compact" - } - ], - "documentation": [ - " Set the presentation duration. If there is current a vote being presented for, will", - " invoke `finalise_vote`." - ] - } - ] - } - }, - "storage": { - "prefix": "Council", - "functions": [ - { - "name": "CandidacyBond", - "modifier": "Default", - "type": { - "PlainType": "Balance" - }, - "fallback": "0x09000000000000000000000000000000", - "documentation": [ - " How much should be locked up in order to submit one's candidacy." - ] - }, - { - "name": "VotingBond", - "modifier": "Default", - "type": { - "PlainType": "Balance" - }, - "fallback": "0x00000000000000000000000000000000", - "documentation": [ - " How much should be locked up in order to be able to submit votes." - ] - }, - { - "name": "PresentSlashPerVoter", - "modifier": "Default", - "type": { - "PlainType": "Balance" - }, - "fallback": "0x01000000000000000000000000000000", - "documentation": [ - " The punishment, per voter, if you provide an invalid presentation." - ] - }, - { - "name": "CarryCount", - "modifier": "Default", - "type": { - "PlainType": "u32" - }, - "fallback": "0x02000000", - "documentation": [ - " How many runners-up should have their approvals persist until the next vote." - ] - }, - { - "name": "PresentationDuration", - "modifier": "Default", - "type": { - "PlainType": "BlockNumber" - }, - "fallback": "0xe803000000000000", - "documentation": [ - " How long to give each top candidate to present themselves after the vote ends." - ] - }, - { - "name": "InactiveGracePeriod", - "modifier": "Default", - "type": { - "PlainType": "VoteIndex" - }, - "fallback": "0x01000000", - "documentation": [ - " How many vote indexes need to go by after a target voter's last vote before they can be reaped if their", - " approvals are moot." - ] - }, - { - "name": "VotingPeriod", - "modifier": "Default", - "type": { - "PlainType": "BlockNumber" - }, - "fallback": "0xe803000000000000", - "documentation": [ - " How often (in blocks) to check for new votes." - ] - }, - { - "name": "TermDuration", - "modifier": "Default", - "type": { - "PlainType": "BlockNumber" - }, - "fallback": "0x0500000000000000", - "documentation": [ - " How long each position is active for." - ] - }, - { - "name": "DesiredSeats", - "modifier": "Default", - "type": { - "PlainType": "u32" - }, - "fallback": "0x00000000", - "documentation": [ - " Number of accounts that should be sitting on the council." - ] - }, - { - "name": "ActiveCouncil", - "modifier": "Default", - "type": { - "PlainType": "Vec<(AccountId,BlockNumber)>" - }, - "fallback": "0x00", - "documentation": [ - " The current council. When there's a vote going on, this should still be used for executive", - " matters. The block number (second element in the tuple) is the block that their position is", - " active until (calculated by the sum of the block number when the council member was elected", - " and their term duration)." - ] - }, - { - "name": "VoteCount", - "modifier": "Default", - "type": { - "PlainType": "VoteIndex" - }, - "fallback": "0x00000000", - "documentation": [ - " The total number of votes that have happened or are in progress." - ] - }, - { - "name": "ApprovalsOf", - "modifier": "Default", - "type": { - "MapType": { - "key": "AccountId", - "value": "Vec" - } - }, - "fallback": "0x00", - "documentation": [ - " A list of votes for each voter, respecting the last cleared vote index that this voter was", - " last active at." - ] - }, - { - "name": "RegisterInfoOf", - "modifier": "Optional", - "type": { - "MapType": { - "key": "AccountId", - "value": "(VoteIndex,u32)" - } - }, - "fallback": "0x00", - "documentation": [ - " The vote index and list slot that the candidate `who` was registered or `None` if they are not", - " currently registered." - ] - }, - { - "name": "LastActiveOf", - "modifier": "Optional", - "type": { - "MapType": { - "key": "AccountId", - "value": "VoteIndex" - } - }, - "fallback": "0x00", - "documentation": [ - " The last cleared vote index that this voter was last active at." - ] - }, - { - "name": "Voters", - "modifier": "Default", - "type": { - "PlainType": "Vec" - }, - "fallback": "0x00", - "documentation": [ - " The present voter list." - ] - }, - { - "name": "Candidates", - "modifier": "Default", - "type": { - "PlainType": "Vec" - }, - "fallback": "0x00", - "documentation": [ - " The present candidate list." - ] - }, - { - "name": "CandidateCount", - "modifier": "Default", - "type": { - "PlainType": "u32" - }, - "fallback": "0x00000000", - "documentation": [] - }, - { - "name": "NextFinalise", - "modifier": "Optional", - "type": { - "PlainType": "(BlockNumber,u32,Vec)" - }, - "fallback": "0x00", - "documentation": [ - " The accounts holding the seats that will become free on the next tally." - ] - }, - { - "name": "SnapshotedStakes", - "modifier": "Default", - "type": { - "PlainType": "Vec" - }, - "fallback": "0x00", - "documentation": [ - " The stakes as they were at the point that the vote ended." - ] - }, - { - "name": "Leaderboard", - "modifier": "Optional", - "type": { - "PlainType": "Vec<(Balance,AccountId)>" - }, - "fallback": "0x00", - "documentation": [ - " Get the leaderboard if we;re in the presentation phase." - ] - } - ] - } - }, - { - "prefix": "council_voting", - "module": { - "name": "Module", - "call": { - "name": "Call", - "functions": [ - { - "id": 0, - "name": "propose", - "arguments": [ - { - "name": "proposal", - "type": "Proposal" - } - ], - "documentation": [] - }, - { - "id": 1, - "name": "vote", - "arguments": [ - { - "name": "proposal", - "type": "Hash" - }, - { - "name": "approve", - "type": "bool" - } - ], - "documentation": [] - }, - { - "id": 2, - "name": "veto", - "arguments": [ - { - "name": "proposal_hash", - "type": "Hash" - } - ], - "documentation": [] - }, - { - "id": 3, - "name": "set_cooloff_period", - "arguments": [ - { - "name": "blocks", - "type": "Compact" - } - ], - "documentation": [] - }, - { - "id": 4, - "name": "set_voting_period", - "arguments": [ - { - "name": "blocks", - "type": "Compact" - } - ], - "documentation": [] - } - ] - } - }, - "storage": { - "prefix": "CouncilVoting", - "functions": [ - { - "name": "CooloffPeriod", - "modifier": "Default", - "type": { - "PlainType": "BlockNumber" - }, - "fallback": "0xe803000000000000", - "documentation": [] - }, - { - "name": "VotingPeriod", - "modifier": "Default", - "type": { - "PlainType": "BlockNumber" - }, - "fallback": "0x0300000000000000", - "documentation": [] - }, - { - "name": "EnactDelayPeriod", - "modifier": "Default", - "type": { - "PlainType": "BlockNumber" - }, - "fallback": "0x0000000000000000", - "documentation": [ - " Number of blocks by which to delay enactment of successful, non-unanimous-council-instigated referendum proposals." - ] - }, - { - "name": "Proposals", - "modifier": "Default", - "type": { - "PlainType": "Vec<(BlockNumber,Hash)>" - }, - "fallback": "0x00", - "documentation": [] - }, - { - "name": "ProposalOf", - "modifier": "Optional", - "type": { - "MapType": { - "key": "Hash", - "value": "Proposal" - } - }, - "fallback": "0x00", - "documentation": [] - }, - { - "name": "ProposalVoters", - "modifier": "Default", - "type": { - "MapType": { - "key": "Hash", - "value": "Vec" - } - }, - "fallback": "0x00", - "documentation": [] - }, - { - "name": "CouncilVoteOf", - "modifier": "Optional", - "type": { - "MapType": { - "key": "(Hash,AccountId)", - "value": "bool" - } - }, - "fallback": "0x00", - "documentation": [] - }, - { - "name": "VetoedProposal", - "modifier": "Optional", - "type": { - "MapType": { - "key": "Hash", - "value": "(BlockNumber,Vec)" - } - }, - "fallback": "0x00", - "documentation": [] - } - ] - } - }, - { - "prefix": "council_motions", - "module": { - "name": "Module", - "call": { - "name": "Call", - "functions": [ - { - "id": 0, - "name": "propose", - "arguments": [ - { - "name": "threshold", - "type": "Compact" - }, - { - "name": "proposal", - "type": "Proposal" - } - ], - "documentation": [] - }, - { - "id": 1, - "name": "vote", - "arguments": [ - { - "name": "proposal", - "type": "Hash" - }, - { - "name": "index", - "type": "Compact" - }, - { - "name": "approve", - "type": "bool" - } - ], - "documentation": [] - } - ] - } - }, - "storage": { - "prefix": "CouncilMotions", - "functions": [ - { - "name": "Proposals", - "modifier": "Default", - "type": { - "PlainType": "Vec" - }, - "fallback": "0x00", - "documentation": [ - " The (hashes of) the active proposals." - ] - }, - { - "name": "ProposalOf", - "modifier": "Optional", - "type": { - "MapType": { - "key": "Hash", - "value": "Proposal" - } - }, - "fallback": "0x00", - "documentation": [ - " Actual proposal for a given hash, if it's current." - ] - }, - { - "name": "Voting", - "modifier": "Optional", - "type": { - "MapType": { - "key": "Hash", - "value": "(ProposalIndex,u32,Vec,Vec)" - } - }, - "fallback": "0x00", - "documentation": [ - " Votes for a given proposal: (required_yes_votes, yes_voters, no_voters)." - ] - }, - { - "name": "ProposalCount", - "modifier": "Default", - "type": { - "PlainType": "u32" - }, - "fallback": "0x00000000", - "documentation": [ - " Proposals so far." - ] - } - ] - } - }, - { - "prefix": "grandpa", - "module": { - "name": "Module", - "call": { - "name": "Call", - "functions": [ - { - "id": 0, - "name": "report_misbehavior", - "arguments": [ - { - "name": "_report", - "type": "Bytes" - } - ], - "documentation": [ - " Report some misbehaviour." - ] - } - ] - } - }, - "storage": { - "prefix": "GrandpaFinality", - "functions": [ - { - "name": "PendingChange", - "modifier": "Optional", - "type": { - "PlainType": "StoredPendingChange" - }, - "fallback": "0x00", - "documentation": [] - } - ] - } - }, - { - "prefix": "treasury", - "module": { - "name": "Module", - "call": { - "name": "Call", - "functions": [ - { - "id": 0, - "name": "propose_spend", - "arguments": [ - { - "name": "value", - "type": "Compact" - }, - { - "name": "beneficiary", - "type": "Address" - } - ], - "documentation": [ - " Put forward a suggestion for spending. A deposit proportional to the value", - " is reserved and slashed if the proposal is rejected. It is returned once the", - " proposal is awarded." - ] - }, - { - "id": 1, - "name": "set_pot", - "arguments": [ - { - "name": "new_pot", - "type": "Compact" - } - ], - "documentation": [ - " Set the balance of funds available to spend." - ] - }, - { - "id": 2, - "name": "configure", - "arguments": [ - { - "name": "proposal_bond", - "type": "Permill" - }, - { - "name": "proposal_bond_minimum", - "type": "Compact" - }, - { - "name": "spend_period", - "type": "Compact" - }, - { - "name": "burn", - "type": "Permill" - } - ], - "documentation": [ - " (Re-)configure this module." - ] - }, - { - "id": 3, - "name": "reject_proposal", - "arguments": [ - { - "name": "proposal_id", - "type": "Compact" - } - ], - "documentation": [ - " Reject a proposed spend. The original deposit will be slashed." - ] - }, - { - "id": 4, - "name": "approve_proposal", - "arguments": [ - { - "name": "proposal_id", - "type": "Compact" - } - ], - "documentation": [ - " Approve a proposal. At a later time, the proposal will be allocated to the beneficiary", - " and the original deposit will be returned." - ] - } - ] - } - }, - "storage": { - "prefix": "Treasury", - "functions": [ - { - "name": "ProposalBond", - "modifier": "Default", - "type": { - "PlainType": "Permill" - }, - "fallback": "0x00000000", - "documentation": [ - " Proportion of funds that should be bonded in order to place a proposal. An accepted", - " proposal gets these back. A rejected proposal doesn't." - ] - }, - { - "name": "ProposalBondMinimum", - "modifier": "Default", - "type": { - "PlainType": "Balance" - }, - "fallback": "0x00000000000000000000000000000000", - "documentation": [ - " Minimum amount of funds that should be placed in a deposit for making a proposal." - ] - }, - { - "name": "SpendPeriod", - "modifier": "Default", - "type": { - "PlainType": "BlockNumber" - }, - "fallback": "0x0100000000000000", - "documentation": [ - " Period between successive spends." - ] - }, - { - "name": "Burn", - "modifier": "Default", - "type": { - "PlainType": "Permill" - }, - "fallback": "0x00000000", - "documentation": [ - " Percentage of spare funds (if any) that are burnt per spend period." - ] - }, - { - "name": "Pot", - "modifier": "Default", - "type": { - "PlainType": "Balance" - }, - "fallback": "0x00000000000000000000000000000000", - "documentation": [ - " Total funds available to this module for spending." - ] - }, - { - "name": "ProposalCount", - "modifier": "Default", - "type": { - "PlainType": "ProposalIndex" - }, - "fallback": "0x00000000", - "documentation": [ - " Number of proposals that have been made." - ] - }, - { - "name": "Proposals", - "modifier": "Optional", - "type": { - "MapType": { - "key": "ProposalIndex", - "value": "Proposal" - } - }, - "fallback": "0x00", - "documentation": [ - " Proposals that have been made." - ] - }, - { - "name": "Approvals", - "modifier": "Default", - "type": { - "PlainType": "Vec" - }, - "fallback": "0x00", - "documentation": [ - " Proposal indices that have been approved but not yet awarded." - ] - } - ] - } - }, - { - "prefix": "contract", - "module": { - "name": "Module", - "call": { - "name": "Call", - "functions": [ - { - "id": 0, - "name": "call", - "arguments": [ - { - "name": "dest", - "type": "Address" - }, - { - "name": "value", - "type": "Compact" - }, - { - "name": "gas_limit", - "type": "Compact" - }, - { - "name": "data", - "type": "Bytes" - } - ], - "documentation": [ - " Make a call to a specified account, optionally transferring some balance.", - " Make a call to a specified account, optionally transferring some balance." - ] - }, - { - "id": 1, - "name": "create", - "arguments": [ - { - "name": "endowment", - "type": "Compact" - }, - { - "name": "gas_limit", - "type": "Compact" - }, - { - "name": "ctor_code", - "type": "Bytes" - }, - { - "name": "data", - "type": "Bytes" - } - ], - "documentation": [ - " Create a new contract, optionally transfering some balance to the created account.", - "", - " Creation is executed as follows:", - "", - " - the destination address is computed based on the sender and hash of the code.", - " - account is created at the computed address.", - " - the `ctor_code` is executed in the context of the newly created account. Buffer returned", - " after the execution is saved as the `code` of the account. That code will be invoked", - " upon any message received by this account." - ] - } - ] - } - }, - "storage": null - }, - { - "prefix": "sudo", - "module": { - "name": "Module", - "call": { - "name": "Call", - "functions": [ - { - "id": 0, - "name": "sudo", - "arguments": [ - { - "name": "proposal", - "type": "Proposal" - } - ], - "documentation": [] - }, - { - "id": 1, - "name": "set_key", - "arguments": [ - { - "name": "new", - "type": "Address" - } - ], - "documentation": [] - } - ] - } - }, - "storage": { - "prefix": "Sudo", - "functions": [ - { - "name": "Key", - "modifier": "Default", - "type": { - "PlainType": "AccountId" - }, - "fallback": "0x0000000000000000000000000000000000000000000000000000000000000000", - "documentation": [] - } - ] - } - } - ], - "outerDispatch": { - "name": "Call", - "calls": [ - { - "name": "Timestamp", - "prefix": "timestamp", - "index": 0 - }, - { - "name": "Consensus", - "prefix": "consensus", - "index": 1 - }, - { - "name": "Indices", - "prefix": "indices", - "index": 2 - }, - { - "name": "Balances", - "prefix": "balances", - "index": 3 - }, - { - "name": "Session", - "prefix": "session", - "index": 4 - }, - { - "name": "Staking", - "prefix": "staking", - "index": 5 - }, - { - "name": "Democracy", - "prefix": "democracy", - "index": 6 - }, - { - "name": "Council", - "prefix": "council", - "index": 7 - }, - { - "name": "CouncilVoting", - "prefix": "council_voting", - "index": 8 - }, - { - "name": "CouncilMotions", - "prefix": "council_motions", - "index": 9 - }, - { - "name": "Grandpa", - "prefix": "grandpa", - "index": 10 - }, - { - "name": "Treasury", - "prefix": "treasury", - "index": 11 - }, - { - "name": "Contract", - "prefix": "contract", - "index": 12 - }, - { - "name": "Sudo", - "prefix": "sudo", - "index": 13 - } - ] - } -} diff --git a/packages/types/src/Metadata/v1/latest.substrate.v0.json b/packages/types/src/Metadata/v0/latest.substrate.v0.json similarity index 85% rename from packages/types/src/Metadata/v1/latest.substrate.v0.json rename to packages/types/src/Metadata/v0/latest.substrate.v0.json index 955fb67d86..cbaf80271b 100644 --- a/packages/types/src/Metadata/v1/latest.substrate.v0.json +++ b/packages/types/src/Metadata/v0/latest.substrate.v0.json @@ -7,14 +7,14 @@ [ { "name": "ExtrinsicSuccess", - "arguments": [], + "args": [], "documentation": [ " An extrinsic completed successfully." ] }, { "name": "ExtrinsicFailed", - "arguments": [], + "args": [], "documentation": [ " An extrinsic failed." ] @@ -26,7 +26,7 @@ [ { "name": "NewAccountIndex", - "arguments": [ + "args": [ "AccountId", "AccountIndex" ], @@ -41,7 +41,7 @@ [ { "name": "NewAccount", - "arguments": [ + "args": [ "AccountId", "Balance" ], @@ -51,7 +51,7 @@ }, { "name": "ReapedAccount", - "arguments": [ + "args": [ "AccountId" ], "documentation": [ @@ -60,7 +60,7 @@ }, { "name": "Transfer", - "arguments": [ + "args": [ "AccountId", "AccountId", "Balance", @@ -77,7 +77,7 @@ [ { "name": "NewSession", - "arguments": [ + "args": [ "BlockNumber" ], "documentation": [ @@ -92,7 +92,7 @@ [ { "name": "Reward", - "arguments": [ + "args": [ "Balance" ], "documentation": [ @@ -101,7 +101,7 @@ }, { "name": "OfflineWarning", - "arguments": [ + "args": [ "AccountId", "u32" ], @@ -112,7 +112,7 @@ }, { "name": "OfflineSlash", - "arguments": [ + "args": [ "AccountId", "Balance" ], @@ -127,7 +127,7 @@ [ { "name": "Tabled", - "arguments": [ + "args": [ "PropIndex", "Balance", "Vec" @@ -136,7 +136,7 @@ }, { "name": "Started", - "arguments": [ + "args": [ "ReferendumIndex", "VoteThreshold" ], @@ -144,28 +144,28 @@ }, { "name": "Passed", - "arguments": [ + "args": [ "ReferendumIndex" ], "documentation": [] }, { "name": "NotPassed", - "arguments": [ + "args": [ "ReferendumIndex" ], "documentation": [] }, { "name": "Cancelled", - "arguments": [ + "args": [ "ReferendumIndex" ], "documentation": [] }, { "name": "Executed", - "arguments": [ + "args": [ "ReferendumIndex", "bool" ], @@ -178,7 +178,7 @@ [ { "name": "VoterReaped", - "arguments": [ + "args": [ "AccountId", "AccountId" ], @@ -188,7 +188,7 @@ }, { "name": "BadReaperSlashed", - "arguments": [ + "args": [ "AccountId" ], "documentation": [ @@ -197,7 +197,7 @@ }, { "name": "TallyStarted", - "arguments": [ + "args": [ "u32" ], "documentation": [ @@ -206,7 +206,7 @@ }, { "name": "TallyFinalised", - "arguments": [ + "args": [ "Vec", "Vec" ], @@ -221,7 +221,7 @@ [ { "name": "TallyCancelation", - "arguments": [ + "args": [ "Hash", "u32", "u32", @@ -234,7 +234,7 @@ }, { "name": "TallyReferendum", - "arguments": [ + "args": [ "Hash", "u32", "u32", @@ -252,7 +252,7 @@ [ { "name": "Proposed", - "arguments": [ + "args": [ "AccountId", "ProposalIndex", "Hash", @@ -264,7 +264,7 @@ }, { "name": "Voted", - "arguments": [ + "args": [ "AccountId", "Hash", "bool", @@ -278,7 +278,7 @@ }, { "name": "Approved", - "arguments": [ + "args": [ "Hash" ], "documentation": [ @@ -287,7 +287,7 @@ }, { "name": "Disapproved", - "arguments": [ + "args": [ "Hash" ], "documentation": [ @@ -296,7 +296,7 @@ }, { "name": "Executed", - "arguments": [ + "args": [ "Hash", "bool" ], @@ -311,7 +311,7 @@ [ { "name": "NewAuthorities", - "arguments": [ + "args": [ "Vec<(SessionKey,u64)>" ], "documentation": [ @@ -325,7 +325,7 @@ [ { "name": "Proposed", - "arguments": [ + "args": [ "ProposalIndex" ], "documentation": [ @@ -334,7 +334,7 @@ }, { "name": "Spending", - "arguments": [ + "args": [ "Balance" ], "documentation": [ @@ -343,7 +343,7 @@ }, { "name": "Awarded", - "arguments": [ + "args": [ "ProposalIndex", "Balance", "AccountId" @@ -354,7 +354,7 @@ }, { "name": "Burnt", - "arguments": [ + "args": [ "Balance" ], "documentation": [ @@ -363,7 +363,7 @@ }, { "name": "Rollover", - "arguments": [ + "args": [ "Balance" ], "documentation": [ @@ -377,7 +377,7 @@ [ { "name": "Transfer", - "arguments": [ + "args": [ "AccountId", "AccountId", "Balance" @@ -387,43 +387,14 @@ ] }, { - "name": "Instantiated", - "arguments": [ + "name": "Created", + "args": [ "AccountId", "AccountId" ], "documentation": [ " Contract deployed by address at the specified address." ] - }, - { - "name": "CodeStored", - "arguments": [ - "Hash" - ], - "documentation": [ - " Code with the specified hash has been stored." - ] - }, - { - "name": "ScheduleUpdated", - "arguments": [ - "u32" - ], - "documentation": [ - " Triggered when the current schedule is updated." - ] - }, - { - "name": "Dispatched", - "arguments": [ - "AccountId", - "bool" - ], - "documentation": [ - " A call was dispatched from the given account. The bool signals whether it was", - " successful execution or not." - ] } ] ], @@ -432,7 +403,7 @@ [ { "name": "Sudid", - "arguments": [ + "args": [ "bool" ], "documentation": [ @@ -441,7 +412,7 @@ }, { "name": "KeyChanged", - "arguments": [ + "args": [ "AccountId" ], "documentation": [ @@ -467,103 +438,103 @@ "functions": [ { "name": "AccountNonce", - "modifier": 0, + "modifier": "Default", "type": { "MapType": { "key": "AccountId", "value": "Index" } }, - "default": "0x0000000000000000", + "fallback": "0x0000000000000000", "documentation": [] }, { "name": "ExtrinsicCount", - "modifier": 0, + "modifier": "Optional", "type": { "PlainType": "u32" }, - "default": "0x00", + "fallback": "0x00", "documentation": [] }, { "name": "BlockHash", - "modifier": 0, + "modifier": "Default", "type": { "MapType": { "key": "BlockNumber", "value": "Hash" } }, - "default": "0x0000000000000000000000000000000000000000000000000000000000000000", + "fallback": "0x0000000000000000000000000000000000000000000000000000000000000000", "documentation": [] }, { "name": "ExtrinsicData", - "modifier": 0, + "modifier": "Default", "type": { "MapType": { "key": "u32", "value": "Bytes" } }, - "default": "0x00", + "fallback": "0x00", "documentation": [] }, { "name": "RandomSeed", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "Hash" }, - "default": "0x0000000000000000000000000000000000000000000000000000000000000000", + "fallback": "0x0000000000000000000000000000000000000000000000000000000000000000", "documentation": [] }, { "name": "Number", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "BlockNumber" }, - "default": "0x0000000000000000", + "fallback": "0x0000000000000000", "documentation": [ " The current block number being processed. Set by `execute_block`." ] }, { "name": "ParentHash", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "Hash" }, - "default": "0x0000000000000000000000000000000000000000000000000000000000000000", + "fallback": "0x0000000000000000000000000000000000000000000000000000000000000000", "documentation": [] }, { "name": "ExtrinsicsRoot", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "Hash" }, - "default": "0x0000000000000000000000000000000000000000000000000000000000000000", + "fallback": "0x0000000000000000000000000000000000000000000000000000000000000000", "documentation": [] }, { "name": "Digest", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "Digest" }, - "default": "0x00", + "fallback": "0x00", "documentation": [] }, { "name": "Events", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "Vec" }, - "default": "0x00", + "fallback": "0x00", "documentation": [] } ] @@ -590,7 +561,7 @@ { "id": 0, "name": "set", - "arguments": [ + "args": [ { "name": "now", "type": "Compact" @@ -615,33 +586,33 @@ "functions": [ { "name": "Now", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "Moment" }, - "default": "0x0000000000000000", + "fallback": "0x0000000000000000", "documentation": [ " Current time for the current block." ] }, { "name": "BlockPeriod", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "Moment" }, - "default": "0x0500000000000000", + "fallback": "0x0500000000000000", "documentation": [ " The minimum (and advised) period between blocks." ] }, { "name": "DidUpdate", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "bool" }, - "default": "0x00", + "fallback": "0x00", "documentation": [ " Did the timestamp get updated in this block?" ] @@ -659,7 +630,7 @@ { "id": 0, "name": "report_misbehavior", - "arguments": [ + "args": [ { "name": "_report", "type": "Bytes" @@ -672,7 +643,7 @@ { "id": 1, "name": "note_offline", - "arguments": [ + "args": [ { "name": "offline", "type": "InherentOfflineReport" @@ -685,7 +656,7 @@ { "id": 2, "name": "remark", - "arguments": [ + "args": [ { "name": "_remark", "type": "Bytes" @@ -698,7 +669,7 @@ { "id": 3, "name": "set_heap_pages", - "arguments": [ + "args": [ { "name": "pages", "type": "u64" @@ -711,7 +682,7 @@ { "id": 4, "name": "set_code", - "arguments": [ + "args": [ { "name": "new", "type": "Bytes" @@ -724,7 +695,7 @@ { "id": 5, "name": "set_storage", - "arguments": [ + "args": [ { "name": "items", "type": "Vec" @@ -742,11 +713,11 @@ "functions": [ { "name": "OriginalAuthorities", - "modifier": 0, + "modifier": "Optional", "type": { "PlainType": "Vec" }, - "default": "0x00", + "fallback": "0x00", "documentation": [] } ] @@ -766,25 +737,25 @@ "functions": [ { "name": "NextEnumSet", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "AccountIndex" }, - "default": "0x00000000", + "fallback": "0x00000000", "documentation": [ " The next free enumeration set." ] }, { "name": "EnumSet", - "modifier": 0, + "modifier": "Default", "type": { "MapType": { "key": "AccountIndex", "value": "Vec" } }, - "default": "0x00", + "fallback": "0x00", "documentation": [ " The enumeration sets." ] @@ -802,7 +773,7 @@ { "id": 0, "name": "transfer", - "arguments": [ + "args": [ { "name": "dest", "type": "Address" @@ -819,7 +790,7 @@ { "id": 1, "name": "set_balance", - "arguments": [ + "args": [ { "name": "who", "type": "Address" @@ -845,58 +816,58 @@ "functions": [ { "name": "TotalIssuance", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "Balance" }, - "default": "0x00000000000000000000000000000000", + "fallback": "0x00000000000000000000000000000000", "documentation": [ " The total amount of stake on the system." ] }, { "name": "ExistentialDeposit", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "Balance" }, - "default": "0x00000000000000000000000000000000", + "fallback": "0x00000000000000000000000000000000", "documentation": [ " The minimum amount allowed to keep an account open." ] }, { "name": "TransferFee", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "Balance" }, - "default": "0x00000000000000000000000000000000", + "fallback": "0x00000000000000000000000000000000", "documentation": [ " The fee required to make a transfer." ] }, { "name": "CreationFee", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "Balance" }, - "default": "0x00000000000000000000000000000000", + "fallback": "0x00000000000000000000000000000000", "documentation": [ " The fee required to create an account. At least as big as ReclaimRebate." ] }, { "name": "FreeBalance", - "modifier": 0, + "modifier": "Default", "type": { "MapType": { "key": "AccountId", "value": "Balance" } }, - "default": "0x00000000000000000000000000000000", + "fallback": "0x00000000000000000000000000000000", "documentation": [ " The 'free' balance of a given account.", "", @@ -913,14 +884,14 @@ }, { "name": "ReservedBalance", - "modifier": 0, + "modifier": "Default", "type": { "MapType": { "key": "AccountId", "value": "Balance" } }, - "default": "0x00000000000000000000000000000000", + "fallback": "0x00000000000000000000000000000000", "documentation": [ " The amount of the balance of a given account that is externally reserved; this can still get", " slashed, but gets slashed last of all.", @@ -938,22 +909,22 @@ }, { "name": "TransactionBaseFee", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "Balance" }, - "default": "0x00000000000000000000000000000000", + "fallback": "0x00000000000000000000000000000000", "documentation": [ " The fee to be paid for making a transaction; the base." ] }, { "name": "TransactionByteFee", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "Balance" }, - "default": "0x00000000000000000000000000000000", + "fallback": "0x00000000000000000000000000000000", "documentation": [ " The fee to be paid for making a transaction; the per-byte portion." ] @@ -971,7 +942,7 @@ { "id": 0, "name": "set_key", - "arguments": [ + "args": [ { "name": "key", "type": "SessionKey" @@ -985,7 +956,7 @@ { "id": 1, "name": "set_length", - "arguments": [ + "args": [ { "name": "new", "type": "Compact" @@ -998,7 +969,7 @@ { "id": 2, "name": "force_new_session", - "arguments": [ + "args": [ { "name": "apply_rewards", "type": "bool" @@ -1016,55 +987,55 @@ "functions": [ { "name": "Validators", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "Vec" }, - "default": "0x00", + "fallback": "0x00", "documentation": [ " The current set of validators." ] }, { "name": "SessionLength", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "BlockNumber" }, - "default": "0xe803000000000000", + "fallback": "0xe803000000000000", "documentation": [ " Current length of the session." ] }, { "name": "CurrentIndex", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "BlockNumber" }, - "default": "0x0000000000000000", + "fallback": "0x0000000000000000", "documentation": [ " Current index of the session." ] }, { "name": "CurrentStart", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "Moment" }, - "default": "0x0000000000000000", + "fallback": "0x0000000000000000", "documentation": [ " Timestamp when current session started." ] }, { "name": "ForcingNewSession", - "modifier": 0, + "modifier": "Optional", "type": { "PlainType": "bool" }, - "default": "0x00", + "fallback": "0x00", "documentation": [ " New session is being forced is this entry exists; in which case, the boolean value is whether", " the new session should be considered a normal rotation (rewardable) or exceptional (slashable)." @@ -1072,36 +1043,36 @@ }, { "name": "LastLengthChange", - "modifier": 0, + "modifier": "Optional", "type": { "PlainType": "BlockNumber" }, - "default": "0x00", + "fallback": "0x00", "documentation": [ " Block at which the session length last changed." ] }, { "name": "NextKeyFor", - "modifier": 0, + "modifier": "Optional", "type": { "MapType": { "key": "AccountId", "value": "SessionKey" } }, - "default": "0x00", + "fallback": "0x00", "documentation": [ " The next key for a given validator." ] }, { "name": "NextSessionLength", - "modifier": 0, + "modifier": "Optional", "type": { "PlainType": "BlockNumber" }, - "default": "0x00", + "fallback": "0x00", "documentation": [ " The next session length." ] @@ -1119,7 +1090,7 @@ { "id": 0, "name": "stake", - "arguments": [], + "args": [], "documentation": [ " Declare the desire to stake for the transactor.", "", @@ -1129,7 +1100,7 @@ { "id": 1, "name": "unstake", - "arguments": [ + "args": [ { "name": "intentions_index", "type": "Compact" @@ -1144,7 +1115,7 @@ { "id": 2, "name": "nominate", - "arguments": [ + "args": [ { "name": "target", "type": "Address" @@ -1155,7 +1126,7 @@ { "id": 3, "name": "unnominate", - "arguments": [ + "args": [ { "name": "target_index", "type": "Compact" @@ -1169,7 +1140,7 @@ { "id": 4, "name": "register_preferences", - "arguments": [ + "args": [ { "name": "intentions_index", "type": "Compact" @@ -1188,7 +1159,7 @@ { "id": 5, "name": "set_sessions_per_era", - "arguments": [ + "args": [ { "name": "new", "type": "Compact" @@ -1201,7 +1172,7 @@ { "id": 6, "name": "set_bonding_duration", - "arguments": [ + "args": [ { "name": "new", "type": "Compact" @@ -1214,7 +1185,7 @@ { "id": 7, "name": "set_validator_count", - "arguments": [ + "args": [ { "name": "new", "type": "Compact" @@ -1227,7 +1198,7 @@ { "id": 8, "name": "force_new_era", - "arguments": [ + "args": [ { "name": "apply_rewards", "type": "bool" @@ -1241,7 +1212,7 @@ { "id": 9, "name": "set_offline_slash_grace", - "arguments": [ + "args": [ { "name": "new", "type": "Compact" @@ -1254,7 +1225,7 @@ { "id": 10, "name": "set_invulnerables", - "arguments": [ + "args": [ { "name": "validators", "type": "Vec" @@ -1272,88 +1243,88 @@ "functions": [ { "name": "ValidatorCount", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "u32" }, - "default": "0x00000000", + "fallback": "0x00000000", "documentation": [ " The ideal number of staking participants." ] }, { "name": "MinimumValidatorCount", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "u32" }, - "default": "0x04000000", + "fallback": "0x04000000", "documentation": [ " Minimum number of staking participants before emergency conditions are imposed." ] }, { "name": "SessionsPerEra", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "BlockNumber" }, - "default": "0xe803000000000000", + "fallback": "0xe803000000000000", "documentation": [ " The length of a staking era in sessions." ] }, { "name": "SessionReward", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "Perbill" }, - "default": "0x3c000000", + "fallback": "0x3c000000", "documentation": [ " Maximum reward, per validator, that is provided per acceptable session." ] }, { "name": "OfflineSlash", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "Perbill" }, - "default": "0x40420f00", + "fallback": "0x40420f00", "documentation": [ " Slash, per validator that is taken for the first time they are found to be offline." ] }, { "name": "OfflineSlashGrace", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "u32" }, - "default": "0x00000000", + "fallback": "0x00000000", "documentation": [ " Number of instances of offline reports before slashing begins for validators." ] }, { "name": "BondingDuration", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "BlockNumber" }, - "default": "0xe803000000000000", + "fallback": "0xe803000000000000", "documentation": [ " The length of the bonding duration in blocks." ] }, { "name": "Invulerables", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "Vec" }, - "default": "0x00", + "fallback": "0x00", "documentation": [ " Any validators that may never be slashed or forcible kicked. It's a Vec since they're easy to initialise", " and the performance hit is minimal (we expect no more than four invulnerables) and restricted to testnets." @@ -1361,172 +1332,172 @@ }, { "name": "CurrentEra", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "BlockNumber" }, - "default": "0x0000000000000000", + "fallback": "0x0000000000000000", "documentation": [ " The current era index." ] }, { "name": "ValidatorPreferences", - "modifier": 0, + "modifier": "Default", "type": { "MapType": { "key": "AccountId", "value": "ValidatorPrefs" } }, - "default": "0x0c00", + "fallback": "0x0c00", "documentation": [ " Preferences that a validator has." ] }, { "name": "Intentions", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "Vec" }, - "default": "0x00", + "fallback": "0x00", "documentation": [ " All the accounts with a desire to stake." ] }, { "name": "Nominating", - "modifier": 0, + "modifier": "Optional", "type": { "MapType": { "key": "AccountId", "value": "AccountId" } }, - "default": "0x00", + "fallback": "0x00", "documentation": [ " All nominator -> nominee relationships." ] }, { "name": "NominatorsFor", - "modifier": 0, + "modifier": "Default", "type": { "MapType": { "key": "AccountId", "value": "Vec" } }, - "default": "0x00", + "fallback": "0x00", "documentation": [ " Nominators for a particular account." ] }, { "name": "CurrentNominatorsFor", - "modifier": 0, + "modifier": "Default", "type": { "MapType": { "key": "AccountId", "value": "Vec" } }, - "default": "0x00", + "fallback": "0x00", "documentation": [ " Nominators for a particular account that is in action right now." ] }, { "name": "CurrentSessionReward", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "Balance" }, - "default": "0x00000000000000000000000000000000", + "fallback": "0x00000000000000000000000000000000", "documentation": [ " Maximum reward, per validator, that is provided per acceptable session." ] }, { "name": "CurrentOfflineSlash", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "Balance" }, - "default": "0x00000000000000000000000000000000", + "fallback": "0x00000000000000000000000000000000", "documentation": [ " Slash, per validator that is taken for the first time they are found to be offline." ] }, { "name": "NextSessionsPerEra", - "modifier": 0, + "modifier": "Optional", "type": { "PlainType": "BlockNumber" }, - "default": "0x00", + "fallback": "0x00", "documentation": [ " The next value of sessions per era." ] }, { "name": "LastEraLengthChange", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "BlockNumber" }, - "default": "0x0000000000000000", + "fallback": "0x0000000000000000", "documentation": [ " The session index at which the era length last changed." ] }, { "name": "StakeRange", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "(Balance,Balance)" }, - "default": "0x0000000000000000000000000000000000000000000000000000000000000000", + "fallback": "0x0000000000000000000000000000000000000000000000000000000000000000", "documentation": [ " The highest and lowest staked validator slashable balances." ] }, { "name": "Bondage", - "modifier": 0, + "modifier": "Default", "type": { "MapType": { "key": "AccountId", "value": "BlockNumber" } }, - "default": "0x0000000000000000", + "fallback": "0x0000000000000000", "documentation": [ " The block at which the `who`'s funds become entirely liquid." ] }, { "name": "SlashCount", - "modifier": 0, + "modifier": "Default", "type": { "MapType": { "key": "AccountId", "value": "u32" } }, - "default": "0x00000000", + "fallback": "0x00000000", "documentation": [ " The number of times a given validator has been reported offline. This gets decremented by one each era that passes." ] }, { "name": "ForcingNewEra", - "modifier": 0, + "modifier": "Optional", "type": { "PlainType": "Null" }, - "default": "0x00", + "fallback": "0x00", "documentation": [ " We are forcing a new era." ] @@ -1544,7 +1515,7 @@ { "id": 0, "name": "propose", - "arguments": [ + "args": [ { "name": "proposal", "type": "Proposal" @@ -1561,7 +1532,7 @@ { "id": 1, "name": "second", - "arguments": [ + "args": [ { "name": "proposal", "type": "Compact" @@ -1574,7 +1545,7 @@ { "id": 2, "name": "vote", - "arguments": [ + "args": [ { "name": "ref_index", "type": "Compact" @@ -1592,7 +1563,7 @@ { "id": 3, "name": "start_referendum", - "arguments": [ + "args": [ { "name": "proposal", "type": "Proposal" @@ -1613,7 +1584,7 @@ { "id": 4, "name": "cancel_referendum", - "arguments": [ + "args": [ { "name": "ref_index", "type": "Compact" @@ -1626,7 +1597,7 @@ { "id": 5, "name": "cancel_queued", - "arguments": [ + "args": [ { "name": "when", "type": "Compact" @@ -1648,183 +1619,183 @@ "functions": [ { "name": "PublicPropCount", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "PropIndex" }, - "default": "0x00000000", + "fallback": "0x00000000", "documentation": [ " The number of (public) proposals that have been made so far." ] }, { "name": "PublicProps", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "Vec<(PropIndex,Proposal,AccountId)>" }, - "default": "0x00", + "fallback": "0x00", "documentation": [ " The public proposals. Unsorted." ] }, { "name": "DepositOf", - "modifier": 0, + "modifier": "Optional", "type": { "MapType": { "key": "PropIndex", "value": "(Balance,Vec)" } }, - "default": "0x00", + "fallback": "0x00", "documentation": [ " Those who have locked a deposit." ] }, { "name": "LaunchPeriod", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "BlockNumber" }, - "default": "0xe803000000000000", + "fallback": "0xe803000000000000", "documentation": [ " How often (in blocks) new public referenda are launched." ] }, { "name": "MinimumDeposit", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "Balance" }, - "default": "0x00000000000000000000000000000000", + "fallback": "0x00000000000000000000000000000000", "documentation": [ " The minimum amount to be used as a deposit for a public referendum proposal." ] }, { "name": "PublicDelay", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "BlockNumber" }, - "default": "0x0000000000000000", + "fallback": "0x0000000000000000", "documentation": [ " The delay before enactment for all public referenda." ] }, { "name": "MaxLockPeriods", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "LockPeriods" }, - "default": "0x00", + "fallback": "0x00", "documentation": [ " The maximum number of additional lock periods a voter may offer to strengthen their vote. Multiples of `PublicDelay`." ] }, { "name": "VotingPeriod", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "BlockNumber" }, - "default": "0xe803000000000000", + "fallback": "0xe803000000000000", "documentation": [ " How often (in blocks) to check for new votes." ] }, { "name": "ReferendumCount", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "ReferendumIndex" }, - "default": "0x00000000", + "fallback": "0x00000000", "documentation": [ " The next free referendum index, aka the number of referendums started so far." ] }, { "name": "NextTally", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "ReferendumIndex" }, - "default": "0x00000000", + "fallback": "0x00000000", "documentation": [ " The next referendum index that should be tallied." ] }, { "name": "ReferendumInfoOf", - "modifier": 0, + "modifier": "Optional", "type": { "MapType": { "key": "ReferendumIndex", "value": "ReferendumInfo" } }, - "default": "0x00", + "fallback": "0x00", "documentation": [ " Information concerning any given referendum." ] }, { "name": "DispatchQueue", - "modifier": 0, + "modifier": "Default", "type": { "MapType": { "key": "BlockNumber", "value": "Vec>" } }, - "default": "0x00", + "fallback": "0x00", "documentation": [ " Queue of successful referenda to be dispatched." ] }, { "name": "Bondage", - "modifier": 0, + "modifier": "Default", "type": { "MapType": { "key": "AccountId", "value": "BlockNumber" } }, - "default": "0x0000000000000000", + "fallback": "0x0000000000000000", "documentation": [ " The block at which the `who`'s funds become liquid." ] }, { "name": "VotersFor", - "modifier": 0, + "modifier": "Default", "type": { "MapType": { "key": "ReferendumIndex", "value": "Vec" } }, - "default": "0x00", + "fallback": "0x00", "documentation": [ " Get the voters for the current proposal." ] }, { "name": "VoteOf", - "modifier": 0, + "modifier": "Default", "type": { "MapType": { "key": "(ReferendumIndex,AccountId)", "value": "Vote" } }, - "default": "0x00", + "fallback": "0x00", "documentation": [ " Get the vote in a given referendum of a particular voter. The result is meaningful only if `voters_for` includes the", " voter when called with the referendum (you'll get the default `Vote` value otherwise). If you don't want to check", @@ -1844,7 +1815,7 @@ { "id": 0, "name": "set_approvals", - "arguments": [ + "args": [ { "name": "votes", "type": "Vec" @@ -1862,7 +1833,7 @@ { "id": 1, "name": "reap_inactive_voter", - "arguments": [ + "args": [ { "name": "reporter_index", "type": "Compact" @@ -1891,7 +1862,7 @@ { "id": 2, "name": "retract_voter", - "arguments": [ + "args": [ { "name": "index", "type": "Compact" @@ -1904,7 +1875,7 @@ { "id": 3, "name": "submit_candidacy", - "arguments": [ + "args": [ { "name": "slot", "type": "Compact" @@ -1919,7 +1890,7 @@ { "id": 4, "name": "present_winner", - "arguments": [ + "args": [ { "name": "candidate", "type": "Address" @@ -1942,7 +1913,7 @@ { "id": 5, "name": "set_desired_seats", - "arguments": [ + "args": [ { "name": "count", "type": "Compact" @@ -1957,7 +1928,7 @@ { "id": 6, "name": "remove_member", - "arguments": [ + "args": [ { "name": "who", "type": "Address" @@ -1972,7 +1943,7 @@ { "id": 7, "name": "set_presentation_duration", - "arguments": [ + "args": [ { "name": "count", "type": "Compact" @@ -1986,7 +1957,7 @@ { "id": 8, "name": "set_term_duration", - "arguments": [ + "args": [ { "name": "count", "type": "Compact" @@ -2005,66 +1976,66 @@ "functions": [ { "name": "CandidacyBond", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "Balance" }, - "default": "0x09000000000000000000000000000000", + "fallback": "0x09000000000000000000000000000000", "documentation": [ " How much should be locked up in order to submit one's candidacy." ] }, { "name": "VotingBond", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "Balance" }, - "default": "0x00000000000000000000000000000000", + "fallback": "0x00000000000000000000000000000000", "documentation": [ " How much should be locked up in order to be able to submit votes." ] }, { "name": "PresentSlashPerVoter", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "Balance" }, - "default": "0x01000000000000000000000000000000", + "fallback": "0x01000000000000000000000000000000", "documentation": [ " The punishment, per voter, if you provide an invalid presentation." ] }, { "name": "CarryCount", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "u32" }, - "default": "0x02000000", + "fallback": "0x02000000", "documentation": [ " How many runners-up should have their approvals persist until the next vote." ] }, { "name": "PresentationDuration", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "BlockNumber" }, - "default": "0xe803000000000000", + "fallback": "0xe803000000000000", "documentation": [ " How long to give each top candidate to present themselves after the vote ends." ] }, { "name": "InactiveGracePeriod", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "VoteIndex" }, - "default": "0x01000000", + "fallback": "0x01000000", "documentation": [ " How many vote indexes need to go by after a target voter's last vote before they can be reaped if their", " approvals are moot." @@ -2072,44 +2043,44 @@ }, { "name": "VotingPeriod", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "BlockNumber" }, - "default": "0xe803000000000000", + "fallback": "0xe803000000000000", "documentation": [ " How often (in blocks) to check for new votes." ] }, { "name": "TermDuration", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "BlockNumber" }, - "default": "0x0500000000000000", + "fallback": "0x0500000000000000", "documentation": [ " How long each position is active for." ] }, { "name": "DesiredSeats", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "u32" }, - "default": "0x00000000", + "fallback": "0x00000000", "documentation": [ " Number of accounts that should be sitting on the council." ] }, { "name": "ActiveCouncil", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "Vec<(AccountId,BlockNumber)>" }, - "default": "0x00", + "fallback": "0x00", "documentation": [ " The current council. When there's a vote going on, this should still be used for executive", " matters. The block number (second element in the tuple) is the block that their position is", @@ -2119,25 +2090,25 @@ }, { "name": "VoteCount", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "VoteIndex" }, - "default": "0x00000000", + "fallback": "0x00000000", "documentation": [ " The total number of votes that have happened or are in progress." ] }, { "name": "ApprovalsOf", - "modifier": 0, + "modifier": "Default", "type": { "MapType": { "key": "AccountId", "value": "Vec" } }, - "default": "0x00", + "fallback": "0x00", "documentation": [ " A list of votes for each voter, respecting the last cleared vote index that this voter was", " last active at." @@ -2145,14 +2116,14 @@ }, { "name": "RegisterInfoOf", - "modifier": 0, + "modifier": "Optional", "type": { "MapType": { "key": "AccountId", "value": "(VoteIndex,u32)" } }, - "default": "0x00", + "fallback": "0x00", "documentation": [ " The vote index and list slot that the candidate `who` was registered or `None` if they are not", " currently registered." @@ -2160,78 +2131,78 @@ }, { "name": "LastActiveOf", - "modifier": 0, + "modifier": "Optional", "type": { "MapType": { "key": "AccountId", "value": "VoteIndex" } }, - "default": "0x00", + "fallback": "0x00", "documentation": [ " The last cleared vote index that this voter was last active at." ] }, { "name": "Voters", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "Vec" }, - "default": "0x00", + "fallback": "0x00", "documentation": [ " The present voter list." ] }, { "name": "Candidates", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "Vec" }, - "default": "0x00", + "fallback": "0x00", "documentation": [ " The present candidate list." ] }, { "name": "CandidateCount", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "u32" }, - "default": "0x00000000", + "fallback": "0x00000000", "documentation": [] }, { "name": "NextFinalise", - "modifier": 0, + "modifier": "Optional", "type": { "PlainType": "(BlockNumber,u32,Vec)" }, - "default": "0x00", + "fallback": "0x00", "documentation": [ " The accounts holding the seats that will become free on the next tally." ] }, { "name": "SnapshotedStakes", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "Vec" }, - "default": "0x00", + "fallback": "0x00", "documentation": [ " The stakes as they were at the point that the vote ended." ] }, { "name": "Leaderboard", - "modifier": 0, + "modifier": "Optional", "type": { "PlainType": "Vec<(Balance,AccountId)>" }, - "default": "0x00", + "fallback": "0x00", "documentation": [ " Get the leaderboard if we;re in the presentation phase." ] @@ -2249,7 +2220,7 @@ { "id": 0, "name": "propose", - "arguments": [ + "args": [ { "name": "proposal", "type": "Proposal" @@ -2260,7 +2231,7 @@ { "id": 1, "name": "vote", - "arguments": [ + "args": [ { "name": "proposal", "type": "Hash" @@ -2275,7 +2246,7 @@ { "id": 2, "name": "veto", - "arguments": [ + "args": [ { "name": "proposal_hash", "type": "Hash" @@ -2286,7 +2257,7 @@ { "id": 3, "name": "set_cooloff_period", - "arguments": [ + "args": [ { "name": "blocks", "type": "Compact" @@ -2297,7 +2268,7 @@ { "id": 4, "name": "set_voting_period", - "arguments": [ + "args": [ { "name": "blocks", "type": "Compact" @@ -2313,88 +2284,88 @@ "functions": [ { "name": "CooloffPeriod", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "BlockNumber" }, - "default": "0xe803000000000000", + "fallback": "0xe803000000000000", "documentation": [] }, { "name": "VotingPeriod", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "BlockNumber" }, - "default": "0x0300000000000000", + "fallback": "0x0300000000000000", "documentation": [] }, { "name": "EnactDelayPeriod", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "BlockNumber" }, - "default": "0x0000000000000000", + "fallback": "0x0000000000000000", "documentation": [ " Number of blocks by which to delay enactment of successful, non-unanimous-council-instigated referendum proposals." ] }, { "name": "Proposals", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "Vec<(BlockNumber,Hash)>" }, - "default": "0x00", + "fallback": "0x00", "documentation": [] }, { "name": "ProposalOf", - "modifier": 0, + "modifier": "Optional", "type": { "MapType": { "key": "Hash", "value": "Proposal" } }, - "default": "0x00", + "fallback": "0x00", "documentation": [] }, { "name": "ProposalVoters", - "modifier": 0, + "modifier": "Default", "type": { "MapType": { "key": "Hash", "value": "Vec" } }, - "default": "0x00", + "fallback": "0x00", "documentation": [] }, { "name": "CouncilVoteOf", - "modifier": 0, + "modifier": "Optional", "type": { "MapType": { "key": "(Hash,AccountId)", "value": "bool" } }, - "default": "0x00", + "fallback": "0x00", "documentation": [] }, { "name": "VetoedProposal", - "modifier": 0, + "modifier": "Optional", "type": { "MapType": { "key": "Hash", "value": "(BlockNumber,Vec)" } }, - "default": "0x00", + "fallback": "0x00", "documentation": [] } ] @@ -2410,7 +2381,7 @@ { "id": 0, "name": "propose", - "arguments": [ + "args": [ { "name": "threshold", "type": "Compact" @@ -2425,7 +2396,7 @@ { "id": 1, "name": "vote", - "arguments": [ + "args": [ { "name": "proposal", "type": "Hash" @@ -2449,50 +2420,50 @@ "functions": [ { "name": "Proposals", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "Vec" }, - "default": "0x00", + "fallback": "0x00", "documentation": [ " The (hashes of) the active proposals." ] }, { "name": "ProposalOf", - "modifier": 0, + "modifier": "Optional", "type": { "MapType": { "key": "Hash", "value": "Proposal" } }, - "default": "0x00", + "fallback": "0x00", "documentation": [ " Actual proposal for a given hash, if it's current." ] }, { "name": "Voting", - "modifier": 0, + "modifier": "Optional", "type": { "MapType": { "key": "Hash", "value": "(ProposalIndex,u32,Vec,Vec)" } }, - "default": "0x00", + "fallback": "0x00", "documentation": [ " Votes for a given proposal: (required_yes_votes, yes_voters, no_voters)." ] }, { "name": "ProposalCount", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "u32" }, - "default": "0x00000000", + "fallback": "0x00000000", "documentation": [ " Proposals so far." ] @@ -2510,7 +2481,7 @@ { "id": 0, "name": "report_misbehavior", - "arguments": [ + "args": [ { "name": "_report", "type": "Bytes" @@ -2528,11 +2499,11 @@ "functions": [ { "name": "PendingChange", - "modifier": 0, + "modifier": "Optional", "type": { "PlainType": "StoredPendingChange" }, - "default": "0x00", + "fallback": "0x00", "documentation": [] } ] @@ -2548,7 +2519,7 @@ { "id": 0, "name": "propose_spend", - "arguments": [ + "args": [ { "name": "value", "type": "Compact" @@ -2567,7 +2538,7 @@ { "id": 1, "name": "set_pot", - "arguments": [ + "args": [ { "name": "new_pot", "type": "Compact" @@ -2580,10 +2551,10 @@ { "id": 2, "name": "configure", - "arguments": [ + "args": [ { "name": "proposal_bond", - "type": "Compact" + "type": "Permill" }, { "name": "proposal_bond_minimum", @@ -2595,7 +2566,7 @@ }, { "name": "burn", - "type": "Compact" + "type": "Permill" } ], "documentation": [ @@ -2605,7 +2576,7 @@ { "id": 3, "name": "reject_proposal", - "arguments": [ + "args": [ { "name": "proposal_id", "type": "Compact" @@ -2618,7 +2589,7 @@ { "id": 4, "name": "approve_proposal", - "arguments": [ + "args": [ { "name": "proposal_id", "type": "Compact" @@ -2637,11 +2608,11 @@ "functions": [ { "name": "ProposalBond", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "Permill" }, - "default": "0x00000000", + "fallback": "0x00000000", "documentation": [ " Proportion of funds that should be bonded in order to place a proposal. An accepted", " proposal gets these back. A rejected proposal doesn't." @@ -2649,80 +2620,80 @@ }, { "name": "ProposalBondMinimum", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "Balance" }, - "default": "0x00000000000000000000000000000000", + "fallback": "0x00000000000000000000000000000000", "documentation": [ " Minimum amount of funds that should be placed in a deposit for making a proposal." ] }, { "name": "SpendPeriod", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "BlockNumber" }, - "default": "0x0100000000000000", + "fallback": "0x0100000000000000", "documentation": [ " Period between successive spends." ] }, { "name": "Burn", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "Permill" }, - "default": "0x00000000", + "fallback": "0x00000000", "documentation": [ " Percentage of spare funds (if any) that are burnt per spend period." ] }, { "name": "Pot", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "Balance" }, - "default": "0x00000000000000000000000000000000", + "fallback": "0x00000000000000000000000000000000", "documentation": [ " Total funds available to this module for spending." ] }, { "name": "ProposalCount", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "ProposalIndex" }, - "default": "0x00000000", + "fallback": "0x00000000", "documentation": [ " Number of proposals that have been made." ] }, { "name": "Proposals", - "modifier": 0, + "modifier": "Optional", "type": { "MapType": { "key": "ProposalIndex", - "value": "TreasuryProposal" + "value": "Proposal" } }, - "default": "0x00", + "fallback": "0x00", "documentation": [ " Proposals that have been made." ] }, { "name": "Approvals", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "Vec" }, - "default": "0x00", + "fallback": "0x00", "documentation": [ " Proposal indices that have been approved but not yet awarded." ] @@ -2739,40 +2710,8 @@ "functions": [ { "id": 0, - "name": "update_schedule", - "arguments": [ - { - "name": "schedule", - "type": "Schedule" - } - ], - "documentation": [ - " Updates the schedule for metering contracts.", - "", - " The schedule must have a greater version than the stored schedule." - ] - }, - { - "id": 1, - "name": "put_code", - "arguments": [ - { - "name": "gas_limit", - "type": "Compact" - }, - { - "name": "code", - "type": "Bytes" - } - ], - "documentation": [ - " Stores code in the storage. You can instantiate contracts only with stored code." - ] - }, - { - "id": 2, "name": "call", - "arguments": [ + "args": [ { "name": "dest", "type": "Address" @@ -2791,13 +2730,14 @@ } ], "documentation": [ + " Make a call to a specified account, optionally transferring some balance.", " Make a call to a specified account, optionally transferring some balance." ] }, { - "id": 3, + "id": 1, "name": "create", - "arguments": [ + "args": [ { "name": "endowment", "type": "Compact" @@ -2807,8 +2747,8 @@ "type": "Compact" }, { - "name": "code_hash", - "type": "CodeHash" + "name": "ctor_code", + "type": "Bytes" }, { "name": "data", @@ -2842,7 +2782,7 @@ { "id": 0, "name": "sudo", - "arguments": [ + "args": [ { "name": "proposal", "type": "Proposal" @@ -2853,7 +2793,7 @@ { "id": 1, "name": "set_key", - "arguments": [ + "args": [ { "name": "new", "type": "Address" @@ -2869,11 +2809,11 @@ "functions": [ { "name": "Key", - "modifier": 0, + "modifier": "Default", "type": { "PlainType": "AccountId" }, - "default": "0x0000000000000000000000000000000000000000000000000000000000000000", + "fallback": "0x0000000000000000000000000000000000000000000000000000000000000000", "documentation": [] } ] @@ -2934,7 +2874,7 @@ "index": 9 }, { - "name": "GrandpaFinality", + "name": "Grandpa", "prefix": "grandpa", "index": 10 }, @@ -2944,7 +2884,7 @@ "index": 11 }, { - "name": "", + "name": "Contract", "prefix": "contract", "index": 12 }, diff --git a/packages/types/src/Metadata/v0/toV1.ts b/packages/types/src/Metadata/v0/toV1.ts new file mode 100644 index 0000000000..203561407d --- /dev/null +++ b/packages/types/src/Metadata/v0/toV1.ts @@ -0,0 +1,60 @@ + +// Copyright 2017-2019 @polkadot/types 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 { stringUpperFirst } from '@polkadot/util'; + +import { Option, Vector } from '../../codec'; +import MetadataV0 from './Metadata'; +import { RuntimeModuleMetadata } from './Modules'; +import { Text } from '../../primitive'; +import { FunctionMetadata } from '../v1/Calls'; +import { EventMetadata } from '../v1/Events'; +import MetadataV1, { ModuleMetadata } from '../v1/Metadata'; +import { StorageFunctionMetadata } from '../v1/Storage'; + +function toV1Calls (modul: RuntimeModuleMetadata) { + return modul.module.call.functions.length === 0 + ? new Option(Vector.with(FunctionMetadata)) + : new Option(Vector.with(FunctionMetadata), modul.module.call.functions); +} + +function toV1Events (metadataV0: MetadataV0, prefix: Text) { + const events = metadataV0.events.find((event) => event.name.eq(prefix)); + + return events + ? new Option(Vector.with(EventMetadata), events.events) + : new Option(Vector.with(EventMetadata)); +} + +function toV1Storage (modul: RuntimeModuleMetadata) { + return modul.storage.isNone + ? new Option(Vector.with(StorageFunctionMetadata)) + : new Option( + Vector.with(StorageFunctionMetadata), + modul.storage.unwrap().functions + ); +} + +/** + * Function that converts MetadataV0 to MetadataV1 + */ +export default function toV1 (metadataV0: MetadataV0): MetadataV1 { + return new MetadataV1({ + modules: metadataV0.modules.map((modul) => { + // The prefix of this module (capitalized) + const prefix = modul.storage.isSome + ? modul.storage.unwrap().prefix.toString() + : stringUpperFirst(modul.prefix.toString()); // If this module doesn't have storage, we just assume the prefix is the name capitalized + + return new ModuleMetadata({ + name: modul.prefix, // Not capitalized + prefix, // Capitalized + storage: toV1Storage(modul), + calls: toV1Calls(modul), + events: toV1Events(metadataV0, modul.prefix) + }); + }) + }); +} diff --git a/packages/types/src/Metadata/v1/Calls.ts b/packages/types/src/Metadata/v1/Calls.ts index de33dc1537..4cd6cde999 100644 --- a/packages/types/src/Metadata/v1/Calls.ts +++ b/packages/types/src/Metadata/v1/Calls.ts @@ -7,7 +7,7 @@ import Vector from '../../codec/Vector'; import Text from '../../primitive/Text'; import Type from '../../primitive/Type'; -export class MetadataCallArg extends Struct { +export class FunctionArgumentMetadata extends Struct { constructor (value?: any) { super({ name: Text, @@ -31,27 +31,24 @@ export class MetadataCallArg extends Struct { } /** - * @name MetadataCall + * @name FunctionMetadata * @description * The definition of a call */ -export class MetadataCall extends Struct { +export class FunctionMetadata extends Struct { constructor (value?: any) { super({ - // NOTE Just commented out, it is not available in current, but an open question - // around the usefulness of supplying this remains (could be re-added) - // id: u16, name: Text, - args: Vector.with(MetadataCallArg), + args: Vector.with(FunctionArgumentMetadata), documentation: Vector.with(Text) }, value); } /** - * @description The [[MetadataCallArg]] for arguments + * @description The [[FunctionArgumentMetadata]] for arguments */ - get args (): Vector { - return this.get('args') as Vector; + get args (): Vector { + return this.get('args') as Vector; } /** @@ -69,13 +66,6 @@ export class MetadataCall extends Struct { return this.documentation; } - // /** - // * @description The call function id - // */ - // get id (): u16 { - // return this.get('id') as u16; - // } - /** * @description The call name */ diff --git a/packages/types/src/Metadata/v1/Events.ts b/packages/types/src/Metadata/v1/Events.ts index ebdf28d0f2..ba9078cdf1 100644 --- a/packages/types/src/Metadata/v1/Events.ts +++ b/packages/types/src/Metadata/v1/Events.ts @@ -2,51 +2,5 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import Struct from '../../codec/Struct'; -import Vector from '../../codec/Vector'; -import Text from '../../primitive/Text'; -import Type from '../../primitive/Type'; - -/** - * @name MetadataEvent - * @description - * The definition of an event - */ -export class MetadataEvent extends Struct { - constructor (value?: any) { - super({ - name: Text, - args: Vector.with(Type), - documentation: Vector.with(Text) - }, value); - } - - /** - * @description The [[Type]] for args - */ - get args (): Vector { - return this.get('args') as Vector; - } - - /** - * @description The [[Text]] documentation - */ - get documentation (): Vector { - return this.get('documentation') as Vector; - } - - /** - * @description The [[Text]] documentation - * @deprecated Use `.documentation` instead. - */ - get docs (): Vector { - return this.documentation; - } - - /** - * @description The call name - */ - get name (): Text { - return this.get('name') as Text; - } -} +// Re-export classes that haven't changed between V0 and V1 +export { EventMetadata } from '../v0/Events'; diff --git a/packages/types/src/Metadata/v1/Metadata.spec.ts b/packages/types/src/Metadata/v1/Metadata.spec.ts index 6dffa5c1c8..9892400d7d 100644 --- a/packages/types/src/Metadata/v1/Metadata.spec.ts +++ b/packages/types/src/Metadata/v1/Metadata.spec.ts @@ -2,45 +2,14 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import extrinsicsFromMeta from '@plugnet/extrinsics/fromMetadata'; - -import createType from '../../codec/createType'; -import Method from '../../primitive/Method'; - -import Metadata from '../Metadata'; -import latestParsed from './latest.substrate.v1.json'; +import latestSubstrate from './latest.substrate.v1.json'; import rpcData from './static'; +import { decodeLatestSubstrate, defaultValues, toV4 } from '../util/testUtil'; describe('MetadataV1', () => { - const metadata = new Metadata(rpcData); + decodeLatestSubstrate(1, rpcData, latestSubstrate); - it('decodes latest properly', () => { - const str = JSON.stringify(metadata.toJSON()); + toV4(1, rpcData); - expect(metadata.version).toBe(1); - expect(metadata.asV1.modules.length).not.toBe(0); - expect(str).toEqual(JSON.stringify(latestParsed)); - }); - - it('converts v1 to V0', () => { - const v0 = metadata.asV0; - - expect(metadata.getUniqTypes(true)).toEqual(v0.getUniqTypes(true)); - }); - - describe('storage with default values', () => { - Method.injectMethods(extrinsicsFromMeta(metadata.asV0)); - - metadata.asV1.modules - .filter(({ storage }) => storage.isSome) - .map((mod) => - mod.storage.unwrap().forEach(({ fallback, name, type }) => { - it(`creates default types for ${mod.prefix}.${name}, type ${type}`, () => { - expect( - () => createType(type.toString(), fallback) - ).not.toThrow(); - }); - }) - ); - }); + defaultValues(rpcData); }); diff --git a/packages/types/src/Metadata/v1/Metadata.ts b/packages/types/src/Metadata/v1/Metadata.ts index 6e8c8d5c94..c9eb2187c9 100644 --- a/packages/types/src/Metadata/v1/Metadata.ts +++ b/packages/types/src/Metadata/v1/Metadata.ts @@ -10,38 +10,38 @@ import Vector from '../../codec/Vector'; import Text from '../../primitive/Text'; import { flattenUniq, validateTypes } from '../util'; -import { MetadataCall } from './Calls'; -import { MetadataEvent } from './Events'; +import { FunctionMetadata } from './Calls'; +import { EventMetadata } from './Events'; import { StorageFunctionMetadata } from './Storage'; /** - * @name MetadataModule + * @name ModuleMetadata * @description * The definition of a module in the system */ -export class MetadataModule extends Struct { +export class ModuleMetadata extends Struct { constructor (value?: any) { super({ name: Text, prefix: Text, storage: Option.with(Vector.with(StorageFunctionMetadata)), - calls: Option.with(Vector.with(MetadataCall)), - events: Option.with(Vector.with(MetadataEvent)) + calls: Option.with(Vector.with(FunctionMetadata)), + events: Option.with(Vector.with(EventMetadata)) }, value); } /** * @description the module calls */ - get calls (): Option> { - return this.get('calls') as Option>; + get calls (): Option> { + return this.get('calls') as Option>; } /** * @description the module events */ - get events (): Option> { - return this.get('events') as Option>; + get events (): Option> { + return this.get('events') as Option>; } /** @@ -71,18 +71,18 @@ export class MetadataModule extends Struct { * @description * The runtime metadata as a decoded structure */ -export default class MetadataV1 extends Struct implements MetadataInterface { +export default class MetadataV1 extends Struct implements MetadataInterface { constructor (value?: any) { super({ - modules: Vector.with(MetadataModule) + modules: Vector.with(ModuleMetadata) }, value); } /** * @description The associated modules for this structure */ - get modules (): Vector { - return this.get('modules') as Vector; + get modules (): Vector { + return this.get('modules') as Vector; } private get callNames () { diff --git a/packages/types/src/Metadata/v1/index.ts b/packages/types/src/Metadata/v1/index.ts index baabf104e4..b2602b2183 100644 --- a/packages/types/src/Metadata/v1/index.ts +++ b/packages/types/src/Metadata/v1/index.ts @@ -2,10 +2,10 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { default as MetadataV1, MetadataModule as MetadataModuleV1 } from './Metadata'; +import { default as MetadataV1, ModuleMetadata as ModuleMetadataV1 } from './Metadata'; export default MetadataV1; export { - MetadataModuleV1 + ModuleMetadataV1 }; diff --git a/packages/types/src/Metadata/v1/toV0.ts b/packages/types/src/Metadata/v1/toV0.ts deleted file mode 100644 index c427e2c4f6..0000000000 --- a/packages/types/src/Metadata/v1/toV0.ts +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright 2017-2019 @polkadot/types 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 { OuterDispatchCall, OuterDispatchMetadata } from '../v0/Calls'; -import { EventMetadata, OuterEventMetadata, OuterEventMetadataEvent } from '../v0/Events'; -import { CallMetadata, FunctionMetadata, RuntimeModuleMetadata, ModuleMetadata } from '../v0/Modules'; -import { StorageFunctionMetadata, StorageMetadata, StorageFunctionType } from '../v0/Storage'; - -import MetadataV0 from '../v0/Metadata'; -import MetadataV1, { MetadataModuleV1 } from '.'; - -function storageV0 (mod: MetadataModuleV1): StorageMetadata | null { - if (mod.storage.isNone) { - return null; - } - - return new StorageMetadata({ - prefix: mod.prefix, - functions: mod.storage.unwrap().map(({ documentation, fallback, modifier, name, type }) => - new StorageFunctionMetadata({ - name, - modifier: modifier.toNumber(), - type: new StorageFunctionType(type), - fallback, - documentation - }) - ) - }); -} - -function moduleV0 (mod: MetadataModuleV1): ModuleMetadata { - return new ModuleMetadata({ - name: 'Module', - call: new CallMetadata({ - name: 'Call', - functions: mod.calls.isNone - ? [] - : mod.calls.unwrap().map(({ args, documentation, name }, id) => - new FunctionMetadata({ - id, - name, - arguments: args, - documentation - }) - ) - }) - }); -} - -function modulesV0 (v1: MetadataV1): Array { - return v1.modules.map((mod) => - new RuntimeModuleMetadata({ - prefix: mod.name, // passed from name, compact with casing - module: moduleV0(mod), - storage: storageV0(mod) - }) - ); -} - -function outerDispatchV0 (v1: MetadataV1): OuterDispatchMetadata { - return new OuterDispatchMetadata({ - name: 'Call', - calls: v1.modules - .filter(({ calls }) => calls.isSome) - .map((mod, index) => - new OuterDispatchCall({ - // name and prefix are swapped in the actual V0 data, i.e. name is UpperCase - name: mod.prefix, - prefix: mod.name, - index - }) - ) - }); -} - -function outerEventV0 (v1: MetadataV1): OuterEventMetadata { - return new OuterEventMetadata({ - name: 'Event', - events: v1.modules - .filter(({ events }) => events.isSome) - .map((mod) => - new OuterEventMetadataEvent([ - mod.name, - mod.events.unwrap().map(({ args, documentation, name }) => - new EventMetadata({ - name, - arguments: args, - documentation - }) - ) - ]) - ) - }); -} - -export default function toV0 (v1: MetadataV1): MetadataV0 { - return new MetadataV0({ - outerEvent: outerEventV0(v1), - modules: modulesV0(v1), - outerDispatch: outerDispatchV0(v1) - }); -} diff --git a/packages/types/src/Metadata/v1/toV2.ts b/packages/types/src/Metadata/v1/toV2.ts new file mode 100644 index 0000000000..971b990c76 --- /dev/null +++ b/packages/types/src/Metadata/v1/toV2.ts @@ -0,0 +1,10 @@ +// Copyright 2017-2019 @polkadot/types 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 MetadataV1 from './Metadata'; +import MetadataV2 from '../v2'; + +export default function toV2 (metadataV1: MetadataV1): MetadataV2 { + return new MetadataV2(metadataV1); +} diff --git a/packages/types/src/Metadata/v4/toV3.ts b/packages/types/src/Metadata/v2/Calls.ts similarity index 54% rename from packages/types/src/Metadata/v4/toV3.ts rename to packages/types/src/Metadata/v2/Calls.ts index 528d155b58..8e3ef477f3 100644 --- a/packages/types/src/Metadata/v4/toV3.ts +++ b/packages/types/src/Metadata/v2/Calls.ts @@ -2,9 +2,8 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import MetadataV3 from '../v3/Metadata'; -import MetadataV4 from '.'; - -export default function toV3 (v4: MetadataV4): MetadataV3 { - return new MetadataV3(v4); -} +// Re-export classes that haven't changed between V1 and V2 +export { + FunctionArgumentMetadata, + FunctionMetadata +} from '../v1/Calls'; diff --git a/packages/types/src/Metadata/v2/toV1.ts b/packages/types/src/Metadata/v2/Events.ts similarity index 54% rename from packages/types/src/Metadata/v2/toV1.ts rename to packages/types/src/Metadata/v2/Events.ts index 05be1a722c..de53bb4245 100644 --- a/packages/types/src/Metadata/v2/toV1.ts +++ b/packages/types/src/Metadata/v2/Events.ts @@ -2,9 +2,5 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import MetadataV1 from '../v1/Metadata'; -import MetadataV2 from '.'; - -export default function toV1 (v2: MetadataV2): MetadataV1 { - return new MetadataV1(v2); -} +// Re-export classes that haven't changed between V1 and V2 +export { EventMetadata } from '../v1/Events'; diff --git a/packages/types/src/Metadata/v2/Metadata.spec.ts b/packages/types/src/Metadata/v2/Metadata.spec.ts index 31454bec29..65598b852a 100644 --- a/packages/types/src/Metadata/v2/Metadata.spec.ts +++ b/packages/types/src/Metadata/v2/Metadata.spec.ts @@ -2,51 +2,14 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import extrinsicsFromMeta from '@plugnet/extrinsics/fromMetadata'; - -import createType from '../../codec/createType'; -import Method from '../../primitive/Method'; - -import Metadata from '../Metadata'; -import latestParsed from './latest.substrate.v2.json'; +import latestSubstrate from './latest.substrate.v2.json'; import rpcData from './static'; +import { decodeLatestSubstrate, defaultValues, toV4 } from '../util/testUtil'; describe('MetadataV2', () => { - const metadata = new Metadata(rpcData); + decodeLatestSubstrate(2, rpcData, latestSubstrate); - it('decodes latest properly', () => { - const str = JSON.stringify(metadata.toJSON()); + toV4(2, rpcData); - expect(metadata.version).toBe(2); - expect(metadata.asV2.modules.length).not.toBe(0); - expect(str).toEqual(JSON.stringify(latestParsed)); - }); - - it('converts v2 to V1', () => { - const v1 = metadata.asV1; - - expect(metadata.getUniqTypes(true)).toEqual(v1.getUniqTypes(true)); - }); - - it('converts v2 to V0', () => { - const v1 = metadata.asV0; - - expect(metadata.getUniqTypes(true)).toEqual(v1.getUniqTypes(true)); - }); - - describe('storage with default values', () => { - Method.injectMethods(extrinsicsFromMeta(metadata.asV0)); - - metadata.asV2.modules - .filter(({ storage }) => storage.isSome) - .map((mod) => - mod.storage.unwrap().forEach(({ fallback, name, type }) => { - it(`creates default types for ${mod.prefix}.${name}, type ${type}`, () => { - expect( - () => createType(type.toString(), fallback) - ).not.toThrow(); - }); - }) - ); - }); + defaultValues(rpcData); }); diff --git a/packages/types/src/Metadata/v2/Metadata.ts b/packages/types/src/Metadata/v2/Metadata.ts index 3a8d1d63c7..0a89730ce0 100644 --- a/packages/types/src/Metadata/v2/Metadata.ts +++ b/packages/types/src/Metadata/v2/Metadata.ts @@ -10,38 +10,38 @@ import Vector from '../../codec/Vector'; import Text from '../../primitive/Text'; import { flattenUniq, validateTypes } from '../util'; -import { MetadataCall } from '../v1/Calls'; -import { MetadataEvent } from '../v1/Events'; +import { FunctionMetadata } from './Calls'; +import { EventMetadata } from './Events'; import { StorageFunctionMetadata } from './Storage'; /** - * @name MetadataModule + * @name ModuleMetadata * @description * The definition of a module in the system */ -export class MetadataModule extends Struct { +export class ModuleMetadata extends Struct { constructor (value?: any) { super({ name: Text, prefix: Text, storage: Option.with(Vector.with(StorageFunctionMetadata)), - calls: Option.with(Vector.with(MetadataCall)), - events: Option.with(Vector.with(MetadataEvent)) + calls: Option.with(Vector.with(FunctionMetadata)), + events: Option.with(Vector.with(EventMetadata)) }, value); } /** * @description the module calls */ - get calls (): Option> { - return this.get('calls') as Option>; + get calls (): Option> { + return this.get('calls') as Option>; } /** * @description the module events */ - get events (): Option> { - return this.get('events') as Option>; + get events (): Option> { + return this.get('events') as Option>; } /** @@ -71,18 +71,18 @@ export class MetadataModule extends Struct { * @description * The runtime metadata as a decoded structure */ -export default class MetadataV2 extends Struct implements MetadataInterface { +export default class MetadataV2 extends Struct implements MetadataInterface { constructor (value?: any) { super({ - modules: Vector.with(MetadataModule) + modules: Vector.with(ModuleMetadata) }, value); } /** * @description The associated modules for this structure */ - get modules (): Vector { - return this.get('modules') as Vector; + get modules (): Vector { + return this.get('modules') as Vector; } private get callNames () { diff --git a/packages/types/src/Metadata/v2/Storage.ts b/packages/types/src/Metadata/v2/Storage.ts index 860068ee91..b8f058cff7 100644 --- a/packages/types/src/Metadata/v2/Storage.ts +++ b/packages/types/src/Metadata/v2/Storage.ts @@ -11,7 +11,6 @@ import Struct from '../../codec/Struct'; import Vector from '../../codec/Vector'; import Bool from '../../primitive/Bool'; import Bytes from '../../primitive/Bytes'; -import Null from '../../primitive/Null'; import Text from '../../primitive/Text'; import Type from '../../primitive/Type'; import { PlainType, StorageFunctionModifier } from '../v1/Storage'; @@ -22,8 +21,6 @@ export { StorageFunctionModifier }; -export class DoubleMapType extends Null {} - export class MapType extends Struct { constructor (value?: any) { super({ @@ -59,20 +56,10 @@ export class StorageFunctionType extends EnumType { constructor (value?: any, index?: number) { super({ PlainType, - MapType, - DoubleMapType + MapType }, value, index); } - /** - * @description The value as a mapped value - */ - get asDoubleMap (): DoubleMapType { - assert(this.isDoubleMap, `Cannot convert '${this.type}' via asDoubleMap`); - - return this.value as DoubleMapType; - } - /** * @description The value as a mapped value */ @@ -91,13 +78,6 @@ export class StorageFunctionType extends EnumType { return this.value as PlainType; } - /** - * @description `true` if the storage entry is a double map - */ - get isDoubleMap (): boolean { - return this.toNumber() === 2; - } - /** * @description `true` if the storage entry is a map */ @@ -116,9 +96,7 @@ export class StorageFunctionType extends EnumType { * @description Returns the string representation of the value */ toString (): string { - if (this.isDoubleMap) { - return `DoubleMap<${this.asDoubleMap.toString()}>`; - } else if (this.isMap) { + if (this.isMap) { if (this.asMap.isLinked) { return `(${this.asMap.value.toString()}, Linkage<${this.asMap.key.toString()}>)`; } @@ -139,7 +117,7 @@ export type StorageFunctionMetadataValue = { }; /** - * @name MetadataModule + * @name ModuleMetadata * @description * The definition of a storage function */ diff --git a/packages/types/src/Metadata/v2/index.ts b/packages/types/src/Metadata/v2/index.ts index 652957147f..b78df7caba 100644 --- a/packages/types/src/Metadata/v2/index.ts +++ b/packages/types/src/Metadata/v2/index.ts @@ -2,10 +2,10 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { default as MetadataV2, MetadataModule as MetadataModuleV2 } from './Metadata'; +import { default as MetadataV2, ModuleMetadata as ModuleMetadataV2 } from './Metadata'; export default MetadataV2; export { - MetadataModuleV2 + ModuleMetadataV2 }; diff --git a/packages/types/src/Metadata/v2/toV3.ts b/packages/types/src/Metadata/v2/toV3.ts new file mode 100644 index 0000000000..000b59ece5 --- /dev/null +++ b/packages/types/src/Metadata/v2/toV3.ts @@ -0,0 +1,10 @@ +// Copyright 2017-2019 @polkadot/types 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 MetadataV2 from './Metadata'; +import MetadataV3 from '../v3'; + +export default function toV3 (metadataV2: MetadataV2): MetadataV3 { + return new MetadataV3(metadataV2); +} diff --git a/packages/types/src/Metadata/v3/toV2.ts b/packages/types/src/Metadata/v3/Calls.ts similarity index 54% rename from packages/types/src/Metadata/v3/toV2.ts rename to packages/types/src/Metadata/v3/Calls.ts index 3b2c4fc380..9911bcdbd2 100644 --- a/packages/types/src/Metadata/v3/toV2.ts +++ b/packages/types/src/Metadata/v3/Calls.ts @@ -2,9 +2,8 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import MetadataV2 from '../v2/Metadata'; -import MetadataV3 from '.'; - -export default function toV2 (v2: MetadataV3): MetadataV2 { - return new MetadataV2(v2); -} +// Re-export classes that haven't changed between V2 and V3 +export { + FunctionArgumentMetadata, + FunctionMetadata +} from '../v2/Calls'; diff --git a/packages/types/src/Metadata/v3/Events.ts b/packages/types/src/Metadata/v3/Events.ts new file mode 100644 index 0000000000..f81e45b6c6 --- /dev/null +++ b/packages/types/src/Metadata/v3/Events.ts @@ -0,0 +1,6 @@ +// Copyright 2017-2019 @polkadot/types authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. + +// Re-export classes that haven't changed between V2 and V3 +export { EventMetadata } from '../v2/Events'; diff --git a/packages/types/src/Metadata/v3/Metadata.spec.ts b/packages/types/src/Metadata/v3/Metadata.spec.ts index 8d59de0f61..cba719ce1d 100644 --- a/packages/types/src/Metadata/v3/Metadata.spec.ts +++ b/packages/types/src/Metadata/v3/Metadata.spec.ts @@ -2,21 +2,14 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import Metadata from '../Metadata'; -import latestParsed from './latest.substrate.v3.json'; +import latestSubstrate from './latest.substrate.v3.json'; import rpcData from './static'; +import { decodeLatestSubstrate, defaultValues, toV4 } from '../util/testUtil'; describe('MetadataV3', () => { - const metadata = new Metadata(rpcData); + decodeLatestSubstrate(3, rpcData, latestSubstrate); - it('decodes latest properly', () => { - const str = JSON.stringify(metadata.toJSON()); + toV4(3, rpcData); - console.error(str); - console.error(metadata.getUniqTypes(true)); - - expect(metadata.version).toBe(3); - expect(metadata.asV3.modules.length).not.toBe(0); - expect(str).toEqual(JSON.stringify(latestParsed)); - }); + defaultValues(rpcData); }); diff --git a/packages/types/src/Metadata/v3/Metadata.ts b/packages/types/src/Metadata/v3/Metadata.ts index 5f2409703b..c7f3d9cf7f 100644 --- a/packages/types/src/Metadata/v3/Metadata.ts +++ b/packages/types/src/Metadata/v3/Metadata.ts @@ -10,38 +10,38 @@ import Vector from '../../codec/Vector'; import Text from '../../primitive/Text'; import { flattenUniq, validateTypes } from '../util'; -import { MetadataCall } from '../v1/Calls'; -import { MetadataEvent } from '../v1/Events'; +import { FunctionMetadata } from './Calls'; +import { EventMetadata } from './Events'; import { StorageFunctionMetadata } from './Storage'; /** - * @name MetadataModule + * @name ModuleMetadata * @description * The definition of a module in the system */ -export class MetadataModule extends Struct { +export class ModuleMetadata extends Struct { constructor (value?: any) { super({ name: Text, prefix: Text, storage: Option.with(Vector.with(StorageFunctionMetadata)), - calls: Option.with(Vector.with(MetadataCall)), - events: Option.with(Vector.with(MetadataEvent)) + calls: Option.with(Vector.with(FunctionMetadata)), + events: Option.with(Vector.with(EventMetadata)) }, value); } /** * @description the module calls */ - get calls (): Option> { - return this.get('calls') as Option>; + get calls (): Option> { + return this.get('calls') as Option>; } /** * @description the module events */ - get events (): Option> { - return this.get('events') as Option>; + get events (): Option> { + return this.get('events') as Option>; } /** @@ -71,18 +71,18 @@ export class MetadataModule extends Struct { * @description * The runtime metadata as a decoded structure */ -export default class MetadataV3 extends Struct implements MetadataInterface { +export default class MetadataV3 extends Struct implements MetadataInterface { constructor (value?: any) { super({ - modules: Vector.with(MetadataModule) + modules: Vector.with(ModuleMetadata) }, value); } /** * @description The associated modules for this structure */ - get modules (): Vector { - return this.get('modules') as Vector; + get modules (): Vector { + return this.get('modules') as Vector; } private get callNames () { diff --git a/packages/types/src/Metadata/v3/Storage.ts b/packages/types/src/Metadata/v3/Storage.ts index 0ee5067aca..b1c5f957b3 100644 --- a/packages/types/src/Metadata/v3/Storage.ts +++ b/packages/types/src/Metadata/v3/Storage.ts @@ -127,7 +127,9 @@ export class StorageFunctionType extends EnumType`; - } else if (this.isMap) { + } + + if (this.isMap) { if (this.asMap.isLinked) { return `(${this.asMap.value.toString()}, Linkage<${this.asMap.key.toString()}>)`; } diff --git a/packages/types/src/Metadata/v3/index.ts b/packages/types/src/Metadata/v3/index.ts index c75e06fc8a..84d77891ce 100644 --- a/packages/types/src/Metadata/v3/index.ts +++ b/packages/types/src/Metadata/v3/index.ts @@ -2,10 +2,10 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { default as MetadataV3, MetadataModule as MetadataModuleV3 } from './Metadata'; +import { default as MetadataV3, ModuleMetadata as ModuleMetadataV3 } from './Metadata'; export default MetadataV3; export { - MetadataModuleV3 + ModuleMetadataV3 }; diff --git a/packages/types/src/Metadata/v3/toV4.ts b/packages/types/src/Metadata/v3/toV4.ts new file mode 100644 index 0000000000..1791555c70 --- /dev/null +++ b/packages/types/src/Metadata/v3/toV4.ts @@ -0,0 +1,68 @@ +// Copyright 2017-2019 @polkadot/types 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 { Option, Vector } from '../../codec'; +import MetadataV3 from './Metadata'; +import StorageHasher from '../../primitive/StorageHasher'; +import MetadataV4 from '../v4'; +import { StorageFunctionMetadata as StorageFunctionMetadataV3 } from '../v3/Storage'; +import { DoubleMapType, MapType, StorageFunctionMetadata, StorageFunctionType } from '../v4/Storage'; + +/** + * Convert V3 StorageFunction to V4 StorageFunction + */ +function toV4StorageFunction (storageFn: StorageFunctionMetadataV3): StorageFunctionMetadata { + const { documentation, fallback, modifier, name, type } = storageFn; + + // Convert the old type to the new type: there is one new field + // called `hasher`, which we initialize to xxHash (the default in + // v3). + const [newType, index] = type.isPlainType + ? [type, 0] + : type.isMap + ? [new MapType({ + hasher: new StorageHasher('Twox128'), + key: type.asMap.key, + value: type.asMap.value, + isLinked: type.asMap.isLinked + }), 1] + : [new DoubleMapType({ + hasher: new StorageHasher('Twox128'), + key1: type.asDoubleMap.key1, + key2: type.asDoubleMap.key2, + value: type.asDoubleMap.value, + key2Hasher: type.asDoubleMap.key2Hasher + }), 2]; + + return new StorageFunctionMetadata({ + name: name, + modifier: modifier, + type: new StorageFunctionType(newType, index), + fallback: fallback, + documentation: documentation + }); +} + +/** + * Convert from MetadataV3 to MetadataV4 + * See https://github.com/paritytech/substrate/pull/2268 for details + */ +export default function toV4 (metadataV3: MetadataV3): MetadataV4 { + return new MetadataV4({ + modules: metadataV3.modules.map((modul) => { + return { + name: modul.name, + prefix: modul.prefix, + storage: modul.storage.isSome + ? new Option( + Vector.with(StorageFunctionMetadata), + modul.storage.unwrap().map(toV4StorageFunction) + ) + : undefined, + calls: modul.calls, + events: modul.events + }; + }) + }); +} diff --git a/packages/types/src/Metadata/v4/Calls.ts b/packages/types/src/Metadata/v4/Calls.ts new file mode 100644 index 0000000000..24ee13dc04 --- /dev/null +++ b/packages/types/src/Metadata/v4/Calls.ts @@ -0,0 +1,9 @@ +// Copyright 2017-2019 @polkadot/types authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. + +// Re-export classes that haven't changed between V3 and V4 +export { + FunctionArgumentMetadata, + FunctionMetadata +} from '../v3/Calls'; diff --git a/packages/types/src/Metadata/v4/Events.ts b/packages/types/src/Metadata/v4/Events.ts new file mode 100644 index 0000000000..689efe418e --- /dev/null +++ b/packages/types/src/Metadata/v4/Events.ts @@ -0,0 +1,6 @@ +// Copyright 2017-2019 @polkadot/types authors & contributors +// This software may be modified and distributed under the terms +// of the Apache-2.0 license. See the LICENSE file for details. + +// Re-export classes that haven't changed between V3 and V4 +export { EventMetadata } from '../v3/Events'; diff --git a/packages/types/src/Metadata/v4/Metadata.spec.ts b/packages/types/src/Metadata/v4/Metadata.spec.ts index 471032e8ea..7010d7711d 100644 --- a/packages/types/src/Metadata/v4/Metadata.spec.ts +++ b/packages/types/src/Metadata/v4/Metadata.spec.ts @@ -2,29 +2,14 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -<<<<<<< HEAD -import extrinsicsFromMeta from '@plugnet/extrinsics/fromMetadata'; - -import createType from '../../codec/createType'; -import Method from '../../primitive/Method'; - -======= ->>>>>>> 57715c50c0... Revert "Update extrinsics FromMetadata. Drop storages with doublemap type when converting v3 to v2 (#888)" (#903) -import Metadata from '../Metadata'; -import latestParsed from './latest.substrate.v4.json'; +import latestSubstrate from './latest.substrate.v4.json'; import rpcData from './static'; +import { decodeLatestSubstrate, defaultValues, toV4 } from '../util/testUtil'; describe('MetadataV4', () => { - const metadata = new Metadata(rpcData); + decodeLatestSubstrate(4, rpcData, latestSubstrate); - it('decodes latest properly', () => { - const str = JSON.stringify(metadata.toJSON()); + toV4(4, rpcData); - console.error(str); - console.error(metadata.getUniqTypes(true)); - - expect(metadata.version).toBe(4); - expect(metadata.asV4.modules.length).not.toBe(0); - expect(str).toEqual(JSON.stringify(latestParsed)); - }); + defaultValues(rpcData); }); diff --git a/packages/types/src/Metadata/v4/Metadata.ts b/packages/types/src/Metadata/v4/Metadata.ts index dbb47a32c6..ea8c2ff56d 100644 --- a/packages/types/src/Metadata/v4/Metadata.ts +++ b/packages/types/src/Metadata/v4/Metadata.ts @@ -10,42 +10,38 @@ import Vector from '../../codec/Vector'; import Text from '../../primitive/Text'; import { flattenUniq, validateTypes } from '../util'; -import { MetadataCall } from '../v1/Calls'; -import { MetadataEvent } from '../v1/Events'; +import { FunctionMetadata } from './Calls'; +import { EventMetadata } from './Events'; import { StorageFunctionMetadata } from './Storage'; -export { - MetadataEvent -}; - /** - * @name MetadataModule + * @name ModuleMetadata * @description * The definition of a module in the system */ -export class MetadataModule extends Struct { +export class ModuleMetadata extends Struct { constructor (value?: any) { super({ name: Text, prefix: Text, storage: Option.with(Vector.with(StorageFunctionMetadata)), - calls: Option.with(Vector.with(MetadataCall)), - events: Option.with(Vector.with(MetadataEvent)) + calls: Option.with(Vector.with(FunctionMetadata)), + events: Option.with(Vector.with(EventMetadata)) }, value); } /** * @description the module calls */ - get calls (): Option> { - return this.get('calls') as Option>; + get calls (): Option> { + return this.get('calls') as Option>; } /** * @description the module events */ - get events (): Option> { - return this.get('events') as Option>; + get events (): Option> { + return this.get('events') as Option>; } /** @@ -75,18 +71,18 @@ export class MetadataModule extends Struct { * @description * The runtime metadata as a decoded structure */ -export default class MetadataV4 extends Struct implements MetadataInterface { +export default class MetadataV4 extends Struct implements MetadataInterface { constructor (value?: any) { super({ - modules: Vector.with(MetadataModule) + modules: Vector.with(ModuleMetadata) }, value); } /** * @description The associated modules for this structure */ - get modules (): Vector { - return this.get('modules') as Vector; + get modules (): Vector { + return this.get('modules') as Vector; } private get callNames () { diff --git a/packages/types/src/Metadata/v4/index.ts b/packages/types/src/Metadata/v4/index.ts index 172f878da1..1225541d08 100644 --- a/packages/types/src/Metadata/v4/index.ts +++ b/packages/types/src/Metadata/v4/index.ts @@ -2,10 +2,10 @@ // This software may be modified and distributed under the terms // of the Apache-2.0 license. See the LICENSE file for details. -import { default as MetadataV4, MetadataModule as MetadataModuleV4 } from './Metadata'; +import { default as MetadataV4, ModuleMetadata as ModuleMetadataV4 } from './Metadata'; export default MetadataV4; export { - MetadataModuleV4 + ModuleMetadataV4 }; diff --git a/packages/types/src/primitive/Event.ts b/packages/types/src/primitive/Event.ts index f7c1f552b8..2e0bf3b576 100644 --- a/packages/types/src/primitive/Event.ts +++ b/packages/types/src/primitive/Event.ts @@ -11,8 +11,7 @@ import Tuple from '../codec/Tuple'; import U8aFixed from '../codec/U8aFixed'; import { TypeDef, getTypeClass, getTypeDef } from '../codec/createType'; import Metadata from '../Metadata'; -import { EventMetadata as EventMetadataV0 } from '../Metadata/v0/Events'; -import { MetadataEvent as EventMetadataV4 } from '../Metadata/v1/Events'; +import { EventMetadata as EventMetadataV4 } from '../Metadata/v4/Events'; import Null from './Null'; import U32 from './U32'; @@ -32,12 +31,12 @@ export class EventIndex extends U32 { * Wrapper for the actual data that forms part of an [[Event]] */ export class EventData extends Tuple { - private _meta: EventMetadataV0 | EventMetadataV4; + private _meta: EventMetadataV4; private _method: string; private _section: string; private _typeDef: Array; - constructor (Types: Array, value: Uint8Array, typeDef: Array, meta: EventMetadataV0 | EventMetadataV4, section: string, method: string) { + constructor (Types: Array, value: Uint8Array, typeDef: Array, meta: EventMetadataV4, section: string, method: string) { super(Types, value); this._meta = meta; @@ -49,7 +48,7 @@ export class EventData extends Tuple { /** * @description The wrapped [[EventMetadata]] */ - get meta (): EventMetadataV0 | EventMetadataV4 { + get meta (): EventMetadataV4 { return this._meta; } @@ -129,37 +128,15 @@ export default class Event extends Struct { // This is called/injected by the API on init, allowing a snapshot of // the available system events to be used in lookups static injectMetadata (metadata: Metadata): void { - if (metadata.version === 4) { - let sectionIndex = 0; - - metadata.asV4.modules.forEach((section) => { + metadata.asV4.modules + .filter((section) => section.events.isSome) + .forEach((section, sectionIndex) => { const sectionName = stringCamelCase(section.name.toString()); - if (!section.events.isNone && !section.events.isEmpty) { - section.events.unwrap().forEach((meta, methodIndex) => { - const methodName = meta.name.toString(); - const eventIndex = new Uint8Array([sectionIndex, methodIndex]); - const typeDef = meta.args.map((arg) => getTypeDef(arg)); - const Types = typeDef.map(getTypeClass); - - EventTypes[eventIndex.toString()] = class extends EventData { - constructor (value: Uint8Array) { - super(Types, value, typeDef, meta, sectionName, methodName); - } - }; - }); - - sectionIndex += 1; - } - }); - } else { - metadata.asV0.events.forEach((section, sectionIndex) => { - const sectionName = stringCamelCase(section.name.toString()); - - section.events.forEach((meta, methodIndex) => { + section.events.unwrap().forEach((meta, methodIndex) => { const methodName = meta.name.toString(); const eventIndex = new Uint8Array([sectionIndex, methodIndex]); - const typeDef = meta.arguments.map((arg) => getTypeDef(arg)); + const typeDef = meta.args.map((arg) => getTypeDef(arg)); const Types = typeDef.map(getTypeClass); EventTypes[eventIndex.toString()] = class extends EventData { @@ -169,7 +146,6 @@ export default class Event extends Struct { }; }); }); - } } /** @@ -189,7 +165,7 @@ export default class Event extends Struct { /** * @description The [[EventMetadata]] with the documentation */ - get meta (): EventMetadataV0 | EventMetadataV4 { + get meta (): EventMetadataV4 { return this.data.meta; } diff --git a/packages/types/src/primitive/Method.spec.ts b/packages/types/src/primitive/Method.spec.ts index 31606463d4..c4d9fe55ec 100644 --- a/packages/types/src/primitive/Method.spec.ts +++ b/packages/types/src/primitive/Method.spec.ts @@ -34,19 +34,19 @@ describe('Method', () => { it('is false with no arguments', () => { expect( - new Method(test, { arguments: [] } as any).hasOrigin + new Method(test, { args: [] } as any).hasOrigin ).toEqual(false); }); it('is false with first argument as non-Origin', () => { expect( - new Method(test, { arguments: [{ name: 'a', type: 'u32' }] } as any).hasOrigin + new Method(test, { args: [{ name: 'a', type: 'u32' }] } as any).hasOrigin ).toEqual(false); }); it('is false with first argument as non-Origin', () => { expect( - new Method(test, { arguments: [{ name: 'a', type: 'Origin' }] } as any).hasOrigin + new Method(test, { args: [{ name: 'a', type: 'Origin' }] } as any).hasOrigin ).toEqual(true); }); }); diff --git a/packages/types/src/primitive/Method.ts b/packages/types/src/primitive/Method.ts index 9c3e698daf..ba54dc8cd7 100644 --- a/packages/types/src/primitive/Method.ts +++ b/packages/types/src/primitive/Method.ts @@ -9,7 +9,7 @@ import { assert, isHex, isObject, isU8a, hexToU8a } from '@plugnet/util'; import { getTypeDef, getTypeClass } from '../codec/createType'; import Struct from '../codec/Struct'; import U8aFixed from '../codec/U8aFixed'; -import { FunctionMetadata, FunctionArgumentMetadata } from '../Metadata/v0/Modules'; +import { FunctionMetadata as FunctionMetadataV4, FunctionArgumentMetadata } from '../Metadata/v4/Calls'; interface DecodeMethodInput { args: any; @@ -18,13 +18,13 @@ interface DecodeMethodInput { interface DecodedMethod extends DecodeMethodInput { argsDef: ArgsDef; - meta: FunctionMetadata; + meta: FunctionMetadataV4; } export interface MethodFunction { (...args: any[]): Method; callIndex: Uint8Array; - meta: FunctionMetadata; + meta: FunctionMetadataV4; method: string; section: string; toJSON: () => any; @@ -63,9 +63,9 @@ export class MethodIndex extends U8aFixed { * {@link https://github.com/paritytech/wiki/blob/master/Extrinsic.md#the-extrinsic-format-for-node}. */ export default class Method extends Struct implements IMethod { - protected _meta: FunctionMetadata; + protected _meta: FunctionMetadataV4; - constructor (value: any, meta?: FunctionMetadata) { + constructor (value: any, meta?: FunctionMetadataV4) { const decoded = Method.decodeMethod(value, meta); super({ @@ -86,7 +86,7 @@ export default class Method extends Struct implements IMethod { * @param _meta - Metadata to use, so that `injectMethods` lookup is not * necessary. */ - private static decodeMethod (value: DecodedMethod | Uint8Array | string, _meta?: FunctionMetadata): DecodedMethod { + private static decodeMethod (value: DecodedMethod | Uint8Array | string, _meta?: FunctionMetadataV4): DecodedMethod { if (isHex(value)) { return Method.decodeMethod(hexToU8a(value), _meta); } else if (isU8a(value)) { @@ -127,16 +127,16 @@ export default class Method extends Struct implements IMethod { return { args: new Uint8Array(), argsDef: {}, - meta: new FunctionMetadata(), + meta: new FunctionMetadataV4(), callIndex: new Uint8Array([255, 255]) }; } // If the extrinsic function has an argument of type `Origin`, we ignore it - static filterOrigin (meta?: FunctionMetadata): Array { + static filterOrigin (meta?: FunctionMetadataV4): Array { // FIXME should be `arg.type !== Origin`, but doesn't work... return meta - ? meta.arguments.filter(({ type }) => + ? meta.args.filter(({ type }) => type.toString() !== 'Origin' ) : []; @@ -161,7 +161,7 @@ export default class Method extends Struct implements IMethod { * * @param meta - The function metadata used to get the definition. */ - private static getArgsDef (meta: FunctionMetadata): ArgsDef { + private static getArgsDef (meta: FunctionMetadataV4): ArgsDef { return Method.filterOrigin(meta).reduce((result, { name, type }) => { const Type = getTypeClass( getTypeDef(type) @@ -215,7 +215,7 @@ export default class Method extends Struct implements IMethod { * @description `true` if the `Origin` type is on the method (extrinsic method) */ get hasOrigin (): boolean { - const firstArg = this.meta.arguments[0]; + const firstArg = this.meta.args[0]; return !!firstArg && firstArg.type.toString() === 'Origin'; } @@ -223,7 +223,7 @@ export default class Method extends Struct implements IMethod { /** * @description The [[FunctionMetadata]] */ - get meta (): FunctionMetadata { + get meta (): FunctionMetadataV4 { return this._meta; } } diff --git a/packages/types/src/primitive/StorageKey.spec.ts b/packages/types/src/primitive/StorageKey.spec.ts index 6624d5d87b..505ea8303d 100644 --- a/packages/types/src/primitive/StorageKey.spec.ts +++ b/packages/types/src/primitive/StorageKey.spec.ts @@ -3,33 +3,71 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { hexToU8a } from '@plugnet/util'; -import storage from '@plugnet/storage/static'; +import fromMetadata from '@plugnet/storage/fromMetadata'; +import rpcDataV3 from '@plugnet/types/Metadata/v3/static'; +import rpcDataV4 from '@plugnet/types/Metadata/v4/static'; +import Metadata from '../Metadata'; import StorageKey from './StorageKey'; describe('StorageKey', () => { - it(`should correctly get Alice's freeBalance storage key (hex)`, () => { - expect( - new StorageKey( - storage - .balances - .freeBalance('5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY') - ) - .toHex() - ).toBe('0xc99f5446efa57788f39ab529311f4550'); // FIXME OK this should be length-prefixed in reality + describe('with MetadataV3 (uses xxHash by default)', () => { + const storage = fromMetadata(new Metadata(rpcDataV3)); + + it(`should correctly get Alice's freeBalance storage key (hex)`, () => { + expect( + new StorageKey( + storage + .balances + .freeBalance('5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY') + ) + .toHex() + ).toBe('0xc99f5446efa57788f39ab529311f4550'); // FIXME OK this should be length-prefixed in reality + }); + + it(`should correctly get Alice's freeBalance storage key (u8a)`, () => { + expect( + new StorageKey( + storage + .balances + .freeBalance('5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY') + ) + .toU8a() + ).toEqual( + // length prefix attached + hexToU8a('0x40c99f5446efa57788f39ab529311f4550') + ); + }); }); - it(`should correctly get Alice's freeBalance storage key (u8a)`, () => { - expect( - new StorageKey( - storage - .balances - .freeBalance('5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY') - ) - .toU8a() - ).toEqual( - // length prefix attached - hexToU8a('0x40c99f5446efa57788f39ab529311f4550') - ); + describe('with MetadataV4 (uses xxHash by default)', () => { + const storage = fromMetadata(new Metadata(rpcDataV4)); + + it(`should correctly get Alice's freeBalance storage key (hex)`, () => { + expect( + new StorageKey( + storage + .balances + .freeBalance('5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY') + ) + .toHex() + ).toBe('0x7f864e18e3dd8b58386310d2fe0919eef27c6e558564b7f67f22d99d20f587bb'); + }); + + it(`should correctly get Alice's freeBalance storage key (u8a)`, () => { + expect( + new StorageKey( + storage + .balances + .freeBalance('5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY') + ) + .toU8a() + ).toEqual( + // length prefix attached + Uint8Array.from([ + 128, 127, 134, 78, 24, 227, 221, 139, 88, 56, 99, 16, 210, 254, 9, 25, 238, 242, 124, 110, 85, 133, 100, 183, 246, 127, 34, 217, 157, 32, 245, 135, 187 + ]) + ); + }); }); }); diff --git a/packages/types/src/primitive/StorageKey.ts b/packages/types/src/primitive/StorageKey.ts index 3eb160362d..594c14f148 100644 --- a/packages/types/src/primitive/StorageKey.ts +++ b/packages/types/src/primitive/StorageKey.ts @@ -7,12 +7,11 @@ import { AnyU8a } from '../types'; import { assert, isFunction, isString, isU8a } from '@plugnet/util'; import Bytes from './Bytes'; -import { StorageFunctionMetadata as MetaV0 } from '../Metadata/v0/Storage'; import { StorageFunctionMetadata as MetaV4 } from '../Metadata/v4/Storage'; export interface StorageFunction { (arg?: any): Uint8Array; - meta: MetaV0 | MetaV4; + meta: MetaV4; method: string; section: string; toJSON: () => any; @@ -26,8 +25,8 @@ export interface StorageFunction { * constructed by passing in a raw key or a StorageFunction with (optional) arguments. */ export default class StorageKey extends Bytes { - private _meta: MetaV0 | MetaV4 | null; - private _outputType: string | null; + private _meta?: MetaV4; + private _outputType?: string; constructor (value?: AnyU8a | StorageKey | StorageFunction | [StorageFunction, any]) { super(StorageKey.decodeStorageKey(value)); @@ -53,7 +52,7 @@ export default class StorageKey extends Bytes { throw new Error(`Unable to convert input ${value} to StorageKey`); } - static getMeta (value: StorageKey | StorageFunction | [StorageFunction, any]): MetaV0 | MetaV4 | null { + static getMeta (value: StorageKey | StorageFunction | [StorageFunction, any]): MetaV4 | undefined { if (value instanceof StorageKey) { return value.meta; } else if (isFunction(value)) { @@ -64,10 +63,10 @@ export default class StorageKey extends Bytes { return fn.meta; } - return null; + return undefined; } - static getType (value: StorageKey | StorageFunction | [StorageFunction, any]): string | null { + static getType (value: StorageKey | StorageFunction | [StorageFunction, any]): string | undefined { if (value instanceof StorageKey) { return value.outputType; } else if (isFunction(value)) { @@ -78,20 +77,20 @@ export default class StorageKey extends Bytes { return fn.meta.type.toString(); } - return null; + return undefined; } /** * @description The metadata or `null` when not available */ - get meta (): MetaV0 | MetaV4 | null { + get meta (): MetaV4 | undefined { return this._meta; } /** * @description The output type, `null` when not available */ - get outputType (): string | null { + get outputType (): string | undefined { return this._outputType; } } diff --git a/packages/types/src/scripts/MetadataMd.ts b/packages/types/src/scripts/MetadataMd.ts index 286f7002b0..da51fc96eb 100644 --- a/packages/types/src/scripts/MetadataMd.ts +++ b/packages/types/src/scripts/MetadataMd.ts @@ -9,7 +9,7 @@ import interfaces from '../../../type-jsonrpc/src'; import Method from '../primitive/Method'; import Metadata from '../Metadata'; import rpcdata from '../Metadata/static'; -import MetadataV0 from '../Metadata/v0'; +import MetadataV4 from '../Metadata/v4'; const ANCHOR_TOP = ''; const LINK_BACK_TO_TOP = ''; @@ -56,7 +56,10 @@ function addRpc () { }, renderHeading + renderAnchors); } -function sortExtrinsicsSectionMethods (a: any, b: any) { +/** + * Sort object by their `.name` + */ +function sortByName (a: T, b: T): number { // ignore upper and lowercase const nameA = a.name.toString().toUpperCase(); const nameB = b.name.toString().toUpperCase(); @@ -64,26 +67,28 @@ function sortExtrinsicsSectionMethods (a: any, b: any) { return nameA.localeCompare(nameB); } -function addEvents (metadata: MetadataV0) { +function addEvents (metadata: MetadataV4) { const renderHeading = `## ${ANCHOR_TOP}Events${DESC_EVENTS}`; - const orderedSections = metadata.events.map((i) => i).sort(); + const orderedSections = metadata.modules.sort(sortByName); let renderAnchors = ''; const sections = orderedSections.reduce((md, meta) => { - if (!meta.events || !meta.events.length) { + if (meta.events.isNone || !meta.events.unwrap().length) { return md; } + const events = meta.events.unwrap(); + const sectionName = stringCamelCase(meta.name.toString()); renderAnchors += sectionLink(sectionName); const renderSection = generateSectionHeader(md, sectionName); - const orderedMethods = meta.events.sort(sortExtrinsicsSectionMethods); + const orderedMethods = events.sort(sortByName); return orderedMethods.reduce((md, func) => { const methodName = func.name.toString(); - const args = func.arguments.map((type) => '`' + type + '`').join(', '); + const args = func.args.map((type) => '`' + type + '`').join(', '); const doc = func.documentation.reduce((md, doc) => `${md} ${doc}`, ''); const renderSignature = `${md}\n▸ **${methodName}**(${args})`; const renderSummary = `${doc ? `\n- **summary**: ${doc}\n` : '\n'}`; @@ -95,21 +100,23 @@ function addEvents (metadata: MetadataV0) { return renderHeading + renderAnchors + sections; } -function addExtrinsics (metadata: MetadataV0) { +function addExtrinsics (metadata: MetadataV4) { const renderHeading = `## ${ANCHOR_TOP}Extrinsics${DESC_EXTRINSICS}`; - const orderedSections = metadata.modules.map((i) => i).sort(); + const orderedSections = metadata.modules.map((i) => i).sort(sortByName); let renderAnchors = ''; const sections = orderedSections.reduce((md, meta) => { - if (!meta.module.call || !meta.module.call.functions.length) { + if (meta.calls.isNone || !meta.calls.unwrap().length) { return md; } + const calls = meta.calls.unwrap(); + const sectionName = stringCamelCase(meta.prefix.toString()); renderAnchors += sectionLink(sectionName); const renderSection = generateSectionHeader(md, sectionName); - const orderedMethods = meta.module.call.functions.sort(sortExtrinsicsSectionMethods); + const orderedMethods = calls.sort(sortByName); return orderedMethods.reduce((md, func) => { const methodName = stringCamelCase(func.name.toString()); @@ -125,21 +132,21 @@ function addExtrinsics (metadata: MetadataV0) { return renderHeading + renderAnchors + sections; } -function addStorage (metadata: MetadataV0) { +function addStorage (metadata: MetadataV4) { const renderHeading = `## ${ANCHOR_TOP}Storage${DESC_STORAGE}`; - const orderedSections = metadata.modules.sort(); + const orderedSections = metadata.modules.sort(sortByName); let renderAnchors = ''; const sections = orderedSections.reduce((md, moduleMetadata) => { if (moduleMetadata.storage.isNone) { return md; } - const sectionName = stringLowerFirst(moduleMetadata.storage.unwrap().prefix.toString()); + const sectionName = stringLowerFirst(moduleMetadata.prefix.toString()); renderAnchors += sectionLink(sectionName); const renderSection = generateSectionHeader(md, sectionName); - const orderedMethods = moduleMetadata.storage.unwrap().functions.sort(); + const orderedMethods = moduleMetadata.storage.unwrap().sort(sortByName); return orderedMethods.reduce((md, func) => { const methodName = stringLowerFirst(func.name.toString()); @@ -177,22 +184,22 @@ function writeToRpcMd () { writeFile('docs/METHODS_RPC.md', addRpc()); } -function writeToStorageMd (metadata: MetadataV0) { +function writeToStorageMd (metadata: MetadataV4) { const options = { flags: 'r', encoding: 'utf8' }; const data = fs.readFileSync('packages/types/src/scripts/METHODS_STORAGE_SUBSTRATE.md', options); writeFile('docs/METHODS_STORAGE.md', addStorage(metadata), data); } -function writeToExtrinsicsMd (metadata: MetadataV0) { +function writeToExtrinsicsMd (metadata: MetadataV4) { writeFile('docs/METHODS_EXTRINSICS.md', addExtrinsics(metadata)); } -function writeToEventsMd (metadata: MetadataV0) { +function writeToEventsMd (metadata: MetadataV4) { writeFile('docs/METHODS_EVENTS.md', addEvents(metadata)); } -const metadata = new Metadata(rpcdata).asV0; +const metadata = new Metadata(rpcdata).asV4; writeToRpcMd(); writeToStorageMd(metadata); diff --git a/packages/types/src/type/Extrinsic.ts b/packages/types/src/type/Extrinsic.ts index 6abac30df7..c96f793377 100644 --- a/packages/types/src/type/Extrinsic.ts +++ b/packages/types/src/type/Extrinsic.ts @@ -10,7 +10,7 @@ import { blake2AsU8a } from '@plugnet/util-crypto'; import Compact from '../codec/Compact'; import Struct from '../codec/Struct'; -import { FunctionMetadata } from '../Metadata/v0/Modules'; +import { FunctionMetadata } from '../Metadata/v4/Calls'; import Method from '../primitive/Method'; import Address from '../primitive/Address'; import Hash from '../primitive/Hash'; diff --git a/packages/types/src/types.ts b/packages/types/src/types.ts index 7c8b3686b6..0f8c1337f4 100644 --- a/packages/types/src/types.ts +++ b/packages/types/src/types.ts @@ -7,13 +7,13 @@ import { KeyringPair } from '@plugnet/keyring/types'; import BN from 'bn.js'; import U8a from './codec/U8a'; +import { FunctionMetadata } from './Metadata/v4/Calls'; import Method from './primitive/Method'; import Address from './primitive/Address'; -import { FunctionMetadata } from './Metadata/v0/Modules'; export type CodecArg = Codec | BN | Boolean | String | Uint8Array | boolean | number | string | undefined | CodecArgArray | CodecArgObject; -export type CodecCallback = (result: T) => any; +export type CodecCallback = (result: T) => any; interface CodecArgObject { [index: string]: CodecArg; @@ -106,7 +106,7 @@ export interface ArgsDef { [index: string]: Constructor; } -export interface IHash extends U8a {} +export interface IHash extends U8a { } export interface IMethod extends Codec { readonly args: Array;