7

What would be the process to map failed transactions (require, throw, etc.) back to the source code line where they occurred?

Any examples of such yet?

Mikko Ohtamaa
  • 22,269
  • 6
  • 62
  • 127

1 Answers1

8

Something you are looking for is here How to map EVM trace to contract source?. As for me for development purposes I use requireDebugModifier from code below, for production I change requireDebugModifier to requireModifier.

contract DebugEvents
{
    event Debug(string message);

    modifier requireDebugModifier(bool arg, string message)
    {
        if (!arg)
        {
            Debug(message);
            return;
        }
        _;

    }

    modifier requireModifier(bool arg)
    {
        require(arg);
        _;
    }
}

contract Test is DebugEvents
{
    function Test() public payable
    {
    }

    function fooDevel(uint i)
    requireDebugModifier(i<10, "I must be less then 10")
    public
    returns (uint)
    {
        return i;
    }


    function fooProduction(uint i)
    requireModifier(i<10)
    public
    returns (uint)
    {
        return i;
    }

}
Alexey Barsuk
  • 2,259
  • 2
  • 17
  • 25
  • 1
    Unfortunately this method only works if you modify the contract and thus not really answer to the question, because it deals with Solidity Events, not throws. – Mikko Ohtamaa Dec 04 '17 at 10:02
  • However the question you linked is currently the most useful source of information on this topic. As far as I can read the answer "no one has done it publicly." I'll grant you the bounty points any case, so that the good karma does not go unspend :) – Mikko Ohtamaa Dec 04 '17 at 10:03