Skip to content

Commit

Permalink
fixed some issues on comments
Browse files Browse the repository at this point in the history
  • Loading branch information
KelvinThai committed Dec 5, 2023
1 parent db0475c commit cc245c6
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ const func = async function (hre) {
if (config.deploy) {
console.log('deploy')
const deployConfig = config.deploy
const l2VRFConsumerMock = await deploy('L2RequestResponseConsumerMock', {
const l2RequestResponseConsumerMock = await deploy('L2RequestResponseConsumerMock', {
args: [deployConfig.l2EndpointAddress],
from: deployer,
log: true
})

console.log('L2RequestResponseConsumerMock:', l2VRFConsumerMock)
console.log('L2RequestResponseConsumerMock:', l2RequestResponseConsumerMock)
}

await updateMigration(migrationDirPath, migration)
}
}

func.id = 'deploy-consumer'
func.tags = ['consumer']
func.id = 'deploy-L2RequestResponseConsumerMock'
func.tags = ['L2RequestResponseConsumerMock']

module.exports = func
4 changes: 2 additions & 2 deletions contracts/deploy/L2VRFConsumerMock/L2VRFConsumer.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const func = async function (hre) {
}
}

func.id = 'deploy-consumer'
func.tags = ['consumer']
func.id = 'deploy-L2VRFConsumerMock'
func.tags = ['L2VRFConsumerMock']

module.exports = func
8 changes: 4 additions & 4 deletions core/src/listener/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { buildLogger } from '../logger'
import { CHAIN, REDIS_HOST, REDIS_PORT } from '../settings'
import { hookConsoleError } from '../utils'
import { getListeners } from './api'
import { IListeners } from './types'
import { postprocessListeners } from './utils'
import { buildListener as buildDataFeedListener } from './data-feed'
import { buildListener as buildL2DataFeedListener } from './data-feed-L2'
import { buildListener as buildRequestResponseListener } from './request-response'
import { buildListener as buildRequestResponseL2FulfillListener } from './requestResponnse-L2-fulfill'
import { buildListener as buildRequestResponseL2RequestListener } from './requestResponnse-L2-request'
import { IListeners } from './types'
import { postprocessListeners } from './utils'
import { buildListener as buildRequestResponseL2FulfillListener } from './request-responnse-L2-fulfill'
import { buildListener as buildRequestResponseL2RequestListener } from './request-responnse-L2-request'
import { buildListener as buildVrfListener } from './vrf'
import { buildListener as buildVrfL2FulfillListener } from './vrf-L2-fulfill'
import { buildListener as buildVrfL2RequestListener } from './vrf-L2-request'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
} from '../types'
import { listenerService } from './listener'
import { ProcessEventOutputType } from './types'
import { parseResponse } from './request-response-L2.utils'

const FILE_NAME = import.meta.url

