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 to batch create and batch revoke attestations with the SDK #280

Merged
Show file tree
Hide file tree
Changes from 1 commit
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
62 changes: 59 additions & 3 deletions sdk/examples/portal/portalExamples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,51 @@ export default class PortalExamples {
);
}

if (methodName.toLowerCase() == "bulkAttest".toLowerCase() || methodName == "")
console.log(await this.veraxSdk.portal.bulkAttest());
if (methodName.toLowerCase() == "simulateBulkAttest".toLowerCase() || methodName == "") {
console.log(
await this.veraxSdk.portal.simulateBulkAttest(
"0x34798a866f52949208e67fb57ad36244024c50c0",
[
{
schemaId: "0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738",
expirationDate: 1693583329,
subject: "0x828c9f04D1a07E3b0aBE12A9F8238a3Ff7E57b47",
attestationData: [{ isBuidler: true }],
},
{
schemaId: "0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738",
expirationDate: 1693583329,
subject: "0x828c9f04D1a07E3b0aBE12A9F8238a3Ff7E57b47",
attestationData: [{ isBuidler: true }],
},
],
[],
),
);
}

if (methodName.toLowerCase() == "bulkAttest".toLowerCase() || methodName == "") {
console.log(
await this.veraxSdk.portal.bulkAttest(
"0x34798a866f52949208e67fb57ad36244024c50c0",
[
{
schemaId: "0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738",
expirationDate: 1693583329,
subject: "0x828c9f04D1a07E3b0aBE12A9F8238a3Ff7E57b47",
attestationData: [{ isBuidler: true }],
},
{
schemaId: "0x9ba590dd7fbd5bd1a7d06cdcb4744e20a49b3520560575cd63de17734a408738",
expirationDate: 1693583329,
subject: "0x828c9f04D1a07E3b0aBE12A9F8238a3Ff7E57b47",
attestationData: [{ isBuidler: false }],
},
],
[[], []],
),
);
}

if (methodName.toLowerCase() == "replace" || methodName == "") console.log(await this.veraxSdk.portal.replace());

Expand All @@ -67,8 +110,21 @@ export default class PortalExamples {
);
}

if (methodName.toLowerCase() == "simulateBulkRevoke".toLowerCase() || methodName == "")
console.log(
await this.veraxSdk.portal.simulateBulkRevoke("0x34798a866f52949208e67fb57ad36244024c50c0", [
"0x00000000000000000000000000000000000000000000000000000000000010a0",
"0x00000000000000000000000000000000000000000000000000000000000010a1",
]),
);

if (methodName.toLowerCase() == "bulkRevoke".toLowerCase() || methodName == "")
console.log(await this.veraxSdk.portal.bulkRevoke());
console.log(
await this.veraxSdk.portal.bulkRevoke("0x34798a866f52949208e67fb57ad36244024c50c0", [
"0x00000000000000000000000000000000000000000000000000000000000010a0",
"0x00000000000000000000000000000000000000000000000000000000000010a1",
]),
);

if (methodName.toLowerCase() == "massImport".toLowerCase() || methodName == "")
console.log(await this.veraxSdk.portal.massImport());
Expand Down
67 changes: 63 additions & 4 deletions sdk/src/dataMapper/PortalDataMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,46 @@ export default class PortalDataMapper extends BaseDataMapper<Portal> {
return hash;
}

async bulkAttest() {
throw new Error("Not implemented");
async simulateBulkAttest(
portalAddress: Address,
attestationPayloads: AttestationPayload[],
validationPayloads: string[][],
) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const attestationPayloadsArg: any[] = [];
alainncls marked this conversation as resolved.
Show resolved Hide resolved
attestationPayloads.forEach(async (attestationPayload) => {
const matchingSchema = await this.veraxSdk.schema.findOneById(attestationPayload.schemaId);
const attestationData = encode(matchingSchema.schema, attestationPayload.attestationData);
attestationPayloadsArg.push([
attestationPayload.schemaId,
attestationPayload.expirationDate,
attestationPayload.subject,
attestationData,
]);
});

try {
const { request } = await this.web3Client.simulateContract({
address: portalAddress,
abi: abiDefaultPortal,
functionName: "bulkAttest",
account: this.walletClient.account,
args: [attestationPayloadsArg, validationPayloads],
});
alainncls marked this conversation as resolved.
Show resolved Hide resolved

return request;
} catch (err) {
this.handleError(err);
}
}

async bulkAttest(portalAddress: Address, attestationPayloads: AttestationPayload[], validationPayloads: string[][]) {
const request = await this.simulateBulkAttest(portalAddress, attestationPayloads, validationPayloads);
const hash: Hash = await this.walletClient.writeContract(request);

console.log(`Transaction sent with hash ${hash}`);

return hash;
alainncls marked this conversation as resolved.
Show resolved Hide resolved
}

async replace() {
Expand Down Expand Up @@ -80,8 +118,29 @@ export default class PortalDataMapper extends BaseDataMapper<Portal> {
return hash;
}

async bulkRevoke() {
throw new Error("Not implemented");
async simulateBulkRevoke(portalAddress: Address, attestationIds: string[]) {
try {
const { request } = await this.web3Client.simulateContract({
address: portalAddress,
abi: abiDefaultPortal,
functionName: "bulkRevoke",
account: this.walletClient.account,
args: [attestationIds],
});

return request;
} catch (err) {
this.handleError(err);
}
}

async bulkRevoke(portalAddress: Address, attestationIds: string[]) {
const request = await this.simulateBulkRevoke(portalAddress, attestationIds);
const hash: Hash = await this.walletClient.writeContract(request);

console.log(`Transaction sent with hash ${hash}`);

return hash;
}

async massImport() {
Expand Down
Loading