diff --git a/antelope_contracts/contracts/erc20/include/erc20/erc20.hpp b/antelope_contracts/contracts/erc20/include/erc20/erc20.hpp index 1176080..abdb44a 100644 --- a/antelope_contracts/contracts/erc20/include/erc20/erc20.hpp +++ b/antelope_contracts/contracts/erc20/include/erc20/erc20.hpp @@ -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, diff --git a/antelope_contracts/contracts/erc20/src/erc20.cpp b/antelope_contracts/contracts/erc20/src/erc20.cpp index fbd53be..3dddc70 100644 --- a/antelope_contracts/contracts/erc20/src/erc20.cpp +++ b/antelope_contracts/contracts/erc20/src/erc20.cpp @@ -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) { + 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());