Skip to content

Commit

Permalink
chore: prefix internal functions w/ underscore (#10943)
Browse files Browse the repository at this point in the history
* chore: prefix internal functions w/ underscore

Where applicable and where it doesn't break existing contracts and
backwards compatibility.

* fix: solhint
  • Loading branch information
makramkd authored Oct 16, 2023
1 parent 7bede8e commit 3f492fe
Show file tree
Hide file tree
Showing 16 changed files with 205 additions and 265 deletions.
5 changes: 2 additions & 3 deletions contracts/src/v0.8/vrf/BatchBlockhashStore.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ contract BatchBlockhashStore {
for (uint256 i = 0; i < blockNumbers.length; i++) {
// skip the block if it's not storeable, the caller will have to check
// after the transaction is mined to see if the blockhash was truly stored.
if (!storeableBlock(blockNumbers[i])) {
if (!_storeableBlock(blockNumbers[i])) {
continue;
}
BHS.store(blockNumbers[i]);
Expand Down Expand Up @@ -73,8 +73,7 @@ contract BatchBlockhashStore {
* using the blockhash() instruction.
* @param blockNumber the block number to check if it's storeable with blockhash()
*/
// solhint-disable-next-line chainlink-solidity/prefix-private-functions-with-underscore
function storeableBlock(uint256 blockNumber) private view returns (bool) {
function _storeableBlock(uint256 blockNumber) private view returns (bool) {
// handle edge case on simulated chains which possibly have < 256 blocks total.
return
ChainSpecificUtil._getBlockNumber() <= 256 ? true : blockNumber >= (ChainSpecificUtil._getBlockNumber() - 256);
Expand Down
12 changes: 5 additions & 7 deletions contracts/src/v0.8/vrf/BatchVRFCoordinatorV2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ contract BatchVRFCoordinatorV2 {
try COORDINATOR.fulfillRandomWords(proofs[i], rcs[i]) returns (uint96 /* payment */) {
continue;
} catch Error(string memory reason) {
uint256 requestId = getRequestIdFromProof(proofs[i]);
uint256 requestId = _getRequestIdFromProof(proofs[i]);
emit ErrorReturned(requestId, reason);
} catch (bytes memory lowLevelData) {
uint256 requestId = getRequestIdFromProof(proofs[i]);
uint256 requestId = _getRequestIdFromProof(proofs[i]);
emit RawErrorReturned(requestId, lowLevelData);
}
}
Expand All @@ -45,18 +45,16 @@ contract BatchVRFCoordinatorV2 {
* @notice Returns the proving key hash associated with this public key.
* @param publicKey the key to return the hash of.
*/
// solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore
function hashOfKey(uint256[2] memory publicKey) internal pure returns (bytes32) {
function _hashOfKey(uint256[2] memory publicKey) internal pure returns (bytes32) {
return keccak256(abi.encode(publicKey));
}

/**
* @notice Returns the request ID of the request associated with the given proof.
* @param proof the VRF proof provided by the VRF oracle.
*/
// solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore
function getRequestIdFromProof(VRFTypes.Proof memory proof) internal pure returns (uint256) {
bytes32 keyHash = hashOfKey(proof.pk);
function _getRequestIdFromProof(VRFTypes.Proof memory proof) internal pure returns (uint256) {
bytes32 keyHash = _hashOfKey(proof.pk);
return uint256(keccak256(abi.encode(keyHash, proof.seed)));
}
}
Expand Down
6 changes: 3 additions & 3 deletions contracts/src/v0.8/vrf/KeepersVRFConsumer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {VRFConsumerBaseV2} from "./VRFConsumerBaseV2.sol";
import {VRFCoordinatorV2Interface} from "./interfaces/VRFCoordinatorV2Interface.sol";

// solhint-disable chainlink-solidity/prefix-immutable-variables-with-i
// solhint-disable chainlink-solidity/prefix-internal-functions-with-underscore

/**
* @title KeepersVRFConsumer
Expand Down Expand Up @@ -76,7 +75,7 @@ contract KeepersVRFConsumer is KeeperCompatibleInterface, VRFConsumerBaseV2 {
if ((block.timestamp - s_lastTimeStamp) > UPKEEP_INTERVAL) {
s_lastTimeStamp = block.timestamp;

requestRandomWords();
_requestRandomWords();
}
}

Expand All @@ -85,6 +84,7 @@ contract KeepersVRFConsumer is KeeperCompatibleInterface, VRFConsumerBaseV2 {
* @param requestId the VRF V2 request ID, provided at request time.
* @param randomWords the randomness provided by Chainlink VRF.
*/
// solhint-disable-next-line chainlink-solidity/prefix-internal-functions-with-underscore
function fulfillRandomWords(uint256 requestId, uint256[] memory randomWords) internal override {
// Check that the request exists. If not, revert.
RequestRecord memory record = s_requests[requestId];
Expand All @@ -99,7 +99,7 @@ contract KeepersVRFConsumer is KeeperCompatibleInterface, VRFConsumerBaseV2 {
/**
* @notice Requests random words from Chainlink VRF.
*/
function requestRandomWords() internal {
function _requestRandomWords() internal {
uint256 requestId = COORDINATOR.requestRandomWords(
KEY_HASH,
SUBSCRIPTION_ID,
Expand Down
Loading

0 comments on commit 3f492fe

Please sign in to comment.