Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(veascan-subgraph): outbox verification event handling #340

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 43 additions & 10 deletions veascan-subgraph-outbox/src/VeaOutbox.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { BigInt, Bytes } from "@graphprotocol/graph-ts";
import { BigInt, Bytes, log } from "@graphprotocol/graph-ts";
import {
Challenged,
Claimed,
MessageRelayed,
Verified,
VeaOutbox,
VerificationStarted,
} from "../generated/VeaOutbox/VeaOutbox";
import {
Challenge,
Expand Down Expand Up @@ -59,22 +60,54 @@ export function handleChallenged(event: Challenged): void {
}
}

export function handleVerificationStarted(event: VerificationStarted): void {
const ref = getRef();
let claim: Claim | null = null;

// Find the corresponding claim
for (
let i = ref.totalClaims.minus(BigInt.fromI32(1));
i.ge(BigInt.fromI32(0));
i = i.minus(BigInt.fromI32(1))
) {
const potentialClaim = Claim.load(i.toString());
if (potentialClaim && potentialClaim.epoch.equals(event.params._epoch)) {
claim = potentialClaim;
break;
}
}
if (!claim) {
log.warning("No corresponding claim found for epoch: {}", [
event.params._epoch.toString(),
]);
return;
}
let verification: Verification;

verification = new Verification(claim.id);
verification.claim = claim.id;
verification.caller = event.transaction.from;
verification.timestamp = event.block.timestamp;
verification.txHash = event.transaction.hash;
verification.save();
log.info("VerificationStarted event received for epoch: {}", [
event.params._epoch.toString(),
]);
}

export function handleVerified(event: Verified): void {
const ref = getRef();
for (
let i = ref.totalClaims.minus(BigInt.fromI32(1));
i.ge(BigInt.fromI32(0));
i.minus(BigInt.fromI32(1))
i = i.minus(BigInt.fromI32(1))
) {
const claim = Claim.load(i.toString());
if (claim!.epoch.equals(event.params._epoch)) {
const verification = new Verification(claim!.id);
verification.claim = claim!.id;
verification.timestamp = event.block.timestamp;
verification.caller = event.transaction.from;
verification.txHash = event.transaction.hash;
verification.save();
break;
if (claim && claim.epoch.equals(event.params._epoch)) {
claim.verified = true;
claim.honest = true;
claim.save();
log.info("Updated claim entity for claim_id {} as complete", [claim.id]);
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions veascan-subgraph-outbox/subgraph.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,6 @@ dataSources:
handler: handleMessageRelayed
- event: Verified(uint256)
handler: handleVerified
- event: VerificationStarted(indexed uint256)
handler: handleVerificationStarted
file: ./src/VeaOutbox.ts
Loading