From 956a2afbea8ff5e09f2f2ef3dae01496b4fd0762 Mon Sep 17 00:00:00 2001 From: zorzal Date: Wed, 18 Dec 2024 08:06:06 -0500 Subject: [PATCH] fix: avoid emitting events with empty data --- .../examples/modules/finality/CallbackModule.sol | 7 +++++-- .../examples/modules/request/HttpRequestModule.sol | 12 ++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/solidity/contracts/examples/modules/finality/CallbackModule.sol b/solidity/contracts/examples/modules/finality/CallbackModule.sol index 00eaa15..5ff088d 100644 --- a/solidity/contracts/examples/modules/finality/CallbackModule.sol +++ b/solidity/contracts/examples/modules/finality/CallbackModule.sol @@ -31,8 +31,11 @@ contract CallbackModule is Module, ICallbackModule { // purposely skips the return data, so we don't care if the call succeeds or fails _params.target.call(abi.encodeCall(IProphetCallback.prophetCallback, (_params.data))); - emit Callback(_response.requestId, _params.target, _params.data); - emit RequestFinalized(_response.requestId, _response, _finalizer); + // response might be empty, but we still want to emit the event with data so we calculate the requestId + bytes32 _requestId = _getId(_request); + + emit Callback(_requestId, _params.target, _params.data); + emit RequestFinalized(_requestId, _response, _finalizer); } /// @inheritdoc IModule diff --git a/solidity/contracts/examples/modules/request/HttpRequestModule.sol b/solidity/contracts/examples/modules/request/HttpRequestModule.sol index 3c9721e..a7a0ddc 100644 --- a/solidity/contracts/examples/modules/request/HttpRequestModule.sol +++ b/solidity/contracts/examples/modules/request/HttpRequestModule.sol @@ -39,9 +39,13 @@ contract HttpRequestModule is Module, IHttpRequestModule { ) external override(IHttpRequestModule, Module) onlyOracle { RequestParameters memory _params = decodeRequestData(_request.requestModuleData); - if (ORACLE.responseCreatedAt(_getId(_response)) != 0) { + bool _hasResponse = ORACLE.responseCreatedAt(_getId(_response)) != 0; + + bytes32 _requestId = _hasResponse ? _response.requestId : _getId(_request); + + if (_hasResponse) { _params.accountingExtension.pay({ - _requestId: _response.requestId, + _requestId: _requestId, _payer: _request.requester, _receiver: _response.proposer, _token: _params.paymentToken, @@ -50,13 +54,13 @@ contract HttpRequestModule is Module, IHttpRequestModule { } else { _params.accountingExtension.release({ _bonder: _request.requester, - _requestId: _getId(_request), + _requestId: _requestId, _token: _params.paymentToken, _amount: _params.paymentAmount }); } - emit RequestFinalized(_response.requestId, _response, _finalizer); + emit RequestFinalized(_requestId, _response, _finalizer); } /// @inheritdoc IModule