From a30325660dcfefb88b694b975f8896ab5c736813 Mon Sep 17 00:00:00 2001 From: Vlad Dobromyslov Date: Fri, 4 Nov 2022 07:51:22 +0200 Subject: [PATCH] #470 Don't use admin_nodeInfo when get network_id --- .../sidechain_net_handler_ethereum.hpp | 2 +- .../sidechain_net_handler_ethereum.cpp | 17 +++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_ethereum.hpp b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_ethereum.hpp index 3944d0a2..322cf5f9 100644 --- a/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_ethereum.hpp +++ b/libraries/plugins/peerplays_sidechain/include/graphene/peerplays_sidechain/sidechain_net_handler_ethereum.hpp @@ -15,9 +15,9 @@ class ethereum_rpc_client : public rpc_client { public: ethereum_rpc_client(const std::string &url, const std::string &user_name, const std::string &password, bool debug_rpc_calls); - std::string admin_node_info(); std::string eth_get_block_by_number(std::string block_number, bool full_block); std::string eth_get_logs(std::string wallet_contract_address); + std::string eth_chainId(); std::string net_version(); std::string eth_get_transaction_count(const std::string ¶ms); std::string eth_gas_price(); diff --git a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_ethereum.cpp b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_ethereum.cpp index 02ec5bce..c71c4748 100644 --- a/libraries/plugins/peerplays_sidechain/sidechain_net_handler_ethereum.cpp +++ b/libraries/plugins/peerplays_sidechain/sidechain_net_handler_ethereum.cpp @@ -28,10 +28,6 @@ ethereum_rpc_client::ethereum_rpc_client(const std::string &url, const std::stri rpc_client(url, user_name, password, debug_rpc_calls) { } -std::string ethereum_rpc_client::admin_node_info() { - return send_post_request("admin_nodeInfo", "", debug_rpc_calls); -} - std::string ethereum_rpc_client::eth_get_block_by_number(std::string block_number, bool full_block) { const std::string params = "[ \"" + block_number + "\", " + (full_block ? "true" : "false") + "]"; return send_post_request("eth_getBlockByNumber", params, debug_rpc_calls); @@ -43,6 +39,10 @@ std::string ethereum_rpc_client::eth_get_logs(std::string wallet_contract_addres return retrieve_value_from_reply(reply_str, ""); } +std::string ethereum_rpc_client::eth_chainId() { + return send_post_request("eth_chainId", "", debug_rpc_calls); +} + std::string ethereum_rpc_client::net_version() { return send_post_request("net_version", "", debug_rpc_calls); } @@ -56,13 +56,14 @@ std::string ethereum_rpc_client::eth_gas_price() { } std::string ethereum_rpc_client::get_chain_id() { - const std::string reply_str = net_version(); - return retrieve_value_from_reply(reply_str, ""); + const std::string reply_str = eth_chainId(); + const auto chain_id_string = retrieve_value_from_reply(reply_str, ""); + return chain_id_string.empty() ? "" : std::to_string(ethereum::from_hex(chain_id_string)); } std::string ethereum_rpc_client::get_network_id() { - const std::string reply_str = admin_node_info(); - return retrieve_value_from_reply(reply_str, "protocols.eth.network"); + const std::string reply_str = net_version(); + return retrieve_value_from_reply(reply_str, ""); } std::string ethereum_rpc_client::get_nonce(const std::string &address) {