From f114729ee5b605ece146d7851deb98dc23308162 Mon Sep 17 00:00:00 2001 From: kayan Date: Fri, 8 Sep 2023 16:44:37 +0800 Subject: [PATCH 1/2] upgradeto action --- .../contracts/erc20/include/erc20/erc20.hpp | 1 + antelope_contracts/contracts/erc20/src/erc20.cpp | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) 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..cb5e76e 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, "memo must be valid 0x EVM address"); + eosio::check(address_bytes->size() == kAddressLength, "memo must be valid 0x EVM 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()); From c4a8b394a91565a4478c879586fd41976e28ed6f Mon Sep 17 00:00:00 2001 From: kayan Date: Fri, 8 Sep 2023 16:46:53 +0800 Subject: [PATCH 2/2] typo --- antelope_contracts/contracts/erc20/src/erc20.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/antelope_contracts/contracts/erc20/src/erc20.cpp b/antelope_contracts/contracts/erc20/src/erc20.cpp index cb5e76e..3dddc70 100644 --- a/antelope_contracts/contracts/erc20/src/erc20.cpp +++ b/antelope_contracts/contracts/erc20/src/erc20.cpp @@ -89,8 +89,8 @@ 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, "memo must be valid 0x EVM address"); - eosio::check(address_bytes->size() == kAddressLength, "memo must be valid 0x EVM 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);