3

I ran this transaction which executed correctly, but one of the internal calls gave me back an out of gas error.

I had a try/catch mechanism to let my code terminate silently (to set some really important business logic actions after internal executions, as you can see from the Transaction).

But I really need to manually revert the transaction only and only if there is an out of gas internal error.

Original code is quite complicated, so I reproduced it in a more simple way, but it is quite similar to the original one.

<!-- language: lang-solidity -->

pragma solidity ^0.6.0;

contract GasEstimation {

  event CorrectExecution(bool result, bool outOfGas);

  function callMe(address location) public payable {
    bool result = false;
    bool outOfGas = false;
    try ToBeCalled(location).externalCall() {
      result = true;
    } catch (bytes memory lowLevelData) {
      //How can I check if externalCall() failed because ran out of gas?
    }
    if(result) {
      /* Some other Gas-Consuming Operations */
      _inCaseOfSuccess();
    } else if(outOfGas) {
      revert("Out Of Gas!");
    }
    emit CorrectExecution(result, outOfGas);
  }

  function _inCaseOfSuccess() private {
    //My other Gas-Consuming Stuff
  }
}

interface ToBeCalled {
  function externalCall() external;
}

0 Answers0