Skip to content

Commit

Permalink
feat: IWOReporterTrustless.extractQueryRelayData*
Browse files Browse the repository at this point in the history
  • Loading branch information
guidiaz committed Oct 9, 2024
1 parent 28a0c98 commit b521ff3
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 27 deletions.
33 changes: 28 additions & 5 deletions contracts/core/trustless/WitOracleTrustlessDefault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ contract WitOracleTrustlessDefault
}
}

function claimQueryRewardsBatch(uint256[] calldata _queryIds)
function claimQueryRewardBatch(uint256[] calldata _queryIds)
virtual override external
returns (uint256 _evmTotalReward)
{
Expand All @@ -332,20 +332,43 @@ contract WitOracleTrustlessDefault
_evmTotalReward += _evmReward;

} catch Error(string memory _reason) {
emit BatchReportError(
emit BatchQueryError(
_queryIds[_ix],
_reason
);

} catch (bytes memory) {
emit BatchReportError(
emit BatchQueryError(
_queryIds[_ix],
_revertWitOracleDataLibUnhandledExceptionReason()
);
}
}
}

function extractQueryRelayData(uint256 _queryId)
virtual override public view
returns (QueryRelayData memory _queryRelayData)
{
Witnet.QueryStatus _queryStatus = getQueryStatus(_queryId);
if (
_queryStatus == Witnet.QueryStatus.Posted
|| _queryStatus == Witnet.QueryStatus.Delayed
) {
_queryRelayData = WitOracleDataLib.extractQueryRelayData(registry, _queryId);
}
}

function extractQueryRelayDataBatch(uint256[] calldata _queryIds)
virtual override external view
returns (QueryRelayData[] memory _relays)
{
_relays = new QueryRelayData[](_queryIds.length);
for (uint _ix = 0; _ix < _queryIds.length; _ix ++) {
_relays[_ix] = extractQueryRelayData(_queryIds[_ix]);
}
}

function disputeQueryResponse(uint256 _queryId)
virtual override external
inStatus(_queryId, Witnet.QueryStatus.Reported)
Expand Down Expand Up @@ -393,13 +416,13 @@ contract WitOracleTrustlessDefault
_evmTotalReward += _evmPartialReward;

} catch Error(string memory _reason) {
emit BatchReportError(
emit BatchQueryError(
_responseReport.queryId,
_reason
);

} catch (bytes memory) {
emit BatchReportError(
emit BatchQueryError(
_responseReport.queryId,
_revertWitOracleDataLibUnhandledExceptionReason()
);
Expand Down
39 changes: 27 additions & 12 deletions contracts/data/WitOracleDataLib.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import "../interfaces/IWitOracleBlocks.sol";
import "../interfaces/IWitOracleConsumer.sol";
import "../interfaces/IWitOracleEvents.sol";
import "../interfaces/IWitOracleReporter.sol";
import "../interfaces/IWitOracleReporterTrustless.sol";
import "../libs/Witnet.sol";
import "../patterns/Escrowable.sol";

Expand Down Expand Up @@ -408,18 +409,11 @@ library WitOracleDataLib {
{
bytecodes = new bytes[](queryIds.length);
for (uint _ix = 0; _ix < queryIds.length; _ix ++) {
Witnet.QueryRequest storage __request = data().queries[queryIds[_ix]].request;
if (__request.radonRadHash != bytes32(0)) {
bytecodes[_ix] = registry.bytecodeOf(
__request.radonRadHash,
__request.radonSLA
);
} else {
bytecodes[_ix] = registry.bytecodeOf(
__request.radonBytecode,
__request.radonSLA
);
}
Witnet.QueryRequest storage __request = seekQueryRequest(queryIds[_ix]);
bytecodes[_ix] = (__request.radonRadHash != bytes32(0)
? registry.bytecodeOf(__request.radonRadHash, __request.radonSLA)
: registry.bytecodeOf(__request.radonBytecode,__request.radonSLA)
);
}
}

Expand Down Expand Up @@ -604,6 +598,27 @@ library WitOracleDataLib {
/// =======================================================================
/// --- IWitOracleReporterTrustless ---------------------------------------

function extractQueryRelayData(
WitOracleRadonRegistry registry,
uint256 queryId
)
public view
returns (IWitOracleReporterTrustless.QueryRelayData memory _queryRelayData)
{
Witnet.QueryRequest storage __request = seekQueryRequest(queryId);
return IWitOracleReporterTrustless.QueryRelayData({
queryId: queryId,
queryEvmBlock: seekQuery(queryId).block,
queryEvmHash: queryHashOf(data(), queryId),
queryEvmReward: __request.evmReward,
queryWitDrBytecodes: (__request.radonRadHash != bytes32(0)
? registry.bytecodeOf(__request.radonRadHash, __request.radonSLA)
: registry.bytecodeOf(__request.radonBytecode,__request.radonSLA)
),
queryWitDrSLA: __request.radonSLA
});
}

function claimQueryReward(
uint256 queryId,
uint256 evmQueryAwaitingBlocks,
Expand Down
8 changes: 4 additions & 4 deletions contracts/interfaces/IWitOracleReporter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ interface IWitOracleReporter {
/// @notice queries providing no actual earnings.
function estimateReportEarnings(
uint256[] calldata queryIds,
bytes calldata reportTxMsgData,
uint256 reportTxGasPrice,
uint256 nanoWitPrice
) external view returns (uint256, uint256);
bytes calldata evmReportTxMsgData,
uint256 evmReportTxGasPrice,
uint256 witEthPrice9
) external view returns (uint256 evmRevenues, uint256 evmExpenses);

/// @notice Retrieves the Witnet Data Request bytecodes and SLAs of previously posted queries.
/// @dev Returns empty buffer if the query does not exist.
Expand Down
22 changes: 17 additions & 5 deletions contracts/interfaces/IWitOracleReporterTrustless.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,25 @@ import "../libs/Witnet.sol";
/// @title The Witnet Request Board Reporter trustless interface.
/// @author The Witnet Foundation.
interface IWitOracleReporterTrustless {

event BatchReportError(uint256 queryId, string reason);


event BatchQueryError(uint256 queryId, string reason);

function extractQueryRelayData(uint256 queryId) external view returns (QueryRelayData memory);
function extractQueryRelayDataBatch(uint256[] calldata queryIds) external view returns (QueryRelayData[] memory);
struct QueryRelayData {
uint256 queryId;
uint256 queryEvmBlock;
bytes32 queryEvmHash;
uint256 queryEvmReward;
bytes queryWitDrBytecodes;
Witnet.RadonSLA queryWitDrSLA;
}

function claimQueryReward(uint256 queryId) external returns (uint256);
function claimQueryRewardsBatch(uint256[] calldata queryIds) external returns (uint256);
function claimQueryRewardBatch(uint256[] calldata queryIds) external returns (uint256);


function disputeQueryResponse(uint256 queryId) external returns (uint256);
function disputeQueryResponse (uint256 queryId) external returns (uint256);

function reportQueryResponse(Witnet.QueryResponseReport calldata report) external returns (uint256);
function reportQueryResponseBatch(Witnet.QueryResponseReport[] calldata reports) external returns (uint256);
Expand Down
2 changes: 1 addition & 1 deletion test/mocks/WitMockedOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ contract WitMockedOracle
{
address[] memory _reporters = new address[](1);
_reporters[0] = msg.sender;
__setReporters(_reporters);
WitOracleDataLib.setReporters(_reporters);
}
}

0 comments on commit b521ff3

Please sign in to comment.