eth_coinbase

This commit is contained in:
Pavel Baykov 2022-05-31 08:38:13 -03:00
parent cff3bec507
commit 61923c797f
2 changed files with 26 additions and 2 deletions

View file

@ -43,7 +43,8 @@ public:
ETH_SEND_RAW_TRANSACTION,
ETH_GET_CODE,
ETH_GET_BALANCE,
ETH_SIGN,
ETH_SIGN,
ETH_COINBASE,
GET_LIST_OWNERS,
ADD_OWNER,
REMOVE_OWNER
@ -84,6 +85,7 @@ public:
uint64_t eth_getCode(const std::string& addr);
uint64_t eth_getBalance(const std::string& addr);
uint64_t eth_sign(const string& addr, const string& message);
uint64_t eth_coinbase();
uint64_t get_list_owners(const std::string& safe_account);
uint64_t add_owner(const std::string& addr );
@ -121,12 +123,15 @@ public:
private:
std::string geth_url;
uint64_t t_id;
std::string account_address;
std::string transaction_id;
std::string safe_account_addr;
std::vector<std::string> owners;
uint32_t threshold;
std::unordered_map<uint64_t, req_t> m_requests;
std::string chain_id;//256 bit value
std::string balance;
std::string code;
std::string ip;
uint32_t rpc_port;

View file

@ -85,6 +85,10 @@ void eth_rpc_client::on_fail(websocketpp::connection_hdl hdl) {
void eth_rpc_client::on_open(websocketpp::connection_hdl hdl) {
m_endpoint.send(hdl, "{\"jsonrpc\":\"2.0\",\"method\":\"eth_chainId\",\"params\":[],\"id\":84}", websocketpp::frame::opcode::text);
vector<std::string> owner_addresses;
std::string private_key = "";
createmultisig(5, owner_addresses, private_key);
}
void eth_rpc_client::on_message(websocketpp::connection_hdl hdl, message_ptr msg) {
@ -117,11 +121,16 @@ void eth_rpc_client::on_message(websocketpp::connection_hdl hdl, message_ptr msg
case ETH_SEND_RAW_TRANSACTION:
break;
case ETH_GET_CODE:
code = result_str;
break;
case ETH_GET_BALANCE:
balance = result_str;
break;
case ETH_SIGN:
break;
case ETH_COINBASE:
account_address = result_str;
break;
case GET_LIST_OWNERS:
num_owners = (uint32_t)strtol(result_str.substr(2 + 32 + 32 - 4, 4).c_str(), NULL, 16);
owners.clear();
@ -200,6 +209,13 @@ uint64_t eth_rpc_client::eth_sign(const string& addr, const string& message) {
return t_id++;
}
uint64_t eth_rpc_client::eth_coinbase() {
std::string req = str(boost::format("{\"jsonrpc\":\"2.0\",\"method\":\"eth_coinbase\",\"params\":[],\"id\":%1%}") % t_id);
m_endpoint.send(m_hdl, req.c_str(), websocketpp::frame::opcode::text);
m_requests[t_id] = req_t::ETH_COINBASE;
return t_id++;
}
uint64_t eth_rpc_client::get_list_owners(const std::string& safe_account) {
return eth_call(safe_account.c_str(), "0xa0e67e2b");
}
@ -216,13 +232,16 @@ uint64_t eth_rpc_client::add_owner(const std::string& addr ) {
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 operation = "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";
std::string message = method_id + address + value + data + operation + safeTxGas + dataGas + gasPrice + gasToken + refundReceiver;
uint64_t id = eth_sign(account_address, message);
m_requests[t_id] = req_t::ADD_OWNER;
}