From e8f8ba4853f8ccf5013251b5f4ab3e52a0c86433 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillermo=20D=C3=ADaz?= Date: Wed, 9 Oct 2024 12:27:12 +0200 Subject: [PATCH] feat: IWOReporterTrustless.extractQueryRelayData* --- .../trustless/WitOracleTrustlessDefault.sol | 33 +++++++++++++--- contracts/data/WitOracleDataLib.sol | 39 +++++++++++++------ contracts/interfaces/IWitOracleReporter.sol | 8 ++-- .../IWitOracleReporterTrustless.sol | 22 ++++++++--- test/mocks/WitMockedOracle.sol | 2 +- 5 files changed, 77 insertions(+), 27 deletions(-) diff --git a/contracts/core/trustless/WitOracleTrustlessDefault.sol b/contracts/core/trustless/WitOracleTrustlessDefault.sol index ebfa7f75..f48aa7e1 100644 --- a/contracts/core/trustless/WitOracleTrustlessDefault.sol +++ b/contracts/core/trustless/WitOracleTrustlessDefault.sol @@ -318,7 +318,7 @@ contract WitOracleTrustlessDefault } } - function claimQueryRewardsBatch(uint256[] calldata _queryIds) + function claimQueryRewardBatch(uint256[] calldata _queryIds) virtual override external returns (uint256 _evmTotalReward) { @@ -332,13 +332,13 @@ 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() ); @@ -346,6 +346,29 @@ contract WitOracleTrustlessDefault } } + 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) @@ -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() ); diff --git a/contracts/data/WitOracleDataLib.sol b/contracts/data/WitOracleDataLib.sol index e78a262c..16d92cc0 100644 --- a/contracts/data/WitOracleDataLib.sol +++ b/contracts/data/WitOracleDataLib.sol @@ -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"; @@ -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) + ); } } @@ -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, diff --git a/contracts/interfaces/IWitOracleReporter.sol b/contracts/interfaces/IWitOracleReporter.sol index 54264dc8..e8ac839f 100644 --- a/contracts/interfaces/IWitOracleReporter.sol +++ b/contracts/interfaces/IWitOracleReporter.sol @@ -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. diff --git a/contracts/interfaces/IWitOracleReporterTrustless.sol b/contracts/interfaces/IWitOracleReporterTrustless.sol index 0e6f1c64..2a47ea69 100644 --- a/contracts/interfaces/IWitOracleReporterTrustless.sol +++ b/contracts/interfaces/IWitOracleReporterTrustless.sol @@ -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); diff --git a/test/mocks/WitMockedOracle.sol b/test/mocks/WitMockedOracle.sol index fa2c56a8..6578cadf 100644 --- a/test/mocks/WitMockedOracle.sol +++ b/test/mocks/WitMockedOracle.sol @@ -30,6 +30,6 @@ contract WitMockedOracle { address[] memory _reporters = new address[](1); _reporters[0] = msg.sender; - __setReporters(_reporters); + WitOracleDataLib.setReporters(_reporters); } }