implement helpers rpc functions, parse json reply, eth_rpc_client stop
This commit is contained in:
parent
eac7f1ead6
commit
c09044bc70
2 changed files with 105 additions and 17 deletions
|
|
@ -54,20 +54,31 @@ public:
|
|||
eth_rpc_client(const std::string &url, const std::string &user_name, const std::string &password, bool debug_rpc_calls);
|
||||
|
||||
void start(std::string uri);
|
||||
void stop();
|
||||
void on_socket_init(websocketpp::connection_hdl);
|
||||
void on_fail(websocketpp::connection_hdl hdl);
|
||||
void on_open(websocketpp::connection_hdl hdl);
|
||||
void on_message(websocketpp::connection_hdl hdl, message_ptr msg);
|
||||
void on_close(websocketpp::connection_hdl);
|
||||
|
||||
std::string get_chain_id();
|
||||
std::string eth_getTransactionReceipt(const std::string& tx_id);
|
||||
std::string eth_call(const std::string& to, const std::string& data);
|
||||
std::string eth_sendTransaction(const std::string& from, const std::string& to, const std::string& data);
|
||||
uint64_t get_chain_id();
|
||||
uint64_t eth_getTransactionReceipt(const std::string& tx_id);
|
||||
uint64_t eth_call(const std::string& to, const std::string& data);
|
||||
uint64_t eth_sendTransaction(const std::string& from, const std::string& to, const std::string& data);
|
||||
uint64_t eth_sendRawTransaction(const std::string& params);
|
||||
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);
|
||||
|
||||
std::vector<std::string> get_list_owners(const std::string& safe_account);
|
||||
uint64_t add_owner(const std::string& addr );
|
||||
uint64_t remove_owner(const std::string& addr);
|
||||
|
||||
std::string addmultisigaddress(const uint32_t nrequired, const std::vector<std::string> public_keys);
|
||||
std::string combinepsbt(const vector<std::string> &psbts);
|
||||
std::string createmultisig(const uint32_t nrequired, const std::vector<std::string> public_keys);
|
||||
|
||||
uint64_t createmultisig(const uint32_t nrequired, const std::vector<std::string> owner_addresses, const std::string &private_key);
|
||||
|
||||
std::string createpsbt();
|
||||
std::string createrawtransaction();
|
||||
std::string createwallet(const std::string &wallet_name);
|
||||
|
|
@ -95,6 +106,7 @@ public:
|
|||
private:
|
||||
std::string geth_url;
|
||||
uint64_t t_id;
|
||||
std::string safe_account_addr;
|
||||
|
||||
std::string ip;
|
||||
uint32_t rpc_port;
|
||||
|
|
|
|||
|
|
@ -19,6 +19,8 @@
|
|||
#include <graphene/chain/son_wallet_object.hpp>
|
||||
#include <graphene/utilities/key_conversion.hpp>
|
||||
|
||||
#include <fc/io/json.hpp>
|
||||
|
||||
namespace graphene { namespace peerplays_sidechain {
|
||||
// =============================================================================
|
||||
|
||||
|
|
@ -62,6 +64,10 @@ void eth_rpc_client::start(std::string uri) {
|
|||
m_endpoint.run();
|
||||
}
|
||||
|
||||
void eth_rpc_client::stop() {
|
||||
m_endpoint.close(m_hdl,websocketpp::close::status::normal,"");
|
||||
}
|
||||
|
||||
void eth_rpc_client::on_socket_init(websocketpp::connection_hdl) {
|
||||
}
|
||||
|
||||
|
|
@ -85,30 +91,86 @@ void eth_rpc_client::on_message(websocketpp::connection_hdl hdl, message_ptr msg
|
|||
|
||||
ilog("on_message: ${msg}", ("msg", msg->get_payload()));
|
||||
|
||||
//m_endpoint.close(hdl,websocketpp::close::status::going_away,"");
|
||||
fc::variants list = fc::json::variants_from_string( msg->get_payload() );
|
||||
|
||||
ilog("json reposnse: ${list}", ("list", list));
|
||||
}
|
||||
|
||||
void eth_rpc_client::on_close(websocketpp::connection_hdl) {
|
||||
ilog("Ethereum websocket close");
|
||||
}
|
||||
|
||||
std::string eth_rpc_client::get_chain_id() {
|
||||
std::string req = str(boost::format("{\"jsonrpc\":\"2.0\",\"method\":\"eth_chainId\",\"params\":[],\"id\":%1%}") % t_id++);
|
||||
uint64_t eth_rpc_client::get_chain_id() {
|
||||
std::string req = str(boost::format("{\"jsonrpc\":\"2.0\",\"method\":\"eth_chainId\",\"params\":[],\"id\":%1%}") % t_id);
|
||||
m_endpoint.send(m_hdl, req.c_str(), websocketpp::frame::opcode::text);
|
||||
|
||||
return t_id++;
|
||||
}
|
||||
|
||||
std::string eth_rpc_client::eth_getTransactionReceipt(const std::string& tx_id) {
|
||||
std::string req = str(boost::format("{\"jsonrpc\":\"2.0\",\"method\":\"eth_getTransactionReceipt\",\"params\":[\"0xbc262e1222ff48cd026a62fd925912ab5006650e311b7711a7216054461a64e0\"],\"id\":%1%}") % t_id++);
|
||||
uint64_t eth_rpc_client::eth_getTransactionReceipt(const std::string& tx_id) {
|
||||
std::string req = str(boost::format("{\"jsonrpc\":\"2.0\",\"method\":\"eth_getTransactionReceipt\",\"params\":[\"%1%\"],\"id\":%2%}") % tx_id.c_str() % t_id);
|
||||
m_endpoint.send(m_hdl, req.c_str(), websocketpp::frame::opcode::text);
|
||||
return "";
|
||||
return t_id++;
|
||||
}
|
||||
|
||||
std::string eth_rpc_client::eth_call(const std::string& to, const std::string& data) {
|
||||
return "";
|
||||
uint64_t eth_rpc_client::eth_call(const std::string& to, const std::string& data) {
|
||||
std::string req = str(boost::format("{\"jsonrpc\": \"2.0\", \"method\": \"eth_call\", \"params\": [{\"to\": \"%1%\", \"data\": \"%2%\"}, \"latest\"], \"id\": %3%}") % to.c_str() % data.c_str() % t_id);
|
||||
m_endpoint.send(m_hdl, req.c_str(), websocketpp::frame::opcode::text);
|
||||
|
||||
return t_id++;
|
||||
}
|
||||
|
||||
std::string eth_rpc_client::eth_sendTransaction(const std::string& from, const std::string& to, const std::string& data) {
|
||||
return "";
|
||||
uint64_t eth_rpc_client::eth_sendTransaction(const std::string& from, const std::string& to, const std::string& data) {
|
||||
std::string req = str(boost::format("{\"jsonrpc\":\"2.0\",\"method\": \"eth_sendTransaction\", \"params\": [{\"from\": \"%1%\", \"to\": \"%2%\", \"data\": \"%3%\"}], \"id\": %4%}") % from.c_str() % to.c_str() % data.c_str() % t_id);
|
||||
m_endpoint.send(m_hdl, req.c_str(), websocketpp::frame::opcode::text);
|
||||
|
||||
return t_id++;
|
||||
}
|
||||
|
||||
uint64_t eth_rpc_client::eth_sendRawTransaction(const std::string& params) {
|
||||
std::string req = str(boost::format("{\"jsonrpc\":\"2.0\",\"method\":\"eth_sendRawTransaction\",\"params\":[\"%1%\"],\"id\":%2%}") % params.c_str() % t_id);
|
||||
m_endpoint.send(m_hdl, req.c_str(), websocketpp::frame::opcode::text);
|
||||
return t_id++;
|
||||
}
|
||||
|
||||
uint64_t eth_rpc_client::eth_getCode(const std::string& addr) {
|
||||
std::string req = str(boost::format("{\"jsonrpc\":\"2.0\",\"method\": \"eth_getCode\", \"params\": [\"%1%\",\"latest\"], \"id\": %2%}") % addr.c_str() % t_id);
|
||||
m_endpoint.send(m_hdl, req.c_str(), websocketpp::frame::opcode::text);
|
||||
|
||||
return t_id++;
|
||||
}
|
||||
|
||||
uint64_t eth_rpc_client::eth_getBalance(const std::string& addr) {
|
||||
std::string req = str(boost::format("{\"jsonrpc\":\"2.0\",\"method\": \"eth_getBalance\", \"params\": [\"%1%\",\"latest\"], \"id\": %2%}") % addr.c_str() % t_id);
|
||||
m_endpoint.send(m_hdl, req.c_str(), websocketpp::frame::opcode::text);
|
||||
|
||||
return t_id++;
|
||||
}
|
||||
|
||||
uint64_t eth_rpc_client::eth_sign(const string& addr, const string& message) {
|
||||
std::string req = str(boost::format("{\"jsonrpc\":\"2.0\",\"method\": \"eth_sign\", \"params\": [\"%1%\",\"%2%\"], \"id\": %2%}") % addr.c_str() % message.c_str() % t_id);
|
||||
m_endpoint.send(m_hdl, req.c_str(), websocketpp::frame::opcode::text);
|
||||
|
||||
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::add_owner(const std::string& 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 eth_rpc_client::addmultisigaddress(const uint32_t nrequired, const std::vector<std::string> public_keys) {
|
||||
|
|
@ -119,8 +181,22 @@ std::string eth_rpc_client::combinepsbt(const vector<std::string> &psbts) {
|
|||
return "";
|
||||
}
|
||||
|
||||
std::string eth_rpc_client::createmultisig(const uint32_t nrequired, const std::vector<std::string> public_keys) {
|
||||
return "";
|
||||
uint64_t eth_rpc_client::createmultisig(const uint32_t nrequired, const std::vector<std::string> owner_addresses, const std::string &private_key) {
|
||||
//That's will create
|
||||
//0x5FbBb31BE52608D2F52247E8400B7fCaA9E0bC12
|
||||
//0x76ce31BD03f601c3fC13732deF921c5Bac282676
|
||||
//0x09EE460834498a4ee361beB819470061B7381B49
|
||||
//0x6AEFbd09209e1eE2e0a589d31e732F69B77713D2
|
||||
//0x631e128b16f9aDCF1bB6385112B1519C917D77a7
|
||||
//0xcD5C788e84220E8b8934Ea4F1dC6a12009bCc91D
|
||||
//0x3627C1B31525887CB9441130C831e35887650305
|
||||
//0x03A13a989AF30C92AD7ABD1E6210308A6c96f373
|
||||
|
||||
|
||||
std::string from = "0xeE52b70e8D7AB5Fe661311D47e81228EAD6B06B9";
|
||||
std::string to = "0xa6B71E26C5e0845f74c812102Ca7114b6a896AB2";
|
||||
std::string data = "0x1688f0b9000000000000000000000000d9db270c1b5e3bd161e8c8503c55ceabee70955200000000000000000000000000000000000000000000000000000000000000604fa262bd05cdef2e3d5261787ee66d9447a4036324990e04380339bec83b4c7a0000000000000000000000000000000000000000000000000000000000000264b63e800d0000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000220000000000000000000000000f48f2b2d2a534e402487b3ee7c18c33aec0fe5e400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000005FbBb31BE52608D2F52247E8400B7fCaA9E0bC1200000000000000000000000076ce31BD03f601c3fC13732deF921c5Bac28267600000000000000000000000009EE460834498a4ee361beB819470061B7381B490000000000000000000000006AEFbd09209e1eE2e0a589d31e732F69B77713D2000000000000000000000000631e128b16f9aDCF1bB6385112B1519C917D77a7000000000000000000000000cD5C788e84220E8b8934Ea4F1dC6a12009bCc91D0000000000000000000000003627C1B31525887CB9441130C831e3588765030500000000000000000000000003A13a989AF30C92AD7ABD1E6210308A6c96f3730000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
|
||||
return eth_sendTransaction(from, to, data);
|
||||
}
|
||||
|
||||
std::string eth_rpc_client::createpsbt() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue