-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "add deployed cypress contracts address (#16)"
This reverts commit d0b4dc2.
- Loading branch information
Bayram Guvanjov
committed
Jun 23, 2023
1 parent
d0b4dc2
commit 3d071db
Showing
5 changed files
with
72 additions
and
90 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,77 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.16; | ||
|
||
import {VRFConsumerBase} from "@bisonai/orakl-contracts/src/v0.1/VRFConsumerBase.sol"; | ||
import {IVRFCoordinator} from "@bisonai/orakl-contracts/src/v0.1/interfaces/IVRFCoordinator.sol"; | ||
import {IPrepayment} from "@bisonai/orakl-contracts/src/v0.1/interfaces/IPrepayment.sol"; | ||
import { VRFConsumerBase } from "@bisonai/orakl-contracts/src/v0.1/VRFConsumerBase.sol"; | ||
import { IVRFCoordinator } from "@bisonai/orakl-contracts/src/v0.1/interfaces/IVRFCoordinator.sol"; | ||
|
||
contract VRFConsumer is VRFConsumerBase { | ||
uint256 public sRandomWord; | ||
address private sOwner; | ||
uint256 public sRandomWord; | ||
address private sOwner; | ||
|
||
IVRFCoordinator COORDINATOR; | ||
IVRFCoordinator COORDINATOR; | ||
|
||
error OnlyOwner(address notOwner); | ||
error OnlyOwner(address notOwner); | ||
|
||
modifier onlyOwner() { | ||
if (msg.sender != sOwner) { | ||
revert OnlyOwner(msg.sender); | ||
} | ||
_; | ||
} | ||
modifier onlyOwner() { | ||
if (msg.sender != sOwner) { | ||
revert OnlyOwner(msg.sender); | ||
} | ||
_; | ||
} | ||
|
||
constructor(address coordinator) VRFConsumerBase(coordinator) { | ||
sOwner = msg.sender; | ||
COORDINATOR = IVRFCoordinator(coordinator); | ||
} | ||
constructor(address coordinator) VRFConsumerBase(coordinator) { | ||
sOwner = msg.sender; | ||
COORDINATOR = IVRFCoordinator(coordinator); | ||
} | ||
|
||
// Receive remaining payment from requestRandomWordsPayment | ||
receive() external payable {} | ||
// Receive remaining payment from requestRandomWordsPayment | ||
receive() external payable {} | ||
|
||
function requestRandomWords( | ||
bytes32 keyHash, | ||
uint64 accId, | ||
uint32 callbackGasLimit, | ||
uint32 numWords | ||
) public onlyOwner returns (uint256 requestId) { | ||
requestId = COORDINATOR.requestRandomWords(keyHash, accId, callbackGasLimit, numWords); | ||
} | ||
function requestRandomWords( | ||
bytes32 keyHash, | ||
uint64 accId, | ||
uint32 callbackGasLimit, | ||
uint32 numWords | ||
) | ||
public | ||
onlyOwner | ||
returns (uint256 requestId) | ||
{ | ||
requestId = COORDINATOR.requestRandomWords( | ||
keyHash, | ||
accId, | ||
callbackGasLimit, | ||
numWords | ||
); | ||
} | ||
|
||
function requestRandomWordsDirect( | ||
bytes32 keyHash, | ||
uint32 callbackGasLimit, | ||
uint32 numWords, | ||
address refundRecipient | ||
) public payable onlyOwner returns (uint256 requestId) { | ||
requestId = COORDINATOR.requestRandomWords{value: msg.value}( | ||
keyHash, | ||
callbackGasLimit, | ||
numWords, | ||
refundRecipient | ||
); | ||
} | ||
function requestRandomWordsDirect( | ||
bytes32 keyHash, | ||
uint32 callbackGasLimit, | ||
uint32 numWords | ||
) | ||
public | ||
payable | ||
onlyOwner | ||
returns (uint256 requestId) | ||
{ | ||
requestId = COORDINATOR.requestRandomWords{value: msg.value}( | ||
keyHash, | ||
callbackGasLimit, | ||
numWords, | ||
address(this) | ||
); | ||
} | ||
|
||
function fulfillRandomWords( | ||
uint256 /* requestId */, | ||
uint256[] memory randomWords | ||
) internal override { | ||
// requestId should be checked if it matches the expected request | ||
// Generate random value between 1 and 50. | ||
sRandomWord = (randomWords[0] % 50) + 1; | ||
} | ||
|
||
function cancelRequest(uint256 requestId) external onlyOwner { | ||
COORDINATOR.cancelRequest(requestId); | ||
} | ||
|
||
function withdrawTemporary(uint64 accId) external onlyOwner { | ||
address prepaymentAddress = COORDINATOR.getPrepaymentAddress(); | ||
IPrepayment(prepaymentAddress).withdrawTemporary(accId, payable(msg.sender)); | ||
} | ||
function fulfillRandomWords( | ||
uint256 /* requestId */, | ||
uint256[] memory randomWords | ||
) | ||
internal | ||
override | ||
{ | ||
// requestId should be checked if it matches the expected request | ||
// Generate random value between 1 and 50. | ||
sRandomWord = (randomWords[0] % 50) + 1; | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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