Skip to content

Commit 7a2ccc0

Browse files
committed
feat(orap): add context to signal
1 parent e5f0212 commit 7a2ccc0

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

packages/orap/orap.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { RekuProviderManager } from '@ora-io/reku'
33
import type { Logger } from '@ora-io/utils'
44
import { logger } from '@ora-io/utils'
55
import { EventSignal } from './signal/event'
6+
import type { Context } from './context'
67

78
export interface ListenOptions {
89
wsProvider: Providers
@@ -22,8 +23,8 @@ export class Orap {
2223
}
2324
}
2425

25-
event(options: any, fn: any) {
26-
const es = new EventSignal(options, fn, this.logger)
26+
event(options: any, fn: any, context?: Context) {
27+
const es = new EventSignal(options, fn, this.logger, context)
2728
this.routes.event.push(es)
2829
return es
2930
}

packages/orap/signal/event.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { ethers } from 'ethers'
33
import { AutoCrossChecker, ONE_MINUTE_MS, RekuProviderManager } from '@ora-io/reku'
44
import type { AutoCrossCheckParam, Providers } from '@ora-io/reku'
55
import type { Logger } from '@ora-io/utils'
6+
import type { Context } from '../context'
67
import type { Signal } from './type'
78

89
export interface EventSignalRegisterParams {
@@ -30,6 +31,7 @@ export class EventSignal implements Signal {
3031
public params: EventSignalRegisterParams,
3132
public callback: EventSignalCallback,
3233
public logger: Logger,
34+
public context?: Context,
3335
) {
3436
this.contract = new ethers.Contract(
3537
params.address,
@@ -48,14 +50,14 @@ export class EventSignal implements Signal {
4850
// to align with crosschecker onMissing, parse the last arg from ContractEventPayload to EventLog
4951
this.subscribeCallback = async (...args: Array<any>) => {
5052
const _contractEventPayload = args.pop()
51-
await this.callback(...args, _contractEventPayload.log)
53+
await this.callback(...args, _contractEventPayload.log, context)
5254
await this.crosschecker?.cache!.addLog(_contractEventPayload.log)
5355
}
5456
// to align with subscribe listener, parse event params and add EventLog to the last
5557
this.crosscheckCallback = async (log: Log) => {
5658
const parsedLog = this.contract.interface.decodeEventLog(this.eventFragment, log.data, log.topics)
5759
this.logger.info('crosschecker capture a missing event! processing...', log.transactionHash, log.index)
58-
await this.callback(...parsedLog, log)
60+
await this.callback(...parsedLog, log, context)
5961
}
6062
}
6163

0 commit comments

Comments
 (0)