Skip to content

Commit 0e98ac3

Browse files
committed
clean up contracts
1 parent e1e640c commit 0e98ac3

File tree

2 files changed

+21
-13
lines changed

2 files changed

+21
-13
lines changed

packages/hardhat/contracts/FeedRegistryConsumer.sol

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ pragma solidity ^0.8.7;
55
import "@chainlink/contracts/src/v0.8/interfaces/FeedRegistryInterface.sol";
66
import "@chainlink/contracts/src/v0.8/Denominations.sol";
77

8-
/**Contract to consume the Chainlink FeedRegistry
8+
/** Simple contract to consume the Chainlink FeedRegistry
99
*
1010
* @notice FeedRegistry address only exists on the Ethereum Mainnet
1111
* @notice https://docs.chain.link/data-feeds/feed-registry#contract-addresses
1212
*/
13+
1314
contract FeedRegistryConsumer {
1415
FeedRegistryInterface internal immutable i_registry;
1516

@@ -21,8 +22,13 @@ contract FeedRegistryConsumer {
2122
* Get the latest price of ETH/USD
2223
*/
2324
function getEthUsdPrice() public view returns (int) {
24-
(, /*uint80 roundID*/ int price, , , ) = /*uint startedAt*/ /*uint timeStamp*/ /*uint80 answeredInRound*/
25-
i_registry.latestRoundData(Denominations.ETH, Denominations.USD);
25+
(
26+
,
27+
/*uint80 roundID*/ int price /*uint startedAt*/ /*uint timeStamp*/ /*uint80 answeredInRound*/,
28+
,
29+
,
30+
31+
) = i_registry.latestRoundData(Denominations.ETH, Denominations.USD);
2632
return price;
2733
}
2834

packages/hardhat/contracts/VRFConsumer.sol

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,25 @@ pragma solidity ^0.8.7;
44
import "@chainlink/contracts/src/v0.8/vrf/VRFV2WrapperConsumerBase.sol";
55
import "@chainlink/contracts/src/v0.8/shared/access/ConfirmedOwner.sol";
66

7-
/**
8-
* Spin the wheel to get a random number from chainlink VRF
7+
/** Simple contract that request random numbers from chainlink VRF
8+
*
9+
* this example uses the "Direct Funding" method
10+
* https://docs.chain.link/vrf#two-methods-to-request-randomness
911
*/
1012

1113
contract VRFConsumer is VRFV2WrapperConsumerBase, ConfirmedOwner {
12-
// State Variables
14+
// if gas consumed by fulfillRandomWords() exceeds this limit, the transaction will revert
15+
uint32 callbackGasLimit = 100000;
16+
// blocks before chainlink node responds (must be greater than a minimum amout set by VRF coordinator contract)
17+
uint16 requestConfirmations = 3;
18+
// how many random numbers to generate
19+
uint32 numValues = 1;
1320
address public linkAddress;
14-
uint32 callbackGasLimit = 100000; // limit for gas can be used when chainlink node calls fulfillRandomWords()
15-
uint16 requestConfirmations = 3; // blocks before chainlink node responds (must be greater than a minimum amout set by VRF coordinator contract)
16-
uint32 numValues = 1; // how many random numbers to generate
1721

22+
// keeping track of who requested which random number
1823
mapping(uint256 => address) public s_spinners; // requestId => msg.sender
1924
mapping(address => uint256) public s_results; // msg.sender => random number
2025

21-
// Events
2226
event WheelSpun(uint256 indexed requestId, address indexed spinner);
2327
event WheelResult(
2428
uint256 indexed requestId,
@@ -38,7 +42,7 @@ contract VRFConsumer is VRFV2WrapperConsumerBase, ConfirmedOwner {
3842

3943
/** This function triggers the request to chainlink node that generates the random number
4044
*
41-
* "requestRandomness()" is inherited from VRFV2WrapperConsumerBase
45+
* requestRandomness() is inherited from VRFV2WrapperConsumerBase
4246
*
4347
* @return requestId each request has a unique ID
4448
*/
@@ -68,7 +72,6 @@ contract VRFConsumer is VRFV2WrapperConsumerBase, ConfirmedOwner {
6872
uint256 requestId,
6973
uint256[] memory randomWords
7074
) internal override {
71-
// The remainder of division by 6 can only be 0 - 5
7275
uint256 randomNumber = (randomWords[0] % 6);
7376
// update mapping to record who received which random number by using the requestId
7477
s_results[s_spinners[requestId]] = randomNumber;
@@ -83,7 +86,6 @@ contract VRFConsumer is VRFV2WrapperConsumerBase, ConfirmedOwner {
8386
);
8487
}
8588

86-
// Getters
8789
function getLinkBalance() public view returns (uint256) {
8890
LinkTokenInterface link = LinkTokenInterface(linkAddress);
8991
return link.balanceOf(address(this));

0 commit comments

Comments
 (0)