Skip to content

Commit e1f8fb4

Browse files
committed
add poi event emitting
1 parent 3587a0d commit e1f8fb4

File tree

6 files changed

+97
-18
lines changed

6 files changed

+97
-18
lines changed

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ services:
2828
postgres_pass: let-me-in
2929
postgres_db: graph-node
3030
ipfs: 'ipfs:5001'
31-
ethereum: 'mainnet:http://anvil:8545'
31+
ethereum: 'foundry:http://anvil:8545'
3232
GRAPH_LOG: debug
3333
GRAPH_ALLOW_NON_DETERMINISTIC_IPFS: 1
3434
ipfs:

src/IPNFT.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ contract IPNFT is ERC721URIStorageUpgradeable, ERC721BurnableUpgradeable, IReser
4646

4747
event Reserved(address indexed reserver, uint256 indexed reservationId);
4848
event IPNFTMinted(address indexed owner, uint256 indexed tokenId, string tokenURI, string symbol);
49+
event IPNFTPOI(uint256 indexed tokenId, bytes poi);
4950
event ReadAccessGranted(uint256 indexed tokenId, address indexed reader, uint256 until);
5051
event AuthorizerUpdated(address authorizer);
5152

@@ -133,6 +134,7 @@ contract IPNFT is ERC721URIStorageUpgradeable, ERC721BurnableUpgradeable, IReser
133134
_mint(to, computedTokenId);
134135
_setTokenURI(computedTokenId, _tokenURI);
135136
emit IPNFTMinted(to, computedTokenId, _tokenURI, _symbol);
137+
emit IPNFTPOI(computedTokenId, poi);
136138
return computedTokenId;
137139
}
138140

