diff --git a/sdk/examples/portal/portalExamples.ts b/sdk/examples/portal/portalExamples.ts index ec0cc9db..7e39e266 100644 --- a/sdk/examples/portal/portalExamples.ts +++ b/sdk/examples/portal/portalExamples.ts @@ -49,7 +49,23 @@ export default class PortalExamples { if (methodName.toLowerCase() == "replace" || methodName == "") console.log(await this.veraxSdk.portal.replace()); - if (methodName.toLowerCase() == "revoke" || methodName == "") console.log(await this.veraxSdk.portal.revoke()); + if (methodName.toLowerCase() == "revoke" || methodName == "") { + console.log( + await this.veraxSdk.portal.revoke( + "0xeea25bc2ec56cae601df33b8fc676673285e12cc", + "0x0000000000000000000000000000000000000000000000000000000000000001", + ), + ); + } + + if (methodName.toLowerCase() == "simulateRevoke".toLowerCase() || methodName == "") { + console.log( + await this.veraxSdk.portal.simulateRevoke( + "0xeea25bc2ec56cae601df33b8fc676673285e12cc", + "0x0000000000000000000000000000000000000000000000000000000000000001", + ), + ); + } if (methodName.toLowerCase() == "bulkRevoke".toLowerCase() || methodName == "") console.log(await this.veraxSdk.portal.bulkRevoke()); diff --git a/sdk/src/dataMapper/BaseDataMapper.ts b/sdk/src/dataMapper/BaseDataMapper.ts index d708b6f7..0a14a2f2 100644 --- a/sdk/src/dataMapper/BaseDataMapper.ts +++ b/sdk/src/dataMapper/BaseDataMapper.ts @@ -36,7 +36,7 @@ export default abstract class BaseDataMapper { return queryResult.data[this.typeName]; } - async findBy(whereClause: Partial) { + async findBy(whereClause: Partial) { const queryResult = await this.apolloClient.query, typeof this.typeName>>({ query: gql(`query GetBy { ${this.typeName}s(where: ${stringifyWhereClause(whereClause)}) ${this.gqlInterface} }`), }); diff --git a/sdk/src/dataMapper/PortalDataMapper.ts b/sdk/src/dataMapper/PortalDataMapper.ts index 998f907e..c5cb808c 100644 --- a/sdk/src/dataMapper/PortalDataMapper.ts +++ b/sdk/src/dataMapper/PortalDataMapper.ts @@ -34,16 +34,7 @@ export default class PortalDataMapper extends BaseDataMapper { return request; } catch (err) { - if (err instanceof BaseError) { - const revertError = err.walk((err) => err instanceof ContractFunctionRevertedError); - if (revertError instanceof ContractFunctionRevertedError) { - const errorName = revertError.data?.errorName ?? ""; - console.error(`Failing with ${errorName}`); - } - } - console.error(err); - - throw new Error("Simulation failed"); + this.handleError(err); } } @@ -64,8 +55,29 @@ export default class PortalDataMapper extends BaseDataMapper { throw new Error("Not implemented"); } - async revoke() { - throw new Error("Not implemented"); + async simulateRevoke(portalAddress: Address, attestationId: string) { + try { + const { request } = await this.web3Client.simulateContract({ + address: portalAddress, + abi: abiDefaultPortal, + functionName: "revoke", + account: this.walletClient.account, + args: [attestationId], + }); + + return request; + } catch (err) { + this.handleError(err); + } + } + + async revoke(portalAddress: Address, attestationId: string) { + const request = await this.simulateRevoke(portalAddress, attestationId); + const hash: Hash = await this.walletClient.writeContract(request); + + console.log(`Transaction sent with hash ${hash}`); + + return hash; } async bulkRevoke() { @@ -83,4 +95,17 @@ export default class PortalDataMapper extends BaseDataMapper { async clone() { throw new Error("Not implemented"); } + + private handleError(err: unknown): never { + if (err instanceof BaseError) { + const revertError = err.walk((err) => err instanceof ContractFunctionRevertedError); + if (revertError instanceof ContractFunctionRevertedError) { + const errorName = revertError.data?.errorName ?? ""; + console.error(`Failing with ${errorName}`); + } + } + console.error(err); + + throw new Error("Simulation failed"); + } }