Skip to content

Commit

Permalink
Merge pull request #5 from GenerationSoftware/gen-1316-pt-v5-rng-witnet
Browse files Browse the repository at this point in the history
Tweaked things
  • Loading branch information
asselstine committed Apr 16, 2024
2 parents 28231ce + 18cda7e commit 36f8b30
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 G9 Software Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 1 addition & 0 deletions src/Requestor.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.24;
import { IWitnetRandomness } from "witnet/interfaces/IWitnetRandomness.sol";

/// @title Requestor
/// @author G9 Software Inc.
/// @notice A contract that requests random numbers from the Witnet Randomness Oracle. Holds the unused balance of Ether.
contract Requestor {
/// @notice Thrown when a new random number is requested
Expand Down
9 changes: 8 additions & 1 deletion src/RngWitnet.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@ import { Requestor } from "./Requestor.sol";
error UnknownRequest(uint32 requestId);

/// @title RngWitnet
/// @author G9 Software Inc.
/// @notice A contract that requests random numbers from the Witnet Randomness Oracle
contract RngWitnet is IRng {

/// @notice Emitted when a new random number is requested
/// @param requestId The id of the request
/// @param sender The address that requested the random number
/// @param paid The amount paid to the Witnet
/// @param cost The actual cost of the RNG request. The paid amount less the cost is refunded to the Requestor contract for the caller.
event RandomNumberRequested(
uint32 indexed requestId,
address indexed sender,
uint256 paid,
uint256 cost
);

Expand Down Expand Up @@ -77,6 +81,7 @@ contract RngWitnet is IRng {
/// @param rngPaymentAmount The amount of Ether to send to the Witnet Randomness Oracle. This amount should be sent in this call, remaining from a previous call, or a combination thereof. The Requestor holds the current balance.
/// @return requestId The id of the request
/// @return lockBlock The block number at which the request was made
/// @return cost The actual cost of the RNG request
function requestRandomNumber(uint256 rngPaymentAmount) public payable returns (uint32 requestId, uint256 lockBlock, uint256 cost) {
Requestor requestor = getRequestor(msg.sender);
unchecked {
Expand All @@ -86,7 +91,7 @@ contract RngWitnet is IRng {
requests[requestId] = lockBlock;
cost = requestor.randomize{value: msg.value}(rngPaymentAmount, witnetRandomness);

emit RandomNumberRequested(requestId, msg.sender, cost);
emit RandomNumberRequested(requestId, msg.sender, rngPaymentAmount, cost);
}

/// @notice Withdraws the balance of the Requestor contract of the caller
Expand Down Expand Up @@ -128,6 +133,8 @@ contract RngWitnet is IRng {
return _drawManager.startDraw(_rewardRecipient, requestId);
}

/// @notice Reverts if the request id is unknown
/// @param _requestId The ID of the request to check
modifier onlyValidRequest(uint32 _requestId) {
if (requests[_requestId] == 0) {
revert UnknownRequest(_requestId);
Expand Down

0 comments on commit 36f8b30

Please sign in to comment.