From 46e248ed30de0e207c53bdf9c1e10f970949fb23 Mon Sep 17 00:00:00 2001 From: John Jones Date: Fri, 18 Jan 2019 13:42:21 -0500 Subject: [PATCH] Remove create-genesis-json --- libraries/app/application.cpp | 65 ++++--------------- libraries/app/application_impl.hxx | 4 +- .../app/include/graphene/app/application.hpp | 16 +---- programs/delayed_node/main.cpp | 8 +-- programs/witness_node/main.cpp | 14 +--- 5 files changed, 22 insertions(+), 85 deletions(-) diff --git a/libraries/app/application.cpp b/libraries/app/application.cpp index 6ae8dfea78..c89ec21be0 100644 --- a/libraries/app/application.cpp +++ b/libraries/app/application.cpp @@ -318,7 +318,7 @@ void application_impl::set_dbg_init_key( graphene::chain::genesis_state_type& ge genesis.initial_witness_candidates[i].block_signing_key = init_pubkey; } -uint8_t application_impl::startup() +void application_impl::startup() { try { fc::create_directories(_data_dir / "blockchain"); @@ -444,18 +444,14 @@ uint8_t application_impl::startup() if( _options->count("api-access") ) { - if(fc::exists(_options->at("api-access").as())) - { - _apiaccess = fc::json::from_file( _options->at("api-access").as() ).as( 20 ); - ilog( "Using api access file from ${path}", - ("path", _options->at("api-access").as().string()) ); - } - else - { - elog("Failed to load file from ${path}", - ("path", _options->at("api-access").as().string())); - return EXIT_FAILURE; - } + fc::path api_access_file = _options->at("api-access").as(); + + FC_ASSERT( fc::exists(api_access_file), + "Failed to load file from ${path}", ("path", api_access_file) ); + + _apiaccess = fc::json::from_file( api_access_file ).as( 20 ); + ilog( "Using api access file from ${path}", + ("path", api_access_file) ); } else { @@ -475,7 +471,6 @@ uint8_t application_impl::startup() reset_p2p_node(_data_dir); reset_websocket_server(); reset_websocket_tls_server(); - return DO_NOT_EXIT; } FC_LOG_AND_RETHROW() } optional< api_access_info > application_impl::get_api_access_info(const string& username)const @@ -986,10 +981,6 @@ void application::set_program_options(boost::program_options::options_descriptio ; command_line_options.add(configuration_file_options); command_line_options.add_options() - ("create-genesis-json", bpo::value(), - "Path to create a Genesis State at. If a well-formed JSON file exists at the path, it will be parsed and any " - "missing fields in a Genesis State will be added, and any unknown fields will be removed. If no file or an " - "invalid file is found, it will be replaced with an example Genesis State.") ("replay-blockchain", "Rebuild object graph by replaying all blocks without validation") ("revalidate-blockchain", "Rebuild object graph by replaying all blocks with full validation") ("resync-blockchain", "Delete all blocks and re-sync with network from scratch") @@ -1001,36 +992,11 @@ void application::set_program_options(boost::program_options::options_descriptio configuration_file_options.add(_cfg_options); } -uint8_t application::initialize(const fc::path& data_dir, const boost::program_options::variables_map& options) +void application::initialize(const fc::path& data_dir, const boost::program_options::variables_map& options) { my->_data_dir = data_dir; my->_options = &options; - if( options.count("create-genesis-json") ) - { - fc::path genesis_out = options.at("create-genesis-json").as(); - genesis_state_type genesis_state = detail::create_example_genesis(); - if( fc::exists(genesis_out) ) - { - try { - genesis_state = fc::json::from_file(genesis_out).as( 20 ); - } catch(const fc::exception& e) { - std::cerr << "Unable to parse existing genesis file:\n" << e.to_string() - << "\nWould you like to replace it? [y/N] "; - char response = std::cin.get(); - if( toupper(response) != 'Y' ) - return EXIT_FAILURE; - } - - std::cerr << "Updating genesis state in file " << genesis_out.generic_string() << "\n"; - } else { - std::cerr << "Creating example genesis state in file " << genesis_out.generic_string() << "\n"; - } - fc::json::save_to_file(genesis_state, genesis_out); - - return EXIT_SUCCESS; - } - if ( options.count("io-threads") ) { const uint16_t num_threads = options["io-threads"].as(); @@ -1057,19 +1023,16 @@ uint8_t application::initialize(const fc::path& data_dir, const boost::program_o if(it == "elasticsearch") ++es_ah_conflict_counter; - if(es_ah_conflict_counter > 1) { - elog("Can't start program with elasticsearch and account_history plugin at the same time"); - return EXIT_FAILURE; - } + FC_ASSERT(es_ah_conflict_counter <= 1, "Can't start program with elasticsearch and account_history plugin at the same time"); + if (!it.empty()) enable_plugin(it); } - return true; } -uint8_t application::startup() +void application::startup() { try { - return my->startup(); + my->startup(); } catch ( const fc::exception& e ) { elog( "${e}", ("e",e.to_detail_string()) ); throw; diff --git a/libraries/app/application_impl.hxx b/libraries/app/application_impl.hxx index 25f7ee9d4c..2d5d48080d 100644 --- a/libraries/app/application_impl.hxx +++ b/libraries/app/application_impl.hxx @@ -36,13 +36,13 @@ class application_impl : public net::node_delegate { } - ~application_impl() + virtual ~application_impl() { } void set_dbg_init_key( graphene::chain::genesis_state_type& genesis, const std::string& init_key ); - uint8_t startup(); + void startup(); fc::optional< api_access_info > get_api_access_info(const string& username)const; diff --git a/libraries/app/include/graphene/app/application.hpp b/libraries/app/include/graphene/app/application.hpp index 579f49fdc0..4892bb9a27 100644 --- a/libraries/app/include/graphene/app/application.hpp +++ b/libraries/app/include/graphene/app/application.hpp @@ -29,10 +29,6 @@ #include -#ifndef DO_NOT_EXIT - #define DO_NOT_EXIT 254 -#endif - namespace graphene { namespace app { namespace detail { class application_impl; } using std::string; @@ -54,17 +50,9 @@ namespace graphene { namespace app { void set_program_options( boost::program_options::options_description& command_line_options, boost::program_options::options_description& configuration_file_options )const; - /** - * Initializes the application - * @returns DO_NOT_EXIT if the calling method should continue, otherwise EXIT_SUCCESS or EXIT_FAILURE - */ - uint8_t initialize(const fc::path& data_dir, const boost::program_options::variables_map&options); + void initialize(const fc::path& data_dir, const boost::program_options::variables_map&options); void initialize_plugins( const boost::program_options::variables_map& options ); - /*** - * Performs startup - * @returns DO_NOT_EXIT if the calling method should continue, otherwise EXIT_SUCCESS or EXIT_FAILURE - */ - uint8_t startup(); + void startup(); void shutdown(); void startup_plugins(); void shutdown_plugins(); diff --git a/programs/delayed_node/main.cpp b/programs/delayed_node/main.cpp index ff2284962a..ac44686d46 100644 --- a/programs/delayed_node/main.cpp +++ b/programs/delayed_node/main.cpp @@ -163,14 +163,10 @@ int main(int argc, char** argv) { if( !options.count("plugins") ) options.insert( std::make_pair( "plugins", bpo::variable_value(std::string("delayed_node account_history market_history"), true) ) ); - uint8_t ret_val; - if ( (ret_val = node.initialize(data_dir, options)) != DO_NOT_EXIT ) - return ret_val; - + node.initialize(data_dir, options); node.initialize_plugins( options ); - if ( (ret_val = node.startup()) != DO_NOT_EXIT ) - return ret_val; + node.startup(); node.startup_plugins(); diff --git a/programs/witness_node/main.cpp b/programs/witness_node/main.cpp index dabcdd46a8..41bbce769f 100644 --- a/programs/witness_node/main.cpp +++ b/programs/witness_node/main.cpp @@ -121,20 +121,10 @@ int main(int argc, char** argv) { bpo::notify(options); - uint8_t ret_val; - if ( ( ret_val = node->initialize(data_dir, options)) != DO_NOT_EXIT ) - { - delete node; - return ret_val; - } + node->initialize(data_dir, options); node->initialize_plugins( options ); - if ( (ret_val = node->startup()) != DO_NOT_EXIT ) - { - delete node; - return ret_val; - } - + node->startup(); node->startup_plugins(); fc::promise::ptr exit_promise = new fc::promise("UNIX Signal Handler");