1
1
// SPDX-License-Identifier: MIT
2
2
pragma solidity 0.8.24 ;
3
3
4
- import "./RNG .sol " ;
4
+ import "./IRNG .sol " ;
5
5
6
6
/// @title RNG with fallback mechanism
7
7
/// @notice Uses multiple RNG implementations with automatic fallback if default RNG does not respond passed a timeout.
8
- contract RNGWithFallback is RNG {
8
+ contract RNGWithFallback is IRNG {
9
9
uint256 public constant DEFAULT_RNG = 0 ;
10
10
11
11
// ************************************* //
12
12
// * Storage * //
13
13
// ************************************* //
14
14
15
15
address public governor; // Governor address
16
- RNG [] public rngs; // List of RNG implementations
16
+ IRNG [] public rngs; // List of RNG implementations
17
17
uint256 public fallbackTimeout; // Number of blocks to wait before falling back to next RNG
18
18
uint256 public requestBlock; // Block number of the current request
19
19
uint256 public currentRngIndex; // Index of the current RNG
@@ -35,14 +35,14 @@ contract RNGWithFallback is RNG {
35
35
36
36
/// @param _governor Governor address
37
37
/// @param _fallbackTimeout Number of blocks to wait before falling back to next RNG
38
- /// @param _initialRng The default RNG
39
- constructor (address _governor , uint256 _fallbackTimeout , RNG _initialRng ) {
40
- require (address (_initialRng ) != address (0 ), "Invalid default RNG " );
38
+ /// @param _defaultRng The default RNG
39
+ constructor (address _governor , uint256 _fallbackTimeout , IRNG _defaultRng ) {
40
+ require (address (_defaultRng ) != address (0 ), "Invalid default RNG " );
41
41
require (_fallbackTimeout > 0 , "Invalid fallback timeout " );
42
42
43
43
governor = _governor;
44
44
fallbackTimeout = _fallbackTimeout;
45
- rngs.push (_initialRng );
45
+ rngs.push (_defaultRng );
46
46
}
47
47
48
48
// ************************************* //
@@ -110,7 +110,7 @@ contract RNGWithFallback is RNG {
110
110
111
111
/// @dev Change the default RNG
112
112
/// @param _newDefaultRng Address of the new default RNG
113
- function changeDefaultRng (RNG _newDefaultRng ) external onlyByGovernor {
113
+ function changeDefaultRng (IRNG _newDefaultRng ) external onlyByGovernor {
114
114
require (address (_newDefaultRng) != address (0 ), "Invalid RNG " );
115
115
rngs[DEFAULT_RNG] = _newDefaultRng;
116
116
emit RNGDefaultChanged (address (_newDefaultRng));
@@ -121,7 +121,7 @@ contract RNGWithFallback is RNG {
121
121
122
122
/// @dev Add a new RNG fallback
123
123
/// @param _newFallbackRng Address of the new RNG fallback
124
- function addRngFallback (RNG _newFallbackRng ) external onlyByGovernor {
124
+ function addRngFallback (IRNG _newFallbackRng ) external onlyByGovernor {
125
125
require (address (_newFallbackRng) != address (0 ), "Invalid RNG " );
126
126
rngs.push (_newFallbackRng);
127
127
emit RNGFallbackAdded (address (_newFallbackRng));
@@ -136,7 +136,7 @@ contract RNGWithFallback is RNG {
136
136
currentRngIndex = DEFAULT_RNG;
137
137
}
138
138
139
- RNG removedRng = rngs[rngs.length - 1 ];
139
+ IRNG removedRng = rngs[rngs.length - 1 ];
140
140
rngs.pop ();
141
141
emit RNGFallbackRemoved (address (removedRng));
142
142
}
0 commit comments