github.com/igggame/nebulas-go@v2.1.0+incompatible/nbre/common/configuration.h (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 #pragma once 21 #include "common/address.h" 22 #include "common/common.h" 23 #include "util/singleton.h" 24 25 namespace neb { 26 27 struct configure_general_failure : public std::exception { 28 inline configure_general_failure(const std::string &msg) : m_msg(msg) {} 29 inline const char *what() const throw() { return m_msg.c_str(); } 30 protected: 31 std::string m_msg; 32 }; 33 34 class configuration : public util::singleton<configuration> { 35 public: 36 configuration(); 37 configuration(const configuration &cf) = delete; 38 configuration &operator=(const configuration &cf) = delete; 39 configuration(configuration &&cf) = delete; 40 ~configuration(); 41 42 inline int32_t ir_warden_time_interval() const { return 1; } 43 44 // nbre storage ir config 45 inline const char *ir_tx_payload_type() const { return "protocol"; } 46 inline const char *nbre_max_height_name() const { return "nbre_max_height"; } 47 inline const char *rt_module_name() const { return "runtime"; } 48 49 inline const char *nbre_auth_table_name() const { return "nbre_auth_table"; } 50 inline const char *auth_module_name() const { return "auth"; } 51 inline const char *auth_func_name() const { return "entry_point_auth"; } 52 53 inline const char *nbre_failed_flag_name() const { 54 return "nbre_failed_flag"; 55 } 56 57 inline const char *nr_func_name() const { return "entry_point_nr"; } 58 inline const char *dip_func_name() const { return "entry_point_dip"; } 59 60 // nbre api config 61 inline const char *ir_list_name() const { return "ir_list"; } 62 63 // dip conf 64 inline const block_height_t &dip_start_block() const { 65 return m_dip_start_block; 66 } 67 inline block_height_t &dip_start_block() { return m_dip_start_block; } 68 inline const block_height_t &dip_block_interval() const { 69 return m_dip_block_interval; 70 } 71 inline block_height_t &dip_block_interval() { return m_dip_block_interval; } 72 73 // dip reward address 74 const address_t &dip_reward_addr() const { return m_dip_reward_addr; } 75 address_t &dip_reward_addr() { return m_dip_reward_addr; } 76 77 // coinbase address 78 const address_t &coinbase_addr() const { return m_coinbase_addr; } 79 address_t &coinbase_addr() { return m_coinbase_addr; } 80 81 // shared memory name identity 82 inline const std::string &shm_name_identity() const { 83 return m_shm_name_identity; 84 } 85 inline std::string &shm_name_identity() { return m_shm_name_identity; } 86 87 // nbre root directory 88 inline const std::string &nbre_root_dir() const { return m_nbre_root_dir; } 89 inline std::string &nbre_root_dir() { return m_nbre_root_dir; } 90 91 // nbre execute path 92 inline const std::string &nbre_exe_name() const { return m_nbre_exe_name; } 93 inline std::string &nbre_exe_name() { return m_nbre_exe_name; } 94 95 // nebulas blockchain database directory 96 inline const std::string &neb_db_dir() const { return m_neb_db_dir; } 97 inline std::string &neb_db_dir() { return m_neb_db_dir; } 98 99 // nbre database directory 100 inline const std::string &nbre_db_dir() const { return m_nbre_db_dir; } 101 inline std::string &nbre_db_dir() { return m_nbre_db_dir; } 102 103 // nbre log directory 104 inline const std::string &nbre_log_dir() const { return m_nbre_log_dir; } 105 inline std::string &nbre_log_dir() { return m_nbre_log_dir; } 106 107 // nbre storage auth table admin address 108 inline const address_t &admin_pub_addr() const { return m_admin_pub_addr; } 109 inline address_t &admin_pub_addr() { return m_admin_pub_addr; } 110 111 // nbre start height 112 inline const uint64_t &nbre_start_height() const { 113 return m_nbre_start_height; 114 } 115 inline uint64_t &nbre_start_height() { return m_nbre_start_height; } 116 117 // nbre net ipc listen 118 inline const std::string &nipc_listen() const { return m_nipc_listen; } 119 inline std::string &nipc_listen() { return m_nipc_listen; } 120 121 // nbre net ipc port 122 inline const uint16_t &nipc_port() const { return m_nipc_port; } 123 inline uint16_t &nipc_port() { return m_nipc_port; } 124 125 inline const std::string &get_exit_msg(uint32_t exit_code) const { 126 assert(exit_code > 0 && exit_code < m_exit_msg_list.size()); 127 return m_exit_msg_list[exit_code - 1]; 128 }; 129 inline void set_exit_msg(const std::string &exit_msg) { 130 m_exit_msg_list.push_back(exit_msg); 131 } 132 133 protected: 134 // dip conf 135 block_height_t m_dip_start_block; 136 block_height_t m_dip_block_interval; 137 address_t m_dip_reward_addr; 138 address_t m_coinbase_addr; 139 140 // shm conf 141 std::string m_shm_name_identity; 142 143 // nbre init params conf 144 std::string m_nbre_root_dir; 145 std::string m_nbre_exe_name; 146 std::string m_neb_db_dir; 147 std::string m_nbre_db_dir; 148 std::string m_nbre_log_dir; 149 address_t m_admin_pub_addr; 150 uint64_t m_nbre_start_height; 151 std::string m_nipc_listen; 152 uint16_t m_nipc_port; 153 154 // exit code and msg list conf 155 std::vector<std::string> m_exit_msg_list; 156 }; 157 158 extern bool use_test_blockchain; 159 extern bool glog_log_to_stderr; 160 } // end namespace neb