Skip to content

Commit

Permalink
Merge pull request #18 from ora-io/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
murongg authored Sep 23, 2024
2 parents 8f3fc42 + 8fc2ce8 commit 35677b1
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ora-stack",
"version": "0.1.7",
"version": "0.1.8",
"private": true,
"packageManager": "[email protected]",
"description": "",
Expand Down
8 changes: 4 additions & 4 deletions packages/orap/examples/declarativeDemo/app.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { EventLog } from 'ethers'
import type { ContractEventPayload } from 'ethers'
import { Logger, randomStr, redisStore } from '@ora-io/utils'
import type { ListenOptions, ToKeyFn } from '../../src'
import { Orap, StoreManager } from '../../src'
Expand Down Expand Up @@ -57,13 +57,13 @@ export function startDemo(options: ListenOptions, storeConfig?: any) {
)
}

async function handleTask(from: string, to: string, amount: number) {
async function handleTask(from: string, to: string, amount: number, _event: ContractEventPayload) {
logger.log('[+] handleTask: from =', from, 'to =', to, 'amount =', amount)
return true
}

async function newEventSignalHook(from: string, to: string, amount: number, event: EventLog) {
logger.log('receive new event signal, tx:', event.transactionHash)
async function newEventSignalHook(from: string, to: string, amount: number, event: ContractEventPayload) {
logger.log('receive new event signal, tx:', event.log.transactionHash)
logger.debug(' - from:', from, ' - to:', to, ' - amount:', amount)
return true // true to continue handle tasks, false to hijack the process.
}
Expand Down
2 changes: 1 addition & 1 deletion packages/orap/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@ora-io/orap",
"type": "module",
"version": "0.1.7",
"version": "0.1.8",
"packageManager": "[email protected]",
"description": "",
"author": "Norman (nom4dv3), MuRong",
Expand Down
10 changes: 8 additions & 2 deletions packages/orap/src/signal/event.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { EventFragment, Interface, InterfaceAbi, Log } from 'ethers'
import { ContractEventPayload, ethers } from 'ethers'
import { ContractEventPayload, ContractUnknownEventPayload, ethers } from 'ethers'
import { AutoCrossChecker, ONE_MINUTE_MS, RekuProviderManager } from '@ora-io/reku'
import type { AutoCrossCheckParam, Providers } from '@ora-io/reku'
import type { Signal } from './interface'
Expand Down Expand Up @@ -53,7 +53,7 @@ export class EventSignal implements Signal {
// to align with subscribe listener, parse event params and add EventLog to the last
this.crosscheckCallback = async (log: Log) => {
const parsedLog = this.contract.interface.decodeEventLog(this.eventFragment, log.data, log.topics)
const payload = new ContractEventPayload(this.contract, this.subscribeCallback, this.params.eventName, this.eventFragment, log)
const payload = this._wrapContractEventPayload(log)
await this.callback(...parsedLog, payload)
}

Expand All @@ -62,6 +62,12 @@ export class EventSignal implements Signal {
this._setCrosscheckOptions(crosscheckOptions)
}

private _wrapContractEventPayload(log: Log) {
if (this.eventFragment)
return new ContractEventPayload(this.contract, this.subscribeCallback, this.params.eventName, this.eventFragment, log)
return new ContractUnknownEventPayload(this.contract, this.subscribeCallback, this.params.eventName, log)
}

private _setCrosscheckOptions(options: Omit<AutoCrossCheckParam, 'address' | 'topics' | 'onMissingLog'>) {
const {
pollingInterval = ONE_MINUTE_MS * 60,
Expand Down
2 changes: 1 addition & 1 deletion packages/reku/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@ora-io/reku",
"type": "module",
"version": "0.1.7",
"version": "0.1.8",
"packageManager": "[email protected]",
"description": "",
"author": "Norman (nom4dv3), MuRong",
Expand Down
2 changes: 1 addition & 1 deletion packages/utils/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@ora-io/utils",
"type": "module",
"version": "0.1.7",
"version": "0.1.8",
"packageManager": "[email protected]",
"description": "",
"author": "Norman (nom4dv3), MuRong",
Expand Down

0 comments on commit 35677b1

Please sign in to comment.