Skip to content

Commit

Permalink
Simplify initialization of config2 singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
elmato committed Sep 5, 2023
1 parent 7e90020 commit 53b9c04
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
1 change: 1 addition & 0 deletions contract/src/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ void evm_contract::withdraw(eosio::name owner, eosio::asset quantity, const eosi

bool evm_contract::gc(uint32_t max) {
assert_unfrozen();
require_auth(get_self());

evm_runtime::state state{get_self(), eosio::same_payer};
return state.gc(max);
Expand Down
12 changes: 3 additions & 9 deletions contract/src/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,24 +336,18 @@ uint64_t state::get_next_account_id() {
_config2 = cfg2.get();
} else {
account_table accounts(_self, _self.value);
uint64_t next_account_id = accounts.available_primary_key();

gc_store_table gc(_self, _self.value);
if(gc.end() != gc.begin()) {
auto itr = --gc.end();
next_account_id = std::max(next_account_id, itr->storage_id+1);
}
_config2 = config2{next_account_id};
_config2 = config2{accounts.available_primary_key()};
}
}
auto id = _config2->next_account_id;
_config2->next_account_id++;
return id;
}

state::~state() {
if(!_config2.has_value()) return;
eosio::singleton<"config2"_n, config2> cfg2{_self, _self.value};
cfg2.set(_config2.value(), _self);
};
}

} // namespace evm_runtime

0 comments on commit 53b9c04

Please sign in to comment.