UNPKG

@verax-attestation-registry/verax-sdk

Version:

Verax Attestation Registry SDK to interact with the subgraph and the contracts

84 lines 3.46 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const constants_1 = require("../utils/constants"); const BaseDataMapper_1 = __importDefault(require("./BaseDataMapper")); const SchemaRegistry_1 = require("../abi/SchemaRegistry"); const transactionSender_1 = require("../utils/transactionSender"); const errorHandler_1 = require("../utils/errorHandler"); class SchemaDataMapper extends BaseDataMapper_1.default { constructor() { super(...arguments); this.typeName = "schema"; this.gqlInterface = `{ id name description context schema attestationCounter }`; } async simulateUpdateRouter(routerAddress) { return this.simulateContract("updateRouter", [routerAddress]); } async updateRouter(routerAddress, options) { const request = await this.simulateUpdateRouter(routerAddress); return (0, transactionSender_1.executeTransaction)(request, this.web3Client, this.walletClient, options?.waitForConfirmation); } async simulateCreate(name, description, context, schemaString) { return this.simulateContract("createSchema", [name, description, context, schemaString]); } async create(name, description, context, schemaString, options) { const request = await this.simulateCreate(name, description, context, schemaString); return (0, transactionSender_1.executeTransaction)(request, this.web3Client, this.walletClient, options?.waitForConfirmation); } async simulateUpdateContext(schemaId, context) { return this.simulateContract("updateContext", [schemaId, context]); } async updateContext(schemaId, context, options) { const request = await this.simulateUpdateContext(schemaId, context); return (0, transactionSender_1.executeTransaction)(request, this.web3Client, this.walletClient, options?.waitForConfirmation); } async getIdFromSchemaString(schema) { return this.executeReadMethod("getIdFromSchemaString", [schema]); } async getSchema(schemaId) { return this.executeReadMethod("getSchema", [schemaId]); } async getSchemasNumber() { return super.findTotalCount(); } async isRegistered(schemaId) { return this.executeReadMethod("isRegistered", [schemaId]); } async executeReadMethod(functionName, args) { return this.web3Client.readContract({ abi: SchemaRegistry_1.abiSchemaRegistry, address: this.conf.schemaRegistryAddress, functionName, args, }); } async simulateContract(functionName, args) { if (!this.walletClient) throw new Error("VeraxSDK - Wallet not available"); try { const { request } = await this.web3Client.simulateContract({ address: this.conf.schemaRegistryAddress, abi: SchemaRegistry_1.abiSchemaRegistry, functionName, account: this.walletClient.account, args, }); return request; } catch (err) { (0, errorHandler_1.handleError)(constants_1.ActionType.Simulation, err); } } } exports.default = SchemaDataMapper; //# sourceMappingURL=SchemaDataMapper.js.map