Convert RPC classes to primitive classes or /srml types (#1192)

* Convert RPC classes to primitive classes or /srml types

* Lint passes... lokking at tests next.

* Tests pass.

* Types with basic docs (lots of work here)

* Update StorageKey.spec.ts

* Add injector to metadata doc generation

* Fix import
This commit is contained in:
Jaco Greeff
2019-07-26 10:23:37 +02:00
committed by GitHub
parent 83515fc0a2
commit 478f54c703
144 changed files with 1824 additions and 2224 deletions
+3 -3
View File
@@ -3,7 +3,7 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { ProviderInterface } from '@polkadot/rpc-provider/types';
import { Hash } from '@polkadot/types/srml/types';
import { Hash, RuntimeVersion, SignedBlock } from '@polkadot/types/srml/types';
import { AnyFunction, Codec, CodecArg, RegistryTypes } from '@polkadot/types/types';
import {
ApiInterfaceRx, ApiInterfaceEvents, ApiOptions, ApiTypes, DecorateMethodOptions,
@@ -23,7 +23,7 @@ import { Storage } from '@polkadot/api-metadata/storage/types';
import storageFromMeta from '@polkadot/api-metadata/storage/fromMetadata';
import RpcCore from '@polkadot/rpc-core';
import { WsProvider } from '@polkadot/rpc-provider';
import { Event, getTypeRegistry, Metadata, Method, RuntimeVersion, SignedBlock, Null, U64 } from '@polkadot/types';
import { Event, getTypeRegistry, Metadata, Method, Null, u64 } from '@polkadot/types';
import Linkage, { LinkageResult } from '@polkadot/types/codec/Linkage';
import { DEFAULT_VERSION as EXTRINSIC_DEFAULT_VERSION } from '@polkadot/types/primitive/Extrinsic/constants';
import { MethodFunction, ModulesWithMethods } from '@polkadot/types/primitive/Method';
@@ -697,7 +697,7 @@ export default abstract class ApiBase<ApiType> {
);
decorated.size = decorateMethod(
(arg1?: CodecArg, arg2?: CodecArg): Observable<U64> =>
(arg1?: CodecArg, arg2?: CodecArg): Observable<u64> =>
this._rpcCore.state.getStorageSize(
creator.meta.type.isDoubleMap
? [creator, [arg1, arg2]]
+3 -3
View File
@@ -5,7 +5,7 @@
import { Balance, BlockNumber, Hash, Index } from '@polkadot/types/srml/types';
import { SignerPayload as ISignerPayload } from './types';
import { Address, ClassOf, Compact, ExtrinsicEra, Struct, U8, Method } from '@polkadot/types';
import { Address, ClassOf, Compact, ExtrinsicEra, Struct, u8, Method } from '@polkadot/types';
export interface SignerPayloadType {
address: Address;
@@ -16,7 +16,7 @@ export interface SignerPayloadType {
method: Method;
nonce: Compact<Index>;
tip: Compact<Balance>;
version: U8;
version: u8;
}
export default class SignerPayload extends Struct.with({
@@ -28,7 +28,7 @@ export default class SignerPayload extends Struct.with({
method: Method,
nonce: ClassOf('Compact<Index>'),
tip: ClassOf('Compact<Balance>'),
version: U8
version: u8
}) {
/**
* @description Returns this as a SignerPayloadType. This works since the Struct.with injects all the getters automatically (just ensure the 2 definitiona are matching)
+3 -3
View File
@@ -2,14 +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 { Hash, Index } from '@polkadot/types/srml/types';
import { ExtrinsicStatus, EventRecord, Hash, Index, SignedBlock } from '@polkadot/types/srml/types';
import { AnyNumber, AnyU8a, Callback, Codec, IExtrinsic, IExtrinsicEra, IKeyringPair, SignatureOptions } from '@polkadot/types/types';
import { ApiInterfaceRx, ApiTypes } from './types';
import BN from 'bn.js';
import { Observable, combineLatest, of } from 'rxjs';
import { first, map, mergeMap, switchMap, tap } from 'rxjs/operators';
import { createType, AccountId, Address, ExtrinsicStatus, EventRecord, getTypeRegistry, Header, Method, SignedBlock, Vector, ExtrinsicEra } from '@polkadot/types';
import { createType, AccountId, Address, getTypeRegistry, Header, Method, Vec, ExtrinsicEra } from '@polkadot/types';
import { isBn, isFunction, isNumber, isUndefined } from '@polkadot/util';
import filterEvents from './util/filterEvents';
@@ -135,7 +135,7 @@ export default function createSubmittableExtrinsic<ApiType> (
return combineLatest([
api.rpc.chain.getBlock(blockHash) as Observable<SignedBlock>,
api.query.system.events.at(blockHash) as Observable<Vector<EventRecord>>
api.query.system.events.at(blockHash) as Observable<Vec<EventRecord>>
]).pipe(
map(([signedBlock, allEvents]): SubmittableResult => {
const result = new SubmittableResult({
+4 -4
View File
@@ -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 { Hash } from '@polkadot/types/srml/types';
import { Hash, RuntimeVersion } from '@polkadot/types/srml/types';
import { AnyFunction, Callback, Codec, CodecArg, IExtrinsic, RegistryTypes, SignatureOptions } from '@polkadot/types/types';
import BN from 'bn.js';
@@ -10,7 +10,7 @@ import { Observable } from 'rxjs';
import { DeriveCustom } from '@polkadot/api-derive';
import { Constants } from '@polkadot/api-metadata/consts/types';
import { ProviderInterface, ProviderInterfaceEmitted } from '@polkadot/rpc-provider/types';
import { RuntimeVersion, u64 as U64 } from '@polkadot/types';
import { u64 } from '@polkadot/types';
import { MethodFunction } from '@polkadot/types/primitive/Method';
import { StorageEntry } from '@polkadot/types/primitive/StorageKey';
@@ -107,7 +107,7 @@ export interface StorageEntryObservable {
hash: (arg1?: CodecArg, arg2?: CodecArg) => Observable<Hash>;
key: (arg1?: CodecArg, arg2?: CodecArg) => string;
multi: <T extends Codec>(args: (CodecArg[] | CodecArg)[]) => Observable<T[]>;
size: (arg1?: CodecArg, arg2?: CodecArg) => Observable<U64>;
size: (arg1?: CodecArg, arg2?: CodecArg) => Observable<u64>;
}
export interface StorageEntryPromiseOverloads {
@@ -129,7 +129,7 @@ export interface StorageEntryPromise extends StorageEntryPromiseOverloads {
hash: (arg1?: CodecArg, arg2?: CodecArg) => Promise<Hash>;
key: (arg1?: CodecArg, arg2?: CodecArg) => string;
multi: StorageEntryPromiseMulti;
size: (arg1?: CodecArg, arg2?: CodecArg) => Promise<U64>;
size: (arg1?: CodecArg, arg2?: CodecArg) => Promise<u64>;
}
export type QueryableStorageEntry<ApiType> =
+3 -1
View File
@@ -2,7 +2,9 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { EventRecord, SignedBlock, U8a } from '@polkadot/types';
import { EventRecord, SignedBlock } from '@polkadot/types/srml/types';
import { U8a } from '@polkadot/types';
import l from './logging';
@@ -2,8 +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 { SignedBlock } from '@polkadot/types/srml/types';
import WsProvider from '@polkadot/rpc-provider/ws';
import { Extrinsic, SignedBlock } from '@polkadot/types';
import { Extrinsic } from '@polkadot/types';
import ApiPromise from '../../../src/promise';
import describeE2E from '../../util/describeE2E';
@@ -2,8 +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 { EventRecord } from '@polkadot/types/srml/types';
import WsProvider from '@polkadot/rpc-provider/ws';
import { AccountId, ClassOf, EventRecord, Header, Option, Vector } from '@polkadot/types';
import { AccountId, ClassOf, Header, Option, Vec } from '@polkadot/types';
import ApiPromise from '../../../src/promise';
import describeE2E from '../../util/describeE2E';
@@ -72,13 +74,13 @@ describeE2E({
it('makes a query at a latest block (specified)', async (): Promise<void> => {
const header = await api.rpc.chain.getHeader() as Header;
const events = await api.query.system.events.at(header.hash) as Vector<EventRecord>;
const events = await api.query.system.events.at(header.hash) as Vec<EventRecord>;
expect(events.length).not.toEqual(0);
});
it('subscribes to events', (done): Promise<() => void> => {
return api.query.system.events((events: Vector<EventRecord>): void => {
return api.query.system.events((events: Vec<EventRecord>): void => {
expect(events).not.toHaveLength(0);
done();
});
@@ -9,7 +9,7 @@ import BN from 'bn.js';
import { DerivedBalances } from '@polkadot/api-derive/types';
import testingPairs from '@polkadot/keyring/testingPairs';
import WsProvider from '@polkadot/rpc-provider/ws';
import { Header, Option, U32, createType } from '@polkadot/types';
import { Header, Option, u32, createType } from '@polkadot/types';
import ApiPromise from '../../../src/promise';
import describeE2E from '../../util/describeE2E';
@@ -65,7 +65,7 @@ describeE2E({
it('subscribes to queries (default)', (done): Promise<() => void> => {
return (
api.query.staking.minimumValidatorCount((defaultCount: U32): void => {
api.query.staking.minimumValidatorCount((defaultCount: u32): void => {
expect(defaultCount.toNumber()).toBe(1);
done();
@@ -2,12 +2,12 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { Hash, SessionIndex } from '@polkadot/types/srml/types';
import { EventRecord, Hash, SessionIndex } from '@polkadot/types/srml/types';
import { HeaderExtended } from '@polkadot/api-derive';
import WsProvider from '@polkadot/rpc-provider/ws';
import { LinkageResult } from '@polkadot/types/codec/Linkage';
import { EventRecord, Header, Option, Vector, createType } from '@polkadot/types';
import { Header, Option, Vec, createType } from '@polkadot/types';
import ApiPromise from '../../../src/promise';
import describeE2E from '../../util/describeE2E';
@@ -80,7 +80,7 @@ describeE2E()('Promise e2e queries', (wsUrl): void => {
it('makes a query at a latest block (specified)', async (): Promise<void> => {
const header = await api.rpc.chain.getHeader() as Header;
const events = await api.query.system.events.at(header.hash) as Vector<EventRecord>;
const events = await api.query.system.events.at(header.hash) as Vec<EventRecord>;
expect(events.length).not.toEqual(0);
+2 -2
View File
@@ -2,14 +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 { Hash, Index } from '@polkadot/types/srml/types';
import { EventRecord, Hash, Index, SignedBlock } from '@polkadot/types/srml/types';
import Keyring from '@polkadot/keyring';
import testingPairs from '@polkadot/keyring/testingPairs';
import WsProvider from '@polkadot/rpc-provider/ws';
import { u8aToHex } from '@polkadot/util';
import { randomAsHex } from '@polkadot/util-crypto';
import { EventRecord, ExtrinsicEra, Header, SignedBlock } from '@polkadot/types';
import { ExtrinsicEra, Header } from '@polkadot/types';
import { SubmittableResult } from '../../../src';
import ApiPromise from '../../../src/promise';
@@ -2,9 +2,11 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { SignedBlock, StorageChangeSet } from '@polkadot/types/srml/types';
import storage from '@polkadot/api-metadata/storage/static';
import WsProvider from '@polkadot/rpc-provider/ws';
import { ClassOf, SignedBlock, StorageChangeSet } from '@polkadot/types';
import { ClassOf } from '@polkadot/types';
import Rpc from '@polkadot/rpc-core';
@@ -42,7 +44,7 @@ describe.skip('e2e Alexander - Polkadot', (): void => {
.getBlock('0x627847bffdf5f3e01ac440d057dec6a37a12a6f329db7ef8367665574b76b5df')
.subscribe((block: SignedBlock): void => {
expect(block).toBeDefined();
expect(block).toBeInstanceOf(SignedBlock);
expect(block).toBeInstanceOf(ClassOf('SignedBlock'));
done();
});
});
@@ -52,7 +54,7 @@ describe.skip('e2e Alexander - Polkadot', (): void => {
.getBlock('0x53416d53a4b1dfcae9165a89d193608e4aa770414f02267f5b2c4015a2e66091')
.subscribe((block: SignedBlock): void => {
expect(block).toBeDefined();
expect(block).toBeInstanceOf(SignedBlock);
expect(block).toBeInstanceOf(ClassOf('SignedBlock'));
done();
});
});
@@ -2,7 +2,9 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { ChainProperties, Extrinsic, Vector } from '@polkadot/types';
import { ChainProperties } from '@polkadot/types/srml/types';
import { ClassOf, Extrinsic, Vec } from '@polkadot/types';
import WsProvider from '@polkadot/rpc-provider/ws';
import Rpc from '@polkadot/rpc-core';
@@ -18,8 +20,8 @@ describe.skip('e2e basics', (): void => {
it('retrieves the pending extrinsics', (done): void => {
rpc.author
.pendingExtrinsics()
.subscribe((extrinsics: Vector<Extrinsic>): void => {
expect(extrinsics).toBeInstanceOf(Vector);
.subscribe((extrinsics: Vec<Extrinsic>): void => {
expect(extrinsics).toBeInstanceOf(Vec);
done();
});
});
@@ -28,7 +30,7 @@ describe.skip('e2e basics', (): void => {
rpc.system
.properties()
.subscribe((properties: ChainProperties): void => {
expect(properties).toBeInstanceOf(ChainProperties);
expect(properties).toBeInstanceOf(ClassOf('ChainProperties'));
console.log('properties', properties);
done();
});
+4 -2
View File
@@ -2,7 +2,9 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { Header, RuntimeVersion } from '@polkadot/types';
import { RuntimeVersion } from '@polkadot/types/srml/types';
import { ClassOf, Header } from '@polkadot/types';
import WsProvider from '@polkadot/rpc-provider/ws';
import Rpc from '@polkadot/rpc-core';
@@ -33,7 +35,7 @@ describe.skip('e2e chain', (): void => {
rpc.chain
.getRuntimeVersion()
.subscribe((version: RuntimeVersion): void => {
expect(version).toBeInstanceOf(RuntimeVersion);
expect(version).toBeInstanceOf(ClassOf('RuntimeVersion'));
done();
});
});
+2 -2
View File
@@ -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 { Balance, Hash } from '@polkadot/types/srml/types';
import { Balance, Hash, StorageData } from '@polkadot/types/srml/types';
import fs from 'fs';
import path from 'path';
@@ -14,7 +14,7 @@ import { Abi } from '@polkadot/api-contract';
import testingPairs from '@polkadot/keyring/testingPairs';
import { KeyringPair } from '@polkadot/keyring/types';
import WsProvider from '@polkadot/rpc-provider/ws';
import { Bytes, Metadata, Moment, StorageData, StorageKey } from '@polkadot/types';
import { Bytes, Metadata, Moment, StorageKey } from '@polkadot/types';
import Rpc from '@polkadot/rpc-core';
import flipperAbi from '../../../../api-contract/test/contracts/flipper.json';
@@ -2,7 +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 { StorageChangeSet } from '@polkadot/types';
import { StorageChangeSet } from '@polkadot/types/srml/types';
import WsProvider from '@polkadot/rpc-provider/ws';
import storage from '@polkadot/api-metadata/storage/static';