-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added handlers for attestations and schemas
- Loading branch information
1 parent
37330bb
commit f258d94
Showing
5 changed files
with
127 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[{"inputs":[],"name":"AlreadyExists","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"uid","type":"bytes32"},{"indexed":false,"internalType":"address","name":"registerer","type":"address"}],"name":"Registered","type":"event"},{"inputs":[],"name":"VERSION","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"uid","type":"bytes32"}],"name":"getSchema","outputs":[{"components":[{"internalType":"bytes32","name":"uid","type":"bytes32"},{"internalType":"contract ISchemaResolver","name":"resolver","type":"address"},{"internalType":"bool","name":"revocable","type":"bool"},{"internalType":"string","name":"schema","type":"string"}],"internalType":"struct SchemaRecord","name":"","type":"tuple"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"schema","type":"string"},{"internalType":"contract ISchemaResolver","name":"resolver","type":"address"},{"internalType":"bool","name":"revocable","type":"bool"}],"name":"register","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"nonpayable","type":"function"}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,23 @@ | ||
type ExampleEntity @entity { | ||
type Attestation @entity { | ||
id: String! | ||
name: String! | ||
data: Bytes! | ||
schema: Schema | ||
recipient: Bytes! # address | ||
attester: Bytes! # address | ||
time: BigInt! | ||
expirationTime: BigInt! | ||
revocationTime: BigInt! | ||
refUID: Bytes! | ||
revoked: Boolean! | ||
txid: Bytes! | ||
} | ||
|
||
type Schema @entity { | ||
id: String! | ||
schema: String! | ||
creator: String! # address | ||
resolver: String! # address | ||
time: BigInt! | ||
revocable: Boolean! | ||
txid: Bytes! | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,53 @@ | ||
import { ponder } from "@/generated"; | ||
|
||
ponder.on("EAS:Attested", async ({ event, context }) => { | ||
console.log(event.params); | ||
console.log("Attested event received!"); | ||
const { Attestation } = context.entities; | ||
|
||
let entity = await Attestation.findUnique({ id: event.params.uid }); | ||
|
||
if (entity == null) { | ||
const attestation = await context.contracts.EAS.getAttestation( | ||
event.params.uid | ||
); | ||
|
||
console.log("creating attestation", attestation); | ||
|
||
await Attestation.create({ | ||
id: event.params.uid, | ||
data: { | ||
data: attestation.data, | ||
time: attestation.time, | ||
expirationTime: attestation.expirationTime, | ||
revocationTime: attestation.revocationTime, | ||
refUID: attestation.refUID, | ||
txid: event.transaction.hash, | ||
revoked: false, | ||
attester: attestation.attester, | ||
recipient: attestation.recipient, | ||
schema: attestation.schema, | ||
}, | ||
}); | ||
|
||
console.log(`Attestation ${event.params.uid} created!`); | ||
} | ||
}); | ||
|
||
ponder.on("EAS:Revoked", async ({ event, context }) => { | ||
console.log(event.params); | ||
const { Attestation } = context.entities; | ||
|
||
let entity = await Attestation.findUnique({ id: event.params.uid }); | ||
|
||
if (!entity) { | ||
return; | ||
} | ||
|
||
await Attestation.update({ | ||
id: event.params.uid, | ||
data: { | ||
revoked: true, | ||
}, | ||
}); | ||
|
||
console.log(`Attestation ${event.params.uid} revoked!`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { ponder } from "@/generated"; | ||
|
||
ponder.on("SchemaRegistry:Registered", async ({ event, context }) => { | ||
const { Schema } = context.entities; | ||
|
||
let entity = await Schema.findUnique({ id: event.params.uid }); | ||
|
||
if (entity == null) { | ||
const schema = await context.contracts.SchemaRegistry.getSchema( | ||
event.params.uid | ||
); | ||
|
||
await Schema.create({ | ||
id: event.params.uid, | ||
data: { | ||
creator: event.transaction.from, | ||
schema: schema.schema, | ||
resolver: schema.resolver, | ||
time: event.block.timestamp, | ||
txid: event.transaction.hash, | ||
revocable: schema.revocable, | ||
}, | ||
}); | ||
|
||
console.log(`Attestation ${event.params.uid} created!`); | ||
} | ||
}); |