mirror of
https://github.com/logos-messaging/logos-messaging-js.git
synced 2026-03-21 22:33:10 +00:00
chore: add rateLimit to MembershipInfo
This commit is contained in:
parent
5f980cb3a7
commit
76f86de9c7
@ -95,15 +95,7 @@ export class RLNContract {
|
||||
contract
|
||||
} = options;
|
||||
|
||||
if (
|
||||
rateLimit < RATE_LIMIT_PARAMS.MIN_RATE ||
|
||||
rateLimit > RATE_LIMIT_PARAMS.MAX_RATE
|
||||
) {
|
||||
throw new Error(
|
||||
`Rate limit must be between ${RATE_LIMIT_PARAMS.MIN_RATE} and ${RATE_LIMIT_PARAMS.MAX_RATE} messages per epoch`
|
||||
);
|
||||
}
|
||||
|
||||
this.validateRateLimit(rateLimit);
|
||||
this.rateLimit = rateLimit;
|
||||
|
||||
const initialRoot = rlnInstance.zerokit.getMerkleRoot();
|
||||
@ -118,6 +110,21 @@ export class RLNContract {
|
||||
this._membersExpiredFilter = this.contract.filters.MembershipExpired();
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates that the rate limit is within the allowed range
|
||||
* @throws Error if the rate limit is outside the allowed range
|
||||
*/
|
||||
private validateRateLimit(rateLimit: number): void {
|
||||
if (
|
||||
rateLimit < RATE_LIMIT_PARAMS.MIN_RATE ||
|
||||
rateLimit > RATE_LIMIT_PARAMS.MAX_RATE
|
||||
) {
|
||||
throw new Error(
|
||||
`Rate limit must be between ${RATE_LIMIT_PARAMS.MIN_RATE} and ${RATE_LIMIT_PARAMS.MAX_RATE} messages per epoch`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current rate limit for this contract instance
|
||||
*/
|
||||
@ -192,6 +199,7 @@ export class RLNContract {
|
||||
* @param newRateLimit The new rate limit to use
|
||||
*/
|
||||
public async setRateLimit(newRateLimit: number): Promise<void> {
|
||||
this.validateRateLimit(newRateLimit);
|
||||
this.rateLimit = newRateLimit;
|
||||
}
|
||||
|
||||
@ -469,7 +477,8 @@ export class RLNContract {
|
||||
membership: {
|
||||
address,
|
||||
treeIndex: membershipId,
|
||||
chainId: network.chainId
|
||||
chainId: network.chainId,
|
||||
rateLimit: decodedData.membershipRateLimit.toNumber()
|
||||
}
|
||||
};
|
||||
} catch (error) {
|
||||
@ -594,7 +603,8 @@ export class RLNContract {
|
||||
membership: {
|
||||
address,
|
||||
treeIndex: membershipId,
|
||||
chainId: network.chainId
|
||||
chainId: network.chainId,
|
||||
rateLimit: decodedData.membershipRateLimit.toNumber()
|
||||
}
|
||||
};
|
||||
} catch (error) {
|
||||
@ -669,16 +679,9 @@ export class RLNContract {
|
||||
|
||||
public async registerMembership(
|
||||
idCommitment: string,
|
||||
rateLimit: number = DEFAULT_RATE_LIMIT
|
||||
rateLimit: number = this.rateLimit
|
||||
): Promise<ethers.ContractTransaction> {
|
||||
if (
|
||||
rateLimit < RATE_LIMIT_PARAMS.MIN_RATE ||
|
||||
rateLimit > RATE_LIMIT_PARAMS.MAX_RATE
|
||||
) {
|
||||
throw new Error(
|
||||
`Rate limit must be between ${RATE_LIMIT_PARAMS.MIN_RATE} and ${RATE_LIMIT_PARAMS.MAX_RATE}`
|
||||
);
|
||||
}
|
||||
this.validateRateLimit(rateLimit);
|
||||
return this.contract.register(idCommitment, rateLimit, []);
|
||||
}
|
||||
|
||||
|
||||
@ -274,7 +274,8 @@ export class Keystore {
|
||||
membership: {
|
||||
treeIndex: _.get(obj, "treeIndex"),
|
||||
chainId: _.get(obj, "membershipContract.chainId"),
|
||||
address: _.get(obj, "membershipContract.address")
|
||||
address: _.get(obj, "membershipContract.address"),
|
||||
rateLimit: _.get(obj, "membershipContract.rateLimit")
|
||||
}
|
||||
};
|
||||
} catch (err) {
|
||||
|
||||
@ -11,6 +11,7 @@ export type MembershipInfo = {
|
||||
chainId: number;
|
||||
address: string;
|
||||
treeIndex: number;
|
||||
rateLimit: number;
|
||||
};
|
||||
|
||||
export type KeystoreEntity = {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user