add_owner, remove_owner, get_list_owners

This commit is contained in:
Pavel Baykov 2022-05-25 09:10:00 -03:00
parent c09044bc70
commit 367a203007
2 changed files with 45 additions and 11 deletions

View file

@ -3,6 +3,7 @@
#include <graphene/peerplays_sidechain/sidechain_net_handler.hpp>
#include <string>
#include <unordered_map>
#include <boost/signals2.hpp>
@ -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<std::string> 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<std::string> public_keys);
std::string combinepsbt(const vector<std::string> &psbts);
@ -107,6 +108,9 @@ private:
std::string geth_url;
uint64_t t_id;
std::string safe_account_addr;
std::vector<std::string> owners;
uint32_t threshold;
std::unordered_map<uint64_t, std::string> m_messages;
std::string ip;
uint32_t rpc_port;

View file

@ -154,22 +154,52 @@ uint64_t eth_rpc_client::eth_sign(const string& addr, const string& message) {
return t_id++;
}
std::vector<std::string> eth_rpc_client::get_list_owners(const std::string& safe_account) {
std::vector<std::string> 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";
}