From 26abae6de32810491d522fc70512ead2f7e2aca6 Mon Sep 17 00:00:00 2001 From: madhurMongia Date: Tue, 8 Oct 2024 19:19:52 +0530 Subject: [PATCH] feat(veascan-subgraph): outbox verification event handling --- veascan-subgraph-outbox/src/VeaOutbox.ts | 53 +++++++++++++++++++----- veascan-subgraph-outbox/subgraph.yaml | 2 + 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/veascan-subgraph-outbox/src/VeaOutbox.ts b/veascan-subgraph-outbox/src/VeaOutbox.ts index 6e7e41f6..85e77413 100644 --- a/veascan-subgraph-outbox/src/VeaOutbox.ts +++ b/veascan-subgraph-outbox/src/VeaOutbox.ts @@ -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, @@ -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]); } } } diff --git a/veascan-subgraph-outbox/subgraph.yaml b/veascan-subgraph-outbox/subgraph.yaml index 7df1148e..0ef5bd2e 100644 --- a/veascan-subgraph-outbox/subgraph.yaml +++ b/veascan-subgraph-outbox/subgraph.yaml @@ -30,4 +30,6 @@ dataSources: handler: handleMessageRelayed - event: Verified(uint256) handler: handleVerified + - event: VerificationStarted(indexed uint256) + handler: handleVerificationStarted file: ./src/VeaOutbox.ts