subgraph/abis/IPNFT.json

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,45 @@
226226
],
227227
"stateMutability": "payable"
228228
},
229+
{
230+
"type": "function",
231+
"name": "mintWithPOI",
232+
"inputs": [
233+
{
234+
"name": "to",
235+
"type": "address",
236+
"internalType": "address"
237+
},
238+
{
239+
"name": "poi",
240+
"type": "bytes",
241+
"internalType": "bytes"
242+
},
243+
{
244+
"name": "_tokenURI",
245+
"type": "string",
246+
"internalType": "string"
247+
},
248+
{
249+
"name": "_symbol",
250+
"type": "string",
251+
"internalType": "string"
252+
},
253+
{
254+
"name": "authorization",
255+
"type": "bytes",
256+
"internalType": "bytes"
257+
}
258+
],
259+
"outputs": [
260+
{
261+
"name": "",
262+
"type": "uint256",
263+
"internalType": "uint256"
264+
}
265+
],
266+
"stateMutability": "payable"
267+
},
229268
{
230269
"type": "function",
231270
"name": "name",
@@ -721,6 +760,25 @@
721760
],
722761
"anonymous": false
723762
},
763+
{
764+
"type": "event",
765+
"name": "IPNFTPOI",
766+
"inputs": [
767+
{
768+
"name": "tokenId",
769+
"type": "uint256",
770+
"indexed": true,
771+
"internalType": "uint256"
772+
},
773+
{
774+
"name": "poi",
775+
"type": "bytes",
776+
"indexed": false,
777+
"internalType": "bytes"
778+
}
779+
],
780+
"anonymous": false
781+
},
724782
{
725783
"type": "event",
726784
"name": "Initialized",

subgraph/schema.graphql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ type Ipnft @entity {
99
ipts: [IPT!] @derivedFrom(field: "ipnft")
1010
metadata: IpnftMetadata
1111
updatedAtTimestamp: BigInt
12+
poi: Bytes
1213
}
1314

1415
type IpnftMetadata @entity {

subgraph/src/ipnftMapping.ts

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ import {
1313
MetadataUpdate as MetadataUpdateEvent,
1414
ReadAccessGranted as ReadAccessGrantedEvent,
1515
Reserved as ReservedEvent,
16-
Transfer as TransferEvent
16+
Transfer as TransferEvent,
17+
IPNFTPOI as IPNFTPOIEvent
1718
} from '../generated/IPNFT/IPNFT'
1819
import { IpnftMetadata as IpnftMetadataTemplate } from '../generated/templates'
1920
import { CanRead, Ipnft, Reservation } from '../generated/schema'
@@ -75,17 +76,21 @@ export function handleReservation(event: ReservedEvent): void {
7576
reservation.save()
7677
}
7778

78-
function updateIpnftMetadata(ipnft: Ipnft, uri: string, timestamp: BigInt): void {
79-
let ipfsLocation = uri.replace('ipfs://', '');
80-
if (!ipfsLocation || ipfsLocation == uri) {
81-
log.error("Invalid URI format for tokenId {}: {}", [ipnft.id, uri])
82-
return
83-
}
79+
function updateIpnftMetadata(
80+
ipnft: Ipnft,
81+
uri: string,
82+
timestamp: BigInt
83+
): void {
84+
let ipfsLocation = uri.replace('ipfs://', '')
85+
if (!ipfsLocation || ipfsLocation == uri) {
86+
log.error('Invalid URI format for tokenId {}: {}', [ipnft.id, uri])
87+
return
88+
}
8489

85-
ipnft.tokenURI = uri
86-
ipnft.metadata = ipfsLocation
87-
ipnft.updatedAtTimestamp = timestamp
88-
IpnftMetadataTemplate.create(ipfsLocation)
90+
ipnft.tokenURI = uri
91+
ipnft.metadata = ipfsLocation
92+
ipnft.updatedAtTimestamp = timestamp
93+
IpnftMetadataTemplate.create(ipfsLocation)
8994
}
9095

9196
//the underlying parameter arrays are misaligned, hence we cannot cast or unify both events
@@ -97,7 +102,17 @@ export function handleMint(event: IPNFTMintedEvent): void {
97102
updateIpnftMetadata(ipnft, event.params.tokenURI, event.block.timestamp)
98103
store.remove('Reservation', event.params.tokenId.toString())
99104
ipnft.save()
105+
}
106+
107+
export function handlePOI(event: IPNFTPOIEvent): void {
108+
let ipnft = Ipnft.load(event.params.tokenId.toString())
109+
if (!ipnft) {
110+
log.error('ipnft {} not found', [event.params.tokenId.toString()])
111+
return
112+
}
100113

114+
ipnft.poi = event.params.poi
115+
ipnft.save()
101116
}
102117

103118
export function handleMetadataUpdated(event: MetadataUpdateEvent): void {
@@ -108,13 +123,14 @@ export function handleMetadataUpdated(event: MetadataUpdateEvent): void {
108123
}
109124

110125
//erc4906 is not emitting the new url, we must query it ourselves
111-
let _ipnftContract = IPNFTContract.bind(event.params._event.address);
126+
let _ipnftContract = IPNFTContract.bind(event.params._event.address)
112127
let newUri = _ipnftContract.tokenURI(event.params._tokenId)
113-
if (!newUri || newUri == "") {
114-
log.debug("no new uri found for token, likely just minted {}", [event.params._tokenId.toString()])
115-
return
128+
if (!newUri || newUri == '') {
129+
log.debug('no new uri found for token, likely just minted {}', [
130+
event.params._tokenId.toString()
131+
])
132+
return
116133
}
117-
updateIpnftMetadata(ipnft, newUri, event.block.timestamp)
134+
updateIpnftMetadata(ipnft, newUri, event.block.timestamp)
118135
ipnft.save()
119136
}
120-

subgraph/subgraph.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ dataSources:
2323
handler: handleReservation
2424
- event: IPNFTMinted(indexed address,indexed uint256,string,string)
2525
handler: handleMint
26+
- event: IPNFTPOI(indexed uint256,bytes)
27+
handler: handlePOI
2628
- event: Transfer(indexed address,indexed address,indexed uint256)
2729
handler: handleTransfer
2830
- event: ReadAccessGranted(indexed uint256,indexed address,uint256)

0 commit comments

Comments
 (0)