fix: use modifier for usable storage

This commit is contained in:
rymnc 2023-08-08 16:10:06 +05:30
parent ae01148ffc
commit 002c0f1213
No known key found for this signature in database
GPG Key ID: AAA088D5C68ECD34
2 changed files with 13 additions and 5 deletions

View File

@ -20,6 +20,11 @@ contract WakuRlnRegistry is Ownable {
event NewStorageContract(uint16 index, address storageAddress);
modifier onlyUsableStorage() {
if (usingStorageIndex >= nextStorageIndex) revert NoStorageContractAvailable();
_;
}
constructor(address _poseidonHasher) Ownable() {
poseidonHasher = IPoseidonHasher(_poseidonHasher);
}
@ -43,9 +48,7 @@ contract WakuRlnRegistry is Ownable {
_insertIntoStorageMap(address(newStorageContract));
}
function register(uint256[] calldata commitments) external payable {
if (usingStorageIndex >= nextStorageIndex) revert NoStorageContractAvailable();
function register(uint256[] calldata commitments) external payable onlyUsableStorage {
// iteratively check if the storage contract is full, and increment the usingStorageIndex if it is
while (true) {
try WakuRln(storages[usingStorageIndex]).register(commitments) {
@ -77,8 +80,7 @@ contract WakuRlnRegistry is Ownable {
WakuRln(storages[storageIndex]).register(commitments);
}
function forceProgress() external onlyOwner {
if (usingStorageIndex >= nextStorageIndex) revert NoStorageContractAvailable();
function forceProgress() external onlyOwner onlyUsableStorage {
usingStorageIndex += 1;
}
}

View File

@ -148,6 +148,12 @@ contract IPoseidonHasher poseidonHasher
event NewStorageContract(uint16 index, address storageAddress)
```
### onlyUsableStorage
```solidity
modifier onlyUsableStorage()
```
### constructor
```solidity