From bd7f06671f09012e4a0c854b188ce21761fb560c Mon Sep 17 00:00:00 2001 From: Amin Latifi Date: Wed, 31 Jul 2024 15:58:42 +0330 Subject: [PATCH] Added support for multiple schema --- .gitignore | 2 +- src/constants.ts | 10 +++++++--- src/mappings/attest.ts | 17 +++++------------ src/mappings/revoke.ts | 11 ++++------- 4 files changed, 17 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index 8a8dfac..f979e75 100644 --- a/.gitignore +++ b/.gitignore @@ -10,7 +10,7 @@ /.env # Backup file -.env.backup +.env.* # Ogranisation config org-config.jsonc \ No newline at end of file diff --git a/src/constants.ts b/src/constants.ts index c85f290..4ee8afc 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -1,4 +1,5 @@ import { assertNotNull } from "@subsquid/evm-processor"; +import { map } from "zod"; const SQUID_NETWORK = process.env.SQUID_NETWORK || "eth-sepolia"; @@ -15,9 +16,12 @@ export const SCHEMA_CONTRACT_ADDRESS = assertNotNull( : "0x0a7E2Ff54e76B8E6659aedc9103FB21c038050D0" ); -export const PROJECT_VERIFY_SCHEMA = assertNotNull( - process.env.PROJECT_VERIFY_ATTESTATION_SCHEMA -).toLocaleLowerCase(); +export const PROJECT_VERIFY_SCHEMA = new Set( + assertNotNull(process.env.PROJECT_VERIFY_ATTESTATION_SCHEMA) + .toLocaleLowerCase() + .split(",") + .map((s) => s.trim()) +); export const LOOKUP_ARCHIVE = IS_PRODUCTION ? "https://v2.archive.subsquid.io/network/optimism-mainnet" diff --git a/src/mappings/attest.ts b/src/mappings/attest.ts index 31b1e7c..8fd8d67 100644 --- a/src/mappings/attest.ts +++ b/src/mappings/attest.ts @@ -1,13 +1,8 @@ import { DataHandlerContext, Log } from "@subsquid/evm-processor"; import { Store } from "@subsquid/typeorm-store"; import * as EASContract from "../abi/EAS"; -import * as SchemaContract from "../abi/Schema"; -import { - PROJECT_VERIFY_SCHEMA, - EAS_CONTRACT_ADDRESS, - SCHEMA_CONTRACT_ADDRESS, -} from "../constants"; +import { PROJECT_VERIFY_SCHEMA } from "../constants"; import { handleAuthorize } from "../controllers/authorizeAttestation"; import { handleProjectAttestation } from "../controllers/projectVerificationAttestation"; @@ -16,12 +11,10 @@ export async function processAttest( log: Log ): Promise { const { schema: schemaUid } = EASContract.events.Attested.decode(log); - switch (schemaUid.toLocaleLowerCase()) { - case PROJECT_VERIFY_SCHEMA: - await handleProjectAttestation(ctx, log); - break; - default: - await handleAuthorize(ctx, log); + if (PROJECT_VERIFY_SCHEMA.has(schemaUid.toLocaleLowerCase())) { + await handleProjectAttestation(ctx, log); + return; } + await handleAuthorize(ctx, log); } diff --git a/src/mappings/revoke.ts b/src/mappings/revoke.ts index 89bd452..2779f2b 100644 --- a/src/mappings/revoke.ts +++ b/src/mappings/revoke.ts @@ -11,12 +11,9 @@ export async function processRevokeLog( ): Promise { const { uid, schema: schemaUid } = EASContract.events.Revoked.decode(log); - switch (schemaUid.toLocaleLowerCase()) { - case PROJECT_VERIFY_SCHEMA: - await handleProjectAttestationRevoke(ctx, uid); - break; - - default: - await handleAuthorizeRevoke(ctx, uid); + if (PROJECT_VERIFY_SCHEMA.has(schemaUid.toLocaleLowerCase())) { + await handleProjectAttestationRevoke(ctx, uid); + return; } + await handleAuthorizeRevoke(ctx, uid); }