diff --git a/sdk/README.md b/sdk/README.md index db9b4507..2fac11e4 100644 --- a/sdk/README.md +++ b/sdk/README.md @@ -243,6 +243,28 @@ pnpm module findby '{\"name\": \"Msg Sender Module\"}' pnpm schema findonebyid "0xce2647ed39aa89e6d1528a56deb6c30667ed2aae1ec2378ec3140c0c5d98a61e" pnpm schema findby '{\"description\": \"Gitcoin Passport Score\"}' + +pnpm schema simulateUpdateRouter "0x980978299e23B8F9B4D11542A83D92C83e781cb6" + +pnpm schema updateRouter "0x980978299e23B8F9B4D11542A83D92C83e781cb6" + +pnpm schema simulateCreate '{\"name\": \"sampleSchema\", \"description\": \"Example schema\", \"context\": \"Created by example\", \"schemaString\": \"bool isExample\"}' + +pnpm schema create '{\"name\": \"sampleSchema\", \"description\": \"Example schema\", \"context\": \"Created by example\", \"schemaString\": \"bool isExample\"}' + +pnpm schema simulateUpdateContext '{\"schemaId\": \"0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738\", \"context\": \"New context\"}' + +pnpm schema updateContext '{\"schemaId\": \"0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738\", \"context\": \"New context\"}' + +pnpm schema getIdFromSchemaString 'bool isExample' + +pnpm schema getSchema "0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738" + +pnpm schema getSchemasNumber + +pnpm schema isRegistered "0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738" + +pnpm schema getSchemaIds 0 ``` ## Other operations diff --git a/sdk/examples/schema/schemaExamples.ts b/sdk/examples/schema/schemaExamples.ts index aa707d6e..f7d93288 100644 --- a/sdk/examples/schema/schemaExamples.ts +++ b/sdk/examples/schema/schemaExamples.ts @@ -1,3 +1,4 @@ +import { Address } from "viem"; import VeraxSdk from "../../src/VeraxSdk"; export default class SchemaExamples { @@ -18,6 +19,84 @@ export default class SchemaExamples { console.log(await this.veraxSdk.schema.findBy(2, 0, { description: "Gitcoin Passport Score" }, "name", "desc")); } - if (methodName.toLowerCase() == "create" || methodName == "") console.log(await this.veraxSdk.schema.create()); + if (methodName.toLowerCase() == "simulateUpdateRouter".toLowerCase() || methodName == "") { + const routerAddress: Address = argv === "" ? "0x736c78b2f2cBf4F921E8551b2acB6A5Edc9177D5" : (argv as Address); + console.log(await this.veraxSdk.schema.simulateUpdateRouter(routerAddress)); + } + + if (methodName.toLowerCase() == "updateRouter".toLowerCase() || methodName == "") { + const routerAddress: Address = argv === "" ? "0x736c78b2f2cBf4F921E8551b2acB6A5Edc9177D5" : (argv as Address); + console.log(await this.veraxSdk.schema.updateRouter(routerAddress)); + } + + if (methodName.toLowerCase() == "simulateCreate".toLowerCase() || methodName == "") { + let params; + if (argv !== "") params = JSON.parse(argv); + const { name, description, context, schemaString } = params ?? { + name: "test", + description: "example", + context: "test", + schemaString: "(bool isBuidler)", + }; + console.log(await this.veraxSdk.schema.simulateCreate(name, description, context, schemaString)); + } + + if (methodName.toLowerCase() == "create".toLowerCase() || methodName == "") { + let params; + if (argv !== "") params = JSON.parse(argv); + const { name, description, context, schemaString } = params ?? { + name: "test", + description: "example", + context: "test", + schemaString: "(bool isBuidler)", + }; + console.log(await this.veraxSdk.schema.create(name, description, context, schemaString)); + } + + if (methodName.toLowerCase() == "simulateUpdateContext".toLowerCase() || methodName == "") { + let params; + if (argv !== "") params = JSON.parse(argv); + const { schemaId, context } = params ?? { + schemaId: "0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738", + context: "new context", + }; + console.log(await this.veraxSdk.schema.simulateUpdateContext(schemaId, context)); + } + + if (methodName.toLowerCase() == "updateContext".toLowerCase() || methodName == "") { + let params; + if (argv !== "") params = JSON.parse(argv); + const { schemaId, context } = params ?? { + schemaId: "0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738", + context: "new context", + }; + console.log(await this.veraxSdk.schema.updateContext(schemaId, context)); + } + + if (methodName.toLowerCase() == "getIdFromSchemaString".toLowerCase() || methodName == "") { + const schemaString: string = argv === "" ? "(bool isBuidler)" : argv; + console.log(await this.veraxSdk.schema.getIdFromSchemaString(schemaString)); + } + + if (methodName.toLowerCase() == "getSchema".toLowerCase() || methodName == "") { + const schemaId: string = + argv === "" ? "0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738" : argv; + console.log(await this.veraxSdk.schema.getSchema(schemaId)); + } + + if (methodName.toLowerCase() == "getSchemasNumber".toLowerCase() || methodName == "") { + console.log(await this.veraxSdk.schema.getSchemasNumber()); + } + + if (methodName.toLowerCase() == "isRegistered".toLowerCase() || methodName == "") { + const schemaId: string = + argv === "" ? "0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738" : argv; + console.log(await this.veraxSdk.schema.isRegistered(schemaId)); + } + + if (methodName.toLowerCase() == "getSchemaIds".toLowerCase() || methodName == "") { + const index: number = argv === "" ? 0 : (argv as unknown as number); + console.log(await this.veraxSdk.schema.getSchemaIds(index)); + } } } diff --git a/sdk/src/dataMapper/SchemaDataMapper.ts b/sdk/src/dataMapper/SchemaDataMapper.ts index 1f0207f5..662eb42c 100644 --- a/sdk/src/dataMapper/SchemaDataMapper.ts +++ b/sdk/src/dataMapper/SchemaDataMapper.ts @@ -1,6 +1,9 @@ +import { Address, Hash } from "viem"; import { Schema_filter, Schema_orderBy } from "../../.graphclient"; import { Schema } from "../types"; +import { handleError } from "../utils/errorHandler"; import BaseDataMapper from "./BaseDataMapper"; +import { abiSchemaRegistry } from "../abi/SchemaRegistry"; export default class SchemaDataMapper extends BaseDataMapper { typeName = "schema"; @@ -12,7 +15,85 @@ export default class SchemaDataMapper extends BaseDataMapper err instanceof ContractFunctionRevertedError); + if (revertError instanceof ContractFunctionRevertedError) { + const errorName = revertError.data?.errorName ?? ""; + console.error(`Failing with ${errorName}`); + } + } + console.error(err); + + throw new Error("Simulation failed"); +}