-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathAddressAddedEventProcessor.ts
More file actions
48 lines (43 loc) · 1.56 KB
/
AddressAddedEventProcessor.ts
File metadata and controls
48 lines (43 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { ethers, Signer, FallbackProvider, Interface } from 'ethers'
import { INDEXER_LOGGER } from '../../../utils/logging/common.js'
import { LOG_LEVELS_STR } from '../../../utils/logging/Logger.js'
import { BaseEventProcessor } from './BaseProcessor.js'
import AccessList from '@oceanprotocol/contracts/artifacts/contracts/accesslists/AccessList.sol/AccessList.json' with { type: 'json' }
const accessListInterface = new Interface(AccessList.abi)
export class AddressAddedEventProcessor extends BaseEventProcessor {
async processEvent(
event: ethers.Log,
chainId: number,
signer: Signer,
provider: FallbackProvider
): Promise<any> {
try {
const decoded = accessListInterface.parseLog({
topics: Array.from(event.topics),
data: event.data
})
if (!decoded) return null
const wallet = decoded.args[0].toString().toLowerCase()
const tokenId = Number(decoded.args[1])
const contractAddress = event.address.toLowerCase()
const { accessList } = await this.getDatabase()
const result = await accessList.addUser(chainId, contractAddress, {
wallet,
tokenId,
block: event.blockNumber,
txId: event.transactionHash
})
INDEXER_LOGGER.logMessage(
`[AddressAdded] ${wallet} (tokenId=${tokenId}) added to ${contractAddress} on chain ${chainId}`
)
return result
} catch (err) {
INDEXER_LOGGER.log(
LOG_LEVELS_STR.LEVEL_ERROR,
`Error processing AddressAdded event: ${err.message}`,
true
)
return null
}
}
}