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: added revoke and simulateRevoke #274

Merged
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
18 changes: 17 additions & 1 deletion sdk/examples/portal/portalExamples.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/dataMapper/BaseDataMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default abstract class BaseDataMapper<T> {
return queryResult.data[this.typeName];
}

async findBy<T extends keyof FilterMap>(whereClause: Partial<FilterMap[T]>) {
async findBy<TFilter extends keyof FilterMap>(whereClause: Partial<FilterMap[TFilter]>) {
const queryResult = await this.apolloClient.query<QueryResult<Array<T>, typeof this.typeName>>({
query: gql(`query GetBy { ${this.typeName}s(where: ${stringifyWhereClause(whereClause)}) ${this.gqlInterface} }`),
});
Expand Down
49 changes: 37 additions & 12 deletions sdk/src/dataMapper/PortalDataMapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,7 @@ export default class PortalDataMapper extends BaseDataMapper<Portal> {

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);
}
}

Expand All @@ -64,8 +55,29 @@ export default class PortalDataMapper extends BaseDataMapper<Portal> {
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() {
Expand All @@ -83,4 +95,17 @@ export default class PortalDataMapper extends BaseDataMapper<Portal> {
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");
}
}
Loading