Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: As a user, I want the SDK to check the transaction was validated before finishing a process #519

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions sdk/examples/attestation/attestationExamples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class AttestationExamples {
this.veraxSdk = _veraxSdk;
}

async run(argv: string, methodName: string = "") {
async run(argv: string, methodName: string = "", waitForConfirmation = false) {
if (methodName.toLowerCase() == "findOneById".toLowerCase() || methodName == "") {
const attestationId: string =
argv === "" ? "0x00000000000000000000000000000000000000000000000000000000000007b5" : argv;
Expand All @@ -35,7 +35,7 @@ export default class AttestationExamples {

if (methodName.toLowerCase() == "updateRouter".toLowerCase() || methodName == "") {
const routerAddress: Address = argv === "" ? "0x736c78b2f2cBf4F921E8551b2acB6A5Edc9177D5" : (argv as Address);
console.log(await this.veraxSdk.attestation.updateRouter(routerAddress));
console.log(await this.veraxSdk.attestation.updateRouter(routerAddress, waitForConfirmation));
}

if (methodName.toLowerCase() == "simulateMassImport".toLowerCase() || methodName == "") {
Expand Down Expand Up @@ -83,15 +83,15 @@ export default class AttestationExamples {
attestationData: [{ isBuidler: true }],
},
];
console.log(await this.veraxSdk.attestation.massImport(portalAddress, attestationPayloads));
console.log(await this.veraxSdk.attestation.massImport(portalAddress, attestationPayloads, waitForConfirmation));
}

if (methodName.toLowerCase() == "simulateIncrementVersionNumber".toLowerCase() || methodName == "") {
console.log(await this.veraxSdk.attestation.simulateIncrementVersionNumber());
}

if (methodName.toLowerCase() == "incrementVersionNumber".toLowerCase() || methodName == "") {
console.log(await this.veraxSdk.attestation.incrementVersionNumber());
console.log(await this.veraxSdk.attestation.incrementVersionNumber(waitForConfirmation));
}

if (methodName.toLowerCase() == "isRegistered".toLowerCase() || methodName == "") {
Expand Down
19 changes: 16 additions & 3 deletions sdk/examples/attestation/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
import { Hex } from "viem";
import { VeraxSdk } from "../../src/VeraxSdk";
import AttestationExamples from "./attestationExamples";
import { config } from "dotenv";
import * as path from "path";

const envPath = path.resolve(__dirname, "../../.env");
config({ path: envPath });

const privateKey = process.env.PRIVATE_KEY as Hex;

let argv: string | null | undefined = process.argv[3] as string;
argv !== null && argv !== undefined ? (argv = argv.replaceAll("\\", "")) : (argv = "");
argv !== null && argv !== undefined && argv !== "wait" ? (argv = argv.replaceAll("\\", "")) : (argv = "");

const waitForConfirmationArgv: string | null | undefined = process.argv[4] as string;
let waitForConfirmation = false;
if ((argv === "" && (process.argv[3] as string) === "wait") || waitForConfirmationArgv === "wait")
waitForConfirmation = true;

const veraxSdk = new VeraxSdk(VeraxSdk.DEFAULT_LINEA_TESTNET);
const veraxSdk = new VeraxSdk(VeraxSdk.DEFAULT_LINEA_TESTNET, undefined, privateKey);

new AttestationExamples(veraxSdk).run(argv, process.argv[2]);
new AttestationExamples(veraxSdk).run(argv, process.argv[2], waitForConfirmation);
19 changes: 16 additions & 3 deletions sdk/examples/module/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
import { Hex } from "viem";
import { VeraxSdk } from "../../src/VeraxSdk";
import ModuleExamples from "./moduleExamples";
import { config } from "dotenv";
import * as path from "path";

const envPath = path.resolve(__dirname, "../../.env");
config({ path: envPath });

const privateKey = process.env.PRIVATE_KEY as Hex;

let argv: string | null | undefined = process.argv[3] as string;
argv !== null && argv !== undefined ? (argv = argv.replaceAll("\\", "")) : (argv = "");
argv !== null && argv !== undefined && argv !== "wait" ? (argv = argv.replaceAll("\\", "")) : (argv = "");

const waitForConfirmationArgv: string | null | undefined = process.argv[4] as string;
let waitForConfirmation = false;
if ((argv === "" && (process.argv[3] as string) === "wait") || waitForConfirmationArgv === "wait")
waitForConfirmation = true;

const veraxSdk = new VeraxSdk(VeraxSdk.DEFAULT_LINEA_TESTNET);
const veraxSdk = new VeraxSdk(VeraxSdk.DEFAULT_LINEA_TESTNET, undefined, privateKey);

new ModuleExamples(veraxSdk).run(argv, process.argv[2]);
new ModuleExamples(veraxSdk).run(argv, process.argv[2], waitForConfirmation);
8 changes: 5 additions & 3 deletions sdk/examples/module/moduleExamples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default class ModuleExamples {
this.veraxSdk = _veraxSdk;
}

async run(argv: string, methodName: string = "") {
async run(argv: string, methodName: string = "", waitForConfirmation = false) {
if (methodName.toLowerCase() == "findOneById".toLowerCase() || methodName == "") {
const moduleId: string = argv === "" ? "0xf75be6f9418710fd516fa82afb3aad07e11a0f1b" : argv;
console.log(await this.veraxSdk.module.findOneById(moduleId));
Expand All @@ -25,7 +25,7 @@ export default class ModuleExamples {

if (methodName.toLowerCase() == "updateRouter".toLowerCase() || methodName == "") {
const routerAddress: Address = argv === "" ? "0x736c78b2f2cBf4F921E8551b2acB6A5Edc9177D5" : (argv as Address);
console.log(await this.veraxSdk.module.updateRouter(routerAddress));
console.log(await this.veraxSdk.module.updateRouter(routerAddress, waitForConfirmation));
}

if (methodName.toLowerCase() == "simulateRegister".toLowerCase() || methodName == "") {
Expand All @@ -47,7 +47,7 @@ export default class ModuleExamples {
description: "example",
moduleAddress: "0x4bb8769e18f1518c35be8405d43d7cc07ecf501c",
};
console.log(await this.veraxSdk.module.register(name, description, moduleAddress));
console.log(await this.veraxSdk.module.register(name, description, moduleAddress, waitForConfirmation));
}

if (methodName.toLowerCase() == "simulateRunModules".toLowerCase() || methodName == "") {
Expand Down Expand Up @@ -98,6 +98,7 @@ export default class ModuleExamples {
attestationPayload,
validationPayloads,
value,
waitForConfirmation,
),
);
}
Expand Down Expand Up @@ -162,6 +163,7 @@ export default class ModuleExamples {
modulesAddresses as Address[],
attestationPayloads,
validationPayloads,
waitForConfirmation,
),
);
}
Expand Down
19 changes: 16 additions & 3 deletions sdk/examples/portal/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
import { Hex } from "viem";
import { VeraxSdk } from "../../src/VeraxSdk";
import PortalExamples from "./portalExamples";
import { config } from "dotenv";
import * as path from "path";

const envPath = path.resolve(__dirname, "../../.env");
config({ path: envPath });

const privateKey = process.env.PRIVATE_KEY as Hex;

let argv: string | null | undefined = process.argv[3] as string;
argv !== null && argv !== undefined ? (argv = argv.replaceAll("\\", "")) : (argv = "");
argv !== null && argv !== undefined && argv !== "wait" ? (argv = argv.replaceAll("\\", "")) : (argv = "");

const waitForConfirmationArgv: string | null | undefined = process.argv[4] as string;
let waitForConfirmation = false;
if ((argv === "" && (process.argv[3] as string) === "wait") || waitForConfirmationArgv === "wait")
waitForConfirmation = true;

const veraxSdk = new VeraxSdk(VeraxSdk.DEFAULT_LINEA_TESTNET);
const veraxSdk = new VeraxSdk(VeraxSdk.DEFAULT_LINEA_TESTNET, undefined, privateKey);

new PortalExamples(veraxSdk).run(argv, process.argv[2]);
new PortalExamples(veraxSdk).run(argv, process.argv[2], waitForConfirmation);
50 changes: 41 additions & 9 deletions sdk/examples/portal/portalExamples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default class PortalExamples {
this.veraxSdk = _veraxSdk;
}

async run(argv: string, methodName: string = "") {
async run(argv: string, methodName: string = "", waitForConfirmation = false) {
if (methodName.toLowerCase() == "findOneById".toLowerCase() || methodName == "") {
const portalId: string = argv === "" ? "0x1495341ab1019798dd08976f4a3e5ab0e095510b" : argv;
console.log(await this.veraxSdk.portal.findOneById(portalId));
Expand Down Expand Up @@ -47,7 +47,9 @@ export default class PortalExamples {
attestationData: [{ isBuidler: true }],
};
const validationPayloads = params?.validationPayloads ?? [];
console.log(await this.veraxSdk.portal.attest(portalAddress, attestationPayload, validationPayloads));
console.log(
await this.veraxSdk.portal.attest(portalAddress, attestationPayload, validationPayloads, waitForConfirmation),
);
}

if (methodName.toLowerCase() == "simulateBulkAttest".toLowerCase() || methodName == "") {
Expand Down Expand Up @@ -99,7 +101,14 @@ export default class PortalExamples {
},
];
const validationPayloads = params?.validationPayloads ?? [[], []];
console.log(await this.veraxSdk.portal.bulkAttest(portalAddress, attestationPayloads, validationPayloads));
console.log(
await this.veraxSdk.portal.bulkAttest(
portalAddress,
attestationPayloads,
validationPayloads,
waitForConfirmation,
),
);
}

if (methodName.toLowerCase() == "revoke" || methodName == "") {
Expand All @@ -110,7 +119,7 @@ export default class PortalExamples {
: "0xeea25bc2ec56cae601df33b8fc676673285e12cc";
const attestationId =
params?.attestationId ?? "0x0000000000000000000000000000000000000000000000000000000000000001";
console.log(await this.veraxSdk.portal.revoke(portalAddress, attestationId));
console.log(await this.veraxSdk.portal.revoke(portalAddress, attestationId, waitForConfirmation));
}

if (methodName.toLowerCase() == "simulateRevoke".toLowerCase() || methodName == "") {
Expand Down Expand Up @@ -147,7 +156,7 @@ export default class PortalExamples {
"0x00000000000000000000000000000000000000000000000000000000000010a0",
"0x00000000000000000000000000000000000000000000000000000000000010a1",
];
console.log(await this.veraxSdk.portal.bulkRevoke(portalAddress, attestationIds));
console.log(await this.veraxSdk.portal.bulkRevoke(portalAddress, attestationIds, waitForConfirmation));
}

if (methodName.toLowerCase() == "simulateReplace".toLowerCase() || methodName == "") {
Expand Down Expand Up @@ -195,7 +204,13 @@ export default class PortalExamples {
};
const validationPayloads = params?.validationPayloads ?? [];
console.log(
await this.veraxSdk.portal.replace(portalAddress, attestationId, attestationPayload, validationPayloads),
await this.veraxSdk.portal.replace(
portalAddress,
attestationId,
attestationPayload,
validationPayloads,
waitForConfirmation,
),
);
}

Expand Down Expand Up @@ -266,7 +281,13 @@ export default class PortalExamples {
];
const validationPayloads = params?.validationPayloads ?? [[], []];
console.log(
await this.veraxSdk.portal.bulkReplace(portalAddress, attestationIds, attestationPayloads, validationPayloads),
await this.veraxSdk.portal.bulkReplace(
portalAddress,
attestationIds,
attestationPayloads,
validationPayloads,
waitForConfirmation,
),
);
}

Expand All @@ -293,7 +314,9 @@ export default class PortalExamples {
isRevocable: true,
ownerName: "test",
};
console.log(await this.veraxSdk.portal.register(id, name, description, isRevocable, ownerName));
console.log(
await this.veraxSdk.portal.register(id, name, description, isRevocable, ownerName, waitForConfirmation),
);
}

if (methodName.toLowerCase() == "simulateDeployDefaultPortal".toLowerCase() || methodName == "") {
Expand Down Expand Up @@ -321,7 +344,16 @@ export default class PortalExamples {
isRevocable: true,
ownerName: "test",
};
console.log(await this.veraxSdk.portal.deployDefaultPortal(modules, name, description, isRevocable, ownerName));
console.log(
await this.veraxSdk.portal.deployDefaultPortal(
modules,
name,
description,
isRevocable,
ownerName,
waitForConfirmation,
),
);
}

if (methodName.toLowerCase() == "getPortalByAddress".toLowerCase() || methodName == "") {
Expand Down
19 changes: 16 additions & 3 deletions sdk/examples/schema/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
import { Hex } from "viem";
import { VeraxSdk } from "../../src/VeraxSdk";
import PortalExamples from "./schemaExamples";
import { config } from "dotenv";
import * as path from "path";

const envPath = path.resolve(__dirname, "../../.env");
config({ path: envPath });

const privateKey = process.env.PRIVATE_KEY as Hex;

let argv: string | null | undefined = process.argv[3] as string;
argv !== null && argv !== undefined ? (argv = argv.replaceAll("\\", "")) : (argv = "");
argv !== null && argv !== undefined && argv !== "wait" ? (argv = argv.replaceAll("\\", "")) : (argv = "");

const waitForConfirmationArgv: string | null | undefined = process.argv[4] as string;
let waitForConfirmation = false;
if ((argv === "" && (process.argv[3] as string) === "wait") || waitForConfirmationArgv === "wait")
waitForConfirmation = true;

const veraxSdk = new VeraxSdk(VeraxSdk.DEFAULT_LINEA_TESTNET);
const veraxSdk = new VeraxSdk(VeraxSdk.DEFAULT_LINEA_TESTNET, undefined, privateKey);

new PortalExamples(veraxSdk).run(argv, process.argv[2]);
new PortalExamples(veraxSdk).run(argv, process.argv[2], waitForConfirmation);
8 changes: 4 additions & 4 deletions sdk/examples/schema/schemaExamples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default class SchemaExamples {
this.veraxSdk = _veraxSdk;
}

async run(argv: string, methodName: string = "") {
async run(argv: string, methodName: string = "", waitForConfirmation = false) {
if (methodName.toLowerCase() == "findOneById".toLowerCase() || methodName == "") {
const schemaId: string =
argv === "" ? "0x01f031da36192c34057c764239eb77bb6ec8ebfb808f72a7bb172f37a5bec31f" : argv;
Expand All @@ -26,7 +26,7 @@ export default class SchemaExamples {

if (methodName.toLowerCase() == "updateRouter".toLowerCase() || methodName == "") {
const routerAddress: Address = argv === "" ? "0x736c78b2f2cBf4F921E8551b2acB6A5Edc9177D5" : (argv as Address);
console.log(await this.veraxSdk.schema.updateRouter(routerAddress));
console.log(await this.veraxSdk.schema.updateRouter(routerAddress, waitForConfirmation));
}

if (methodName.toLowerCase() == "simulateCreate".toLowerCase() || methodName == "") {
Expand All @@ -50,7 +50,7 @@ export default class SchemaExamples {
context: "test",
schemaString: "(bool isBuidler)",
};
console.log(await this.veraxSdk.schema.create(name, description, context, schemaString));
console.log(await this.veraxSdk.schema.create(name, description, context, schemaString, waitForConfirmation));
}

if (methodName.toLowerCase() == "simulateUpdateContext".toLowerCase() || methodName == "") {
Expand All @@ -70,7 +70,7 @@ export default class SchemaExamples {
schemaId: "0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738",
context: "new context",
};
console.log(await this.veraxSdk.schema.updateContext(schemaId, context));
console.log(await this.veraxSdk.schema.updateContext(schemaId, context, waitForConfirmation));
}

if (methodName.toLowerCase() == "getIdFromSchemaString".toLowerCase() || methodName == "") {
Expand Down
16 changes: 10 additions & 6 deletions sdk/src/dataMapper/AttestationDataMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ export default class AttestationDataMapper extends BaseDataMapper<
return this.simulateContract("updateRouter", [routerAddress]);
}

async updateRouter(routerAddress: Address) {
async updateRouter(routerAddress: Address, waitForConfirmation: boolean = false) {
const request = await this.simulateUpdateRouter(routerAddress);
return executeTransaction(request, this.walletClient);
return executeTransaction(request, this.web3Client, this.walletClient, waitForConfirmation);
}

async simulateMassImport(portalAddress: Address, attestationPayloads: AttestationPayload[]) {
Expand All @@ -137,18 +137,22 @@ export default class AttestationDataMapper extends BaseDataMapper<
return this.simulateContract("massImport", [attestationPayloadsArg, portalAddress]);
}

async massImport(portalAddress: Address, attestationPayloads: AttestationPayload[]) {
async massImport(
portalAddress: Address,
attestationPayloads: AttestationPayload[],
waitForConfirmation: boolean = false,
) {
const request = await this.simulateMassImport(portalAddress, attestationPayloads);
return executeTransaction(request, this.walletClient);
return executeTransaction(request, this.web3Client, this.walletClient, waitForConfirmation);
}

async simulateIncrementVersionNumber() {
return this.simulateContract("incrementVersionNumber", []);
}

async incrementVersionNumber() {
async incrementVersionNumber(waitForConfirmation: boolean = false) {
const request = await this.simulateIncrementVersionNumber();
return executeTransaction(request, this.walletClient);
return executeTransaction(request, this.web3Client, this.walletClient, waitForConfirmation);
}

async isRegistered(attestationId: string) {
Expand Down
Loading
Loading