4

If a deferred transaction fails for whatever reason, it triggers an onerror event, which can be captured as follows:

void apply_onerror(const onerror& error )
{
  print("What can I do with this?\n");
}

void mycontract::apply(account_name contract, account_name act)
{
  switch(act)
  {
    case N(onerror):
    if( contract == N(eosio) )
    {
      apply_onerror( onerror::from_current_action() );
    }
  }
}

How can one use this apply_onerror function to debug or re-execute the transaction?

1

To resend failed transaction you have to unpack it from onerror struct and resend it.

transaction failed_tx = error.unpack_sent_trx();
failed_tx.send(tx_id, self);

see also proxy contract

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.