Skip to content

Commit

Permalink
perf: reduce the cost of creating a request (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
gas1cent authored Nov 21, 2023
1 parent ec411b8 commit 4fd09e6
Show file tree
Hide file tree
Showing 28 changed files with 1,732 additions and 2,395 deletions.
45 changes: 29 additions & 16 deletions solidity/contracts/Module.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ import {IModule} from '../interfaces/IModule.sol';
import {IOracle} from '../interfaces/IOracle.sol';

abstract contract Module is IModule {
IOracle public immutable ORACLE;

/// @inheritdoc IModule
mapping(bytes32 _requestId => bytes _requestData) public requestData;
IOracle public immutable ORACLE;

constructor(IOracle _oracle) payable {
ORACLE = _oracle;
Expand All @@ -23,24 +21,39 @@ abstract contract Module is IModule {
}

/// @inheritdoc IModule
function oracle() external view returns (address _oracle) {
_oracle = address(ORACLE);
}
function finalizeRequest(
IOracle.Request calldata _request,
IOracle.Response calldata _response,
address _finalizer
) external virtual onlyOracle {}

/// @inheritdoc IModule
function setupRequest(bytes32 _requestId, bytes calldata _data) public virtual onlyOracle {
requestData[_requestId] = _data;
_afterSetupRequest(_requestId, _data);
/**
* @notice Computes the id a given request
*
* @param _request The request to compute the id for
* @return _id The id the request
*/
function _getId(IOracle.Request calldata _request) internal pure returns (bytes32 _id) {
_id = keccak256(abi.encode(_request));
}

/// @inheritdoc IModule
function finalizeRequest(bytes32 _requestId, address _finalizer) external virtual onlyOracle {}
/**
* @notice Computes the id a given response
*
* @param _response The response to compute the id for
* @return _id The id the response
*/
function _getId(IOracle.Response calldata _response) internal pure returns (bytes32 _id) {
_id = keccak256(abi.encode(_response));
}

/**
* @notice The hook that is called after `setupRequest`
* @notice Computes the id a given dispute
*
* @param _requestId The ID of the request
* @param _data The data of the request
* @param _dispute The dispute to compute the id for
* @return _id The id the dispute
*/
function _afterSetupRequest(bytes32 _requestId, bytes calldata _data) internal virtual {}
function _getId(IOracle.Dispute calldata _dispute) internal pure returns (bytes32 _id) {
_id = keccak256(abi.encode(_dispute));
}
}
Loading

0 comments on commit 4fd09e6

Please sign in to comment.