test-pkg-ngn
Version:
A library containing helper functions that facilitate scripting for keepers of the Keep3r Network
45 lines (44 loc) • 2.13 kB
TypeScript
import { Block } from '@ethersproject/abstract-provider';
import { providers } from 'ethers';
import { Observable } from 'rxjs';
/**
* Class in charge of managing the fetching of blocks and how they are provided acoss the app.
*
*/
export declare class BlockListener {
private provider;
private count;
private block$;
private subs;
/**
* @param provider - JsonRpc provider that has the methods needed to fetch and listen for new blocks.
*/
constructor(provider: providers.BaseProvider);
/**
* This function is able to provide a listener for new incoming blocks with all their data.
* Returns and observable that emits an event every time a new block arrives.
*
* @dev
* Block listener is initialized only if the subscriptions account is zero. Otherwise it will skip the initialization
* and just return the block$ observable where the new blocks are being pushed.
* For the fetching part we need to combine two different functions to fetch and deliver new blocks:
* - One that fetches the current block just once when this function is called and push it to block$ observable.
* - One that hooks to the 'block' event of the provider that returns just the number of the new block, and then use
* provider.getBlock(blockNumber) method to fetch all the data of that block and push it to block$ observable.
*
* @param debugId - Optional id to help with debugging.
* @returns An observable that emits blocks
*/
stream(debugId?: string): Observable<Block>;
/**
* Stops block fetching and remove all the internal subscriptions to blockNumber observable.
*
* @dev
* This will only stop block fetching and subscription to blockNumber IF the amount of subscriptions to block$ observable
* is zero. If amount is zero this means that theres no part of the code actually listening to the block$ observable
* so theres no need for us to keep listening for new blocks incoming.
*
* @param debugId - Optional id to help with debugging.
*/
stop(debugId?: string): void;
}