Merge branch 'feature/son-for-hive' into issue/son-for-hive-rpc-connection
This commit is contained in:
commit
1de31c96c8
7 changed files with 199 additions and 47 deletions
|
|
@ -3,31 +3,24 @@
|
|||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
//#include <boost/asio.hpp>
|
||||
//#include <boost/asio/ssl.hpp>
|
||||
#include <curl/curl.h>
|
||||
|
||||
#include <boost/algorithm/string/case_conv.hpp>
|
||||
#include <boost/algorithm/string/trim.hpp>
|
||||
#include <boost/asio/buffer.hpp>
|
||||
|
||||
#include <boost/property_tree/json_parser.hpp>
|
||||
#include <boost/property_tree/ptree.hpp>
|
||||
|
||||
#include <curl/curl.h>
|
||||
|
||||
#include <fc/crypto/base64.hpp>
|
||||
#include <fc/log/logger.hpp>
|
||||
#include <fc/network/ip.hpp>
|
||||
|
||||
#include <boost/algorithm/string/case_conv.hpp>
|
||||
#include <boost/algorithm/string/trim.hpp>
|
||||
|
||||
namespace graphene { namespace peerplays_sidechain {
|
||||
|
||||
using namespace boost::asio;
|
||||
|
||||
namespace detail {
|
||||
|
||||
// https_call_impl
|
||||
|
||||
class https_call_impl {
|
||||
public:
|
||||
https_call_impl(https_call &call, const void *body_data, size_t body_size, http_response &response);
|
||||
|
|
@ -249,8 +242,6 @@ void https_call_impl::process_response() {
|
|||
|
||||
} // namespace detail
|
||||
|
||||
// https_call
|
||||
|
||||
https_call::https_call(const std::string &host, const std::string &ip_addr, uint16_t port, const std::string &method, const std::string &path, const std::string &headers, const std::string &content_type) :
|
||||
m_host(host),
|
||||
m_method(method),
|
||||
|
|
@ -274,14 +265,12 @@ bool https_call::exec(const void *body_data, size_t body_size, http_response *re
|
|||
m_error_what = decltype(m_error_what)();
|
||||
|
||||
try {
|
||||
try {
|
||||
resp.clear();
|
||||
impl.exec();
|
||||
} catch (const std::exception &e) {
|
||||
resp.clear();
|
||||
m_error_what = e.what();
|
||||
return false;
|
||||
}
|
||||
resp.clear();
|
||||
impl.exec();
|
||||
} catch (const std::exception &e) {
|
||||
resp.clear();
|
||||
m_error_what = e.what();
|
||||
return false;
|
||||
} catch (...) {
|
||||
resp.clear();
|
||||
m_error_what = "unknown exception";
|
||||
|
|
@ -291,10 +280,6 @@ bool https_call::exec(const void *body_data, size_t body_size, http_response *re
|
|||
return true;
|
||||
}
|
||||
|
||||
}} // namespace graphene::peerplays_sidechain
|
||||
|
||||
namespace graphene { namespace peerplays_sidechain {
|
||||
|
||||
static std::string resolve_host_addr(const std::string &host_name) {
|
||||
using namespace boost::asio;
|
||||
io_service service;
|
||||
|
|
@ -318,10 +303,6 @@ static std::string strip_proto_name(const std::string &url, std::string *schema)
|
|||
return url.substr(index + 3);
|
||||
}
|
||||
|
||||
}} // namespace graphene::peerplays_sidechain
|
||||
|
||||
namespace graphene { namespace peerplays_sidechain {
|
||||
|
||||
rpc_client::rpc_client(std::string url, uint32_t _port, std::string _user, std::string _password, bool _debug_rpc_calls) :
|
||||
port(_port),
|
||||
user(_user),
|
||||
|
|
@ -432,6 +413,87 @@ std::string rpc_client::send_post_request(std::string method, std::string params
|
|||
return "";
|
||||
}
|
||||
|
||||
//fc::http::reply rpc_client::send_post_request(std::string body, bool show_log) {
|
||||
// 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;
|
||||
//}
|
||||
|
||||
//static size_t write_callback(char *ptr, size_t size, size_t nmemb, rpc_reply *reply) {
|
||||
// size_t retval = 0;
|
||||
// if (reply != nullptr) {
|
||||
// reply->body.append(ptr, size * nmemb);
|
||||
// retval = size * nmemb;
|
||||
// }
|
||||
// return retval;
|
||||
//}
|
||||
|
||||
//rpc_reply rpc_client::send_post_request(std::string body, bool show_log) {
|
||||
//
|
||||
// struct curl_slist *headers = nullptr;
|
||||
// headers = curl_slist_append(headers, "Accept: application/json");
|
||||
// headers = curl_slist_append(headers, "Content-Type: application/json");
|
||||
// headers = curl_slist_append(headers, "charset: utf-8");
|
||||
//
|
||||
// CURL *curl = curl_easy_init();
|
||||
// if (ip.find("https://", 0) != 0) {
|
||||
// curl_easy_setopt(curl, CURLOPT_URL, ip.c_str());
|
||||
// curl_easy_setopt(curl, CURLOPT_PORT, port);
|
||||
// } else {
|
||||
// std::string full_address = ip + ":" + std::to_string(port);
|
||||
// curl_easy_setopt(curl, CURLOPT_URL, full_address.c_str());
|
||||
// curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, false);
|
||||
// curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, false);
|
||||
// }
|
||||
// if (!user.empty()) {
|
||||
// curl_easy_setopt(curl, CURLOPT_USERNAME, user.c_str());
|
||||
// curl_easy_setopt(curl, CURLOPT_PASSWORD, password.c_str());
|
||||
// }
|
||||
//
|
||||
// curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
|
||||
// curl_easy_setopt(curl, CURLOPT_POSTFIELDS, body.c_str());
|
||||
//
|
||||
// //curl_easy_setopt(curl, CURLOPT_VERBOSE, true);
|
||||
//
|
||||
// rpc_reply reply;
|
||||
//
|
||||
// curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_callback);
|
||||
// curl_easy_setopt(curl, CURLOPT_WRITEDATA, &reply);
|
||||
//
|
||||
// curl_easy_perform(curl);
|
||||
//
|
||||
// curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &reply.status);
|
||||
//
|
||||
// curl_easy_cleanup(curl);
|
||||
// curl_slist_free_all(headers);
|
||||
//
|
||||
// if (show_log) {
|
||||
// std::string url = ip + ":" + std::to_string(port);
|
||||
// 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;
|
||||
//}
|
||||
|
||||
http_response rpc_client::send_post_request(std::string body, bool show_log) {
|
||||
|
||||
http_response response;
|
||||
|
|
|
|||
|
|
@ -3,11 +3,11 @@
|
|||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
#include <fc/network/http/connection.hpp>
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/asio/ssl.hpp>
|
||||
|
||||
#include <fc/network/http/connection.hpp>
|
||||
|
||||
namespace graphene { namespace peerplays_sidechain {
|
||||
|
||||
struct http_response {
|
||||
|
|
@ -48,10 +48,6 @@ private:
|
|||
boost::asio::ip::tcp::endpoint m_endpoint;
|
||||
};
|
||||
|
||||
}} // namespace graphene::peerplays_sidechain
|
||||
|
||||
namespace graphene { namespace peerplays_sidechain {
|
||||
|
||||
class rpc_client {
|
||||
public:
|
||||
rpc_client(std::string url, uint32_t _port, std::string _user, std::string _password, bool _debug_rpc_calls);
|
||||
|
|
@ -75,6 +71,7 @@ protected:
|
|||
private:
|
||||
https_call *https;
|
||||
//fc::http::reply send_post_request(std::string body, bool show_log);
|
||||
//rpc_reply send_post_request(std::string body, bool show_log);
|
||||
http_response send_post_request(std::string body, bool show_log);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -6,12 +6,12 @@ namespace graphene { namespace peerplays_sidechain { namespace hive {
|
|||
|
||||
#define HBD_NAI "@@000000013"
|
||||
#define HBD_PRECISION 3
|
||||
#define HBD_SYMBOL_U64 (uint64_t('H') | (uint64_t('B') << 8) | (uint64_t('D') << 16))
|
||||
#define HBD_SYMBOL_U64 (uint64_t('S') | (uint64_t('B') << 8) | (uint64_t('D') << 16))
|
||||
#define HBD_SYMBOL_SER (uint64_t(3) | (HBD_SYMBOL_U64 << 8))
|
||||
|
||||
#define HIVE_NAI "@@000000021"
|
||||
#define HIVE_PRECISION 3
|
||||
#define HIVE_SYMBOL_U64 (uint64_t('H') | (uint64_t('I') << 8) | (uint64_t('V') << 16) | (uint64_t('E') << 24))
|
||||
#define HIVE_SYMBOL_U64 (uint64_t('S') | (uint64_t('T') << 8) | (uint64_t('E') << 16) | (uint64_t('E') << 24) | (uint64_t('M') << 32))
|
||||
#define HIVE_SYMBOL_SER (uint64_t(3) | (HIVE_SYMBOL_U64 << 8))
|
||||
|
||||
#define TBD_NAI "@@000000013"
|
||||
|
|
|
|||
|
|
@ -13,7 +13,6 @@
|
|||
namespace graphene { namespace peerplays_sidechain { namespace hive {
|
||||
|
||||
struct vote_operation {};
|
||||
|
||||
struct comment_operation {};
|
||||
|
||||
struct transfer_operation {
|
||||
|
|
@ -24,17 +23,11 @@ struct transfer_operation {
|
|||
};
|
||||
|
||||
struct transfer_to_vesting_operation {};
|
||||
|
||||
struct withdraw_vesting_operation {};
|
||||
|
||||
struct limit_order_create_operation {};
|
||||
|
||||
struct limit_order_cancel_operation {};
|
||||
|
||||
struct feed_publish_operation {};
|
||||
|
||||
struct convert_operation {};
|
||||
|
||||
struct account_create_operation {};
|
||||
|
||||
struct account_update_operation {
|
||||
|
|
@ -46,6 +39,42 @@ struct account_update_operation {
|
|||
std::string json_metadata;
|
||||
};
|
||||
|
||||
struct witness_update_operation {};
|
||||
struct account_witness_vote_operation {};
|
||||
struct account_witness_proxy_operation {};
|
||||
struct pow_operation {};
|
||||
struct custom_operation {};
|
||||
struct report_over_production_operation {};
|
||||
struct delete_comment_operation {};
|
||||
struct custom_json_operation {};
|
||||
struct comment_options_operation {};
|
||||
struct set_withdraw_vesting_route_operation {};
|
||||
struct limit_order_create2_operation {};
|
||||
struct claim_account_operation {};
|
||||
struct create_claimed_account_operation {};
|
||||
struct request_account_recovery_operation {};
|
||||
struct recover_account_operation {};
|
||||
struct change_recovery_account_operation {};
|
||||
struct escrow_transfer_operation {};
|
||||
struct escrow_dispute_operation {};
|
||||
struct escrow_release_operation {};
|
||||
struct pow2_operation {};
|
||||
struct escrow_approve_operation {};
|
||||
struct transfer_to_savings_operation {};
|
||||
struct transfer_from_savings_operation {};
|
||||
struct cancel_transfer_from_savings_operation {};
|
||||
struct custom_binary_operation {};
|
||||
struct decline_voting_rights_operation {};
|
||||
struct reset_account_operation {};
|
||||
struct set_reset_account_operation {};
|
||||
struct claim_reward_balance_operation {};
|
||||
|
||||
struct delegate_vesting_shares_operation {
|
||||
hive::account_name_type delegator;
|
||||
hive::account_name_type delegatee;
|
||||
hive::asset vesting_shares;
|
||||
};
|
||||
|
||||
}}} // namespace graphene::peerplays_sidechain::hive
|
||||
|
||||
FC_REFLECT(graphene::peerplays_sidechain::hive::vote_operation, )
|
||||
|
|
@ -61,3 +90,34 @@ FC_REFLECT(graphene::peerplays_sidechain::hive::convert_operation, )
|
|||
FC_REFLECT(graphene::peerplays_sidechain::hive::account_create_operation, )
|
||||
FC_REFLECT(graphene::peerplays_sidechain::hive::account_update_operation,
|
||||
(account)(owner)(active)(posting)(memo_key)(json_metadata))
|
||||
FC_REFLECT(graphene::peerplays_sidechain::hive::witness_update_operation, )
|
||||
FC_REFLECT(graphene::peerplays_sidechain::hive::account_witness_vote_operation, )
|
||||
FC_REFLECT(graphene::peerplays_sidechain::hive::account_witness_proxy_operation, )
|
||||
FC_REFLECT(graphene::peerplays_sidechain::hive::pow_operation, )
|
||||
FC_REFLECT(graphene::peerplays_sidechain::hive::custom_operation, )
|
||||
FC_REFLECT(graphene::peerplays_sidechain::hive::report_over_production_operation, )
|
||||
FC_REFLECT(graphene::peerplays_sidechain::hive::delete_comment_operation, )
|
||||
FC_REFLECT(graphene::peerplays_sidechain::hive::custom_json_operation, )
|
||||
FC_REFLECT(graphene::peerplays_sidechain::hive::comment_options_operation, )
|
||||
FC_REFLECT(graphene::peerplays_sidechain::hive::set_withdraw_vesting_route_operation, )
|
||||
FC_REFLECT(graphene::peerplays_sidechain::hive::limit_order_create2_operation, )
|
||||
FC_REFLECT(graphene::peerplays_sidechain::hive::claim_account_operation, )
|
||||
FC_REFLECT(graphene::peerplays_sidechain::hive::create_claimed_account_operation, )
|
||||
FC_REFLECT(graphene::peerplays_sidechain::hive::request_account_recovery_operation, )
|
||||
FC_REFLECT(graphene::peerplays_sidechain::hive::recover_account_operation, )
|
||||
FC_REFLECT(graphene::peerplays_sidechain::hive::change_recovery_account_operation, )
|
||||
FC_REFLECT(graphene::peerplays_sidechain::hive::escrow_transfer_operation, )
|
||||
FC_REFLECT(graphene::peerplays_sidechain::hive::escrow_dispute_operation, )
|
||||
FC_REFLECT(graphene::peerplays_sidechain::hive::escrow_release_operation, )
|
||||
FC_REFLECT(graphene::peerplays_sidechain::hive::pow2_operation, )
|
||||
FC_REFLECT(graphene::peerplays_sidechain::hive::escrow_approve_operation, )
|
||||
FC_REFLECT(graphene::peerplays_sidechain::hive::transfer_to_savings_operation, )
|
||||
FC_REFLECT(graphene::peerplays_sidechain::hive::transfer_from_savings_operation, )
|
||||
FC_REFLECT(graphene::peerplays_sidechain::hive::cancel_transfer_from_savings_operation, )
|
||||
FC_REFLECT(graphene::peerplays_sidechain::hive::custom_binary_operation, )
|
||||
FC_REFLECT(graphene::peerplays_sidechain::hive::decline_voting_rights_operation, )
|
||||
FC_REFLECT(graphene::peerplays_sidechain::hive::reset_account_operation, )
|
||||
FC_REFLECT(graphene::peerplays_sidechain::hive::set_reset_account_operation, )
|
||||
FC_REFLECT(graphene::peerplays_sidechain::hive::claim_reward_balance_operation, )
|
||||
FC_REFLECT(graphene::peerplays_sidechain::hive::delegate_vesting_shares_operation,
|
||||
(delegator)(delegatee)(vesting_shares))
|
||||
|
|
|
|||
|
|
@ -19,7 +19,42 @@ typedef fc::static_variant<
|
|||
convert_operation,
|
||||
|
||||
account_create_operation,
|
||||
account_update_operation>
|
||||
account_update_operation,
|
||||
|
||||
witness_update_operation,
|
||||
account_witness_vote_operation,
|
||||
account_witness_proxy_operation,
|
||||
|
||||
pow_operation,
|
||||
|
||||
custom_operation,
|
||||
|
||||
report_over_production_operation,
|
||||
|
||||
delete_comment_operation,
|
||||
custom_json_operation,
|
||||
comment_options_operation,
|
||||
set_withdraw_vesting_route_operation,
|
||||
limit_order_create2_operation,
|
||||
claim_account_operation,
|
||||
create_claimed_account_operation,
|
||||
request_account_recovery_operation,
|
||||
recover_account_operation,
|
||||
change_recovery_account_operation,
|
||||
escrow_transfer_operation,
|
||||
escrow_dispute_operation,
|
||||
escrow_release_operation,
|
||||
pow2_operation,
|
||||
escrow_approve_operation,
|
||||
transfer_to_savings_operation,
|
||||
transfer_from_savings_operation,
|
||||
cancel_transfer_from_savings_operation,
|
||||
custom_binary_operation,
|
||||
decline_voting_rights_operation,
|
||||
reset_account_operation,
|
||||
set_reset_account_operation,
|
||||
claim_reward_balance_operation,
|
||||
delegate_vesting_shares_operation>
|
||||
hive_operation;
|
||||
|
||||
}}} // namespace graphene::peerplays_sidechain::hive
|
||||
|
|
|
|||
|
|
@ -1546,7 +1546,7 @@ bool sidechain_net_handler_bitcoin::settle_sidechain_transaction(const sidechain
|
|||
|
||||
if (sto.object_id.is<son_wallet_withdraw_id_type>()) {
|
||||
auto swwo = database.get<son_wallet_withdraw_object>(sto.object_id);
|
||||
settle_amount = swwo.withdraw_amount;
|
||||
settle_amount = asset(swwo.withdraw_amount, database.get_global_properties().parameters.btc_asset());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -150,12 +150,10 @@ 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);
|
||||
|
||||
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));
|
||||
FC_ASSERT(false);
|
||||
}
|
||||
|
||||
chain_id = chain_id_type(chain_id_str);
|
||||
|
||||
std::string is_test_net = node_rpc_client->get_is_test_net();
|
||||
|
|
|
|||
Loading…
Reference in a new issue