From 367a20300795e0aafee280deb0224f2f69c2689e Mon Sep 17 00:00:00 2001 From: Pavel Baykov Date: Wed, 25 May 2022 09:10:00 -0300 Subject: [PATCH] add_owner, remove_owner, get_list_owners --- .../sidechain_net_handler_eth.hpp | 8 +++- .../sidechain_net_handler_eth.cpp | 48 +++++++++++++++---- 2 files changed, 45 insertions(+), 11 deletions(-) diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_eth.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_eth.hpp index 3d80cb15..3faf4a4a 100644 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_eth.hpp +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_eth.hpp @@ -3,6 +3,7 @@ #include #include +#include #include @@ -70,9 +71,9 @@ public: uint64_t eth_getBalance(const std::string& addr); uint64_t eth_sign(const string& addr, const string& message); - std::vector get_list_owners(const std::string& safe_account); + uint64_t get_list_owners(const std::string& safe_account); uint64_t add_owner(const std::string& addr ); - uint64_t remove_owner(const std::string& addr); + uint64_t remove_owner(const std::string& addr, uint32_t threshold); std::string addmultisigaddress(const uint32_t nrequired, const std::vector public_keys); std::string combinepsbt(const vector &psbts); @@ -107,6 +108,9 @@ private: std::string geth_url; uint64_t t_id; std::string safe_account_addr; + std::vector owners; + uint32_t threshold; + std::unordered_map m_messages; std::string ip; uint32_t rpc_port; diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_eth.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_eth.cpp index af3b0209..00c88db9 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_eth.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_eth.cpp @@ -154,22 +154,52 @@ uint64_t eth_rpc_client::eth_sign(const string& addr, const string& message) { return t_id++; } -std::vector eth_rpc_client::get_list_owners(const std::string& safe_account) { - std::vector output; - - return output; +uint64_t eth_rpc_client::get_list_owners(const std::string& safe_account) { + return eth_call(safe_account.c_str(), "0xa0e67e2b"); } uint64_t eth_rpc_client::add_owner(const std::string& addr ) { -} + if (std::count(owners.begin(), owners.end(), addr)){ + FC_THROW_EXCEPTION(fc::exception, "Owners allready have addr: ${addr}", ("addr", addr)); + } -uint64_t eth_rpc_client::remove_owner(const std::string& addr) { //It's require to execute //execTransaction method of smart contract , using safe-account address //execTransaction(address to, uint256 value, bytes data, uint8 operation, uint256 safeTxGas, uint256 dataGas, uint256 gasPrice, address gasToken, address refundReceiver, bytes signatures) - //std::string address = safe_account_addr; - //std::string value = str(boost::format("%020u") % 0); - //std::string data = "f8dc5dd9000000000000000000000000" + prev_addr; + std::string method_id = "6a761202"; + std::string address = safe_account_addr; + std::string value = str(boost::format("%020u") % 0); + std::string data = "f8dc5dd9000000000000000000000000" + owners[0] + "000000000000000000000000" + addr + str(boost::format("%032u") % threshold); + std::string operatio = "0"; + std::string safeTxGas = str(boost::format("%032u") % 0); + std::string dataGas = str(boost::format("%032u") % 0); + std::string gasPrice = str(boost::format("%032u") % 0); + std::string gasToken = "0000000000000000000000000000000000000000"; + std::string refundReceiver = "0000000000000000000000000000000000000000"; +} + +uint64_t eth_rpc_client::remove_owner(const std::string& addr, uint32_t threshold) { + if (!std::count(owners.begin(), owners.end(), addr)){ + FC_THROW_EXCEPTION(fc::exception, "Owners does not have addr: ${addr}", ("addr", addr)); + } + + if (threshold == owners.size()){ + FC_THROW_EXCEPTION(fc::exception, "Owners size does not meet threshold: ${th}", ("th", threshold)); + } + + //It's require to execute + //execTransaction method of smart contract , using safe-account address + //execTransaction(address to, uint256 value, bytes data, uint8 operation, uint256 safeTxGas, uint256 dataGas, uint256 gasPrice, address gasToken, address refundReceiver, bytes signatures) + std::string method_id = "6a761202"; + std::string address = safe_account_addr; + std::string value = str(boost::format("%032u") % 0); + std::string data = "f8dc5dd90000000000000000000000000000000000000000000000000000000000000001000000000000000000000000" + addr + str(boost::format("%032u") % threshold); + std::string operatio = "0"; + std::string safeTxGas = str(boost::format("%032u") % 0); + std::string dataGas = str(boost::format("%032u") % 0); + std::string gasPrice = str(boost::format("%032u") % 0); + std::string gasToken = "0000000000000000000000000000000000000000"; + std::string refundReceiver = "0000000000000000000000000000000000000000"; }