SON connection pool.

This commit is contained in:
timur 2022-11-16 07:32:17 -04:00
parent f209ab8ee6
commit 6e0064aefe
2 changed files with 20 additions and 2 deletions

View file

@ -52,7 +52,8 @@ private:
std::string rpc_password;
std::string wallet_account_name;
hive_rpc_client *rpc_client;
std::vector<hive_rpc_client*> rpc_clients;
int n_active_rpc_client;
hive::chain_id_type chain_id;
hive::network network_type;
@ -63,6 +64,7 @@ private:
void schedule_hive_listener();
void hive_listener_loop();
void handle_event(const std::string &event_data);
hive_rpc_client *get_active_rpc_client();
};
}} // namespace graphene::peerplays_sidechain

View file

@ -146,7 +146,9 @@ sidechain_net_handler_hive::sidechain_net_handler_hive(peerplays_sidechain_plugi
}
}
rpc_client = new hive_rpc_client(rpc_url, rpc_user, rpc_password, debug_rpc_calls);
hive_rpc_client *rpc_client = new hive_rpc_client(rpc_url, rpc_user, rpc_password, debug_rpc_calls);
rpc_clients.push_back(rpc_client);
n_active_rpc_client = 0;
const std::string chain_id_str = rpc_client->get_chain_id();
if (chain_id_str.empty()) {
@ -254,6 +256,7 @@ bool sidechain_net_handler_hive::process_proposal(const proposal_object &po) {
account_auths[wallet_son.public_key] = wallet_son.weight;
}
hive_rpc_client *rpc_client = get_active_rpc_client();
const std::string memo_key = rpc_client->get_account_memo_key(wallet_account_name);
hive::authority active;
@ -303,6 +306,7 @@ bool sidechain_net_handler_hive::process_proposal(const proposal_object &po) {
uint64_t swdo_sidechain_amount = swdo->sidechain_amount.value;
uint64_t swdo_op_idx = std::stoll(swdo->sidechain_uid.substr(swdo->sidechain_uid.find_last_of("-")));
hive_rpc_client *rpc_client = get_active_rpc_client();
const std::string tx_str = rpc_client->account_history_api_get_transaction(swdo_txid);
if (tx_str != "") {
@ -499,6 +503,7 @@ void sidechain_net_handler_hive::process_primary_wallet() {
account_auths[active_son.public_key] = active_son.weight;
}
hive_rpc_client *rpc_client = get_active_rpc_client();
const std::string memo_key = rpc_client->get_account_memo_key(wallet_account_name);
if (memo_key.empty()) {
@ -672,6 +677,7 @@ bool sidechain_net_handler_hive::process_withdrawal(const son_wallet_withdraw_ob
t_op.amount.symbol = symbol;
t_op.memo = "";
hive_rpc_client *rpc_client = get_active_rpc_client();
const std::string block_id_str = rpc_client->get_head_block_id();
hive::block_id_type head_block_id(block_id_str);
@ -731,6 +737,7 @@ std::string sidechain_net_handler_hive::process_sidechain_transaction(const side
hive::signed_transaction htrx;
fc::raw::unpack(ss_trx, htrx, 1000);
hive_rpc_client *rpc_client = get_active_rpc_client();
const std::string chain_id_str = rpc_client->get_chain_id();
const hive::chain_id_type chain_id(chain_id_str);
@ -759,6 +766,7 @@ std::string sidechain_net_handler_hive::send_sidechain_transaction(const sidecha
}
std::string params = fc::json::to_string(htrx);
hive_rpc_client *rpc_client = get_active_rpc_client();
rpc_client->network_broadcast_api_broadcast_transaction(params);
return htrx.id().str();
@ -774,6 +782,7 @@ bool sidechain_net_handler_hive::settle_sidechain_transaction(const sidechain_tr
return false;
}
hive_rpc_client *rpc_client = get_active_rpc_client();
const std::string tx_str = rpc_client->account_history_api_get_transaction(sto.sidechain_transaction);
if (tx_str != "") {
@ -821,6 +830,7 @@ void sidechain_net_handler_hive::schedule_hive_listener() {
void sidechain_net_handler_hive::hive_listener_loop() {
schedule_hive_listener();
hive_rpc_client *rpc_client = get_active_rpc_client();
const std::string reply = rpc_client->database_api_get_dynamic_global_properties();
if (!reply.empty()) {
std::stringstream ss(reply);
@ -848,6 +858,7 @@ void sidechain_net_handler_hive::hive_listener_loop() {
}
void sidechain_net_handler_hive::handle_event(const std::string &event_data) {
hive_rpc_client *rpc_client = get_active_rpc_client();
const std::string block = rpc_client->block_api_get_block(std::atoll(event_data.c_str()));
if (block != "") {
add_to_son_listener_log("BLOCK : " + event_data);
@ -948,4 +959,9 @@ void sidechain_net_handler_hive::handle_event(const std::string &event_data) {
}
}
hive_rpc_client *sidechain_net_handler_hive::get_active_rpc_client()
{
return rpc_clients[n_active_rpc_client];
}
}} // namespace graphene::peerplays_sidechain