github.com/igggame/nebulas-go@v2.1.0+incompatible/nbre/cmd/dummy_neb/generator/cli_generator.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/cli_generator.h" 21 #include "auth_table_generator.h" 22 #include "cmd/dummy_neb/cli/pkg.h" 23 24 cli_generator::cli_generator() : generator_base(nullptr, nullptr, 0, 0) { 25 } 26 cli_generator::~cli_generator() {} 27 28 void cli_generator::update_info(generate_block *block) { 29 m_block = block; 30 m_all_accounts = block->get_all_accounts(); 31 m_new_tx_num = m_pkgs.size(); 32 } 33 34 std::shared_ptr<corepb::Account> cli_generator::gen_account() { 35 return nullptr; 36 } 37 std::shared_ptr<corepb::Transaction> cli_generator::gen_tx() { 38 while (!m_pkgs.empty()) { 39 auto ret = m_pkgs.try_pop_front(); 40 if (!ret.first) 41 continue; 42 auto pkg = ret.second; 43 address_t to_addr; 44 if (pkg->type_id() == cli_submit_ir_pkg) { 45 cli_submit_ir_t *req = (cli_submit_ir_t *)pkg.get(); 46 std::string payload_base64 = req->get<p_payload>(); 47 auto payload_bytes = neb::bytes::from_base64(payload_base64); 48 49 if (req->get<p_type>() == "nr") { 50 if (m_nr_admin_addr.empty()) { 51 m_nr_admin_addr = m_all_accounts->random_user_addr(); 52 } 53 to_addr = m_nr_admin_addr; 54 LOG(INFO) << "submit nr ir"; 55 return m_block->add_protocol_transaction(to_addr, payload_bytes); 56 } else if (req->get<p_type>() == "dip") { 57 if (m_dip_admin_addr.empty()) { 58 m_dip_admin_addr = m_all_accounts->random_user_addr(); 59 } 60 to_addr = m_dip_admin_addr; 61 LOG(INFO) << "submit dip ir"; 62 return m_block->add_protocol_transaction(to_addr, payload_bytes); 63 64 } else if (req->get<p_type>() == "auth") { 65 if (m_auth_admin_addr.empty()) { 66 m_auth_admin_addr = m_all_accounts->random_user_addr(); 67 } 68 if (m_nr_admin_addr.empty()) { 69 m_nr_admin_addr = m_all_accounts->random_user_addr(); 70 } 71 if (m_dip_admin_addr.empty()) { 72 m_dip_admin_addr = m_all_accounts->random_user_addr(); 73 } 74 to_addr = m_auth_admin_addr; 75 LOG(INFO) << "submit auth table"; 76 return m_block->add_protocol_transaction( 77 to_addr, gen_auth_table_payload(m_nr_admin_addr, m_dip_admin_addr)); 78 } 79 } 80 } 81 return nullptr; 82 } 83 checker_tasks::task_container_ptr_t cli_generator::gen_tasks() { 84 return nullptr; 85 } 86