Skip to content

Commit

Permalink
ON-457: wip revoke role handler
Browse files Browse the repository at this point in the history
  • Loading branch information
juo-dev committed Aug 30, 2023
1 parent a9de8f2 commit 588bf9a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
27 changes: 25 additions & 2 deletions src/erc7432/role/revoke-handler.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,31 @@
import { log } from '@graphprotocol/graph-ts'
import { RoleRevoked } from '../../../generated/Roles/ERC7432Roles'
import { Nft, Role } from '../../../generated/schema'
import { generateId } from '../../utils/helper'

export function handleRoleRevoked(event: RoleRevoked): void {
let entity = Role.load(event.params.role.toHex())
const tokenId = event.params._tokenId.toString()
const address = event.address.toHexString()

const nftId = generateId(tokenId, address)
const nft = Nft.load(nftId)

if (!nft) {
log.info('NFT {} does not exist, skipping transfer...', [nftId])
return
}

const nftOwner = nft.owner

if (nftOwner != address) {
log.info('NFT {} is not owned by {}, skipping transfer...', [address])
return
}

if (event.address!) let entity = Role.load(event.params._role.toHex())

if (entity == null) {
entity = new Role(event.params.role.toHex())
entity = new Role(event.params._role.toHex())
}

entity.account = event.params.account.toHex()
Expand Down
6 changes: 3 additions & 3 deletions subgraph-goerli.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ dataSources:
source:
address: '0x8680fC3Df31805B1F7f8BfB702f723460d360FE9'
abi: ERC7432Roles
startBlock: 8099655
startBlock: 9568669
mapping:
kind: ethereum/events
apiVersion: 0.0.6
Expand All @@ -44,8 +44,8 @@ dataSources:
- name: ERC7432Roles
file: ./abis/ERC7432Roles.json
eventHandlers:
- event: RoleGranted(indexed bytes32,indexed address,indexed uint256, address, uint64, bytes)
- event: RoleGranted(indexed bytes32,indexed address,indexed uint256,address,uint64,bytes)
handler: handleRoleGranted
- event: RoleRevoked(indexed bytes32,indexed address,indexed uint256, address)
- event: RoleRevoked(indexed bytes32,indexed address,indexed uint256,address)
handler: handleRoleRevoked
file: ./src/erc7432/index.ts
4 changes: 2 additions & 2 deletions subgraph-mumbai.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ dataSources:
- name: ERC7432Roles
file: ./abis/ERC7432Roles.json
eventHandlers:
- event: RoleGranted(indexed bytes32,indexed address,indexed uint256, address, uint64, bytes)
- event: RoleGranted(indexed bytes32,indexed address,indexed uint256,address,uint64,bytes)
handler: handleRoleGranted
- event: RoleRevoked(indexed bytes32,indexed address,indexed uint256, address)
- event: RoleRevoked(indexed bytes32,indexed address,indexed uint256,address)
handler: handleRoleRevoked
file: ./src/erc7432/index.ts

0 comments on commit 588bf9a

Please sign in to comment.