github.com/igggame/nebulas-go@v2.1.0+incompatible/nbre/cmd/dummy_neb/generator/checkers.cpp (about) 1 // Copyright (C) 2018 go-nebulas authors 2 // 3 // This file is part of the go-nebulas library. 4 // 5 // the go-nebulas library is free software: you can redistribute it and/or 6 // modify 7 // it under the terms of the GNU General Public License as published by 8 // the Free Software Foundation, either version 3 of the License, or 9 // (at your option) any later version. 10 // 11 // the go-nebulas library is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU General Public License for more details. 15 // 16 // You should have received a copy of the GNU General Public License 17 // along with the go-nebulas library. If not, see 18 // <http://www.gnu.org/licenses/>. 19 // 20 #include "cmd/dummy_neb/generator/checkers.h" 21 #include "cmd/dummy_neb/dummy_callback.h" 22 #include "core/net_ipc/nipc_pkg.h" 23 24 nbre_version_checker::nbre_version_checker() : checker_task_base() {} 25 26 nbre_version_checker::~nbre_version_checker() {} 27 28 void nbre_version_checker::check() { 29 callback_handler::instance().add_version_handler( 30 reinterpret_cast<uint64_t>(this), 31 [this](uint64_t, uint32_t major, uint32_t minor, uint32_t patch) { 32 nbre_version_ack ack; 33 ack.set<p_holder>(0); 34 ack.set<p_major>(major); 35 ack.set<p_minor>(minor); 36 ack.set<p_patch>(patch); 37 auto result = ack.serialize_to_string(); 38 apply_result(result); 39 }); 40 m_b_is_running = true; 41 ipc_nbre_version(this, 0xfffful); 42 } 43 std::string nbre_version_checker::name() const { return "ipc_nbre_version"; } 44 45 nbre_nr_result_check::nbre_nr_result_check(const std::string &nr_handle) 46 : checker_task_base(), m_nr_handle(nr_handle) {} 47 48 nbre_nr_result_check::~nbre_nr_result_check() {} 49 50 void nbre_nr_result_check::check() { 51 callback_handler::instance().add_nr_result_handler( 52 reinterpret_cast<uint64_t>(this), 53 [this](uint64_t, const char *nr_result) { 54 auto result = std::string(nr_result); 55 apply_result(result); 56 }); 57 m_b_is_running = true; 58 ipc_nbre_nr_result_by_handle(this, m_nr_handle.c_str()); 59 } 60 61 std::string nbre_nr_result_check::name() const { 62 std::stringstream ss; 63 ss << "ipc_nbre_nr_result(" << m_nr_handle << ")"; 64 return ss.str(); 65 } 66 67 nbre_nr_handle_check::nbre_nr_handle_check(uint64_t start_block, 68 uint64_t end_block) 69 : checker_task_base(), m_start_block(start_block), m_end_block(end_block) {} 70 71 std::string nbre_nr_handle_check::name() const { 72 std::stringstream ss; 73 ss << "ipc_nbre_nr_handle(" << m_start_block << "," << m_end_block << ")"; 74 return ss.str(); 75 } 76 nbre_nr_handle_check::~nbre_nr_handle_check() {} 77 78 void nbre_nr_handle_check::check() { 79 callback_handler::instance().add_nr_handler( 80 reinterpret_cast<uint64_t>(this), 81 [this](uint64_t, const char *nr_handle) { 82 if (!m_nr_result_checker) { 83 m_nr_result_checker = 84 std::make_shared<nbre_nr_result_check>(std::string(nr_handle)); 85 checker_tasks::instance().add_task(m_nr_result_checker); 86 } 87 apply_result(std::string(nr_handle)); 88 }); 89 m_b_is_running = true; 90 ipc_nbre_nr_handle(this, m_start_block, m_end_block, 0); 91 } 92 93 nbre_dip_reward_check::nbre_dip_reward_check(uint64_t height) 94 : checker_task_base(), m_height(height) {} 95 96 nbre_dip_reward_check::~nbre_dip_reward_check() {} 97 98 std::string nbre_dip_reward_check::name() const { 99 std::stringstream ss; 100 ss << "ipc_nbre_dip_reward(" << m_height << ")"; 101 return ss.str(); 102 } 103 104 void nbre_dip_reward_check::check() { 105 callback_handler::instance().add_dip_reward_handler( 106 reinterpret_cast<uint64_t>(this), 107 [this](uint64_t, const char *dip_reward) { 108 apply_result(std::string(dip_reward)); 109 }); 110 m_b_is_running = true; 111 ipc_nbre_dip_reward(this, m_height, 0); 112 }