Expand Down Expand Up @@ -67,29 +68,7 @@ async function processEvent({ iface, logger }: { iface: ethers.utils.Interface;
_logger.debug(eventData, 'eventData')

const requestId = eventData.requestId.toString()
let response: number | string | boolean = 0
switch (eventData.jobId) {
case ethers.utils.id('uint128'):
response = Number(eventData.responseUint128)
break
case ethers.utils.id('int256'):
response = Number(eventData.responseInt256)
break
case ethers.utils.id('bool'):
response = eventData.responseBool
break
case ethers.utils.id('string'):
response = eventData.responseString
break
case ethers.utils.id('bytes32'):
response = eventData.responseBytes32
break
case ethers.utils.id('bytes'):
response = eventData.responseBytes
break
default:
break
}
const response = parseResponse[eventData.jobId](eventData)
const jobData: IL2RequestResponseFulfillListenerWorker = {
callbackAddress: L1_ENDPOINT,
blockNum: log.blockNumber,
Expand All @@ -98,7 +77,7 @@ async function processEvent({ iface, logger }: { iface: ethers.utils.Interface;
jobId: eventData.jobId.toString(),
callbackGasLimit: eventData.callbackGasLimit,
sender: eventData.sender,
response: response
response
}
_logger.debug(jobData, 'jobData')

Expand Down
30 changes: 30 additions & 0 deletions core/src/listener/request-response-L2.utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { ethers } from 'ethers'
import { IL2DataRequestFulfilled } from '../types'

export const UINT128 = ethers.utils.id('uint128')
export const INT256 = ethers.utils.id('uint128')
export const BOOL = ethers.utils.id('bool')
export const STRING = ethers.utils.id('string')
export const BYTES32 = ethers.utils.id('bytes32')
export const BYTES = ethers.utils.id('bytes')

export const parseResponse = {
[UINT128]: function (x: IL2DataRequestFulfilled) {
return Number(x.responseUint128)
},
[INT256]: function (x: IL2DataRequestFulfilled) {
return Number(x.responseInt256)
},
[BOOL]: function (x: IL2DataRequestFulfilled) {
return x.responseBool
},
[STRING]: function (x: IL2DataRequestFulfilled) {
return x.responseString
},
[BYTES32]: function (x: IL2DataRequestFulfilled) {
return x.responseBytes32
},
[BYTES]: function (x: IL2DataRequestFulfilled) {
return x.responseBytes
}
} satisfies Record<string, (x: IL2DataRequestFulfilled) => number | string | boolean>
4 changes: 4 additions & 0 deletions core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export interface IL2DataRequested {
callbackGasLimit: number
sender: string
numSubmission: number
/* eslint-disable @typescript-eslint/no-explicit-any */
req: any
}

Expand Down Expand Up @@ -199,6 +200,7 @@ export interface IL2RequestResponseListenerWorker {
callbackGasLimit: number
sender: string
numSubmission: number
/* eslint-disable @typescript-eslint/no-explicit-any */
req: any
}

Expand All @@ -210,6 +212,7 @@ export interface IL2RequestResponseFulfillListenerWorker {
callbackGasLimit: number
sender: string
l2RequestId: string
/* eslint-disable @typescript-eslint/no-explicit-any */
response: any
}

Expand Down Expand Up @@ -417,6 +420,7 @@ export interface IL2RequestResponseRequestTransactionParameters {
numSubmission: number
sender: string
l2RequestId: string
/* eslint-disable @typescript-eslint/no-explicit-any */
req: any
}

Expand Down
9 changes: 2 additions & 7 deletions core/src/worker/request-response-L2-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import { Queue, Worker } from 'bullmq'
import { ethers } from 'ethers'
import { Logger } from 'pino'
import type { RedisClientType } from 'redis'
import { getVrfConfig } from '../api'
import {
BULLMQ_CONNECTION,
CHAIN,
L1_ENDPOINT,
L2_REPORTER_REQUEST_RESPONSE_REQUEST_QUEUE_NAME,
L2_WORKER_REQUEST_RESPONSE_REQUEST_QUEUE_NAME,
Expand All @@ -17,7 +15,6 @@ import {
IL2RequestResponseListenerWorker,
IL2RequestResponseRequestTransactionParameters,
ITransactionParameters,
IVrfConfig,
QueueType
} from '../types'

Expand All @@ -26,11 +23,9 @@ const FILE_NAME = import.meta.url
export async function worker(redisClient: RedisClientType, _logger: Logger) {
const logger = _logger.child({ name: 'worker', file: FILE_NAME })
const queue = new Queue(L2_REPORTER_REQUEST_RESPONSE_REQUEST_QUEUE_NAME, BULLMQ_CONNECTION)
// FIXME add checks if exists and if includes all information
const vrfConfig = await getVrfConfig({ chain: CHAIN, logger })
const worker = new Worker(
L2_WORKER_REQUEST_RESPONSE_REQUEST_QUEUE_NAME,
await job(queue, vrfConfig, _logger),
await job(queue, _logger),
BULLMQ_CONNECTION
)

Expand All @@ -44,7 +39,7 @@ export async function worker(redisClient: RedisClientType, _logger: Logger) {
process.on('SIGTERM', handleExit)
}

export async function job(reporterQueue: QueueType, config: IVrfConfig, _logger: Logger) {
export async function job(reporterQueue: QueueType, _logger: Logger) {
const logger = _logger.child({ name: 'l2RequestResponseRequestJob', file: FILE_NAME })
const iface = new ethers.utils.Interface(L1Endpoint__factory.abi)

Expand Down

0 comments on commit cc245c6

Please sign in to comment.