Mark api.query.<section>.<method>.at as deprecated (#4023)
* Use api.at internally for sizeAt/entriesAt/keysAt * Remove debug logs * Mark api.query.<section>.<method>.at as deprecated * formatting * @deprecated formatting * commenting
This commit is contained in:
@@ -24,20 +24,19 @@ import { memo } from '../util';
|
||||
* ```
|
||||
*/
|
||||
export function getBlock (instanceId: string, api: ApiInterfaceRx): (hash: Uint8Array | string) => Observable<SignedBlockExtended | undefined> {
|
||||
return memo(instanceId, (hash: Uint8Array | string): Observable<SignedBlockExtended | undefined> =>
|
||||
// we get the block first, setting up the registry
|
||||
api.rpc.chain.getBlock(hash).pipe(
|
||||
switchMap((signedBlock) =>
|
||||
return memo(instanceId, (blockHash: Uint8Array | string): Observable<SignedBlockExtended | undefined> =>
|
||||
api.queryAt(blockHash).pipe(
|
||||
switchMap((queryAt) =>
|
||||
combineLatest([
|
||||
api.query.system.events.at(hash),
|
||||
api.query.session
|
||||
? api.query.session.validators.at(hash)
|
||||
api.rpc.chain.getBlock(blockHash),
|
||||
queryAt.system.events(),
|
||||
queryAt.session
|
||||
? queryAt.session.validators()
|
||||
: of([])
|
||||
]).pipe(
|
||||
map(([events, validators]) =>
|
||||
createSignedBlockExtended(api.registry, signedBlock, events, validators)
|
||||
)
|
||||
)
|
||||
])
|
||||
),
|
||||
map(([signedBlock, events, validators]) =>
|
||||
createSignedBlockExtended(api.registry, signedBlock, events, validators)
|
||||
),
|
||||
catchError((): Observable<undefined> =>
|
||||
// where rpc.chain.getHeader throws, we will land here - it can happen that
|
||||
|
||||
@@ -6,17 +6,11 @@ import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { AccountId } from '@polkadot/types/interfaces';
|
||||
import type { HeaderExtended } from '../type/types';
|
||||
|
||||
import { catchError, map, of, switchMap } from 'rxjs';
|
||||
import { catchError, combineLatest, map, of, switchMap } from 'rxjs';
|
||||
|
||||
import { createHeaderExtended } from '../type';
|
||||
import { memo } from '../util';
|
||||
|
||||
function _getValidators (api: ApiInterfaceRx, hash: Uint8Array | string): Observable<AccountId[]> {
|
||||
return api.query.session
|
||||
? api.query.session.validators.at(hash)
|
||||
: of([] as AccountId[]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @name getHeader
|
||||
* @param {( Uint8Array | string )} hash - A block hash as U8 array or string.
|
||||
@@ -33,14 +27,17 @@ function _getValidators (api: ApiInterfaceRx, hash: Uint8Array | string): Observ
|
||||
*/
|
||||
export function getHeader (instanceId: string, api: ApiInterfaceRx): (hash: Uint8Array | string) => Observable<HeaderExtended | undefined> {
|
||||
return memo(instanceId, (hash: Uint8Array | string): Observable<HeaderExtended | undefined> =>
|
||||
// we get the header first, setting up the registry
|
||||
api.rpc.chain.getHeader(hash).pipe(
|
||||
switchMap((header) =>
|
||||
_getValidators(api, hash).pipe(
|
||||
map((validators) =>
|
||||
createHeaderExtended(header.registry, header, validators)
|
||||
)
|
||||
)
|
||||
api.queryAt(hash).pipe(
|
||||
switchMap((queryAt) =>
|
||||
combineLatest([
|
||||
api.rpc.chain.getHeader(hash),
|
||||
queryAt.session
|
||||
? queryAt.session.validators()
|
||||
: of([] as AccountId[])
|
||||
])
|
||||
),
|
||||
map(([header, validators]) =>
|
||||
createHeaderExtended(header.registry, header, validators)
|
||||
),
|
||||
catchError((): Observable<undefined> =>
|
||||
// where rpc.chain.getHeader throws, we will land here - it can happen that
|
||||
|
||||
@@ -5,7 +5,7 @@ import type { Observable } from 'rxjs';
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { SignedBlockExtended } from '../type/types';
|
||||
|
||||
import { map, switchMap } from 'rxjs';
|
||||
import { combineLatest, map, of, switchMap } from 'rxjs';
|
||||
|
||||
import { createSignedBlockExtended } from '../type';
|
||||
import { memo } from '../util';
|
||||
@@ -21,16 +21,19 @@ export function subscribeNewBlocks (instanceId: string, api: ApiInterfaceRx): ()
|
||||
const blockHash = header.createdAtHash || header.hash;
|
||||
|
||||
// we get the block first, setting up the registry
|
||||
return api.rpc.chain.getBlock(blockHash).pipe(
|
||||
switchMap((block) =>
|
||||
api.query.system.events.at(blockHash).pipe(
|
||||
map((events) =>
|
||||
createSignedBlockExtended(block.registry, block, events, header.validators)
|
||||
)
|
||||
)
|
||||
return api.queryAt(blockHash).pipe(
|
||||
switchMap((queryAt) =>
|
||||
combineLatest([
|
||||
of(header),
|
||||
api.rpc.chain.getBlock(blockHash),
|
||||
queryAt.system.events()
|
||||
])
|
||||
)
|
||||
);
|
||||
})
|
||||
}),
|
||||
map(([header, block, events]) =>
|
||||
createSignedBlockExtended(block.registry, block, events, header.validators)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import type { Observable } from 'rxjs';
|
||||
import type { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import type { EventRecord, Hash, SignedBlock } from '@polkadot/types/interfaces';
|
||||
|
||||
import { map, switchMap } from 'rxjs';
|
||||
import { combineLatest, map, switchMap } from 'rxjs';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
@@ -15,17 +15,15 @@ interface Result {
|
||||
}
|
||||
|
||||
export function events (instanceId: string, api: ApiInterfaceRx): (at: Hash) => Observable<Result> {
|
||||
return memo(instanceId, (at: Hash) =>
|
||||
// we get the block first, setting up the registry
|
||||
api.rpc.chain.getBlock(at).pipe(
|
||||
switchMap((block) =>
|
||||
api.query.system.events.at(at).pipe(
|
||||
map((events): Result => ({
|
||||
block,
|
||||
events
|
||||
}))
|
||||
)
|
||||
)
|
||||
return memo(instanceId, (blockHash: Hash) =>
|
||||
api.queryAt(blockHash).pipe(
|
||||
switchMap((queryAt) =>
|
||||
combineLatest([
|
||||
api.rpc.chain.getBlock(blockHash),
|
||||
queryAt.system.events()
|
||||
])
|
||||
),
|
||||
map(([block, events]): Result => ({ block, events }))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user