mirror of
https://github.com/pezkuwichain/pezkuwi-api.git
synced 2026-11-27 07:59:54 +00:00
Rebrand: polkadot → pezkuwi, substrate → bizinikiwi, kusama → dicle
This commit is contained in:
commit
d5f038faea
1383 files changed
+1088018
No files matched your search
@@ -0,0 +1,33 @@
|
||||
// Copyright 2017-2025 @pezkuwi/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { BlockNumber } from '@pezkuwi/types/interfaces';
|
||||
import type { DeriveApi } from '../types.js';
|
||||
|
||||
import { combineLatest, map } from 'rxjs';
|
||||
|
||||
import { memo } from '../util/index.js';
|
||||
|
||||
/**
|
||||
* @name bestNumberLag
|
||||
* @returns A number of blocks
|
||||
* @description Calculates the lag between finalized head and best head
|
||||
* @examplew
|
||||
* ```javascript
|
||||
* api.derive.chain.bestNumberLag((lag) => {
|
||||
* console.log(`finalized is ${lag} blocks behind head`);
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function bestNumberLag (instanceId: string, api: DeriveApi): () => Observable<BlockNumber> {
|
||||
return memo(instanceId, (): Observable<BlockNumber> =>
|
||||
combineLatest([
|
||||
api.derive.chain.bestNumber(),
|
||||
api.derive.chain.bestNumberFinalized()
|
||||
]).pipe(
|
||||
map(([bestNumber, bestNumberFinalized]): BlockNumber =>
|
||||
api.registry.createType('BlockNumber', bestNumber.sub(bestNumberFinalized))
|
||||
)
|
||||
));
|
||||
}
|
||||
Reference in new issue
Block a user