Created
May 27, 2020 11:29
-
-
Save alexroan/d91ce76522cf1f6dc17a5e024fc2ff4a to your computer and use it in GitHub Desktop.
lottery/RandomNumberGenerator.sol
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pragma solidity ^0.6.2; | |
import "./VRFConsumerBase.sol"; | |
import "./Lottery.sol"; | |
contract RandomNumberGenerator is VRFConsumerBase { | |
address requester; | |
bytes32 keyHash; | |
uint256 fee; | |
constructor(address _vrfCoordinator, address _link, bytes32 _keyHash, uint256 _fee) | |
VRFConsumerBase(_vrfCoordinator, _link) public { | |
keyHash = _keyHash; | |
fee = _fee; | |
} | |
function fulfillRandomness(bytes32 _requestId, uint256 _randomness) external override { | |
Lottery(requester).numberDrawn(_requestId, _randomness); | |
} | |
function request(uint256 _seed) public returns(bytes32 requestId) { | |
require(keyHash != bytes32(0), "Must have valid key hash"); | |
requester = msg.sender; | |
return this.requestRandomness(keyHash, fee, _seed); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment