1

As shown with code below, I modify table in an inline action, and then want to get the latest data. But the data I get is not the latest. Why?

void mycontract::myfunc()
{
   action (
      permission_level{_self,N(active)},
      _self, N(modifytable),
      std::make_tuple(/* some latest data */)
   ).send();

    my_table mytable(_self, _self);
    auto item = mytable.find(uint64_t(0));
    if (item != mytable.end()) {

        /////////////////////////////////////////////////
        // when i get item->data here, 
        // it is not the currently latest data.
        // why?
        /////////////////////////////////////////////////
        item->data;

        mytable.erase(item);
    } 
}

void mycontract::modifytable(/* ... */)
{
  my_table mytable(_self, _self);
  auto item = mytable.find(uint64_t(0));
  if (item == mytable.end()) {
      mytable.emplace(_self, [&](auto& i) {
        i.index = uint64_t(0);
        i.data = /*latest data*/;

      });
  } else {
      mytable.modify(item, _self, [&](auto& i) {
        i.data = /*latest data*/;
      });
  }
}

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.