Minor updates

Main change: config parameters: instead of "hive-node-ip" and "hive-node-rpc-port" single parameter "hive-node-rpc-url" is implemented
This commit is contained in:
moss9001 2021-11-26 14:43:05 +02:00
parent 65276283ec
commit ce216b4646
5 changed files with 33 additions and 27 deletions

View file

@ -712,7 +712,17 @@ http_call::http_call(const url_data &url, const std::string &method, const std::
m_context = 0;
}
set_port(url.port);
if (url.port)
m_port_default = url.port;
else {
if (url.schema_type == url_schema_type::https)
m_port_default = https_port;
else
m_port_default = http_port;
}
m_port = m_port_default;
set_path(url.path);
try {
@ -765,10 +775,10 @@ uint16_t http_call::port() const {
}
void http_call::set_port(uint16_t port) {
if (port == 0)
m_port = is_ssl() ? https_port : http_port;
else
if (port)
m_port = port;
else
m_port = m_port_default;
}
bool http_call::exec(const http_request &request, http_response *response) {
@ -812,7 +822,7 @@ void http_call::ctor_priv() {
namespace graphene { namespace peerplays_sidechain {
rpc_client::rpc_client(const std::string &url, uint16_t port, const std::string &user_name, const std::string &password, bool debug) :
rpc_client::rpc_client(const std::string &url, const std::string &user_name, const std::string &password, bool debug) :
debug_rpc_calls(debug),
request_id(0),
client(url)
@ -821,7 +831,6 @@ rpc_client::rpc_client(const std::string &url, uint16_t port, const std::string
client.set_method("POST");
client.set_headers("Authorization : Basic" + fc::base64_encode(user_name + ":" + password));
client.set_port(port);
}
std::string rpc_client::retrieve_array_value_from_reply(std::string reply_str, std::string array_path, uint32_t idx) {

View file

@ -31,6 +31,7 @@ struct url_data {
schema_type(url_schema_type::unknown),
port(0) {
}
url_data(const std::string &url);
void clear();
@ -97,6 +98,7 @@ private:
static constexpr auto response_first_alloc_bytes = 32 * 1024;
static constexpr auto response_next_alloc_bytes = 256 * 1024;
std::string m_host;
uint16_t m_port_default;
uint16_t m_port;
std::string m_path;
std::string m_method;
@ -116,7 +118,7 @@ namespace graphene { namespace peerplays_sidechain {
class rpc_client {
public:
rpc_client(const std::string &url, uint16_t port, const std::string &user_name, const std::string &password, bool debug);
rpc_client(const std::string &url, const std::string &user_name, const std::string &password, bool debug);
protected:
std::string retrieve_array_value_from_reply(std::string reply_str, std::string array_path, uint32_t idx);

View file

@ -14,7 +14,7 @@ namespace graphene { namespace peerplays_sidechain {
class hive_node_rpc_client : public rpc_client {
public:
hive_node_rpc_client(std::string _ip, uint32_t _port, std::string _user, std::string _password, bool _debug_rpc_calls);
hive_node_rpc_client(const std::string & url, const std::string & user_name, const std::string & password, bool debug_rpc_calls);
std::string account_history_api_get_transaction(std::string transaction_id);
std::string block_api_get_block(uint32_t block_number);
@ -48,8 +48,7 @@ public:
bool settle_sidechain_transaction(const sidechain_transaction_object &sto, asset &settle_amount);
private:
std::string node_ip;
uint32_t node_rpc_port;
std::string node_rpc_url;
std::string node_rpc_user;
std::string node_rpc_password;
hive_node_rpc_client *node_rpc_client;

View file

@ -156,8 +156,8 @@ void peerplays_sidechain_plugin_impl::plugin_set_program_options(
"Tuple of [Bitcoin public key, Bitcoin private key] (may specify multiple times)");
cli.add_options()("hive-sidechain-enabled", bpo::value<bool>()->default_value(false), "Hive sidechain handler enabled");
cli.add_options()("hive-node-ip", bpo::value<string>()->default_value("127.0.0.1"), "Hive node IP address");
cli.add_options()("hive-node-rpc-port", bpo::value<uint32_t>()->default_value(28090), "Hive node RPC port");
cli.add_options()("hive-node-rpc-url", bpo::value<string>()->default_value("127.0.0.1"), "Hive node URL (http(s)://host:port/)");
//cli.add_options()("hive-node-rpc-port", bpo::value<uint32_t>()->default_value(28090), "Deprecated: Hive node RPC port. See: hive-node-rpc-url");
cli.add_options()("hive-node-rpc-user", bpo::value<string>(), "Hive node RPC user");
cli.add_options()("hive-node-rpc-password", bpo::value<string>(), "Hive node RPC password");
cli.add_options()("hive-private-key", bpo::value<vector<string>>()->composing()->multitoken()->DEFAULT_VALUE_VECTOR(std::make_pair("TST6LLegbAgLAy28EHrffBVuANFWcFgmqRMW13wBmTExqFE9SCkg4", "5JNHfZYKGaomSFvd4NUdQ9qMcEAC43kujbfjueTHpVapX1Kzq2n")),

View file

@ -32,8 +32,8 @@
namespace graphene { namespace peerplays_sidechain {
hive_node_rpc_client::hive_node_rpc_client(std::string _ip, uint32_t _port, std::string _user, std::string _password, bool _debug_rpc_calls) :
rpc_client(_ip, _port, _user, _password, _debug_rpc_calls) {
hive_node_rpc_client::hive_node_rpc_client(const std::string & url, const std::string & user_name, const std::string & password, bool debug_rpc_calls) :
rpc_client(url, user_name, password, debug_rpc_calls) {
}
std::string hive_node_rpc_client::account_history_api_get_transaction(std::string transaction_id) {
@ -122,19 +122,14 @@ sidechain_net_handler_hive::sidechain_net_handler_hive(peerplays_sidechain_plugi
debug_rpc_calls = options.at("debug-rpc-calls").as<bool>();
}
if ((options.count("hive-node-url") > 0) && (options.count("hive-node-ip") > 0))
FC_THROW("both keys are present: hive-node-url and hive-node-ip");
if (options.count("hive-node-rpc-url"))
node_rpc_url = options.at("hive-node-rpc-url").as<std::string>();
if (options.count("hive-node-ip"))
node_ip = options.at("hive-node-ip").as<std::string>();
// if (options.count("hive-node-rpc-port"))
// node_rpc_port = options.at("hive-node-rpc-port").as<uint32_t>();
// else
// node_rpc_port = 0;
if (options.count("hive-node-url"))
node_ip = options.at("hive-node-url").as<std::string>();
if (options.count("hive-node-rpc-port"))
node_rpc_port = options.at("hive-node-rpc-port").as<uint32_t>();
else
node_rpc_port = 0;
if (options.count("hive-node-rpc-user")) {
node_rpc_user = options.at("hive-node-rpc-user").as<std::string>();
} else {
@ -158,11 +153,12 @@ sidechain_net_handler_hive::sidechain_net_handler_hive(peerplays_sidechain_plugi
}
}
node_rpc_client = new hive_node_rpc_client(node_ip, node_rpc_port, node_rpc_user, node_rpc_password, debug_rpc_calls);
node_rpc_client = new hive_node_rpc_client(node_rpc_url, node_rpc_user, node_rpc_password, debug_rpc_calls);
std::string chain_id_str = node_rpc_client->get_chain_id();
if (chain_id_str.empty()) {
elog("No Hive node running at ${ip} or wrong rpc port: ${port}", ("ip", node_ip)("port", node_rpc_port));
// elog("No Hive node running at ${url} or wrong rpc port: ${port}", ("url", node_rpc_url)("port", node_rpc_port));
elog("No Hive node running at ${url}", ("url", node_rpc_url));
FC_ASSERT(false);
}
chain_id = chain_id_type(chain_id_str);