Skip to content
EOSIO contracts references, examples and best-practices
Branch: master
Clone or download
Latest commit a831061 Mar 23, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE Initial commit Jan 31, 2019
README.md Update README.md Mar 23, 2019

README.md

eos-contracts-best-practices

EOSIO contracts references, examples and best-practices

Examples

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);
  }

References

Security best-practices

https://github.com/slowmist/eos-smart-contract-security-best-practices/blob/master/README_EN.md

https://github.com/NoneAge/EOS_dApp_Security_Incident_Analysis

Performance best-practices:

https://medium.com/@bytemaster/developing-efficient-contracts-8a8e62011c6d

More References:

Reviewed by:

You can’t perform that action at this time.