github.com/igggame/nebulas-go@v2.1.0+incompatible/nbre/cmd/dummy_neb/generator/transaction_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 21 #include "cmd/dummy_neb/generator/transaction_generator.h" 22 23 transaction_generator::transaction_generator(all_accounts *accounts, 24 generate_block *block, 25 int new_account_num, int tx_num) 26 : generator_base(accounts, block, new_account_num, tx_num), 27 m_new_addresses(), m_last_used_address_index(0) {} 28 29 transaction_generator::~transaction_generator() {} 30 31 std::shared_ptr<corepb::Account> transaction_generator::gen_account() { 32 auto ret = m_block->gen_user_account(100_nas); 33 m_new_addresses.push_back(neb::to_address(ret->address())); 34 return ret; 35 } 36 37 std::shared_ptr<corepb::Transaction> transaction_generator::gen_tx() { 38 auto from_addr = 39 neb::to_address(m_all_accounts->random_user_account()->address()); 40 address_t to_addr; 41 if (m_last_used_address_index < m_new_addresses.size()) { 42 to_addr = m_new_addresses[m_last_used_address_index]; 43 m_last_used_address_index++; 44 } else { 45 to_addr = neb::to_address(m_all_accounts->random_user_account()->address()); 46 } 47 return m_block->add_binary_transaction(from_addr, to_addr, 1_nas); 48 } 49 50 checker_tasks::task_container_ptr_t transaction_generator::gen_tasks() { 51 return nullptr; 52 }