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 2c89aa50..11df4cb8 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 @@ -17,6 +17,8 @@ #include #include +#include + namespace graphene { namespace peerplays_sidechain { typedef websocketpp::client client; @@ -67,7 +69,7 @@ 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 start(); void stop(); void on_socket_init(websocketpp::connection_hdl); void on_fail(websocketpp::connection_hdl hdl); @@ -133,6 +135,7 @@ private: ethereum_function_call_encoder m_ethereum_function_call_encoder; + std::shared_ptr _thread; std::string signature; std::string geth_url; uint64_t t_id; diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_eth.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_eth.cpp index caa88650..f3fcabb5 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_eth.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_eth.cpp @@ -67,7 +67,7 @@ std::string eth_rpc_client::ethereum_function_call_encoder::encode_bytes(const s } -eth_rpc_client::eth_rpc_client(const std::string &url, const std::string &user_name, const std::string &password, bool debug_rpc_calls) { +eth_rpc_client::eth_rpc_client(const std::string &url, const std::string &user_name, const std::string &password, bool debug_rpc_calls) : _thread(std::make_shared("eth_rpc_client")){ geth_url = url; user = user_name; this->password = password; @@ -91,20 +91,24 @@ eth_rpc_client::eth_rpc_client(const std::string &url, const std::string &user_n m_endpoint.set_fail_handler(bind(&type::on_fail,this,::_1)); } -void eth_rpc_client::start(std::string uri) { - websocketpp::lib::error_code ec; - client::connection_ptr con = m_endpoint.get_connection(uri, ec); - m_hdl = con->get_handle(); +void eth_rpc_client::start() { + ilog("### eth_rpc_client::start uri: ${uri}", ("uri", geth_url)); + auto future = _thread->async([this] + { + websocketpp::lib::error_code ec; + client::connection_ptr con = m_endpoint.get_connection(this->geth_url, ec); + m_hdl = con->get_handle(); - if (ec) { - m_endpoint.get_alog().write(websocketpp::log::alevel::app,ec.message()); - return; - } + if (ec) { + m_endpoint.get_alog().write(websocketpp::log::alevel::app,ec.message()); + return; + } - m_endpoint.connect(con); + m_endpoint.connect(con); - // Start the ASIO io_service run loop - m_endpoint.run(); + // Start the ASIO io_service run loop + m_endpoint.run(); + }); } void eth_rpc_client::stop() { @@ -455,7 +459,7 @@ sidechain_net_handler_eth::sidechain_net_handler_eth(peerplays_sidechain_plugin url = options.at("ethereum-node-rpc-url").as(); eth_client = std::unique_ptr(new eth_rpc_client(url, rpc_user, rpc_password, debug_rpc_calls)); - eth_client->start(url); + eth_client->start(); /* if (!wallet.empty()) { eth_client->loadwallet(wallet);