UNPKG

argosjs

Version:

Ethereum smart-contract events visualiser

88 lines (87 loc) 2.62 kB
import { Network, Networkish } from "ethers/utils"; import { Database } from "../database/Database"; import { Strategies } from "../utils/strategy"; import { ContractType, DatabaseConstructorType, ProviderEnum, ProviderType, WatcherEnum } from "../utils/types"; export interface WatcherConstructor { type: WatcherEnum; provider: ProviderEnum; clearDB: boolean; address: string; db: DatabaseConstructorType; abi: string; providerConf: ProviderConfig; exportDir: string; } export interface ProviderConfig { logSizePerOp: number; default?: { network?: string | Network; }; timeout?: number; infura?: { network?: Networkish; projectId?: string; }; etherscan?: { network?: Networkish; api?: string; }; jsonrpc?: { network: Networkish; url?: string; username?: string; password?: string; allowInsecure?: boolean; }; web3?: { host?: string; }; ipc?: { path?: string; network?: Networkish; }; } export interface EventInfoDataStruct { [property: string]: any; } export default abstract class Watcher { provider: ProviderType; dbService: Database; contract: ContractType; /** * Create a watcher for any network */ constructor(); /** * Get events from log * @param {string} eventName the event name to watch * @param {number} fromBlock the start block, default is 0 * @param {number} toBlock the ending block, default is 'lastest' * @param {number} nbTasks how many batches required to process the log */ abstract getEvents(eventName: string, fromBlock: number, toBlock: number): Promise<void>; /** * Watch event with particular model * @param {string} eventName name of the event * @param {Neode.SchemaObject} dbModel the model loaded via require() * @param {Date} fromDate timestamp * @param {Date} toDate timestamp */ abstract watchEvents(eventName: string, fromDate: Date, toDate: Date): Promise<void>; /** * Convert timestamp to blocknumber * @param {Date} date */ abstract timeToBlock(date: Date): Promise<number>; /** * Load the strategies to the watcher * @param strategies the user-defined strategy to extract and persists data */ abstract setStrategies(strategies: Strategies): void; /** * Tell the Watcher to clear the database before the next operation * @param clearFlag */ abstract setClearDBFlag(clearFlag: boolean): void; } export { Watcher };