Intermediate
This commit is contained in:
parent
f59d34c001
commit
7237ac0e71
5 changed files with 104 additions and 38 deletions
|
|
@ -16,6 +16,7 @@ add_library( peerplays_sidechain
|
|||
bitcoin/sign_bitcoin_transaction.cpp
|
||||
common/rpc_client.cpp
|
||||
common/https_call.cpp
|
||||
common/net_utl.cpp
|
||||
common/utils.cpp
|
||||
hive/asset.cpp
|
||||
hive/operations.cpp
|
||||
|
|
|
|||
22
libraries/plugins/peerplays_sidechain/common/net_utl.cpp
Normal file
22
libraries/plugins/peerplays_sidechain/common/net_utl.cpp
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
#include "https_call.h"
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
|
||||
|
||||
namespace peerplays {
|
||||
namespace net {
|
||||
|
||||
std::string resolveHostAddr(const std::string & hostName) {
|
||||
using namespace boost::asio;
|
||||
io_service service;
|
||||
ip::tcp::resolver resolver(service);
|
||||
auto query = ip::tcp::resolver::query(hostName, "");
|
||||
auto iter = resolver.resolve(query);
|
||||
auto endpoint = *iter;
|
||||
auto addr = endpoint.address();
|
||||
return addr.to_string();
|
||||
}
|
||||
|
||||
|
||||
} // net
|
||||
} // peerplays
|
||||
11
libraries/plugins/peerplays_sidechain/common/net_utl.h
Normal file
11
libraries/plugins/peerplays_sidechain/common/net_utl.h
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace peerplays {
|
||||
namespace net {
|
||||
|
||||
std::string resolveHostAddr(const std::string & hostName);
|
||||
|
||||
} // net
|
||||
} // peerplays
|
||||
|
|
@ -10,6 +10,7 @@
|
|||
#include <fc/network/ip.hpp>
|
||||
|
||||
#include "https_call.h"
|
||||
#include "net_utl.h"
|
||||
|
||||
namespace graphene { namespace peerplays_sidechain {
|
||||
|
||||
|
|
@ -103,54 +104,84 @@ std::string rpc_client::send_post_request(std::string method, std::string params
|
|||
|
||||
fc::http::reply rpc_client::send_post_request(std::string body, bool show_log) {
|
||||
|
||||
using namespace peerplays::net;
|
||||
|
||||
HttpRequest request("POST", "/", authorization.key + ":" + authorization.val, body);
|
||||
|
||||
HttpsCall call(ip, port);
|
||||
|
||||
HttpResponse response;
|
||||
|
||||
fc::http::reply reply;
|
||||
auto temp = ip.substr(0, 6);
|
||||
boost::algorithm::to_lower(temp);
|
||||
|
||||
if (temp == "https:") {
|
||||
|
||||
auto host = ip.substr(8);
|
||||
|
||||
using namespace peerplays::net;
|
||||
|
||||
HttpsCall call(host, port);
|
||||
HttpRequest request("POST", "/", authorization.key + ":" + authorization.val, body);
|
||||
HttpResponse response;
|
||||
|
||||
if (call.exec(request, &response)) {
|
||||
reply.status = response.statusCode;
|
||||
reply.body.resize(response.body.size());
|
||||
memcpy(&reply.body[0], &response.body[0], response.body.size());
|
||||
}
|
||||
|
||||
if (show_log) {
|
||||
std::string url = ip + ":" + std::to_string(port);
|
||||
ilog("### Request URL: ${url}", ("url", url));
|
||||
ilog("### Request: ${body}", ("body", body));
|
||||
ilog("### Response code: ${code}", ("code", response.statusCode));
|
||||
ilog("### Response len: ${len}", ("len", response.body.size()));
|
||||
std::stringstream ss(std::string(reply.body.begin(), reply.body.end()));
|
||||
ilog("### Response body: ${ss}", ("ss", ss.str()));
|
||||
}
|
||||
|
||||
return reply;
|
||||
|
||||
if (call.exec(request, &response)) {
|
||||
reply.status = response.statusCode;
|
||||
reply.body.resize(response.body.size());
|
||||
memcpy(&reply.body[0], &response.body[0], response.body.size());
|
||||
}
|
||||
|
||||
std::string host;
|
||||
|
||||
if (temp == "http:/")
|
||||
host = ip.substr(7);
|
||||
else
|
||||
host = ip;
|
||||
|
||||
fc::ip::endpoint endpoint;
|
||||
|
||||
try {
|
||||
endpoint = fc::ip::endpoint(fc::ip::address(host), port));
|
||||
} catch (...) {
|
||||
try {
|
||||
endpoint = fc::ip::endpoint(fc::ip::address(peerplays::net::resolveHostIp(host)), port));
|
||||
} catch (...) {
|
||||
if (show_log) {
|
||||
std::string url = ip + ":" + std::to_string(port);
|
||||
ilog("### Request URL: ${url}", ("url", url));
|
||||
ilog("### Request: ${body}", ("body", body));
|
||||
ilog("### Request: error: host address resolve failed");
|
||||
}
|
||||
return reply;
|
||||
}
|
||||
}
|
||||
|
||||
fc::http::connection conn;
|
||||
conn.connect_to(endpoint);
|
||||
std::string url = "http://" + host + ":" + std::to_string(port);
|
||||
|
||||
//if (wallet.length() > 0) {
|
||||
// url = url + "/wallet/" + wallet;
|
||||
//}
|
||||
|
||||
reply = conn.request("POST", url, body, fc::http::headers{authorization});
|
||||
|
||||
if (show_log) {
|
||||
std::string url = "https://" + ip + ":" + std::to_string(port);
|
||||
ilog("### Request URL: ${url}", ("url", url));
|
||||
ilog("### Request: ${body}", ("body", body));
|
||||
ilog("### Response code: ${code}", ("code", response.statusCode));
|
||||
ilog("### Response len: ${len}", ("len", response.body.size()));
|
||||
std::stringstream ss(std::string(reply.body.begin(), reply.body.end()));
|
||||
ilog("### Response body: ${ss}", ("ss", ss.str()));
|
||||
ilog("### Response: ${ss}", ("ss", ss.str()));
|
||||
}
|
||||
|
||||
return reply;
|
||||
/*
|
||||
fc::http::connection conn;
|
||||
conn.connect_to(fc::ip::endpoint(fc::ip::address(ip), port));
|
||||
|
||||
std::string url = "http://" + ip + ":" + std::to_string(port);
|
||||
|
||||
//if (wallet.length() > 0) {
|
||||
// url = url + "/wallet/" + wallet;
|
||||
//}
|
||||
|
||||
fc::http::reply reply = conn.request("POST", url, body, fc::http::headers{authorization});
|
||||
|
||||
if (show_log) {
|
||||
ilog("### Request URL: ${url}", ("url", url));
|
||||
ilog("### Request: ${body}", ("body", body));
|
||||
std::stringstream ss(std::string(reply.body.begin(), reply.body.end()));
|
||||
ilog("### Response: ${ss}", ("ss", ss.str()));
|
||||
}
|
||||
|
||||
return reply;
|
||||
*/
|
||||
}
|
||||
|
||||
}} // namespace graphene::peerplays_sidechain
|
||||
|
|
|
|||
|
|
@ -144,15 +144,16 @@ sidechain_net_handler_hive::sidechain_net_handler_hive(peerplays_sidechain_plugi
|
|||
private_keys[key_pair.first] = key_pair.second;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
fc::http::connection conn;
|
||||
|
||||
try {
|
||||
conn.connect_to(fc::ip::endpoint(fc::ip::address(node_ip), node_rpc_port));
|
||||
} catch (fc::exception &e) {
|
||||
elog("No Hive node running at ${ip} or wrong rpc port: ${port}", ("ip", node_ip)("port", node_rpc_port));
|
||||
FC_ASSERT(false);
|
||||
}
|
||||
|
||||
*/
|
||||
node_rpc_client = new hive_node_rpc_client(node_ip, node_rpc_port, node_rpc_user, node_rpc_password, debug_rpc_calls);
|
||||
|
||||
std::string chain_id_str = node_rpc_client->get_chain_id();
|
||||
|
|
|
|||
Loading…
Reference in a new issue