github.com/igggame/nebulas-go@v2.1.0+incompatible/nbre/runtime/dip/dip_impl.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 "runtime/dip/dip_impl.h" 22 #include "common/address.h" 23 #include "common/common.h" 24 #include "common/configuration.h" 25 #include "fs/blockchain/blockchain_api_test.h" 26 #include "runtime/dip/dip_handler.h" 27 #include "runtime/dip/dip_reward.h" 28 #include "runtime/nr/impl/nebulas_rank.h" 29 #include <boost/property_tree/json_parser.hpp> 30 #include <boost/property_tree/ptree.hpp> 31 32 namespace neb { 33 namespace rt { 34 namespace dip { 35 36 dip_ret_type entry_point_dip_impl(compatible_uint64_t start_block, 37 compatible_uint64_t end_block, 38 version_t version, compatible_uint64_t height, 39 const nr::nr_ret_type &nr_ret, 40 dip_float_t alpha, dip_float_t beta) { 41 42 std::unique_ptr<neb::fs::blockchain_api_base> pba; 43 if (neb::use_test_blockchain) { 44 pba = std::unique_ptr<neb::fs::blockchain_api_base>( 45 new neb::fs::blockchain_api_test()); 46 } else { 47 pba = std::unique_ptr<neb::fs::blockchain_api_base>( 48 new neb::fs::blockchain_api()); 49 } 50 nr::transaction_db_ptr_t tdb_ptr = 51 std::make_unique<neb::fs::transaction_db>(pba.get()); 52 nr::account_db_ptr_t adb_ptr = 53 std::make_unique<neb::fs::account_db>(pba.get()); 54 55 std::vector<std::pair<std::string, std::string>> meta_info; 56 meta_info.push_back( 57 std::make_pair("start_height", std::to_string(start_block))); 58 meta_info.push_back(std::make_pair("end_height", std::to_string(end_block))); 59 meta_info.push_back(std::make_pair("version", std::to_string(version))); 60 61 dip_ret_type ret; 62 std::get<0>(ret) = 1; 63 std::get<1>(ret) = meta_info_to_json(meta_info); 64 65 auto &nr_result = std::get<2>(nr_ret); 66 std::get<2>(ret) = dip_reward::get_dip_reward( 67 start_block, end_block, height, nr_result, tdb_ptr, adb_ptr, alpha, beta); 68 LOG(INFO) << "get dip reward resurned"; 69 70 std::get<3>(ret) = nr_ret; 71 LOG(INFO) << "append nr_ret to dip_ret"; 72 73 return ret; 74 } 75 76 std::string dip_param_list(compatible_uint64_t dip_start_block, 77 compatible_uint64_t dip_block_interval, 78 const std::string &dip_reward_addr, 79 const std::string &dip_coinbase_addr, version_t v) { 80 81 auto reward_addr_bytes = bytes::from_base58(dip_reward_addr); 82 auto coinbase_addr_bytes = bytes::from_base58(dip_coinbase_addr); 83 84 dip_params_t param; 85 param.set<start_block>(dip_start_block); 86 param.set<block_interval>(dip_block_interval); 87 param.set<reward_addr>(address_to_string(reward_addr_bytes)); 88 param.set<coinbase_addr>(address_to_string(coinbase_addr_bytes)); 89 param.set<p_version>(v); 90 91 LOG(INFO) << "init dip params: " << dip_start_block << ',' 92 << dip_block_interval << ',' << dip_reward_addr << ',' 93 << dip_coinbase_addr << ',' << v; 94 LOG(INFO) << "begin to seri"; 95 auto ret = param.serialize_to_string(); 96 LOG(INFO) << "seri done"; 97 return ret; 98 } 99 } // namespace dip 100 } // namespace rt 101 } // namespace neb