Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: internal library #58

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions solidity/contracts/Oracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import {OracleAccessController} from './access/OracleAccessController.sol';
import {OracleTypehash} from './utils/OracleTypehash.sol';

contract Oracle is IOracle, OracleAccessController {
using ValidatorLib for *;

/// @inheritdoc IOracle
mapping(bytes32 _requestId => uint256 _finalizedAt) public finalizedAt;

Expand Down
32 changes: 16 additions & 16 deletions solidity/libraries/ValidatorLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ library ValidatorLib {
* @param _request The request to compute the id for
* @return _id The id the request
*/
function _getId(IOracle.Request calldata _request) public pure returns (bytes32 _id) {
function _getId(IOracle.Request memory _request) internal pure returns (bytes32 _id) {
_id = keccak256(abi.encode(_request));
}

Expand All @@ -30,7 +30,7 @@ library ValidatorLib {
* @param _response The response to compute the id for
* @return _id The id the response
*/
function _getId(IOracle.Response calldata _response) public pure returns (bytes32 _id) {
function _getId(IOracle.Response memory _response) internal pure returns (bytes32 _id) {
_id = keccak256(abi.encode(_response));
}

Expand All @@ -40,7 +40,7 @@ library ValidatorLib {
* @param _dispute The dispute to compute the id for
* @return _id The id the dispute
*/
function _getId(IOracle.Dispute calldata _dispute) public pure returns (bytes32 _id) {
function _getId(IOracle.Dispute memory _dispute) internal pure returns (bytes32 _id) {
_id = keccak256(abi.encode(_dispute));
}

Expand All @@ -52,9 +52,9 @@ library ValidatorLib {
* @return _responseId The id the response
*/
function _validateResponse(
IOracle.Request calldata _request,
IOracle.Response calldata _response
) public pure returns (bytes32 _responseId) {
IOracle.Request memory _request,
IOracle.Response memory _response
Comment on lines +55 to +56
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm worried about this change negatively impacting gas consumption, I need measure it before approving it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally, 2k gas less gas usage with this change.

we need to add gas snapshots to our CI process

) internal pure returns (bytes32 _responseId) {
bytes32 _requestId = _getId(_request);
_responseId = _getId(_response);

Expand All @@ -69,9 +69,9 @@ library ValidatorLib {
* @return _disputeId The id the dispute
*/
function _validateDispute(
IOracle.Request calldata _request,
IOracle.Dispute calldata _dispute
) public pure returns (bytes32 _disputeId) {
IOracle.Request memory _request,
IOracle.Dispute memory _dispute
) internal pure returns (bytes32 _disputeId) {
bytes32 _requestId = _getId(_request);
_disputeId = _getId(_dispute);

Expand All @@ -86,9 +86,9 @@ library ValidatorLib {
* @return _disputeId The id the dispute
*/
function _validateDispute(
IOracle.Response calldata _response,
IOracle.Dispute calldata _dispute
) public pure returns (bytes32 _disputeId) {
IOracle.Response memory _response,
IOracle.Dispute memory _dispute
) internal pure returns (bytes32 _disputeId) {
bytes32 _responseId = _getId(_response);
_disputeId = _getId(_dispute);

Expand All @@ -105,10 +105,10 @@ library ValidatorLib {
* @return _disputeId The id the dispute
*/
function _validateResponseAndDispute(
IOracle.Request calldata _request,
IOracle.Response calldata _response,
IOracle.Dispute calldata _dispute
) public pure returns (bytes32 _responseId, bytes32 _disputeId) {
IOracle.Request memory _request,
IOracle.Response memory _response,
IOracle.Dispute memory _dispute
) internal pure returns (bytes32 _responseId, bytes32 _disputeId) {
bytes32 _requestId = _getId(_request);
_responseId = _getId(_response);
_disputeId = _getId(_dispute);
Expand Down
Loading