feat: Metadata V6 with module constants (#1059)
* feat: metadata v6, minus static and test * fix: update v5 to v6 everywhere * fix: lint and testUtil * fix typo * fix: match final metadata. constants no longer optional, StorageFunctionMetadata renamed to StorageEntryMetadata. * fix: constants constructor * fix: unit tests pass * fix: linting and renaming, make tests pass * fix: skip e2e remove console log * fix: formatting test * fix api e2e tests * fix: put the skip back * feat: yarn test:skip-e2e * fix: grumbles, add fresh flipper wasm * fix: grumbles, add fresh flipper wasm * fix: changelog * fix ci
This commit is contained in:
Binary file not shown.
@@ -19,4 +19,4 @@
|
||||
"return_type": "bool"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ import { AnyFunction, Codec, CodecArg, RegistryTypes } from '@polkadot/types/typ
|
||||
import {
|
||||
ApiInterface$Rx, ApiInterface$Events, ApiOptions, ApiTypes, DecorateMethodOptions,
|
||||
DecoratedRpc, DecoratedRpc$Section,
|
||||
QueryableModuleStorage, QueryableStorage, QueryableStorageFunction, QueryableStorageMulti, QueryableStorageMultiArg, QueryableStorageMultiArgs,
|
||||
QueryableModuleStorage, QueryableStorage, QueryableStorageEntry, QueryableStorageMulti, QueryableStorageMultiArg, QueryableStorageMultiArgs,
|
||||
SubmittableExtrinsicFunction, SubmittableExtrinsics, SubmittableModuleExtrinsics, Signer
|
||||
} from './types';
|
||||
|
||||
@@ -23,7 +23,7 @@ import storageFromMeta from '@polkadot/storage/fromMetadata';
|
||||
import { Event, getTypeRegistry, Hash, Metadata, Method, RuntimeVersion, Null, VectorAny } from '@polkadot/types';
|
||||
import Linkage, { LinkageResult } from '@polkadot/types/codec/Linkage';
|
||||
import { MethodFunction, ModulesWithMethods } from '@polkadot/types/primitive/Method';
|
||||
import { StorageFunction } from '@polkadot/types/primitive/StorageKey';
|
||||
import { StorageEntry } from '@polkadot/types/primitive/StorageKey';
|
||||
import { assert, compactStripLength, isFunction, isObject, isUndefined, logger, u8aToHex } from '@polkadot/util';
|
||||
import { cryptoWaitReady } from '@polkadot/util-crypto';
|
||||
|
||||
@@ -523,8 +523,8 @@ export default abstract class ApiBase<ApiType> {
|
||||
private decorateMulti<ApiType> (decorateMethod: ApiBase<ApiType>['decorateMethod']): QueryableStorageMulti<ApiType> {
|
||||
return decorateMethod(
|
||||
(calls: QueryableStorageMultiArgs<ApiType>) => {
|
||||
const mapped = calls.map((arg: QueryableStorageMultiArg<ApiType>): [QueryableStorageFunction<ApiType>, ...Array<CodecArg>] =>
|
||||
// the input is a QueryableStorageFunction, convert to StorageFunction
|
||||
const mapped = calls.map((arg: QueryableStorageMultiArg<ApiType>): [QueryableStorageEntry<ApiType>, ...Array<CodecArg>] =>
|
||||
// the input is a QueryableStorageEntry, convert to StorageEntry
|
||||
Array.isArray(arg)
|
||||
? [arg[0].creator, ...arg.slice(1)]
|
||||
: [arg.creator] as any
|
||||
@@ -575,7 +575,7 @@ export default abstract class ApiBase<ApiType> {
|
||||
}, {} as QueryableStorage<ApiType>);
|
||||
}
|
||||
|
||||
private decorateStorageEntry<ApiType> (creator: StorageFunction, decorateMethod: ApiBase<ApiType>['decorateMethod']): QueryableStorageFunction<ApiType> {
|
||||
private decorateStorageEntry<ApiType> (creator: StorageEntry, decorateMethod: ApiBase<ApiType>['decorateMethod']): QueryableStorageEntry<ApiType> {
|
||||
const decorated = creator.headKey
|
||||
? this.decorateStorageEntryLinked(creator, decorateMethod)
|
||||
: decorateMethod(
|
||||
@@ -633,10 +633,10 @@ export default abstract class ApiBase<ApiType> {
|
||||
: [creator, arg1])
|
||||
);
|
||||
|
||||
return this.decorateFunctionMeta(creator, decorated) as unknown as QueryableStorageFunction<ApiType>;
|
||||
return this.decorateFunctionMeta(creator, decorated) as unknown as QueryableStorageEntry<ApiType>;
|
||||
}
|
||||
|
||||
private decorateStorageEntryLinked<ApiType> (method: StorageFunction, decorateMethod: ApiBase<ApiType>['decorateMethod']): ReturnType<ApiBase<ApiType>['decorateMethod']> {
|
||||
private decorateStorageEntryLinked<ApiType> (method: StorageEntry, decorateMethod: ApiBase<ApiType>['decorateMethod']): ReturnType<ApiBase<ApiType>['decorateMethod']> {
|
||||
const result: Map<Codec, [Codec, Linkage<Codec>]> = new Map();
|
||||
let subject: BehaviorSubject<LinkageResult>;
|
||||
let head: Codec | null = null;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import { ProviderInterface } from '@polkadot/rpc-provider/types';
|
||||
import { AnyFunction, Callback, Codec } from '@polkadot/types/types';
|
||||
import { ApiOptions, DecorateMethodOptions, ObsInnerType, StorageFunctionPromiseOverloads, UnsubscribePromise } from '../types';
|
||||
import { ApiOptions, DecorateMethodOptions, ObsInnerType, StorageEntryPromiseOverloads, UnsubscribePromise } from '../types';
|
||||
|
||||
import { EMPTY } from 'rxjs';
|
||||
import { catchError, first, tap } from 'rxjs/operators';
|
||||
@@ -198,7 +198,7 @@ export default class ApiPromise extends ApiBase<'promise'> {
|
||||
};
|
||||
}
|
||||
|
||||
protected decorateMethod<Method extends AnyFunction> (method: Method, options?: DecorateMethodOptions): StorageFunctionPromiseOverloads {
|
||||
protected decorateMethod<Method extends AnyFunction> (method: Method, options?: DecorateMethodOptions): StorageEntryPromiseOverloads {
|
||||
const needsCallback = options && options.methodName && options.methodName.includes('subscribe');
|
||||
|
||||
return function (...args: any[]) {
|
||||
@@ -247,6 +247,6 @@ export default class ApiPromise extends ApiBase<'promise'> {
|
||||
)
|
||||
.subscribe(callback);
|
||||
}) as UnsubscribePromise;
|
||||
} as StorageFunctionPromiseOverloads;
|
||||
} as StorageEntryPromiseOverloads;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 { QueryableStorageFunction as QueryableStorageFunctionBase, SubmittableExtrinsicFunction as SubmittableExtrinsicFunctionBase } from '../types';
|
||||
import { QueryableStorageEntry as QueryableStorageEntryBase, SubmittableExtrinsicFunction as SubmittableExtrinsicFunctionBase } from '../types';
|
||||
|
||||
import { SubmittableExtrinsic as SubmittableExtrinsicBase } from '../SubmittableExtrinsic';
|
||||
|
||||
export type QueryableStorageFunction = QueryableStorageFunctionBase<'promise'>;
|
||||
export type QueryableStorageEntry = QueryableStorageEntryBase<'promise'>;
|
||||
export type SubmittableExtrinsic = SubmittableExtrinsicBase<'promise'>;
|
||||
export type SubmittableExtrinsicFunction = SubmittableExtrinsicFunctionBase<'promise'>;
|
||||
|
||||
+12
-12
@@ -8,7 +8,7 @@ import { ProviderInterface, ProviderInterface$Emitted } from '@polkadot/rpc-prov
|
||||
import { Hash, RuntimeVersion, u64 as U64 } from '@polkadot/types';
|
||||
import { AnyFunction, Callback, Codec, CodecArg, IExtrinsic, RegistryTypes, SignatureOptions } from '@polkadot/types/types';
|
||||
import { MethodFunction } from '@polkadot/types/primitive/Method';
|
||||
import { StorageFunction } from '@polkadot/types/primitive/StorageKey';
|
||||
import { StorageEntry } from '@polkadot/types/primitive/StorageKey';
|
||||
|
||||
import ApiBase from './Base';
|
||||
import { ISubmittableResult, SubmittableExtrinsic } from './SubmittableExtrinsic';
|
||||
@@ -87,18 +87,18 @@ export interface DecoratedRpc<ApiType> {
|
||||
system: DecoratedRpc$Section<ApiType>;
|
||||
}
|
||||
|
||||
export interface StorageFunctionObservable {
|
||||
export interface StorageEntryObservable {
|
||||
(arg1?: CodecArg, arg2?: CodecArg): Observable<Codec>;
|
||||
<T extends Codec>(arg1?: CodecArg, arg2?: CodecArg): Observable<T>;
|
||||
at: (hash: Hash | Uint8Array | string, arg1?: CodecArg, arg2?: CodecArg) => Observable<Codec>;
|
||||
creator: StorageFunction;
|
||||
creator: StorageEntry;
|
||||
hash: (arg1?: CodecArg, arg2?: CodecArg) => Observable<Hash>;
|
||||
key: (arg1?: CodecArg, arg2?: CodecArg) => string;
|
||||
multi: (args: Array<CodecArg[] | CodecArg>) => Observable<Codec>;
|
||||
size: (arg1?: CodecArg, arg2?: CodecArg) => Observable<U64>;
|
||||
}
|
||||
|
||||
export interface StorageFunctionPromiseOverloads {
|
||||
export interface StorageEntryPromiseOverloads {
|
||||
(arg1?: CodecArg, arg2?: CodecArg): Promise<Codec>;
|
||||
<T extends Codec>(arg1?: CodecArg, arg2?: CodecArg): Promise<T>;
|
||||
<T extends Codec>(callback: Callback<T>): UnsubscribePromise;
|
||||
@@ -106,27 +106,27 @@ export interface StorageFunctionPromiseOverloads {
|
||||
<T extends Codec>(arg1: CodecArg, arg2: CodecArg, callback: Callback<T>): UnsubscribePromise;
|
||||
}
|
||||
|
||||
export interface StorageFunctionPromise extends StorageFunctionPromiseOverloads {
|
||||
export interface StorageEntryPromise extends StorageEntryPromiseOverloads {
|
||||
at: (hash: Hash | Uint8Array | string, arg1?: CodecArg, arg2?: CodecArg) => Promise<Codec>;
|
||||
creator: StorageFunction;
|
||||
creator: StorageEntry;
|
||||
hash: (arg1?: CodecArg, arg2?: CodecArg) => Promise<Hash>;
|
||||
key: (arg1?: CodecArg, arg2?: CodecArg) => string;
|
||||
multi: <T extends Codec>(args: Array<CodecArg[] | CodecArg>, callback?: Callback<Array<T>>) => Promise<Array<T>>;
|
||||
size: (arg1?: CodecArg, arg2?: CodecArg) => Promise<U64>;
|
||||
}
|
||||
|
||||
export type QueryableStorageFunction<ApiType> =
|
||||
export type QueryableStorageEntry<ApiType> =
|
||||
ApiType extends 'rxjs'
|
||||
? StorageFunctionObservable
|
||||
: StorageFunctionPromise;
|
||||
? StorageEntryObservable
|
||||
: StorageEntryPromise;
|
||||
|
||||
export interface QueryableModuleStorage<ApiType> {
|
||||
[index: string]: QueryableStorageFunction<ApiType>;
|
||||
[index: string]: QueryableStorageEntry<ApiType>;
|
||||
}
|
||||
|
||||
export type QueryableStorageMultiArg<ApiType> =
|
||||
QueryableStorageFunction<ApiType> |
|
||||
[QueryableStorageFunction<ApiType>, ...Array<CodecArg>];
|
||||
QueryableStorageEntry<ApiType> |
|
||||
[QueryableStorageEntry<ApiType>, ...Array<CodecArg>];
|
||||
|
||||
export type QueryableStorageMultiArgs<ApiType> = Array<QueryableStorageMultiArg<ApiType>>;
|
||||
|
||||
|
||||
@@ -49,11 +49,8 @@ describe.skip('Promise e2e contracts', () => {
|
||||
api.tx.contracts
|
||||
.putCode(MAX_GAS, `0x${flipperCode}`)
|
||||
.signAndSend(keyring.eve, (result: SubmittableResult) => {
|
||||
console.error('putCode', JSON.stringify(result));
|
||||
|
||||
if (result.status.isFinalized) {
|
||||
const record = result.findRecord('contract', 'CodeStored');
|
||||
|
||||
if (record) {
|
||||
codeHash = record.event.data[0] as Hash;
|
||||
|
||||
|
||||
@@ -135,7 +135,7 @@ describe.skip('Promise e2e transactions', () => {
|
||||
// don't wait for status, just get hash. Here we generate a large-ish payload
|
||||
// to ensure that we can sign with the hashed version as well (and have it accepted)
|
||||
const hash: Hash = await api.tx.democracy
|
||||
.propose(api.tx.consensus.setCode(randomAsHex(4096)), 10000)
|
||||
.propose(api.tx.system.setCode(randomAsHex(4096)), 10000)
|
||||
.signAndSend(keyring.bob);
|
||||
|
||||
expect(hash.toHex()).toHaveLength(66);
|
||||
|
||||
@@ -49,7 +49,7 @@ describe.skip('Rx e2e transactions', () => {
|
||||
first(),
|
||||
switchMap((nonce: Index) =>
|
||||
api.tx.democracy
|
||||
.propose(api.tx.consensus.setCode('0xdeadbeef'), 10000)
|
||||
.propose(api.tx.system.setCode('0xdeadbeef'), 10000)
|
||||
.sign(keyring.alice, { nonce })
|
||||
.send()
|
||||
)
|
||||
|
||||
@@ -10,6 +10,7 @@ import Metadata from '@polkadot/types/Metadata';
|
||||
import rpcMetadataV3 from '@polkadot/types/Metadata/v3/static';
|
||||
import rpcMetadataV4 from '@polkadot/types/Metadata/v4/static';
|
||||
import rpcMetadataV5 from '@polkadot/types/Metadata/v5/static';
|
||||
import rpcMetadataV6 from '@polkadot/types/Metadata/v6/static';
|
||||
|
||||
import Api from '.';
|
||||
|
||||
@@ -111,8 +112,9 @@ function formattingTests (version: string, storage: Storage, encodedValues: [str
|
||||
});
|
||||
|
||||
it('handles the case where Option<Bytes> are retrieved', (done) => {
|
||||
let call = Number(version.slice(1)) <= 5 ? storage.contract.pristineCode : storage.contracts.pristineCode;
|
||||
api.state
|
||||
.subscribeStorage([[storage.contract.pristineCode, '0x00']])
|
||||
.subscribeStorage([[call, '0x00']])
|
||||
.subscribe((value: any) => {
|
||||
// console.error(value);
|
||||
|
||||
@@ -140,3 +142,9 @@ formattingTests('v5', fromMetadata(new Metadata(rpcMetadataV5)), [
|
||||
'0x1dbb0224910f42a14e7f1406b24c6fe8157296691b02a78756e01946038fffab',
|
||||
'0xc7879f4faa637a90d782070a3cb6be99a9fb0316e19a0454ce93c4f0a34712f1'
|
||||
]);
|
||||
|
||||
formattingTests('v6', fromMetadata(new Metadata(rpcMetadataV6)), [
|
||||
'0xec8f96437274a883afcac82d01a9defeb68209cd4f2c084632813692aa5e65ad',
|
||||
'0x1dbb0224910f42a14e7f1406b24c6fe8157296691b02a78756e01946038fffab',
|
||||
'0xc7879f4faa637a90d782070a3cb6be99a9fb0316e19a0454ce93c4f0a34712f1'
|
||||
]);
|
||||
|
||||
@@ -11,7 +11,7 @@ import interfaces from '@polkadot/jsonrpc';
|
||||
import testKeyring from '@polkadot/keyring/testing';
|
||||
import storage from '@polkadot/storage/static';
|
||||
import { Codec } from '@polkadot/types/types';
|
||||
import rpcMetadataV5 from '@polkadot/types/Metadata/v5/static';
|
||||
import rpcMetadataV6 from '@polkadot/types/Metadata/v6/static';
|
||||
import { Header, RuntimeVersion } from '@polkadot/types';
|
||||
import { bnToU8a, logger, u8aToHex } from '@polkadot/util';
|
||||
import { randomAsU8a } from '@polkadot/util-crypto';
|
||||
@@ -50,7 +50,7 @@ export default class Mock implements ProviderInterface {
|
||||
);
|
||||
},
|
||||
'system_chain': (): string => 'mockChain',
|
||||
'state_getMetadata': (): string => rpcMetadataV5,
|
||||
'state_getMetadata': (): string => rpcMetadataV6,
|
||||
'system_name': (): string => 'mockClient',
|
||||
'system_version': (): string => '9.8.7'
|
||||
};
|
||||
|
||||
@@ -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 { FunctionMetadata } from '@polkadot/types/Metadata/v5/Calls';
|
||||
import { FunctionMetadata } from '@polkadot/types/Metadata/v6/Calls';
|
||||
import { MethodFunction } from '@polkadot/types/primitive/Method';
|
||||
import { Method } from '@polkadot/types';
|
||||
import { assert, stringCamelCase } from '@polkadot/util';
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Extrinsic, Metadata } from '@polkadot/types';
|
||||
import json from '@polkadot/types/Metadata/v5/static';
|
||||
import json from '@polkadot/types/Metadata/v6/static';
|
||||
|
||||
import fromV5 from '.';
|
||||
import fromV6 from '.';
|
||||
|
||||
// Use the pre-generated metadata
|
||||
const metadata = new Metadata(json);
|
||||
const newExtrinsics = fromV5(metadata);
|
||||
const newExtrinsics = fromV6(metadata);
|
||||
|
||||
describe('fromMetadata', () => {
|
||||
it('should throw if an incorrect number of args is supplied', () => {
|
||||
|
||||
@@ -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 { ModuleMetadata } from '@polkadot/types/Metadata/v5/Metadata';
|
||||
import { ModuleMetadata } from '@polkadot/types/Metadata/v6/Metadata';
|
||||
import { Methods, ModulesWithMethods } from '@polkadot/types/primitive/Method';
|
||||
import Metadata from '@polkadot/types/Metadata';
|
||||
import { stringCamelCase } from '@polkadot/util';
|
||||
@@ -18,7 +18,7 @@ import createUnchecked from './createUnchecked';
|
||||
* @param metadata - The metadata to extend the storage object against.
|
||||
*/
|
||||
export default function fromMetadata (metadata: Metadata): ModulesWithMethods {
|
||||
return metadata.asV5.modules
|
||||
return metadata.asV6.modules
|
||||
.filter((modul) => modul.calls.isSome)
|
||||
.reduce((result, modul: ModuleMetadata, sectionIndex) => {
|
||||
const section = stringCamelCase(modul.name.toString());
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Metadata } from '@polkadot/types';
|
||||
import metadataRpc from '@polkadot/types/Metadata/v5/static';
|
||||
import metadataRpc from '@polkadot/types/Metadata/v6/static';
|
||||
import { ModulesWithMethods } from '@polkadot/types/primitive/Method';
|
||||
|
||||
import fromMetadata from './fromMetadata';
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { StorageHasher, Text } from '@polkadot/types';
|
||||
import { StorageFunction } from '@polkadot/types/primitive/StorageKey';
|
||||
import { StorageEntry } from '@polkadot/types/primitive/StorageKey';
|
||||
import { stringToU8a, u8aConcat, u8aToHex } from '@polkadot/util';
|
||||
|
||||
import createFunction from './createFunction';
|
||||
@@ -57,7 +57,7 @@ describe('createFunction', () => {
|
||||
});
|
||||
|
||||
describe('the created double map function', () => {
|
||||
let storageFn: StorageFunction;
|
||||
let storageFn: StorageEntry;
|
||||
beforeAll(() => {
|
||||
storageFn = createFunction(
|
||||
'GenericAsset',
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { createType, Bytes, Compact, StorageKey, Text, U8a } from '@polkadot/types';
|
||||
import { PlainType, StorageFunctionMetadata, StorageFunctionModifier, StorageFunctionType } from '@polkadot/types/Metadata/v5/Storage';
|
||||
import { StorageFunction } from '@polkadot/types/primitive/StorageKey';
|
||||
import { PlainType, StorageEntryMetadata, StorageEntryModifier, StorageEntryType } from '@polkadot/types/Metadata/v6/Storage';
|
||||
import { StorageEntry } from '@polkadot/types/primitive/StorageKey';
|
||||
import { assert, isNull, isUndefined, stringLowerFirst, stringToU8a, u8aConcat } from '@polkadot/util';
|
||||
|
||||
import getHasher, { HasherFunction } from './getHasher';
|
||||
@@ -24,7 +24,7 @@ export interface CreateItemOptions {
|
||||
* 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 {
|
||||
export default function createFunction (section: Text | string, method: Text | string, meta: StorageEntryMetadata, options: CreateItemOptions = {}): StorageEntry {
|
||||
const stringKey = options.key
|
||||
? options.key
|
||||
: `${section.toString()} ${method.toString()}`;
|
||||
@@ -81,10 +81,10 @@ export default function createFunction (section: Text | string, method: Text | s
|
||||
if (meta.type.isMap && meta.type.asMap.isLinked) {
|
||||
const keyHash = new U8a(hasher(`head of ${stringKey}`));
|
||||
const keyFn: any = () => keyHash;
|
||||
keyFn.meta = new StorageFunctionMetadata({
|
||||
keyFn.meta = new StorageEntryMetadata({
|
||||
name: meta.name,
|
||||
modifier: new StorageFunctionModifier('Required'),
|
||||
type: new StorageFunctionType(new PlainType(meta.type.asMap.key), 0),
|
||||
modifier: new StorageEntryModifier('Required'),
|
||||
type: new StorageEntryType(new PlainType(meta.type.asMap.key), 0),
|
||||
fallback: new Bytes(),
|
||||
documentation: meta.documentation
|
||||
});
|
||||
@@ -96,5 +96,5 @@ export default function createFunction (section: Text | string, method: Text | s
|
||||
storageFn.section = stringLowerFirst(section.toString());
|
||||
storageFn.toJSON = (): any => meta.toJSON();
|
||||
|
||||
return storageFn as StorageFunction;
|
||||
return storageFn as StorageEntry;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import testingPairs from '@polkadot/keyring/testingPairs';
|
||||
import { Metadata } from '@polkadot/types';
|
||||
import json from '@polkadot/types/Metadata/v5/static';
|
||||
import json from '@polkadot/types/Metadata/v6/static';
|
||||
import { u8aToHex } from '@polkadot/util';
|
||||
|
||||
import fromMetadata from './';
|
||||
|
||||
@@ -18,7 +18,7 @@ import { storage } from './storage';
|
||||
* @param metadata - The metadata to extend the storage object against.
|
||||
*/
|
||||
export default function fromMetadata (metadata: Metadata): Storage {
|
||||
return metadata.asV5.modules.reduce((result, moduleMetadata) => {
|
||||
return metadata.asV6.modules.reduce((result, moduleMetadata) => {
|
||||
if (moduleMetadata.storage.isNone) {
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -2,8 +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 { StorageFunctionMetadata, StorageFunctionModifier, StorageFunctionType } from '@polkadot/types/Metadata/v5/Storage';
|
||||
import { StorageFunction } from '@polkadot/types/primitive/StorageKey';
|
||||
import { StorageEntryMetadata, StorageEntryModifier, StorageEntryType } from '@polkadot/types/Metadata/v6/Storage';
|
||||
import { StorageEntry } from '@polkadot/types/primitive/StorageKey';
|
||||
import { Text, Vector } from '@polkadot/types';
|
||||
|
||||
import createFunction from './createFunction';
|
||||
@@ -14,16 +14,16 @@ interface SubstrateMetadata {
|
||||
}
|
||||
|
||||
// Small helper function to factorize code on this page.
|
||||
const createRuntimeFunction = (method: string, key: string, { documentation, type }: SubstrateMetadata): StorageFunction =>
|
||||
const createRuntimeFunction = (method: string, key: string, { documentation, type }: SubstrateMetadata): StorageEntry =>
|
||||
createFunction(
|
||||
new Text('Substrate'),
|
||||
new Text(method),
|
||||
{
|
||||
documentation: new Vector(Text, [documentation]),
|
||||
modifier: new StorageFunctionModifier(1), // default
|
||||
type: new StorageFunctionType(type, 0),
|
||||
modifier: new StorageEntryModifier(1), // default
|
||||
type: new StorageEntryType(type, 0),
|
||||
toJSON: (): any => key
|
||||
} as StorageFunctionMetadata,
|
||||
} as StorageEntryMetadata,
|
||||
{
|
||||
key,
|
||||
skipHashing: true
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Metadata } from '@polkadot/types';
|
||||
import metadataRpc from '@polkadot/types/Metadata/v5/static';
|
||||
import metadataRpc from '@polkadot/types/Metadata/v6/static';
|
||||
|
||||
import fromMetadata from './fromMetadata';
|
||||
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { StorageFunction } from '@polkadot/types/primitive/StorageKey';
|
||||
import { StorageEntry } from '@polkadot/types/primitive/StorageKey';
|
||||
|
||||
export interface ModuleStorage {
|
||||
[key: string]: StorageFunction;
|
||||
[key: string]: StorageEntry;
|
||||
}
|
||||
|
||||
export interface Storage {
|
||||
[key: string]: ModuleStorage; // Will hold modules returned by state_getMetadata
|
||||
substrate: { [key: string]: StorageFunction };
|
||||
substrate: { [key: string]: StorageEntry };
|
||||
}
|
||||
|
||||
@@ -13,11 +13,13 @@ import MetadataV2 from './v2';
|
||||
import MetadataV3 from './v3';
|
||||
import MetadataV4 from './v4';
|
||||
import MetadataV5 from './v5';
|
||||
import MetadataV6 from './v6';
|
||||
import v0ToV1 from './v0/toV1';
|
||||
import v1ToV2 from './v1/toV2';
|
||||
import v2ToV3 from './v2/toV3';
|
||||
import v3ToV4 from './v3/toV4';
|
||||
import v4ToV5 from './v4/toV5';
|
||||
import v5ToV6 from './v5/toV6';
|
||||
|
||||
class MetadataEnum extends Enum {
|
||||
constructor (value?: any) {
|
||||
@@ -27,7 +29,8 @@ class MetadataEnum extends Enum {
|
||||
MetadataV2, // once rolled-out, can replace this with MetadataDeprecated
|
||||
MetadataV3, // once rolled-out, can replace this with MetadataDeprecated
|
||||
MetadataV4, // once rolled-out, can replace this with MetadataDeprecated
|
||||
MetadataV5
|
||||
MetadataV5, // once rolled-out, can replace this with MetadataDeprecated
|
||||
MetadataV6
|
||||
}, value);
|
||||
}
|
||||
|
||||
@@ -85,6 +88,15 @@ class MetadataEnum extends Enum {
|
||||
return this.value as MetadataV5;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the wrapped values as a V6 object
|
||||
*/
|
||||
get asV6 (): MetadataV6 {
|
||||
assert(this.isV6, `Cannot convert '${this.type}' via asV6`);
|
||||
|
||||
return this.value as MetadataV6;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description `true` if Deprecated
|
||||
*/
|
||||
@@ -134,6 +146,13 @@ class MetadataEnum extends Enum {
|
||||
return this.type === 'MetadataV5';
|
||||
}
|
||||
|
||||
/**
|
||||
* @description `true` if V6
|
||||
*/
|
||||
get isV6 (): boolean {
|
||||
return this.type === 'MetadataV6';
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The version this metadata represents
|
||||
*/
|
||||
@@ -153,6 +172,7 @@ export default class MetadataVersioned extends Struct {
|
||||
private _convertedV3?: MetadataV3;
|
||||
private _convertedV4?: MetadataV4;
|
||||
private _convertedV5?: MetadataV5;
|
||||
private _convertedV6?: MetadataV6;
|
||||
|
||||
constructor (value?: any) {
|
||||
super({
|
||||
@@ -242,10 +262,6 @@ export default class MetadataVersioned extends Struct {
|
||||
return this._convertedV3;
|
||||
}
|
||||
|
||||
getUniqTypes (throwError: boolean): Array<string> {
|
||||
return this.asV5.getUniqTypes(throwError);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the wrapped values as a V4 object
|
||||
*/
|
||||
@@ -279,4 +295,25 @@ export default class MetadataVersioned extends Struct {
|
||||
|
||||
return this._convertedV5;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the wrapped values as a V6 object
|
||||
*/
|
||||
get asV6 (): MetadataV6 {
|
||||
assert(this.metadata.version <= 6, `Cannot convert metadata from v${this.metadata.version} to v6`);
|
||||
|
||||
if (this.metadata.version === 6) {
|
||||
return this.metadata.asV6;
|
||||
}
|
||||
|
||||
if (isUndefined(this._convertedV6)) {
|
||||
this._convertedV6 = v5ToV6(this.asV5);
|
||||
}
|
||||
|
||||
return this._convertedV6;
|
||||
}
|
||||
|
||||
getUniqTypes (throwError: boolean): Array<string> {
|
||||
return this.asV6.getUniqTypes(throwError);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,11 @@
|
||||
1. New branch :)
|
||||
2. `curl -H "Content-Type: application/json" -d '{"id":1, "jsonrpc":"2.0", "method": "state_getMetadata", "params":[]}' http://localhost:9933`
|
||||
3. Copy the latest version folder (vx) in `types/Metadata`
|
||||
3. Copy the result (hex-only) into `static.ts`, as of now linked to `v5/static.ts`
|
||||
3. Copy the result (hex-only) into `static.ts`, as of now linked to `v6/static.ts`
|
||||
4. Rust Metadata tests, `yarn run test packages/types/src/Metadata`
|
||||
5. Add new class types as required (find missing in Rust code, add)
|
||||
6. Add all classes to `src/classes.ts`
|
||||
7. Repeat 4-6 until passing
|
||||
8. Update parsed JSON to actual output version, `v5/latest.*.json`
|
||||
8. Update parsed JSON to actual output version, `v6/latest.*.json`
|
||||
9. All tests
|
||||
10. Make PR
|
||||
|
||||
@@ -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 './v5/static';
|
||||
import metadata from './v6/static';
|
||||
|
||||
export default metadata;
|
||||
|
||||
@@ -31,17 +31,17 @@ export function decodeLatestSubstrate<Modules extends Codec> (
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a `version`, MetadataV5 and MetadataV{version} should output the same
|
||||
* Given a `version`, MetadataV6 and MetadataV{version} should output the same
|
||||
* unique types.
|
||||
*/
|
||||
export function toV5<Modules extends Codec> (version: number, rpcData: string) {
|
||||
it('converts to V5', () => {
|
||||
export function toV6<Modules extends Codec> (version: number, rpcData: string) {
|
||||
it('converts to V6', () => {
|
||||
const metadata = new Metadata(rpcData)[`asV${version}` as keyof Metadata];
|
||||
const metadataV5 = new Metadata(rpcData).asV5;
|
||||
const metadataV6 = new Metadata(rpcData).asV6;
|
||||
|
||||
expect(
|
||||
(metadata as unknown as MetadataInterface<Modules>).getUniqTypes(true)
|
||||
).toEqual(metadataV5.getUniqTypes(true));
|
||||
).toEqual(metadataV6.getUniqTypes(true));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -53,7 +53,7 @@ export function defaultValues (rpcData: string) {
|
||||
const metadata = new Metadata(rpcData);
|
||||
Method.injectMethods(extrinsicsFromMeta(metadata));
|
||||
|
||||
metadata.asV5.modules
|
||||
metadata.asV6.modules
|
||||
.filter(({ storage }) => storage.isSome)
|
||||
.map((mod) =>
|
||||
mod.storage.unwrap().forEach(({ fallback, name, type }) => {
|
||||
|
||||
@@ -6,7 +6,7 @@ import MetadataV0 from './';
|
||||
import Metadata from '../';
|
||||
import latestSubstrateV0 from './latest.substrate.v0.json';
|
||||
import rpcData from './static';
|
||||
import { defaultValues, toV5 } from '../util/testUtil';
|
||||
import { defaultValues, toV6 } from '../util/testUtil';
|
||||
|
||||
describe('Metadata', () => {
|
||||
it('works with fallback', () => {
|
||||
@@ -27,7 +27,7 @@ describe('Metadata', () => {
|
||||
expect(json).toEqual(latestSubstrateV0);
|
||||
});
|
||||
|
||||
toV5(0, rpcData);
|
||||
toV6(0, rpcData);
|
||||
|
||||
defaultValues(rpcData);
|
||||
});
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
|
||||
import latestSubstrate from './latest.substrate.v1.json';
|
||||
import rpcData from './static';
|
||||
import { decodeLatestSubstrate, defaultValues, toV5 } from '../util/testUtil';
|
||||
import { decodeLatestSubstrate, defaultValues, toV6 } from '../util/testUtil';
|
||||
|
||||
describe('MetadataV1', () => {
|
||||
decodeLatestSubstrate(1, rpcData, latestSubstrate);
|
||||
|
||||
toV5(1, rpcData);
|
||||
toV6(1, rpcData);
|
||||
|
||||
defaultValues(rpcData);
|
||||
});
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
|
||||
import latestSubstrate from './latest.substrate.v2.json';
|
||||
import rpcData from './static';
|
||||
import { decodeLatestSubstrate, defaultValues, toV5 } from '../util/testUtil';
|
||||
import { decodeLatestSubstrate, defaultValues, toV6 } from '../util/testUtil';
|
||||
|
||||
describe('MetadataV2', () => {
|
||||
decodeLatestSubstrate(2, rpcData, latestSubstrate);
|
||||
|
||||
toV5(2, rpcData);
|
||||
toV6(2, rpcData);
|
||||
|
||||
defaultValues(rpcData);
|
||||
});
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
|
||||
import latestSubstrate from './latest.substrate.v3.json';
|
||||
import rpcData from './static';
|
||||
import { decodeLatestSubstrate, defaultValues, toV5 } from '../util/testUtil';
|
||||
import { decodeLatestSubstrate, defaultValues, toV6 } from '../util/testUtil';
|
||||
|
||||
describe('MetadataV3', () => {
|
||||
decodeLatestSubstrate(3, rpcData, latestSubstrate);
|
||||
|
||||
toV5(3, rpcData);
|
||||
toV6(3, rpcData);
|
||||
|
||||
defaultValues(rpcData);
|
||||
});
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
|
||||
import latestSubstrate from './latest.substrate.v4.json';
|
||||
import rpcData from './static';
|
||||
import { decodeLatestSubstrate, defaultValues, toV5 } from '../util/testUtil';
|
||||
import { decodeLatestSubstrate, defaultValues, toV6 } from '../util/testUtil';
|
||||
|
||||
describe('MetadataV4', () => {
|
||||
decodeLatestSubstrate(4, rpcData, latestSubstrate);
|
||||
|
||||
toV5(4, rpcData);
|
||||
toV6(4, rpcData);
|
||||
|
||||
defaultValues(rpcData);
|
||||
});
|
||||
|
||||
@@ -6,12 +6,12 @@ import polkadotJson from './latest.polkadot.v5.json';
|
||||
import substrateJson from './latest.substrate.v5.json';
|
||||
import polkadotData from './static.polkadot';
|
||||
import substrateData from './static';
|
||||
import { decodeLatestSubstrate, defaultValues, toV5 } from '../util/testUtil';
|
||||
import { decodeLatestSubstrate, defaultValues, toV6 } from '../util/testUtil';
|
||||
|
||||
describe('MetadataV5 (substrate)', () => {
|
||||
decodeLatestSubstrate(5, substrateData, substrateJson);
|
||||
|
||||
toV5(5, substrateData);
|
||||
toV6(5, substrateData);
|
||||
|
||||
defaultValues(substrateData);
|
||||
});
|
||||
@@ -19,7 +19,7 @@ describe('MetadataV5 (substrate)', () => {
|
||||
describe('MetadataV5 (polkadot)', () => {
|
||||
decodeLatestSubstrate(5, polkadotData, polkadotJson);
|
||||
|
||||
toV5(5, polkadotData);
|
||||
toV6(5, polkadotData);
|
||||
|
||||
defaultValues(polkadotData);
|
||||
});
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
// 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 MetadataV5 from './Metadata';
|
||||
import MetadataV6 from '../v6';
|
||||
|
||||
/**
|
||||
* Convert from MetadataV5 to MetadataV6
|
||||
* See https://github.com/polkadot-js/api/issues/1043 for details
|
||||
*/
|
||||
export default function toV6 (metadataV5: MetadataV5): MetadataV6 {
|
||||
return new MetadataV6({
|
||||
modules: metadataV5.modules.map((modul) => {
|
||||
return {
|
||||
name: modul.name,
|
||||
prefix: modul.prefix,
|
||||
storage: modul.storage,
|
||||
calls: modul.calls,
|
||||
events: modul.events,
|
||||
constants: []
|
||||
};
|
||||
})
|
||||
});
|
||||
}
|
||||
@@ -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 V5 and V6
|
||||
export {
|
||||
FunctionArgumentMetadata,
|
||||
FunctionMetadata
|
||||
} from '../v5/Calls';
|
||||
@@ -0,0 +1,48 @@
|
||||
// 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 Bytes from '../../primitive/Bytes';
|
||||
import Text from '../../primitive/Text';
|
||||
import Type from '../../primitive/Type';
|
||||
import Struct from '../../codec/Struct';
|
||||
import Vector from '../../codec/Vector';
|
||||
|
||||
export class ModuleConstantMetadata extends Struct {
|
||||
constructor (value?: any) {
|
||||
super({
|
||||
name: Text,
|
||||
type: Type,
|
||||
value: Bytes,
|
||||
documentation: Vector.with(Text)
|
||||
}, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The argument name
|
||||
*/
|
||||
get name (): Text {
|
||||
return this.get('name') as Text;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The [[Type]]
|
||||
*/
|
||||
get type (): Type {
|
||||
return this.get('type') as Type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The value as [[Bytes]]
|
||||
*/
|
||||
get value (): Bytes {
|
||||
return this.get('value') as Bytes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The documentation
|
||||
*/
|
||||
get documentation (): Vector<Text> {
|
||||
return this.get('documentation') as Vector<Text>;
|
||||
}
|
||||
}
|
||||
@@ -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 V5 and V6
|
||||
export { EventMetadata } from '../v5/Events';
|
||||
@@ -0,0 +1,15 @@
|
||||
// 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 substrateJson from './latest.substrate.v6.json';
|
||||
import substrateData from './static';
|
||||
import { decodeLatestSubstrate, defaultValues, toV6 } from '../util/testUtil';
|
||||
|
||||
describe('MetadataV6 (substrate)', () => {
|
||||
decodeLatestSubstrate(6, substrateData, substrateJson);
|
||||
|
||||
toV6(6, substrateData);
|
||||
|
||||
defaultValues(substrateData);
|
||||
});
|
||||
@@ -0,0 +1,151 @@
|
||||
// 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 { MetadataInterface } from '../types';
|
||||
|
||||
import Option from '../../codec/Option';
|
||||
import Struct from '../../codec/Struct';
|
||||
import Vector from '../../codec/Vector';
|
||||
import Text from '../../primitive/Text';
|
||||
import { flattenUniq, validateTypes } from '../util';
|
||||
|
||||
import { FunctionMetadata } from './Calls';
|
||||
import { ModuleConstantMetadata } from './Constants';
|
||||
import { EventMetadata } from './Events';
|
||||
import { StorageEntryMetadata } from './Storage';
|
||||
|
||||
/**
|
||||
* @name ModuleMetadata
|
||||
* @description
|
||||
* The definition of a module in the system
|
||||
*/
|
||||
export class ModuleMetadata extends Struct {
|
||||
constructor (value?: any) {
|
||||
super({
|
||||
name: Text,
|
||||
prefix: Text,
|
||||
storage: Option.with(Vector.with(StorageEntryMetadata)),
|
||||
calls: Option.with(Vector.with(FunctionMetadata)),
|
||||
events: Option.with(Vector.with(EventMetadata)),
|
||||
constants: Vector.with(ModuleConstantMetadata)
|
||||
}, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description the module calls
|
||||
*/
|
||||
get calls (): Option<Vector<FunctionMetadata>> {
|
||||
return this.get('calls') as Option<Vector<FunctionMetadata>>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description the module constants
|
||||
*/
|
||||
get constants (): Vector<ModuleConstantMetadata> {
|
||||
return this.get('constants') as Vector<ModuleConstantMetadata>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description the module events
|
||||
*/
|
||||
get events (): Option<Vector<EventMetadata>> {
|
||||
return this.get('events') as Option<Vector<EventMetadata>>;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description the module name
|
||||
*/
|
||||
get name (): Text {
|
||||
return this.get('name') as Text;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description the module prefix
|
||||
*/
|
||||
get prefix (): Text {
|
||||
return this.get('prefix') as Text;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description the associated module storage
|
||||
*/
|
||||
get storage (): Option<Vector<StorageEntryMetadata>> {
|
||||
return this.get('storage') as Option<Vector<StorageEntryMetadata>>;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @name MetadataV6
|
||||
* @description
|
||||
* The runtime metadata as a decoded structure
|
||||
*/
|
||||
export default class MetadataV6 extends Struct implements MetadataInterface<ModuleMetadata> {
|
||||
constructor (value?: any) {
|
||||
super({
|
||||
modules: Vector.with(ModuleMetadata)
|
||||
}, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The associated modules for this structure
|
||||
*/
|
||||
get modules (): Vector<ModuleMetadata> {
|
||||
return this.get('modules') as Vector<ModuleMetadata>;
|
||||
}
|
||||
|
||||
private get callNames () {
|
||||
return this.modules.map((mod) =>
|
||||
mod.calls.isNone
|
||||
? []
|
||||
: mod.calls.unwrap().map((fn) =>
|
||||
fn.args.map((arg) => arg.type.toString())
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private get constantNames () {
|
||||
return this.modules.map((mod) =>
|
||||
mod.constants.map((c) =>
|
||||
c.type.toString()
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private get eventNames () {
|
||||
return this.modules.map((mod) =>
|
||||
mod.events.isNone
|
||||
? []
|
||||
: mod.events.unwrap().map((event) =>
|
||||
event.args.map((arg) => arg.toString())
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private get storageNames () {
|
||||
return this.modules.map((mod) =>
|
||||
mod.storage.isNone
|
||||
? []
|
||||
: mod.storage.unwrap().map((fn) => {
|
||||
if (fn.type.isMap) {
|
||||
return [fn.type.asMap.key.toString(), fn.type.asMap.value.toString()];
|
||||
} else if (fn.type.isDoubleMap) {
|
||||
return [fn.type.asDoubleMap.key1.toString(), fn.type.asDoubleMap.key2.toString(), fn.type.asDoubleMap.value.toString()];
|
||||
} else {
|
||||
return [fn.type.asType.toString()];
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Helper to retrieve a list of all type that are found, sorted and de-deuplicated
|
||||
*/
|
||||
getUniqTypes (throwError: boolean): Array<string> {
|
||||
const types = flattenUniq([this.callNames, this.constantNames, this.eventNames, this.storageNames]);
|
||||
|
||||
validateTypes(types, throwError);
|
||||
|
||||
return types;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// 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 { DoubleMapType, MapType, PlainType, StorageFunctionMetadata, StorageFunctionMetadataValue, StorageFunctionModifier, StorageFunctionType } from '../v5/Storage';
|
||||
|
||||
// Re-export classes that haven't changed between V5 and V6
|
||||
export {
|
||||
MapType,
|
||||
PlainType,
|
||||
DoubleMapType,
|
||||
StorageFunctionMetadata as StorageEntryMetadata,
|
||||
StorageFunctionMetadataValue as StorageEntryMetadataValue,
|
||||
StorageFunctionModifier as StorageEntryModifier,
|
||||
StorageFunctionType as StorageEntryType
|
||||
};
|
||||
@@ -0,0 +1,11 @@
|
||||
// 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 { default as MetadataV6, ModuleMetadata as ModuleMetadataV6 } from './Metadata';
|
||||
|
||||
export default MetadataV6;
|
||||
|
||||
export {
|
||||
ModuleMetadataV6
|
||||
};
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@@ -11,7 +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 EventMetadataV5 } from '../Metadata/v5/Events';
|
||||
import { EventMetadata as EventMetadataV6 } from '../Metadata/v6/Events';
|
||||
import Null from './Null';
|
||||
import U32 from './U32';
|
||||
import Unconstructable from './Unconstructable';
|
||||
@@ -32,12 +32,12 @@ export class EventIndex extends U32 {
|
||||
* Wrapper for the actual data that forms part of an [[Event]]
|
||||
*/
|
||||
export class EventData extends Tuple {
|
||||
private _meta: EventMetadataV5;
|
||||
private _meta: EventMetadataV6;
|
||||
private _method: string;
|
||||
private _section: string;
|
||||
private _typeDef: Array<TypeDef>;
|
||||
|
||||
constructor (Types: Array<Constructor>, value: Uint8Array, typeDef: Array<TypeDef>, meta: EventMetadataV5, section: string, method: string) {
|
||||
constructor (Types: Array<Constructor>, value: Uint8Array, typeDef: Array<TypeDef>, meta: EventMetadataV6, section: string, method: string) {
|
||||
super(Types, value);
|
||||
|
||||
this._meta = meta;
|
||||
@@ -49,7 +49,7 @@ export class EventData extends Tuple {
|
||||
/**
|
||||
* @description The wrapped [[EventMetadata]]
|
||||
*/
|
||||
get meta (): EventMetadataV5 {
|
||||
get meta (): EventMetadataV6 {
|
||||
return this._meta;
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ 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 {
|
||||
metadata.asV5.modules
|
||||
metadata.asV6.modules
|
||||
.filter((section) => section.events.isSome)
|
||||
.forEach((section, sectionIndex) => {
|
||||
const sectionName = stringCamelCase(section.name.toString());
|
||||
@@ -166,7 +166,7 @@ export default class Event extends Struct {
|
||||
/**
|
||||
* @description The [[EventMetadata]] with the documentation
|
||||
*/
|
||||
get meta (): EventMetadataV5 {
|
||||
get meta (): EventMetadataV6 {
|
||||
return this.data.meta;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import { assert, isHex, isObject, isU8a, hexToU8a } from '@polkadot/util';
|
||||
import { getTypeDef, getTypeClass } from '../codec/createType';
|
||||
import Struct from '../codec/Struct';
|
||||
import U8aFixed from '../codec/U8aFixed';
|
||||
import { FunctionMetadata as FunctionMetadataV5, FunctionArgumentMetadata } from '../Metadata/v5/Calls';
|
||||
import { FunctionMetadata as FunctionMetadataV6, FunctionArgumentMetadata } from '../Metadata/v6/Calls';
|
||||
|
||||
interface DecodeMethodInput {
|
||||
args: any;
|
||||
@@ -18,13 +18,13 @@ interface DecodeMethodInput {
|
||||
|
||||
interface DecodedMethod extends DecodeMethodInput {
|
||||
argsDef: ArgsDef;
|
||||
meta: FunctionMetadataV5;
|
||||
meta: FunctionMetadataV6;
|
||||
}
|
||||
|
||||
export interface MethodFunction {
|
||||
(...args: any[]): Method;
|
||||
callIndex: Uint8Array;
|
||||
meta: FunctionMetadataV5;
|
||||
meta: FunctionMetadataV6;
|
||||
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: FunctionMetadataV5;
|
||||
protected _meta: FunctionMetadataV6;
|
||||
|
||||
constructor (value: any, meta?: FunctionMetadataV5) {
|
||||
constructor (value: any, meta?: FunctionMetadataV6) {
|
||||
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 = new Uint8Array(), _meta?: FunctionMetadataV5): DecodedMethod {
|
||||
private static decodeMethod (value: DecodedMethod | Uint8Array | string = new Uint8Array(), _meta?: FunctionMetadataV6): DecodedMethod {
|
||||
if (isHex(value)) {
|
||||
return Method.decodeMethod(hexToU8a(value), _meta);
|
||||
} else if (isU8a(value)) {
|
||||
@@ -126,7 +126,7 @@ export default class Method extends Struct implements IMethod {
|
||||
}
|
||||
|
||||
// If the extrinsic function has an argument of type `Origin`, we ignore it
|
||||
static filterOrigin (meta?: FunctionMetadataV5): Array<FunctionArgumentMetadata> {
|
||||
static filterOrigin (meta?: FunctionMetadataV6): Array<FunctionArgumentMetadata> {
|
||||
// FIXME should be `arg.type !== Origin`, but doesn't work...
|
||||
return meta
|
||||
? meta.args.filter(({ type }) =>
|
||||
@@ -154,7 +154,7 @@ export default class Method extends Struct implements IMethod {
|
||||
*
|
||||
* @param meta - The function metadata used to get the definition.
|
||||
*/
|
||||
private static getArgsDef (meta: FunctionMetadataV5): ArgsDef {
|
||||
private static getArgsDef (meta: FunctionMetadataV6): ArgsDef {
|
||||
return Method.filterOrigin(meta).reduce((result, { name, type }) => {
|
||||
const Type = getTypeClass(
|
||||
getTypeDef(type)
|
||||
@@ -216,7 +216,7 @@ export default class Method extends Struct implements IMethod {
|
||||
/**
|
||||
* @description The [[FunctionMetadata]]
|
||||
*/
|
||||
get meta (): FunctionMetadataV5 {
|
||||
get meta (): FunctionMetadataV6 {
|
||||
return this._meta;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import fromMetadata from '@polkadot/storage/fromMetadata';
|
||||
import rpcDataV3 from '@polkadot/types/Metadata/v3/static';
|
||||
import rpcDataV4 from '@polkadot/types/Metadata/v4/static';
|
||||
import rpcDataV5 from '@polkadot/types/Metadata/v5/static';
|
||||
import rpcDataV6 from '@polkadot/types/Metadata/v6/static';
|
||||
|
||||
import Metadata from '../Metadata';
|
||||
import StorageKey from './StorageKey';
|
||||
@@ -123,4 +124,32 @@ describe('StorageKey', () => {
|
||||
).toEqual(Uint8Array.from([1, 1, 48, 7, 201, 255, 112, 39, 246, 89, 0, 171, 205, 252, 164, 253, 177, 7, 234, 212, 126, 42, 158, 53, 88, 224, 27, 105, 27, 15, 74, 95, 133, 24, 212, 135, 50, 102, 20, 240, 102, 65, 99, 8, 191, 106, 164, 229, 4, 29, 25, 73, 146, 142, 75, 38, 237, 233, 142, 60, 235, 179, 106, 59, 23, 38]));
|
||||
});
|
||||
});
|
||||
|
||||
describe('with MetadataV6', () => {
|
||||
const storage = fromMetadata(new Metadata(rpcDataV6));
|
||||
|
||||
it(`should correctly get the EventTopics double map storage key (hex)`, () => {
|
||||
expect(
|
||||
new StorageKey([
|
||||
storage
|
||||
.system
|
||||
.eventTopics,
|
||||
['any', [1, 2, 3]]
|
||||
])
|
||||
.toHex()
|
||||
).toBe('0x3007c9ff7027f65900abcdfca4fdb107ead47e2a9e3558e01b691b0f4a5f8518d487326614f066416308bf6aa4e5041d1949928e4b26ede98e3cebb36a3b1726');
|
||||
});
|
||||
|
||||
it(`should correctly get the EventTopics double map storage key (u8a)`, () => {
|
||||
expect(
|
||||
new StorageKey([
|
||||
storage
|
||||
.system
|
||||
.eventTopics,
|
||||
['any', [1, 2, 3]]
|
||||
])
|
||||
.toU8a()
|
||||
).toEqual(Uint8Array.from([1, 1, 48, 7, 201, 255, 112, 39, 246, 89, 0, 171, 205, 252, 164, 253, 177, 7, 234, 212, 126, 42, 158, 53, 88, 224, 27, 105, 27, 15, 74, 95, 133, 24, 212, 135, 50, 102, 20, 240, 102, 65, 99, 8, 191, 106, 164, 229, 4, 29, 25, 73, 146, 142, 75, 38, 237, 233, 142, 60, 235, 179, 106, 59, 23, 38]));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -4,14 +4,14 @@
|
||||
|
||||
import { assert, isFunction, isString, isU8a } from '@polkadot/util';
|
||||
|
||||
import { StorageFunctionMetadata as MetaV5 } from '../Metadata/v5/Storage';
|
||||
import { StorageEntryMetadata as MetaV6 } from '../Metadata/v6/Storage';
|
||||
import { AnyU8a } from '../types';
|
||||
import Bytes from './Bytes';
|
||||
|
||||
export interface StorageFunction {
|
||||
export interface StorageEntry {
|
||||
(arg?: any): Uint8Array;
|
||||
headKey?: Uint8Array;
|
||||
meta: MetaV5;
|
||||
meta: MetaV6;
|
||||
method: string;
|
||||
section: string;
|
||||
toJSON: () => any;
|
||||
@@ -27,15 +27,15 @@ type Decoded = {
|
||||
* @name StorageKey
|
||||
* @description
|
||||
* A representation of a storage key (typically hashed) in the system. It can be
|
||||
* constructed by passing in a raw key or a StorageFunction with (optional) arguments.
|
||||
* constructed by passing in a raw key or a StorageEntry with (optional) arguments.
|
||||
*/
|
||||
export default class StorageKey extends Bytes {
|
||||
private _meta?: MetaV5;
|
||||
private _meta?: MetaV6;
|
||||
private _method?: string;
|
||||
private _outputType?: string;
|
||||
private _section?: string;
|
||||
|
||||
constructor (value?: AnyU8a | StorageKey | StorageFunction | [StorageFunction, any]) {
|
||||
constructor (value?: AnyU8a | StorageKey | StorageEntry | [StorageEntry, any]) {
|
||||
const { key, method, section } = StorageKey.decodeStorageKey(value);
|
||||
|
||||
super(key);
|
||||
@@ -46,7 +46,7 @@ export default class StorageKey extends Bytes {
|
||||
this._section = section;
|
||||
}
|
||||
|
||||
static decodeStorageKey (value?: AnyU8a | StorageKey | StorageFunction | [StorageFunction, any]): Decoded {
|
||||
static decodeStorageKey (value?: AnyU8a | StorageKey | StorageEntry | [StorageEntry, any]): Decoded {
|
||||
if (value instanceof StorageKey) {
|
||||
return {
|
||||
key: value,
|
||||
@@ -65,7 +65,7 @@ export default class StorageKey extends Bytes {
|
||||
section: value.section
|
||||
};
|
||||
} else if (Array.isArray(value)) {
|
||||
const [fn, ...arg]: [StorageFunction, ...Array<any>] = value as any;
|
||||
const [fn, ...arg]: [StorageEntry, ...Array<any>] = value as any;
|
||||
|
||||
assert(isFunction(fn), 'Expected function input for key construction');
|
||||
|
||||
@@ -79,7 +79,7 @@ export default class StorageKey extends Bytes {
|
||||
throw new Error(`Unable to convert input ${value} to StorageKey`);
|
||||
}
|
||||
|
||||
static getMeta (value: StorageKey | StorageFunction | [StorageFunction, any]): MetaV5 | undefined {
|
||||
static getMeta (value: StorageKey | StorageEntry | [StorageEntry, any]): MetaV6 | undefined {
|
||||
if (value instanceof StorageKey) {
|
||||
return value.meta;
|
||||
} else if (isFunction(value)) {
|
||||
@@ -93,7 +93,7 @@ export default class StorageKey extends Bytes {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
static getType (value: StorageKey | StorageFunction | [StorageFunction, any]): string | undefined {
|
||||
static getType (value: StorageKey | StorageEntry | [StorageEntry, any]): string | undefined {
|
||||
if (value instanceof StorageKey) {
|
||||
return value.outputType;
|
||||
} else if (isFunction(value)) {
|
||||
@@ -110,7 +110,7 @@ export default class StorageKey extends Bytes {
|
||||
/**
|
||||
* @description The metadata or `undefined` when not available
|
||||
*/
|
||||
get meta (): MetaV5 | undefined {
|
||||
get meta (): MetaV6 | undefined {
|
||||
return this._meta;
|
||||
}
|
||||
|
||||
|
||||
@@ -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 MetadataV5 from '../Metadata/v5';
|
||||
import MetadataV6 from '../Metadata/v6';
|
||||
|
||||
const ANCHOR_TOP = '';
|
||||
const LINK_BACK_TO_TOP = '';
|
||||
@@ -67,7 +67,7 @@ function sortByName<T extends { name: any }> (a: T, b: T): number {
|
||||
return nameA.localeCompare(nameB);
|
||||
}
|
||||
|
||||
function addEvents (metadata: MetadataV5) {
|
||||
function addEvents (metadata: MetadataV6) {
|
||||
const renderHeading = `## ${ANCHOR_TOP}Events${DESC_EVENTS}`;
|
||||
const orderedSections = metadata.modules.sort(sortByName);
|
||||
let renderAnchors = '';
|
||||
@@ -100,7 +100,7 @@ function addEvents (metadata: MetadataV5) {
|
||||
return renderHeading + renderAnchors + sections;
|
||||
}
|
||||
|
||||
function addExtrinsics (metadata: MetadataV5) {
|
||||
function addExtrinsics (metadata: MetadataV6) {
|
||||
const renderHeading = `## ${ANCHOR_TOP}Extrinsics${DESC_EXTRINSICS}`;
|
||||
const orderedSections = metadata.modules.map((i) => i).sort(sortByName);
|
||||
let renderAnchors = '';
|
||||
@@ -132,7 +132,7 @@ function addExtrinsics (metadata: MetadataV5) {
|
||||
return renderHeading + renderAnchors + sections;
|
||||
}
|
||||
|
||||
function addStorage (metadata: MetadataV5) {
|
||||
function addStorage (metadata: MetadataV6) {
|
||||
const renderHeading = `## ${ANCHOR_TOP}Storage${DESC_STORAGE}`;
|
||||
const orderedSections = metadata.modules.sort(sortByName);
|
||||
let renderAnchors = '';
|
||||
@@ -184,22 +184,22 @@ function writeToRpcMd () {
|
||||
writeFile('docs/METHODS_RPC.md', addRpc());
|
||||
}
|
||||
|
||||
function writeToStorageMd (metadata: MetadataV5) {
|
||||
function writeToStorageMd (metadata: MetadataV6) {
|
||||
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: MetadataV5) {
|
||||
function writeToExtrinsicsMd (metadata: MetadataV6) {
|
||||
writeFile('docs/METHODS_EXTRINSICS.md', addExtrinsics(metadata));
|
||||
}
|
||||
|
||||
function writeToEventsMd (metadata: MetadataV5) {
|
||||
function writeToEventsMd (metadata: MetadataV6) {
|
||||
writeFile('docs/METHODS_EVENTS.md', addEvents(metadata));
|
||||
}
|
||||
|
||||
const metadata = new Metadata(rpcdata).asV5;
|
||||
const metadata = new Metadata(rpcdata).asV6;
|
||||
|
||||
writeToRpcMd();
|
||||
writeToStorageMd(metadata);
|
||||
|
||||
@@ -9,7 +9,7 @@ import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
import Compact from '../codec/Compact';
|
||||
import Struct from '../codec/Struct';
|
||||
import { FunctionMetadata } from '../Metadata/v5/Calls';
|
||||
import { FunctionMetadata } from '../Metadata/v6/Calls';
|
||||
import Method from '../primitive/Method';
|
||||
import Address from '../primitive/Address';
|
||||
import Hash from '../primitive/Hash';
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import BN from 'bn.js';
|
||||
|
||||
import U8a from './codec/U8a';
|
||||
import { FunctionMetadata } from './Metadata/v5/Calls';
|
||||
import { FunctionMetadata } from './Metadata/v6/Calls';
|
||||
import Method from './primitive/Method';
|
||||
import Address from './primitive/Address';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user