diff --git a/sdk/README.md b/sdk/README.md index 185f792f..98fec480 100644 --- a/sdk/README.md +++ b/sdk/README.md @@ -275,6 +275,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..d6985492 100644 --- a/sdk/src/dataMapper/SchemaDataMapper.ts +++ b/sdk/src/dataMapper/SchemaDataMapper.ts @@ -1,6 +1,10 @@ +import { Address } from "viem"; import { Schema_filter, Schema_orderBy } from "../../.graphclient"; import { Schema } from "../types"; import BaseDataMapper from "./BaseDataMapper"; +import { abiSchemaRegistry } from "../abi/SchemaRegistry"; +import { executeTransaction } from "../utils/transactionSender"; +import { handleSimulationError } from "../utils/simulationErrorHandler"; export default class SchemaDataMapper extends BaseDataMapper { typeName = "schema"; @@ -12,7 +16,75 @@ export default class SchemaDataMapper extends BaseDataMapper