Convert all type/* (and some primitives) to srml/* (#1189)
* Convert (almost-all) non-primitives (and some primitives) to srml/* * Move Vote to primitives, remove type folder * Move Balance :-o * Fixup tests, override Balance.toRaw()
This commit is contained in:
@@ -3,6 +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 { AnyFunction, Codec, CodecArg, RegistryTypes } from '@polkadot/types/types';
|
||||
import {
|
||||
ApiInterfaceRx, ApiInterfaceEvents, ApiOptions, ApiTypes, DecorateMethodOptions,
|
||||
@@ -22,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, Hash, Metadata, Method, RuntimeVersion, SignedBlock, Null, U64 } from '@polkadot/types';
|
||||
import { Event, getTypeRegistry, Metadata, Method, RuntimeVersion, SignedBlock, 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';
|
||||
|
||||
@@ -2,9 +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 { Balance, BlockNumber, Hash, Index } from '@polkadot/types/srml/types';
|
||||
import { SignerPayload as ISignerPayload } from './types';
|
||||
|
||||
import { Address, Balance, BlockNumber, Compact, ExtrinsicEra, Hash, Nonce, Struct, U8, Method } from '@polkadot/types';
|
||||
import { Address, ClassOf, Compact, ExtrinsicEra, Struct, U8, Method } from '@polkadot/types';
|
||||
|
||||
export interface SignerPayloadType {
|
||||
address: Address;
|
||||
@@ -13,20 +14,20 @@ export interface SignerPayloadType {
|
||||
era: ExtrinsicEra;
|
||||
genesisHash: Hash;
|
||||
method: Method;
|
||||
nonce: Compact<Nonce>;
|
||||
nonce: Compact<Index>;
|
||||
tip: Compact<Balance>;
|
||||
version: U8;
|
||||
}
|
||||
|
||||
export default class SignerPayload extends Struct.with({
|
||||
address: Address,
|
||||
blockHash: Hash,
|
||||
blockNumber: BlockNumber,
|
||||
blockHash: ClassOf('Hash'),
|
||||
blockNumber: ClassOf('BlockNumber'),
|
||||
era: ExtrinsicEra,
|
||||
genesisHash: Hash,
|
||||
genesisHash: ClassOf('Hash'),
|
||||
method: Method,
|
||||
nonce: Compact.with(Nonce),
|
||||
tip: Compact.with(Balance),
|
||||
nonce: ClassOf('Compact<Index>'),
|
||||
tip: ClassOf('Compact<Balance>'),
|
||||
version: U8
|
||||
}) {
|
||||
/**
|
||||
|
||||
@@ -2,13 +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 { 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 { AccountId, Address, ExtrinsicStatus, EventRecord, getTypeRegistry, Hash, Header, Index, Method, SignedBlock, Vector, ExtrinsicEra } from '@polkadot/types';
|
||||
import { createType, AccountId, Address, ExtrinsicStatus, EventRecord, getTypeRegistry, Header, Method, SignedBlock, Vector, ExtrinsicEra } from '@polkadot/types';
|
||||
import { isBn, isFunction, isNumber, isUndefined } from '@polkadot/util';
|
||||
|
||||
import filterEvents from './util/filterEvents';
|
||||
@@ -250,7 +251,7 @@ export default function createSubmittableExtrinsic<ApiType> (
|
||||
// if we have a nonce already, don't retrieve the latest, use what is there
|
||||
isUndefined(options.nonce)
|
||||
? api.query.system.accountNonce<Index>(address)
|
||||
: of(new Index(options.nonce)),
|
||||
: of(createType<Index>('Index', options.nonce)),
|
||||
// if we have an era provided already or eraLength is <= 0 (immortal)
|
||||
// don't get the latest block, just pass null, handle in mergeMap
|
||||
(isUndefined(options.era) || (isNumber(options.era) && options.era > 0))
|
||||
|
||||
@@ -4,12 +4,14 @@
|
||||
|
||||
// Simple non-runnable checks to test type definitions in the editor itself
|
||||
|
||||
import { Index } from '@polkadot/types/srml/types';
|
||||
|
||||
import { ApiPromise } from '@polkadot/api';
|
||||
import { HeaderExtended } from '@polkadot/api-derive';
|
||||
import { ConstantCodec } from '@polkadot/api-metadata/consts/types';
|
||||
import testKeyring from '@polkadot/keyring/testingPairs';
|
||||
import { IExtrinsic, IMethod } from '@polkadot/types/types';
|
||||
import { Header, Nonce } from '@polkadot/types';
|
||||
import { Header } from '@polkadot/types';
|
||||
|
||||
import { SubmittableResult } from './';
|
||||
|
||||
@@ -65,7 +67,7 @@ export default async function test (): Promise<void> {
|
||||
console.log('hash:', (await transfer.signAndSend(keyring.alice)).toHex());
|
||||
|
||||
// passing options, but waiting for hash
|
||||
const nonce = await api.query.system.accountNonce<Nonce>(keyring.alice.address);
|
||||
const nonce = await api.query.system.accountNonce<Index>(keyring.alice.address);
|
||||
|
||||
(await api.tx.balances
|
||||
.transfer(keyring.bob.address, 12345)
|
||||
@@ -82,7 +84,7 @@ export default async function test (): Promise<void> {
|
||||
});
|
||||
|
||||
// with options and the callback
|
||||
const nonce2 = await api.query.system.accountNonce<Nonce>(keyring.alice.address);
|
||||
const nonce2 = await api.query.system.accountNonce<Index>(keyring.alice.address);
|
||||
const unsub2 = await api.tx.balances
|
||||
.transfer(keyring.bob.address, 12345)
|
||||
.signAndSend(keyring.alice, { nonce: nonce2 }, ({ status }: SubmittableResult): void => {
|
||||
|
||||
@@ -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 { Hash } from '@polkadot/types';
|
||||
import Mock from '@polkadot/rpc-provider/mock/index';
|
||||
import { createType } from '@polkadot/types';
|
||||
|
||||
import { ApiPromise } from '..';
|
||||
import { ApiOptions } from '../types';
|
||||
@@ -18,7 +18,7 @@ describe('Metadata queries', (): void => {
|
||||
|
||||
it('Create API instance with metadata map and makes the runtime, rpc, state & extrinsics available', async (): Promise<void> => {
|
||||
const rpcData = await mock.send('state_getMetadata', []);
|
||||
const genesisHash = new Hash(await mock.send('chain_getBlockHash', [])).toHex();
|
||||
const genesisHash = createType('Hash', await mock.send('chain_getBlockHash', [])).toHex();
|
||||
const specVersion = 0;
|
||||
const metadata: any = {};
|
||||
const key = `${genesisHash}-${specVersion}`;
|
||||
|
||||
@@ -2,13 +2,15 @@
|
||||
// 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 { AnyFunction, Callback, Codec, CodecArg, IExtrinsic, RegistryTypes, SignatureOptions } from '@polkadot/types/types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
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 { Hash, RuntimeVersion, u64 as U64 } from '@polkadot/types';
|
||||
import { AnyFunction, Callback, Codec, CodecArg, IExtrinsic, RegistryTypes, SignatureOptions } from '@polkadot/types/types';
|
||||
import { RuntimeVersion, u64 as U64 } from '@polkadot/types';
|
||||
import { MethodFunction } from '@polkadot/types/primitive/Method';
|
||||
import { StorageEntry } from '@polkadot/types/primitive/StorageKey';
|
||||
|
||||
|
||||
@@ -2,12 +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 { BlockNumber } from '@polkadot/types/srml/types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
|
||||
import ApiRx from '@polkadot/api/rx/Api';
|
||||
import { HeaderExtended } from '@polkadot/api-derive';
|
||||
import { DerivedBalances, DerivedContractFees, DerivedElectionsInfo, DerivedFees, DerivedSessionInfo } from '@polkadot/api-derive/types';
|
||||
import { AccountId, AccountIndex, BlockNumber, Index } from '@polkadot/types';
|
||||
import { AccountId, AccountIndex, ClassOf } from '@polkadot/types';
|
||||
import { WsProvider } from '@polkadot/rpc-provider';
|
||||
|
||||
const WS = 'ws://127.0.0.1:9944/';
|
||||
@@ -121,7 +123,7 @@ describe.skip('Api-RX derive e2e', (): void => {
|
||||
api.derive.balances.all(ID).subscribe((balances: DerivedBalances): void => {
|
||||
expect(balances).toEqual(expect.objectContaining({
|
||||
accountId: expect.any(AccountId),
|
||||
accountNonce: expect.any(Index),
|
||||
accountNonce: expect.any(ClassOf('Index')),
|
||||
availableBalance: expect.any(BN),
|
||||
freeBalance: expect.any(BN),
|
||||
lockedBalance: expect.any(BN),
|
||||
@@ -154,7 +156,7 @@ describe.skip('Api-RX derive e2e', (): void => {
|
||||
describe('bestNumber', (): void => {
|
||||
it('Get the latest block number', async (done): Promise<void> => {
|
||||
api.derive.chain.bestNumber().subscribe((blockNumber: BlockNumber): void => {
|
||||
expect(blockNumber instanceof BlockNumber).toBe(true);
|
||||
expect(blockNumber instanceof ClassOf('BlockNumber')).toBe(true);
|
||||
expect(blockNumber.gten(0)).toBe(true);
|
||||
done();
|
||||
});
|
||||
@@ -164,7 +166,7 @@ describe.skip('Api-RX derive e2e', (): void => {
|
||||
describe('bestNumberFinalized', (): void => {
|
||||
it('Get the latest finalised block number', async (done): Promise<void> => {
|
||||
api.derive.chain.bestNumberFinalized().subscribe((blockNumber: BlockNumber): void => {
|
||||
expect(blockNumber instanceof BlockNumber).toBe(true);
|
||||
expect(blockNumber instanceof ClassOf('BlockNumber')).toBe(true);
|
||||
expect(blockNumber.gten(0)).toBe(true);
|
||||
done();
|
||||
});
|
||||
@@ -174,7 +176,7 @@ describe.skip('Api-RX derive e2e', (): void => {
|
||||
describe('bestNumberLag', (): void => {
|
||||
it('lag between finalised head and best head', async (done): Promise<void> => {
|
||||
api.derive.chain.bestNumberLag().subscribe((numberLag: BlockNumber): void => {
|
||||
expect(numberLag instanceof BlockNumber).toBe(true);
|
||||
expect(numberLag instanceof ClassOf('BlockNumber')).toBe(true);
|
||||
expect(numberLag.gten(0)).toBe(true);
|
||||
done();
|
||||
});
|
||||
|
||||
@@ -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 { AccountId, EventRecord, Hash, Header, Option, Vector } from '@polkadot/types';
|
||||
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
import { AccountId, ClassOf, EventRecord, Header, Option, Vector } from '@polkadot/types';
|
||||
|
||||
import ApiPromise from '../../../src/promise';
|
||||
import describeE2E from '../../util/describeE2E';
|
||||
@@ -45,7 +44,7 @@ describeE2E({
|
||||
it('Gets the hash of the last finalized header', async (done): Promise<() => void> => {
|
||||
return (
|
||||
api.rpc.chain.getFinalizedHead((head): void => {
|
||||
expect(head instanceof Hash).toBe(true);
|
||||
expect(head instanceof ClassOf('Hash')).toBe(true);
|
||||
done();
|
||||
})
|
||||
);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
import { BlockNumber } from '@polkadot/types';
|
||||
import { ClassOf } from '@polkadot/types';
|
||||
|
||||
import ApiPromise from '../../../src/promise';
|
||||
import describeE2E from '../../util/describeE2E';
|
||||
@@ -25,7 +25,7 @@ describeE2E({
|
||||
});
|
||||
|
||||
it('democracy.cooloffPeriod parameter type', (): void => {
|
||||
expect(api.consts.democracy.cooloffPeriod).toBeInstanceOf(BlockNumber);
|
||||
expect(api.consts.democracy.cooloffPeriod).toBeInstanceOf(ClassOf('BlockNumber'));
|
||||
expect(
|
||||
api.consts.democracy.cooloffPeriod.eq(432000) || // Substrate
|
||||
api.consts.democracy.cooloffPeriod.eq(259200) // Polkadot
|
||||
|
||||
@@ -2,13 +2,15 @@
|
||||
// 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 fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
import { Abi } from '@polkadot/api-contract';
|
||||
import testingPairs from '@polkadot/keyring/testingPairs';
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
import { Address, Hash } from '@polkadot/types';
|
||||
import { Address } from '@polkadot/types';
|
||||
|
||||
import { SubmittableResult } from '../../../src';
|
||||
import ApiPromise from '../../../src/promise';
|
||||
|
||||
@@ -2,12 +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 { Balance, Index } from '@polkadot/types/srml/types';
|
||||
|
||||
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 { Balance, Header, Index, Option, U32 } from '@polkadot/types';
|
||||
import { Header, Option, U32, createType } from '@polkadot/types';
|
||||
|
||||
import ApiPromise from '../../../src/promise';
|
||||
import describeE2E from '../../util/describeE2E';
|
||||
@@ -157,7 +159,7 @@ describeE2E({
|
||||
// assume the account Alice is only used in test(the balance of Alice does not change in this test case)
|
||||
const key = api.query.balances.freeBalance.key(keyring.alice_stash.address);
|
||||
const balanceData = await api.rpc.state.getStorage(key) as Option<any>;
|
||||
const balanceRPC = new Balance(balanceData.unwrapOr(undefined));
|
||||
const balanceRPC = createType<Balance>('Balance', balanceData.unwrapOr(undefined));
|
||||
|
||||
const balance = await api.query.balances.freeBalance(keyring.alice_stash.address);
|
||||
|
||||
|
||||
@@ -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 { SessionIndex } from '@polkadot/types/srml/session/types';
|
||||
import { 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, Hash, Header, Option, Vector, createType } from '@polkadot/types';
|
||||
import { EventRecord, Header, Option, Vector, createType } from '@polkadot/types';
|
||||
|
||||
import ApiPromise from '../../../src/promise';
|
||||
import describeE2E from '../../util/describeE2E';
|
||||
|
||||
@@ -2,12 +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 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, Hash, Header, Index, SignedBlock } from '@polkadot/types';
|
||||
import { EventRecord, ExtrinsicEra, Header, SignedBlock } from '@polkadot/types';
|
||||
|
||||
import { SubmittableResult } from '../../../src';
|
||||
import ApiPromise from '../../../src/promise';
|
||||
|
||||
@@ -2,11 +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 { Balance } from '@polkadot/types/srml/types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { Observable } from 'rxjs';
|
||||
import { switchMap } from 'rxjs/operators';
|
||||
|
||||
import { Balance, Header } from '@polkadot/types';
|
||||
import { Header } from '@polkadot/types';
|
||||
import testingPairs from '@polkadot/keyring/testingPairs';
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
|
||||
|
||||
@@ -2,10 +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 { Index } from '@polkadot/types/srml/types';
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { first, switchMap } from 'rxjs/operators';
|
||||
|
||||
import { Index } from '@polkadot/types';
|
||||
import testingPairs from '@polkadot/keyring/testingPairs';
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import storage from '@polkadot/api-metadata/storage/static';
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
import { BlockNumber, Index, SignedBlock, StorageChangeSet } from '@polkadot/types';
|
||||
import { ClassOf, SignedBlock, StorageChangeSet } from '@polkadot/types';
|
||||
|
||||
import Rpc from '@polkadot/rpc-core';
|
||||
|
||||
@@ -28,8 +28,8 @@ describe.skip('e2e Alexander - Polkadot', (): void => {
|
||||
expect(data).toHaveLength(2);
|
||||
expect(data).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.any(BlockNumber),
|
||||
expect.any(Index)
|
||||
expect.any(ClassOf('BlockNumber')),
|
||||
expect.any(ClassOf('Index'))
|
||||
])
|
||||
);
|
||||
|
||||
|
||||
@@ -2,6 +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 { Balance, Hash } from '@polkadot/types/srml/types';
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
@@ -12,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 { Balance, Bytes, Hash, Metadata, Moment, StorageData, StorageKey } from '@polkadot/types';
|
||||
import { Bytes, Metadata, Moment, StorageData, StorageKey } from '@polkadot/types';
|
||||
|
||||
import Rpc from '@polkadot/rpc-core';
|
||||
import flipperAbi from '../../../../api-contract/test/contracts/flipper.json';
|
||||
|
||||
Reference in New Issue
Block a user