0

Let's say I have 3 conditions which can lead to revert(). which way should I handle it? 3 types of events or one event with extra parameters?

3 events types:

if condition A:
 emit causeA(dataA1, dataA2)
 revert()
if condition B:
 emit causeB(dataB1, dataB2)
 revert()
if condition C:
 emit causeC(dataC1, dataC2)
 revert()

1 event:

if condition A:
 emit cause(dataA1, dataA2,-1,-1,-1,-1)
 revert()
if condition B:
 emit cause(-1,-1,dataB1, dataB2,-1,-1)
 revert()
if condition C:
 emit cause(-1,-1,-1,-1,dataC1, dataC2)
 revert()

Backend:

  1. Would need to fetch by 3 types of events and switch by the result.
  2. Add the logic after fetching the event to figure what happened or search for the cases != -1 and then act.
1

None of the above.

revert() will ensure no event is emitted. This, because revert "reverts" state changes and events are, indeed, state changes. Ergo, any events are reverted so you won't get the diagnostic outputs you are looking for.

Use revert() with reason, revert("<reason>"); or require() with reason, require(<exp>, "<reason>");.

contract Test {

  function test() public pure {
    require(1 != 2, "1 is 2");
    require(2 != 3, "2 is 3");
  }
}

Hope it helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.