Skip to content

Commit

Permalink
Merge pull request #101 from Giveth/feat/multiple_schema_support
Browse files Browse the repository at this point in the history
Added support for multiple schema
  • Loading branch information
aminlatifi authored Aug 12, 2024
2 parents 7d339ce + bd7f066 commit 53bdebf
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/.env

# Backup file
.env.backup
.env.*

# Ogranisation config
org-config.jsonc
10 changes: 7 additions & 3 deletions src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { assertNotNull } from "@subsquid/evm-processor";
import { map } from "zod";

const SQUID_NETWORK = process.env.SQUID_NETWORK || "eth-sepolia";

Expand All @@ -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"
Expand Down
17 changes: 5 additions & 12 deletions src/mappings/attest.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -16,12 +11,10 @@ export async function processAttest(
log: Log
): Promise<void> {
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);
}
11 changes: 4 additions & 7 deletions src/mappings/revoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@ export async function processRevokeLog(
): Promise<void> {
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);
}

0 comments on commit 53bdebf

Please sign in to comment.