From eba09cf8730142b24e72728714b4cf9bccae13b3 Mon Sep 17 00:00:00 2001 From: Satyajeet Kolhapure Date: Fri, 13 Oct 2023 11:39:56 +0100 Subject: [PATCH 1/2] feat: added bulkAttest and bulkRevoke methods to SDK --- sdk/examples/portal/portalExamples.ts | 62 ++++++++++++++++++++++-- sdk/src/dataMapper/PortalDataMapper.ts | 67 ++++++++++++++++++++++++-- 2 files changed, 122 insertions(+), 7 deletions(-) diff --git a/sdk/examples/portal/portalExamples.ts b/sdk/examples/portal/portalExamples.ts index 7e39e266..c5d2bfff 100644 --- a/sdk/examples/portal/portalExamples.ts +++ b/sdk/examples/portal/portalExamples.ts @@ -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()); @@ -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()); diff --git a/sdk/src/dataMapper/PortalDataMapper.ts b/sdk/src/dataMapper/PortalDataMapper.ts index c5cb808c..73a2c0b1 100644 --- a/sdk/src/dataMapper/PortalDataMapper.ts +++ b/sdk/src/dataMapper/PortalDataMapper.ts @@ -47,8 +47,46 @@ export default class PortalDataMapper extends BaseDataMapper { 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[] = []; + 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], + }); + + 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; } async replace() { @@ -80,8 +118,29 @@ export default class PortalDataMapper extends BaseDataMapper { 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() { From 0ffca860857cd632fbca7145380dd1b12e379132 Mon Sep 17 00:00:00 2001 From: Alain Nicolas Date: Fri, 13 Oct 2023 16:01:04 +0200 Subject: [PATCH 2/2] fix: typing --- sdk/src/dataMapper/PortalDataMapper.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sdk/src/dataMapper/PortalDataMapper.ts b/sdk/src/dataMapper/PortalDataMapper.ts index 73a2c0b1..dbe6d907 100644 --- a/sdk/src/dataMapper/PortalDataMapper.ts +++ b/sdk/src/dataMapper/PortalDataMapper.ts @@ -52,18 +52,19 @@ export default class PortalDataMapper extends BaseDataMapper { attestationPayloads: AttestationPayload[], validationPayloads: string[][], ) { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const attestationPayloadsArg: any[] = []; - attestationPayloads.forEach(async (attestationPayload) => { + const attestationPayloadsArg = []; + + for (const attestationPayload of attestationPayloads) { 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({