Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add upgradeto action #20

Merged
merged 2 commits into from
Sep 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions antelope_contracts/contracts/erc20/include/erc20/erc20.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class [[eosio::contract]] erc20 : public contract {
// evm runtime will call this to notify erc20 about the message from 'from' with 'data'.
[[eosio::action]] void onbridgemsg(const bridge_message_t &message);
[[eosio::action]] void upgrade();
[[eosio::action]] void upgradeto(std::string impl_address);

[[eosio::action]] void regtoken(eosio::name eos_contract_name,
std::string evm_token_name, std::string evm_token_symbol,
Expand Down
16 changes: 16 additions & 0 deletions antelope_contracts/contracts/erc20/src/erc20.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,22 @@ void erc20::upgrade() {
});
}

void erc20::upgradeto(std::string impl_address) {
require_auth(get_self());
auto address_bytes = from_hex(impl_address);
eosio::check(!!address_bytes, "implementation address must be valid 0x EVM address");
eosio::check(address_bytes->size() == kAddressLength, "invalid length of implementation address");

uint64_t id = 0;
impl_contract_table_t contract_table(_self, _self.value);

contract_table.emplace(_self, [&](auto &v) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to provide a more meaningful error message if someone calls upgradeto after the table entry with id of 0 was already created (e.g. due to a prior call of upgradeto or upgrade. Right now it goes deep into chainbase code before it would give an confusing error about a uniqueness constraint being violated.

I won't block this PR from being merged in because of this. But maybe @yarkinwho can add that check to this action with a better error message when he adds the tests in his PR (and includes in those tests checks that calling upgrade or upgradeto after they have already been called will fail as expected).

v.id = id;
v.address.resize(kAddressLength);
memcpy(&(v.address[0]), address_bytes->data(), kAddressLength);
});
}

[[eosio::action]] void erc20::regtoken(eosio::name token_contract, std::string evm_token_name, std::string evm_token_symbol, const eosio::asset& ingress_fee, const eosio::asset &egress_fee, uint8_t erc20_precision) {
require_auth(get_self());

Expand Down