Refactor Hive transaction inspection, eliminate redundant RPC calls
This commit is contained in:
parent
de9ee9fc76
commit
ae079b3564
1 changed files with 65 additions and 52 deletions
|
|
@ -35,7 +35,7 @@ hive_node_rpc_client::hive_node_rpc_client(std::string _ip, uint32_t _port, std:
|
|||
}
|
||||
|
||||
std::string hive_node_rpc_client::account_history_api_get_transaction(std::string transaction_id) {
|
||||
std::string params = "{ \"id\": \"" + transaction_id + "\", \"include_reversible\": \"true\" }";
|
||||
std::string params = "{ \"id\": \"" + transaction_id + "\" }";
|
||||
return send_post_request("account_history_api.get_transaction", params, debug_rpc_calls);
|
||||
}
|
||||
|
||||
|
|
@ -161,9 +161,11 @@ sidechain_net_handler_hive::sidechain_net_handler_hive(peerplays_sidechain_plugi
|
|||
std::string is_test_net = node_rpc_client->get_is_test_net();
|
||||
network_type = is_test_net.compare("true") == 0 ? hive::network::testnet : hive::network::mainnet;
|
||||
if (network_type == hive::network::mainnet) {
|
||||
ilog("Running on Hive mainnet, chain id ${chain_id_str}", ("chain_id_str", chain_id_str));
|
||||
hive::asset::hbd_symbol_ser = HBD_SYMBOL_SER;
|
||||
hive::asset::hive_symbol_ser = HIVE_SYMBOL_SER;
|
||||
} else {
|
||||
ilog("Running on Hive testnet, chain id ${chain_id_str}", ("chain_id_str", chain_id_str));
|
||||
hive::asset::hbd_symbol_ser = TBD_SYMBOL_SER;
|
||||
hive::asset::hive_symbol_ser = TESTS_SYMBOL_SER;
|
||||
}
|
||||
|
|
@ -817,7 +819,6 @@ void sidechain_net_handler_hive::hive_listener_loop() {
|
|||
schedule_hive_listener();
|
||||
|
||||
std::string reply = node_rpc_client->database_api_get_dynamic_global_properties();
|
||||
|
||||
if (!reply.empty()) {
|
||||
std::stringstream ss(reply);
|
||||
boost::property_tree::ptree json;
|
||||
|
|
@ -831,6 +832,16 @@ void sidechain_net_handler_hive::hive_listener_loop() {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
//std::string reply = node_rpc_client->get_last_irreversible_block_num();
|
||||
//if (!reply.empty()) {
|
||||
// uint64_t last_irreversible_block = std::stoul(reply);
|
||||
// if (last_irreversible_block != last_block_received) {
|
||||
// std::string event_data = std::to_string(last_irreversible_block);
|
||||
// handle_event(event_data);
|
||||
// last_block_received = last_irreversible_block;
|
||||
// }
|
||||
//}
|
||||
}
|
||||
|
||||
void sidechain_net_handler_hive::handle_event(const std::string &event_data) {
|
||||
|
|
@ -840,18 +851,13 @@ void sidechain_net_handler_hive::handle_event(const std::string &event_data) {
|
|||
boost::property_tree::ptree block_json;
|
||||
boost::property_tree::read_json(ss, block_json);
|
||||
|
||||
for (const auto &tx_ids_child : block_json.get_child("result.block.transaction_ids")) {
|
||||
const auto &transaction_id = tx_ids_child.second.get_value<std::string>();
|
||||
|
||||
std::string tx_str = node_rpc_client->account_history_api_get_transaction(transaction_id);
|
||||
if (tx_str != "") {
|
||||
|
||||
std::stringstream ss_tx(tx_str);
|
||||
boost::property_tree::ptree tx;
|
||||
boost::property_tree::read_json(ss_tx, tx);
|
||||
size_t tx_idx = -1;
|
||||
for (const auto &tx_ids_child : block_json.get_child("result.block.transactions")) {
|
||||
boost::property_tree::ptree tx = tx_ids_child.second;
|
||||
tx_idx = tx_idx + 1;
|
||||
|
||||
size_t op_idx = -1;
|
||||
for (const auto &ops : tx.get_child("result.operations")) {
|
||||
for (const auto &ops : tx.get_child("operations")) {
|
||||
const auto &op = ops.second;
|
||||
op_idx = op_idx + 1;
|
||||
|
||||
|
|
@ -863,6 +869,8 @@ void sidechain_net_handler_hive::handle_event(const std::string &event_data) {
|
|||
std::string from = op_value.get<std::string>("from");
|
||||
std::string to = op_value.get<std::string>("to");
|
||||
|
||||
if (to == "son-account") {
|
||||
|
||||
const auto &amount_child = op_value.get_child("amount");
|
||||
|
||||
uint64_t amount = amount_child.get<uint64_t>("amount");
|
||||
|
|
@ -885,7 +893,6 @@ void sidechain_net_handler_hive::handle_event(const std::string &event_data) {
|
|||
from = memo;
|
||||
}
|
||||
|
||||
if (to == "son-account") {
|
||||
const auto &sidechain_addresses_idx = database.get_index_type<sidechain_address_index>().indices().get<by_sidechain_and_deposit_address_and_expires>();
|
||||
const auto &addr_itr = sidechain_addresses_idx.find(std::make_tuple(sidechain, from, time_point_sec::maximum()));
|
||||
account_id_type accn = account_id_type();
|
||||
|
|
@ -901,6 +908,13 @@ void sidechain_net_handler_hive::handle_event(const std::string &event_data) {
|
|||
accn = addr_itr->sidechain_address_account;
|
||||
}
|
||||
|
||||
std::vector<std::string> transaction_ids;
|
||||
for (const auto &tx_ids_child : block_json.get_child("result.block.transaction_ids")) {
|
||||
const auto &transaction_id = tx_ids_child.second.get_value<std::string>();
|
||||
transaction_ids.push_back(transaction_id);
|
||||
}
|
||||
std::string transaction_id = transaction_ids.at(tx_idx);
|
||||
|
||||
std::stringstream ss;
|
||||
ss << "hive"
|
||||
<< "-" << transaction_id << "-" << op_idx;
|
||||
|
|
@ -925,7 +939,6 @@ void sidechain_net_handler_hive::handle_event(const std::string &event_data) {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}} // namespace graphene::peerplays_sidechain
|
||||
|
|
|
|||
Loading…
Reference in a new issue