-
Notifications
You must be signed in to change notification settings - Fork 1
/
ConsumerBase.sol
35 lines (31 loc) · 1.25 KB
/
ConsumerBase.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.4;
abstract contract ConsumerBase {
error OnlyCoordinatorCanFulfill(address have, address want);
address private immutable qrngCoordinator;
/**
* @param _qrngCoordinator address of QRNGCoordinator contract
*/
constructor(address _qrngCoordinator) {
qrngCoordinator = _qrngCoordinator;
}
/**
* @notice fulfillRandomness handles the QRNG response. Your contract must
* @notice implement it. See "SECURITY CONSIDERATIONS" above for important
* @notice principles to keep in mind when implementing your fulfillRandomness
* @notice method.
*
* @param requestId The Id initially returned by requestRandomness
* @param randomWords fulfilled qrng random numbers
*/
function fulfillRandomWords(uint256 requestId, uint256[] memory randomWords) internal virtual;
// rawFulfillRandomness is called by QRNGCoordinator.
// rawFulfillRandomness then calls fulfillRandomness, after validating
// the origin of the call
function rawFulfillRandomWords(uint256 requestId, uint256[] memory randomWords) external {
if (msg.sender != qrngCoordinator) {
revert OnlyCoordinatorCanFulfill(msg.sender, qrngCoordinator);
}
fulfillRandomWords(requestId, randomWords);
}
}