0

When I send EOS in a contract to several recipients, it can happen that this fails, e.g. because a recipient has a contract running like that:

Example contract of one recipient:

[[eosio::on_notify("eosio.token::transfer")]]
void deposit(name from, name to, eosio::asset quantity, std::string memo){
  if (from == get_self() || to != get_self()){
    return;
  }
}

Withdraw function in my contract:

void withdrawall(std::list<transaction> trans)
{        
  for(auto& tr : trans)
  {
    action{
      permission_level{ get_self(), "active"_n},
      "eosio.token"_n,
      "transfer"_n,
      std::make_tuple(get_self(), tr.to, tr.funds, std::string(""))
    }.send();
  }
}

Because one transaction cannot be executed, all transactions fail. Is there a way to catch such failures in the contract and execute alternative code?

  • Hm, the only thing I can think of is instead of an sending an action per item in your list, sending a deferred tx per item in your list. Maybe batches of tx wrapped in deffered tx. But that approach would be slower and consume much more CPU. – cmadh Sep 24 '19 at 1:16
  • This is not a pleasant way to go, but if there is no alternative I will use it. Thanks for the tip. – elpol Sep 24 '19 at 22:48

Your Answer

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

Browse other questions tagged or ask your own question.