import { EventEmitter } from 'events'; import { TransactionError } from '../types'; import { TransactionReceipt, TransactionResponse, } from '@ethersproject/abstract-provider'; import { PopulatedTransaction } from 'ethers'; // base transaction manager event export type BaseTransactionManagerEvent = { transactionRequest: PopulatedTransaction; transactionId: string; }; // event to emit from transaction manager for transaction queued export type TransactionQueuedEvent = { isLiveQueue: boolean; } & BaseTransactionManagerEvent; export type TransactionStarted = {} & BaseTransactionManagerEvent; // event to emit from transaction manager for transaction confirmed export type TransactionConfirmedEvent = { transactionResponse: TransactionResponse; } & BaseTransactionManagerEvent; // event to emit from transaction manager for transaction failed export type TransactionFailedEvent = { transactionError: TransactionError; } & BaseTransactionManagerEvent; // event to emit from transaction manager for transaction retried export type TransactionRetriedEvent = { retryCount: number; } & BaseTransactionManagerEvent; // event to emait from transaction manager for transaction max retries reached export type TransactionMaxRetriesReachedEvent = { retryCount: number; } & BaseTransactionManagerEvent; // event to emit for transaction manager for transaction executed export type TransactionExecutedEvent = { transactionReceipt?: TransactionReceipt; } & BaseTransactionManagerEvent; export type TransactionTimedOutEvent = { transactionError?: TransactionError; } & BaseTransactionManagerEvent; export type TransactionCompletedEvent = { transactionError: TransactionError; } & BaseTransactionManagerEvent; export type TransactionGasError = { transactionError: TransactionError; } & BaseTransactionManagerEvent; // transaction manager event emitter interface export declare interface TransactionManagerEventEmitter { on(event: string, listener: () => void): this; on( event: 'transactionQueued', listener: (event: TransactionQueuedEvent) => void, ): this; on( event: 'transactionConfirmed', listener: (event: TransactionConfirmedEvent) => void, ): this; on( event: 'transactionFailed', listener: (event: TransactionFailedEvent) => void, ): this; on( event: 'transactionRetried', listener: (event: TransactionRetriedEvent) => void, ): this; on( event: 'transactionMaxRetriesReached', listener: (event: TransactionMaxRetriesReachedEvent) => void, ): this; on( event: 'transactionExecuted', listener: (event: TransactionExecutedEvent) => void, ); on( event: 'transactionCompleted', listener: (event: TransactionCompletedEvent) => void, ): this; on( event: 'transactionTimedOut', listener: (event: TransactionTimedOutEvent) => void, ); on( event: 'transactionGasError', listener: (event: TransactionGasError) => void, ); on( event: 'transactionStarted', listener: (event: TransactionStarted) => void, ); } // transaction manager event emitter export class TransactionManagerEventEmitter extends EventEmitter implements TransactionManagerEventEmitter { transactionQueued(event: TransactionQueuedEvent): void { this.emit('transactionQueued', event); } transactionConfirmed(event: TransactionConfirmedEvent): void { this.emit('transactionConfirmed', event); } transactionFailed(event: TransactionFailedEvent): void { this.emit('transactionFailed', event); } transactionRetried(event: TransactionRetriedEvent): void { this.emit('transactionRetried', event); } transactionMaxRetriesReached(event: TransactionMaxRetriesReachedEvent): void { this.emit('transactionMaxRetriesReached', event); } transactionExecuted(event: TransactionExecutedEvent): void { this.emit('transactionExecuted', event); } transactionProcessingCompleted(event: TransactionCompletedEvent): void { this.emit('transactionCompleted', event); } transactionTimedOut(event: TransactionTimedOutEvent): void { this.emit('transactionTimedOut', event); } transactionGasError(event: TransactionGasError): void { this.emit('transactionGasError', event); } transactionStarted(event: TransactionStarted): void { this.emit('transactionStarted', event); } }