mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-05 15:23:12 +00:00
chore: cannot erase membership if it isn't expired/in grace period
This commit is contained in:
parent
917ea7821f
commit
5a5d7b3e26
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user