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

View File

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