0

Ok, so I made a beginner coding error in a token contract, mis-typing the return value from get without & (yes, I now see the Warning in the docs at https://developers.eos.io/manuals/eosio.cdt/latest/classeosio_1_1multi__index/#function-get) and wound up with a corrupted stat table. I can't erase it because it no longer matches the abi table definitions and accessing it throws an error.

The only thing I have thought of is to reverse-engineer a table declaration under which the corrupted table is readable, then upload code which does an erase loop using that.

Using the chain API get_table_rows I get the following response from the corrupted table:

"rows":["0100000000000000000000000000000004534545445300000070520a83a920cdc0e94558d1339db9"]

Any suggestions for a suitable table declaration? Or am I on the wrong track?

3
  • I've not tried it but something like this may help github.com/liquidapps-io/…
    – Nat
    Nov 8, 2021 at 0:07
  • 1
    @Nat that worked great! Although it feels odd using a function declared internal_use_do_not_use::db_lowerbound_i64 ;)
    – Chuck
    Nov 9, 2021 at 5:57
  • I'll add it as an answer then : )
    – Nat
    Nov 9, 2021 at 20:30

1 Answer 1

0

You can try the following from here: https://github.com/liquidapps-io/eos-contracts-best-practices#deleting-table-rows-without-declaring-tables

Deleting table rows without declaring tables

  void clear_secondary_idx256(name TableName, uint8_t index_num, uint64_t scope){
    uint64_t primary = 0;

    auto key = eosio::key256();
    auto it2 = eosio::_multi_index_detail::secondary_index_db_functions<key256>::db_idx_lowerbound(
      _self.value, 
      scope, 
      (static_cast<uint64_t>(TableName.value) & 0xFFFFFFFFFFFFFFF0ULL)
                                    | (index_num & 0x000000000000000FULL), 
      key, 
      primary);
    while (it2 >= 0) {
        auto del = it2;
        uint64_t dummy;
        it2 = db_idx256_next(it2, &dummy);
        db_idx256_remove(del);
    }
  }
  void clear_primary(name TableName, uint64_t scope){
    auto it = db_lowerbound_i64(_self.value, scope, TableName.value, 0);
    while (it >= 0) {
        auto del = it;
        uint64_t dummy;
        it = db_next_i64(it, &dummy);
        db_remove_i64(del);
    }
  }

  ACTION clearpkgs(){
    require_auth(_self);
    clear_primary("package"_n, _self.value);
    clear_secondary_idx256("package"_n, 0, _self.value);
    clear_secondary_idx256("package"_n, 1, _self.value);
  }

Your Answer

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

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