Make Block, Header & Digest generic (#1196)
* Make Block, Header & Digest generic * It lints * Linting passes, tests passes
This commit is contained in:
@@ -114,7 +114,7 @@ export default abstract class ApiBase<ApiType> {
|
||||
* const api = new Api().isReady();
|
||||
*
|
||||
* api.rpc.subscribeNewHead((header) => {
|
||||
* console.log(`new block #${header.blockNumber.toNumber()}`);
|
||||
* console.log(`new block #${header.number.toNumber()}`);
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
|
||||
@@ -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 { ExtrinsicStatus, EventRecord, Hash, Index, SignedBlock } from '@polkadot/types/interfaces';
|
||||
import { ExtrinsicStatus, EventRecord, Hash, Header, Index, SignedBlock } from '@polkadot/types/interfaces';
|
||||
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, getTypeRegistry, Header, Method, Vec, ExtrinsicEra } from '@polkadot/types';
|
||||
import { createType, AccountId, Address, getTypeRegistry, Method, Vec, ExtrinsicEra } from '@polkadot/types';
|
||||
import { isBn, isFunction, isNumber, isUndefined } from '@polkadot/util';
|
||||
|
||||
import filterEvents from './util/filterEvents';
|
||||
@@ -194,12 +194,10 @@ export default function createSubmittableExtrinsic<ApiType> (
|
||||
return expandOptions(options, { nonce });
|
||||
}
|
||||
|
||||
const { blockNumber, hash } = header;
|
||||
|
||||
return expandOptions(options, {
|
||||
blockHash: hash,
|
||||
blockHash: header.hash,
|
||||
era: new ExtrinsicEra({
|
||||
current: blockNumber,
|
||||
current: header.number,
|
||||
period: options.era || DEFAULT_MORTAL_LENGTH
|
||||
}),
|
||||
nonce
|
||||
@@ -274,7 +272,7 @@ export default function createSubmittableExtrinsic<ApiType> (
|
||||
...eraOptions,
|
||||
address,
|
||||
method: _extrinsic.method,
|
||||
blockNumber: header ? header.blockNumber : 0,
|
||||
blockNumber: header ? header.number : 0,
|
||||
genesisHash: api.genesisHash,
|
||||
version: api.extrinsicType
|
||||
});
|
||||
@@ -290,7 +288,7 @@ export default function createSubmittableExtrinsic<ApiType> (
|
||||
|
||||
updateId = await api.signer.sign(_extrinsic, address, {
|
||||
...eraOptions,
|
||||
blockNumber: header ? header.blockNumber : new BN(0),
|
||||
blockNumber: header ? header.number.toBn() : new BN(0),
|
||||
genesisHash: api.genesisHash
|
||||
});
|
||||
} else {
|
||||
|
||||
@@ -4,15 +4,14 @@
|
||||
|
||||
// Simple non-runnable checks to test type definitions in the editor itself
|
||||
|
||||
import { Index } from '@polkadot/types/interfaces';
|
||||
import { Header, Index } from '@polkadot/types/interfaces';
|
||||
|
||||
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 { createType, Header } from '@polkadot/types';
|
||||
import { createTypeUnsafe } from '@polkadot/types/codec/createType';
|
||||
import createType, { createTypeUnsafe } from '@polkadot/types/codec/createType';
|
||||
|
||||
import { SubmittableResult } from './';
|
||||
|
||||
@@ -38,11 +37,11 @@ export default async function test (): Promise<void> {
|
||||
});
|
||||
|
||||
await api.rpc.chain.subscribeNewHead<Header>((header): void => {
|
||||
console.log('current blockNumber:', header.blockNumber);
|
||||
console.log('current blockNumber:', header.number);
|
||||
});
|
||||
|
||||
await api.rpc.chain.subscribeNewHead((header: Header): void => {
|
||||
console.log('current blockNumber:', header.blockNumber);
|
||||
console.log('current blockNumber:', header.number);
|
||||
});
|
||||
|
||||
await api.derive.chain.subscribeNewHead((header: HeaderExtended): void => {
|
||||
|
||||
@@ -40,7 +40,7 @@ import Combinator, { CombinatorCallback, CombinatorFunction } from './Combinator
|
||||
*
|
||||
* // make a subscription to the network head
|
||||
* api.rpc.chain.subscribeNewHead((header) => {
|
||||
* console.log(`Chain is at #${header.blockNumber}`);
|
||||
* console.log(`Chain is at #${header.number}`);
|
||||
* });
|
||||
* ```
|
||||
* <BR>
|
||||
@@ -138,7 +138,7 @@ export default class ApiPromise extends ApiBase<'promise'> {
|
||||
*
|
||||
* new Api().isReady.then((api) => {
|
||||
* api.rpc.subscribeNewHead((header) => {
|
||||
* console.log(`new block #${header.blockNumber.toNumber()}`);
|
||||
* console.log(`new block #${header.number.toNumber()}`);
|
||||
* });
|
||||
* });
|
||||
* ```
|
||||
|
||||
@@ -37,7 +37,7 @@ import ApiBase from '../Base';
|
||||
*
|
||||
* // make a call to retrieve the current network head
|
||||
* api.rpc.chain.subscribeNewHead().subscribe((header) => {
|
||||
* console.log(`Chain is at #${header.blockNumber}`);
|
||||
* console.log(`Chain is at #${header.number}`);
|
||||
* });
|
||||
* ```
|
||||
* <BR>
|
||||
@@ -131,7 +131,7 @@ export default class ApiRx extends ApiBase<'rxjs'> {
|
||||
* api.rpc.chain.subscribeNewHead()
|
||||
* ))
|
||||
* .subscribe((header) => {
|
||||
* console.log(`new block #${header.blockNumber.toNumber()}`);
|
||||
* console.log(`new block #${header.number.toNumber()}`);
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
@@ -157,7 +157,7 @@ export default class ApiRx extends ApiBase<'rxjs'> {
|
||||
* api.rpc.chain.subscribeNewHead()
|
||||
* ))
|
||||
* .subscribe((header) => {
|
||||
* console.log(`new block #${header.blockNumber.toNumber()}`);
|
||||
* console.log(`new block #${header.number.toNumber()}`);
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
|
||||
@@ -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 { EventRecord } from '@polkadot/types/interfaces';
|
||||
import { EventRecord, Header } from '@polkadot/types/interfaces';
|
||||
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
import { AccountId, ClassOf, Header, Option, Vec } from '@polkadot/types';
|
||||
import { AccountId, ClassOf, Option, Vec } from '@polkadot/types';
|
||||
|
||||
import ApiPromise from '../../../src/promise';
|
||||
import describeE2E from '../../util/describeE2E';
|
||||
@@ -55,7 +55,7 @@ describeE2E({
|
||||
it('Subscribes to the best finalized header on ALEX', async (done): Promise<() => void> => {
|
||||
return (
|
||||
api.rpc.chain.subscribeFinalizedHeads((head): void => {
|
||||
expect(head instanceof Header).toBe(true);
|
||||
expect(head instanceof ClassOf('Header')).toBe(true);
|
||||
done();
|
||||
})
|
||||
);
|
||||
|
||||
@@ -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 { Balance, Index } from '@polkadot/types/interfaces';
|
||||
import { Balance, Header, Index } from '@polkadot/types/interfaces';
|
||||
|
||||
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 { Option, u32, createType } from '@polkadot/types';
|
||||
|
||||
import ApiPromise from '../../../src/promise';
|
||||
import describeE2E from '../../util/describeE2E';
|
||||
|
||||
@@ -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 { Header } from '@polkadot/types/interfaces';
|
||||
|
||||
import testingPairs from '@polkadot/keyring/testingPairs';
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
import { Header, Option } from '@polkadot/types';
|
||||
import { Option } from '@polkadot/types';
|
||||
import { encodeAddress, randomAsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
import ApiPromise from '../../../src/promise';
|
||||
|
||||
@@ -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 { EventRecord, Hash, SessionIndex } from '@polkadot/types/interfaces';
|
||||
import { EventRecord, Hash, Header, SessionIndex } from '@polkadot/types/interfaces';
|
||||
|
||||
import { HeaderExtended } from '@polkadot/api-derive';
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
import { LinkageResult } from '@polkadot/types/codec/Linkage';
|
||||
import { Header, Option, Vec, createType } from '@polkadot/types';
|
||||
import { Option, Vec, createType } from '@polkadot/types';
|
||||
|
||||
import ApiPromise from '../../../src/promise';
|
||||
import describeE2E from '../../util/describeE2E';
|
||||
@@ -34,7 +34,7 @@ describeE2E()('Promise e2e queries', (wsUrl): void => {
|
||||
it('subscribes to rpc', (done): Promise<() => void> => {
|
||||
return (
|
||||
api.rpc.chain.subscribeNewHead((header: Header): void => {
|
||||
expect(header.blockNumber.isZero()).toBe(false);
|
||||
expect(header.number.isEmpty).toBe(false);
|
||||
|
||||
done();
|
||||
})
|
||||
@@ -44,7 +44,7 @@ describeE2E()('Promise e2e queries', (wsUrl): void => {
|
||||
it('subscribes to finalized', (done): Promise<() => void> => {
|
||||
return (
|
||||
api.rpc.chain.subscribeFinalizedHeads((header: Header): void => {
|
||||
expect(header.blockNumber.isZero()).toBe(false);
|
||||
expect(header.number.isEmpty).toBe(false);
|
||||
|
||||
done();
|
||||
})
|
||||
@@ -54,7 +54,7 @@ describeE2E()('Promise e2e queries', (wsUrl): void => {
|
||||
it('subscribes to derive', (done): Promise<() => void> => {
|
||||
return (
|
||||
api.derive.chain.subscribeNewHead((header: HeaderExtended): void => {
|
||||
expect(header.blockNumber.isZero()).toBe(false);
|
||||
expect(header.number.isEmpty).toBe(false);
|
||||
|
||||
done();
|
||||
})
|
||||
|
||||
@@ -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 { EventRecord, Hash, Index, SignedBlock } from '@polkadot/types/interfaces';
|
||||
import { EventRecord, Hash, Header, Index, SignedBlock } from '@polkadot/types/interfaces';
|
||||
|
||||
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 { ExtrinsicEra, Header } from '@polkadot/types';
|
||||
import { ExtrinsicEra } from '@polkadot/types';
|
||||
|
||||
import { SubmittableResult } from '../../../src';
|
||||
import ApiPromise from '../../../src/promise';
|
||||
@@ -161,7 +161,7 @@ describeE2E({
|
||||
|
||||
it('makes a transfer (specified era, previous block)', async (done): Promise<void> => {
|
||||
const signedBlock = await api.rpc.chain.getBlock() as SignedBlock;
|
||||
const currentHeight = signedBlock.block.header.number.subn(1);
|
||||
const currentHeight = signedBlock.block.header.number.toBn().subn(1);
|
||||
const exERA = new ExtrinsicEra({ current: currentHeight, period: 10 });
|
||||
const ex = api.tx.balances.transfer(keyring.eve.address, 12345);
|
||||
|
||||
@@ -181,7 +181,7 @@ describeE2E({
|
||||
const ex = api.tx.balances.transfer(keyring.eve.address, 12345);
|
||||
|
||||
await api.rpc.chain.subscribeNewHead(async (header: Header): Promise<void> => {
|
||||
if (header.blockNumber.toNumber() === eraDeath - 1) {
|
||||
if (header.number.toNumber() === eraDeath - 1) {
|
||||
try {
|
||||
await ex.signAndSend(keyring.alice, { blockHash, era: exERA, nonce } as any);
|
||||
} catch (error) {
|
||||
@@ -209,7 +209,7 @@ describeE2E({
|
||||
const ex = api.tx.balances.transfer(keyring.eve.address, 12345);
|
||||
|
||||
await api.rpc.chain.subscribeNewHead(async (header: Header): Promise<void> => {
|
||||
if (header.blockNumber.toNumber() === eraDeath - 1) {
|
||||
if (header.number.toNumber() === eraDeath - 1) {
|
||||
try {
|
||||
await ex.signAndSend(keyring.alice.address, { blockHash, era: exERA, nonce } as any);
|
||||
} catch (error) {
|
||||
|
||||
@@ -2,13 +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 { Balance } from '@polkadot/types/interfaces';
|
||||
import { Balance, Header } from '@polkadot/types/interfaces';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { Observable } from 'rxjs';
|
||||
import { switchMap } from 'rxjs/operators';
|
||||
|
||||
import { Header } from '@polkadot/types';
|
||||
import testingPairs from '@polkadot/keyring/testingPairs';
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
|
||||
|
||||
@@ -2,9 +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 { RuntimeVersion } from '@polkadot/types/interfaces';
|
||||
import { Header, RuntimeVersion } from '@polkadot/types/interfaces';
|
||||
|
||||
import { ClassOf, Header } from '@polkadot/types';
|
||||
import { ClassOf } from '@polkadot/types';
|
||||
import WsProvider from '@polkadot/rpc-provider/ws';
|
||||
|
||||
import Rpc from '@polkadot/rpc-core';
|
||||
@@ -23,7 +23,7 @@ describe.skip('e2e chain', (): void => {
|
||||
rpc.chain
|
||||
.subscribeNewHead()
|
||||
.subscribe((header: Header): void => {
|
||||
expect(header).toBeInstanceOf(Header);
|
||||
expect(header).toBeInstanceOf(ClassOf('Header'));
|
||||
|
||||
if (++count === 3) {
|
||||
done();
|
||||
|
||||
Reference in New Issue
Block a user