Skip to content

Commit

Permalink
feat(reku): ContractManager rename to RekuContractManager
Browse files Browse the repository at this point in the history
  • Loading branch information
murongg committed Dec 2, 2024
1 parent 3ff9603 commit a9c4e16
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion packages/reku/src/provider/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { ContractAddress, Fn } from '@ora-io/utils'
import type { Interface, InterfaceAbi } from 'ethers'
import { ethers } from 'ethers'

export class ContractManager {
export class RekuContractManager {
private _contract?: ethers.Contract
private _listeners: Map<ethers.ContractEventName, Fn> = new Map()

Expand Down
18 changes: 9 additions & 9 deletions packages/reku/src/provider/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Interface, WebSocketProvider, ethers } from 'ethers'
import type { ErrorEvent, WebSocket } from 'ws'
import type { ContractAddress } from '@ora-io/utils'
import { debug } from '../debug'
import { ContractManager } from './contract'
import { RekuContractManager } from './contract'

export interface RekuProviderManagerOptions {
/**
Expand All @@ -21,7 +21,7 @@ export type RekuProviderManagerEvent = 'error' | 'close'

export class RekuProviderManager {
private _provider?: ethers.JsonRpcProvider | ethers.WebSocketProvider
private _contracts: Map<ContractAddress, ContractManager> = new Map()
private _contracts: Map<ContractAddress, RekuContractManager> = new Map()

private _heartbeatInterval = 10 * 1000

Expand Down Expand Up @@ -54,20 +54,20 @@ export class RekuProviderManager {
return this._contracts
}

addContract(address: ContractAddress, contract: ethers.Contract): ContractManager | undefined
addContract(address: ContractAddress, abi: Interface | InterfaceAbi): ContractManager | undefined
addContract(address: ContractAddress, abi: Interface | InterfaceAbi | ethers.Contract): ContractManager | undefined {
addContract(address: ContractAddress, contract: ethers.Contract): RekuContractManager | undefined
addContract(address: ContractAddress, abi: Interface | InterfaceAbi): RekuContractManager | undefined
addContract(address: ContractAddress, abi: Interface | InterfaceAbi | ethers.Contract): RekuContractManager | undefined {
if (this._provider) {
if (abi instanceof Interface || Array.isArray(abi)) {
if (!abi)
throw new Error('ABI must be provided when address is a string')

const contract = new ContractManager(address, abi, this._provider)
const contract = new RekuContractManager(address, abi, this._provider)
this._contracts.set(address, contract)
return contract
}
else if (abi instanceof ethers.Contract) {
const contract = new ContractManager(address, abi.interface, this._provider)
const contract = new RekuContractManager(address, abi.interface, this._provider)
this._contracts.set(address, contract)
return contract
}
Expand Down Expand Up @@ -155,10 +155,10 @@ export class RekuProviderManager {
// reconnect provider
this.connect()
// reset contracts
const contracts: Map<ContractAddress, ContractManager> = new Map()
const contracts: Map<ContractAddress, RekuContractManager> = new Map()
this._contracts.forEach((contract) => {
if (this._provider) {
const newContract = new ContractManager(contract.address, contract.abi, this._provider)
const newContract = new RekuContractManager(contract.address, contract.abi, this._provider)
contract.listeners.forEach((listener, event) => {
newContract.addListener(event, listener)
})
Expand Down
8 changes: 4 additions & 4 deletions packages/reku/tests/contract.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ethers } from 'ethers'
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
import { sleep } from '@ora-io/utils'
import { ContractManager } from '../src/provider/contract'
import { RekuContractManager } from '../src/provider/contract'

describe('ContractManager', () => {
let contractManager: ContractManager
describe('RekuContractManager', () => {
let contractManager: RekuContractManager
const address = '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48'
const abi: string[] = [
'event Transfer(address indexed from, address indexed to, uint256 value)',
Expand All @@ -13,7 +13,7 @@ describe('ContractManager', () => {
const provider = new ethers.WebSocketProvider('wss://ethereum-rpc.publicnode.com')

beforeEach(() => {
contractManager = new ContractManager(address, abi, provider)
contractManager = new RekuContractManager(address, abi, provider)
})

afterEach(() => {
Expand Down

0 comments on commit a9c4e16

Please sign in to comment.