chore: cannot erase membership if it isn't expired/in grace period

This commit is contained in:
Danish Arora 2025-05-15 16:24:43 +05:30
parent 917ea7821f
commit 5a5d7b3e26
No known key found for this signature in database
GPG Key ID: 1C6EF37CDAE1426E

View File

@ -432,6 +432,13 @@ export class RLNBaseContract {
idCommitmentBigInt: bigint,
eraseFromMembershipSet: boolean = true
): Promise<ethers.ContractTransaction> {
if (
!(await this.isExpired(idCommitmentBigInt)) &&
!(await this.isInGracePeriod(idCommitmentBigInt))
) {
throw new Error("Membership is not expired or in grace period");
}
const estimatedGas = await this.contract.estimateGas[
"eraseMemberships(uint256[],bool)"
]([idCommitmentBigInt], eraseFromMembershipSet);
@ -711,4 +718,32 @@ export class RLNBaseContract {
return undefined;
}
}
/**
* Checks if a membership is expired for the given idCommitment
* @param idCommitmentBigInt The idCommitment as bigint
* @returns Promise<boolean> True if expired, false otherwise
*/
public async isExpired(idCommitmentBigInt: bigint): Promise<boolean> {
try {
return await this.contract.isExpired(idCommitmentBigInt);
} catch (error) {
log.error("Error in isExpired:", error);
return false;
}
}
/**
* Checks if a membership is in grace period for the given idCommitment
* @param idCommitmentBigInt The idCommitment as bigint
* @returns Promise<boolean> True if in grace period, false otherwise
*/
public async isInGracePeriod(idCommitmentBigInt: bigint): Promise<boolean> {
try {
return await this.contract.isInGracePeriod(idCommitmentBigInt);
} catch (error) {
log.error("Error in isInGracePeriod:", error);
return false;
}
}
}