diff --git a/aleth-bootnode/main.cpp b/aleth-bootnode/main.cpp index 6a1f39d606d..9983bed7d84 100644 --- a/aleth-bootnode/main.cpp +++ b/aleth-bootnode/main.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include #include @@ -28,6 +29,7 @@ namespace fs = boost::filesystem; using namespace dev; using namespace dev::p2p; +using namespace dev::eth; using namespace std; namespace @@ -77,7 +79,7 @@ int main(int argc, char** argv) catch (po::error const& e) { cout << e.what() << "\n"; - return -1; + return AlethErrors::ArgumentProcessingFailure; } if (vm.count("help")) @@ -87,7 +89,7 @@ int main(int argc, char** argv) << "USAGE:\n" << " " << c_programName << " [options]\n\n"; cout << generalOptions << clientNetworking << loggingProgramOptions; - return 0; + return AlethErrors::Success; } /// Networking params. @@ -132,9 +134,27 @@ int main(int argc, char** argv) Host h(c_programName, netPrefs, &netData); h.start(); +<<<<<<< HEAD cout << "Node ID: " << h.enode() << endl; +======= + if (!h.haveNetwork()) + return AlethErrors::NetworkStartFailure; + + cout << "Node ID: " << h.enode() << endl; + + if (!noBootstrap) + { + for (auto const& bn : defaultBootNodes()) + { + bi::tcp::endpoint ep = Network::resolveHost(bn.second); + h.addNode( + bn.first, NodeIPEndpoint{ep.address(), ep.port() /* udp */, ep.port() /* tcp */}); + } + } + +>>>>>>> 08da79820... Move bootnodes list from Host to Common ExitHandler exitHandler; signal(SIGTERM, &ExitHandler::exitHandler); signal(SIGABRT, &ExitHandler::exitHandler); @@ -149,5 +169,5 @@ int main(int argc, char** argv) if (!netData.empty()) writeFile(getDataDir() / fs::path(c_networkConfigFileName), &netData); - return 0; + return AlethErrors::Success; } diff --git a/aleth-key/main.cpp b/aleth-key/main.cpp index e0efe63657b..b3cccd9b04e 100644 --- a/aleth-key/main.cpp +++ b/aleth-key/main.cpp @@ -1,23 +1,12 @@ -/* - This file is part of cpp-ethereum. - - cpp-ethereum is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - cpp-ethereum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . -*/ +// Aleth: Ethereum C++ client, tools and libraries. +// Copyright 2019 Aleth Authors. +// Licensed under the GNU General Public License, Version 3. #include "KeyAux.h" #include #include +#include #include #include @@ -40,7 +29,7 @@ void version() const auto* buildinfo = aleth_get_buildinfo(); cout << "aleth-key " << buildinfo->project_version << "\nBuild: " << buildinfo->system_name << "/" << buildinfo->build_type << endl; - exit(0); + exit(AlethErrors::Success); } int main(int argc, char** argv) @@ -73,14 +62,14 @@ int main(int argc, char** argv) catch (po::error const& e) { cerr << e.what(); - return -1; + return AlethErrors::ArgumentProcessingFailure; } for (size_t i = 0; i < unrecognisedOptions.size(); ++i) if (!m.interpretOption(i, unrecognisedOptions)) { cerr << "Invalid argument: " << unrecognisedOptions[i] << endl; - return -1; + return AlethErrors::ArgumentProcessingFailure; } if (vm.count("help")) @@ -90,7 +79,7 @@ int main(int argc, char** argv) << "Options:" << endl << endl; KeyCLI::streamHelp(cout); cout << allowedOptions; - return 0; + return AlethErrors::Success; } if (vm.count("version")) version(); @@ -99,5 +88,5 @@ int main(int argc, char** argv) m.execute(); - return 0; + return AlethErrors::Success; } \ No newline at end of file diff --git a/aleth-vm/main.cpp b/aleth-vm/main.cpp index 872e0a4ab4f..5a0fb084524 100644 --- a/aleth-vm/main.cpp +++ b/aleth-vm/main.cpp @@ -1,28 +1,13 @@ -/* - This file is part of cpp-ethereum. - - cpp-ethereum is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - cpp-ethereum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . -*/ - -/// @file -/// EVM Execution tool. +// Aleth: Ethereum C++ client, tools and libraries. +// Copyright 2019 Aleth Authors. +// Licensed under the GNU General Public License, Version 3. #include #include #include #include #include +#include #include #include #include @@ -58,7 +43,7 @@ void version() const auto* buildinfo = aleth_get_buildinfo(); cout << "aleth-vm " << buildinfo->project_version << "\n"; cout << "Build: " << buildinfo->system_name << "/" << buildinfo->build_type << "\n"; - exit(0); + exit(AlethErrors::Success); } enum class Mode @@ -191,13 +176,13 @@ int main(int argc, char** argv) else { cerr << "Unknown argument: " << arg << '\n'; - return -1; + return AlethErrors::UnknownArgument; } } if (vm.count("help")) { cout << allowedOptions; - return 0; + return AlethErrors::Success; } if (vm.count("version")) { @@ -243,7 +228,7 @@ int main(int argc, char** argv) else { cerr << "Unknown network type: " << network << "\n"; - return -1; + return AlethErrors::UnknownNetworkType; } } if (vm.count("input")) @@ -377,5 +362,5 @@ int main(int argc, char** argv) << '\n'; cout << "exec time: " << fixed << setprecision(6) << execTime << '\n'; } - return 0; + return AlethErrors::Success; } diff --git a/aleth/main.cpp b/aleth/main.cpp index 3452f3b003a..99094c8a82e 100644 --- a/aleth/main.cpp +++ b/aleth/main.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -53,6 +54,7 @@ namespace { std::atomic g_silence = {false}; +constexpr const char* c_networkConfigFileName = "network.rlp"; void version() { @@ -360,7 +362,7 @@ int main(int argc, char** argv) catch (po::error const& e) { cerr << e.what() << "\n"; - return -1; + return AlethErrors::ArgumentProcessingFailure; } miner.interpretOptions(vm); @@ -373,7 +375,7 @@ int main(int argc, char** argv) if (vm.count("version")) { version(); - return 0; + return AlethErrors::Success; } if (vm.count("test")) { @@ -419,7 +421,7 @@ int main(int argc, char** argv) if (parsingError) { cerr << "Unrecognized peerset: " << peersetStr << "\n"; - return -1; + return AlethErrors::UnrecognizedPeerset; } } @@ -445,7 +447,7 @@ int main(int argc, char** argv) } catch (...) { cerr << "Unknown --mining option: " << m << "\n"; - return -1; + return AlethErrors::UnknownMiningOption; } } if (vm.count("bootstrap")) @@ -473,13 +475,13 @@ int main(int argc, char** argv) if (configJSON.empty()) { cerr << "Config file not found or empty (" << configPath.string() << ")\n"; - return -1; + return AlethErrors::ConfigFileEmptyOrNotFound; } } catch (...) { cerr << "Bad --config option: " << vm["config"].as() << "\n"; - return -1; + return AlethErrors::BadConfigOption; } } if (vm.count("extra-data")) @@ -491,7 +493,7 @@ int main(int argc, char** argv) catch (...) { cerr << "Bad " << "--extra-data" << " option: " << vm["extra-data"].as() << "\n"; - return -1; + return AlethErrors::BadExtraDataOption; } } if (vm.count("mainnet")) @@ -513,7 +515,7 @@ int main(int argc, char** argv) catch (...) { cerr << "Bad --ask option: " << vm["ask"].as() << "\n"; - return -1; + return AlethErrors::BadAskOption; } } if (vm.count("bid")) @@ -525,7 +527,7 @@ int main(int argc, char** argv) catch (...) { cerr << "Bad --bid option: " << vm["bid"].as() << "\n"; - return -1; + return AlethErrors::BadBidOption; } } if (vm.count("listen-ip")) @@ -587,7 +589,7 @@ int main(int argc, char** argv) else { cerr << "Bad " << "--format" << " option: " << m << "\n"; - return -1; + return AlethErrors::BadFormatOption; } } if (vm.count("to")) @@ -607,7 +609,7 @@ int main(int argc, char** argv) else { cerr << "Bad " << "--upnp" << " option: " << m << "\n"; - return -1; + return AlethErrors::BadUpnpOption; } } #endif @@ -619,7 +621,7 @@ int main(int argc, char** argv) catch (...) { cerr << "Bad " << "--network-id" << " option: " << vm["network-id"].as() << "\n"; - return -1; + return AlethErrors::BadNetworkIdOption; } if (vm.count("private")) try @@ -629,7 +631,7 @@ int main(int argc, char** argv) catch (...) { cerr << "Bad " << "--private" << " option: " << vm["private"].as() << "\n"; - return -1; + return AlethErrors::BadPrivateOption; } if (vm.count("kill")) withExisting = WithExisting::Kill; @@ -645,12 +647,12 @@ int main(int argc, char** argv) catch (BadHexCharacter&) { cerr << "Bad hex in " << "--address" << " option: " << vm["address"].as() << "\n"; - return -1; + return AlethErrors::BadHexValueInAddressOption; } catch (...) { cerr << "Bad " << "--address" << " option: " << vm["address"].as() << "\n"; - return -1; + return AlethErrors::BadAddressOption; } if ((vm.count("import-secret"))) { @@ -673,7 +675,7 @@ int main(int argc, char** argv) AccountManager::streamWalletHelp(cout); cout << clientDefaultMode << clientTransacting << clientNetworking << clientMining << minerOptions; cout << importExportMode << dbOptions << vmOptions << loggingProgramOptions << generalOptions; - return 0; + return AlethErrors::Success; } if (!configJSON.empty()) @@ -687,7 +689,7 @@ int main(int argc, char** argv) { cerr << "provided configuration is not well formatted\n"; cerr << "sample: \n" << genesisInfo(eth::Network::MainNetworkTest) << "\n"; - return 0; + return AlethErrors::Success; } } @@ -757,7 +759,7 @@ int main(int argc, char** argv) netPrefs.allowLocalDiscovery = allowLocalDiscovery; netPrefs.pin = vm.count("pin") != 0; - auto nodesState = contents(getDataDir() / fs::path("network.rlp")); + auto nodesState = contents(getDataDir() / fs::path(c_networkConfigFileName)); if (testingMode) chainParams.allowFutureBlocks = true; @@ -780,7 +782,7 @@ int main(int argc, char** argv) catch (...) { cerr << "Bad block number/hash option: " << s << "\n"; - return -1; + return AlethErrors::BadBlockNumberHashOption; } }; @@ -801,7 +803,7 @@ int main(int argc, char** argv) default:; } } - return 0; + return AlethErrors::Success; } if (mode == OperationMode::Import) @@ -857,7 +859,7 @@ int main(int argc, char** argv) } double e = chrono::duration_cast(chrono::steady_clock::now() - t).count() / 1000.0; cout << imported << " imported in " << e << " seconds at " << (round(imported * 10 / e) / 10) << " blocks/s (#" << web3.ethereum()->number() << ")\n"; - return 0; + return AlethErrors::Success; } try @@ -886,7 +888,7 @@ int main(int argc, char** argv) catch(...) { cerr << "Error initializing key manager: " << boost::current_exception_diagnostic_information() << "\n"; - return -1; + return AlethErrors::KeyManagerInitializationFailure; } for (auto const& presale: presaleImports) @@ -914,7 +916,7 @@ int main(int argc, char** argv) catch (...) { cerr << "Error during importing the snapshot: " << boost::current_exception_diagnostic_information() << endl; - return -1; + return AlethErrors::SnapshotImportFailure; } } @@ -1024,7 +1026,7 @@ int main(int argc, char** argv) web3.addNode(p.first, p.second.first); if (bootstrap && privateChain.empty()) - for (auto const& i: Host::pocHosts()) + for (auto const& i : defaultBootNodes()) web3.requirePeer(i.first, i.second); if (!remoteHost.empty()) web3.addNode(p2p::NodeID(), remoteHost + ":" + toString(remotePort)); @@ -1049,7 +1051,7 @@ int main(int argc, char** argv) web3.stopNetwork(); auto netData = web3.saveNetwork(); if (!netData.empty()) - writeFile(getDataDir() / fs::path("network.rlp"), netData); + writeFile(getDataDir() / fs::path(c_networkConfigFileName), netData); } - return 0; + return AlethErrors::Success; } diff --git a/libethcore/Common.h b/libethcore/Common.h index 949327f66c4..1f959134ca9 100644 --- a/libethcore/Common.h +++ b/libethcore/Common.h @@ -1,25 +1,6 @@ -/* - This file is part of cpp-ethereum. - - cpp-ethereum is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - cpp-ethereum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . -*/ -/** @file Common.h - * @author Gav Wood - * @date 2014 - * - * Ethereum-specific data structures & algorithms. - */ +// Aleth: Ethereum C++ client, tools and libraries. +// Copyright 2019 Aleth Authors. +// Licensed under the GNU General Public License, Version 3. #pragma once @@ -236,5 +217,34 @@ enum class IfDropped Retry ///< Import transaction even if it was dropped before. }; +/// Errors returned from main +enum AlethErrors +{ + Success = 0, + UnrecognizedPeerset, + ArgumentProcessingFailure, + UnknownArgument, + UnknownMiningOption, + ConfigFileEmptyOrNotFound, + UnknownNetworkType, + BadNetworkIdOption, + BadConfigOption, + BadExtraDataOption, + BadAskOption, + BadBidOption, + BadFormatOption, + BadUpnpOption, + BadPrivateOption, + BadAddressOption, + BadHexValueInAddressOption, + BadBlockNumberHashOption, + KeyManagerInitializationFailure, + SnapshotImportFailure, + NetworkStartFailure, + BadRlp, + RlpDataNotAList, + UnsupportedJsonType, + InvalidJson +}; } } diff --git a/rlp/main.cpp b/rlp/main.cpp index d29bdafec6d..f98047daaad 100644 --- a/rlp/main.cpp +++ b/rlp/main.cpp @@ -1,40 +1,26 @@ -/* - This file is part of cpp-ethereum. +// Aleth: Ethereum C++ client, tools and libraries. +// Copyright 2019 Aleth Authors. +// Licensed under the GNU General Public License, Version 3. - cpp-ethereum is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - cpp-ethereum is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with cpp-ethereum. If not, see . -*/ -/** @file main.cpp - * @author Gav Wood - * @date 2014 - * RLP tool. - */ -#include -#include -#include -#include -#include -#include -#include #include +#include #include #include #include #include #include -#include +#include +#include +#include +#include +#include +#include +#include +#include using namespace std; using namespace dev; +using namespace dev::eth; + namespace js = json_spirit; namespace po = boost::program_options; @@ -204,7 +190,7 @@ int main(int argc, char** argv) catch (po::error const& e) { cerr << e.what(); - return -1; + return AlethErrors::ArgumentProcessingFailure; } @@ -234,7 +220,7 @@ int main(int argc, char** argv) << " extract [ | -- ] Extract all items in the RLP list, named by hash." << endl << " assemble [ | ] ... Given a manifest & files, output the RLP." << endl << renderOptions << generalOptions; - exit(0); + exit(AlethErrors::Success); } if (vm.count("lenience")) lenience = true; @@ -335,17 +321,17 @@ int main(int argc, char** argv) { if (!rlp.isList()) { - cout << "Error: Invalid format; RLP data is not a list." << endl; - exit(1); + cerr << "Error: Invalid format; RLP data is not a list." << endl; + exit(AlethErrors::BadRlp); } cout << rlp.itemCount() << " items:" << endl; for (auto i: rlp) { if (!i.isData()) { - cout << "Error: Invalid format; RLP list item is not data." << endl; + cerr << "Error: Invalid format; RLP list item is not data." << endl; if (!lenience) - exit(1); + exit(AlethErrors::BadRlp); } cout << " " << i.size() << " bytes: " << sha3(i.data()) << endl; } @@ -355,17 +341,17 @@ int main(int argc, char** argv) { if (!rlp.isList()) { - cout << "Error: Invalid format; RLP data is not a list." << endl; - exit(1); + cerr << "Error: Invalid format; RLP data is not a list." << endl; + exit(AlethErrors::BadRlp); } cout << rlp.itemCount() << " items:" << endl; for (auto i: rlp) { if (!i.isData()) { - cout << "Error: Invalid format; RLP list item is not data." << endl; + cerr << "Error: Invalid format; RLP list item is not data." << endl; if (!lenience) - exit(1); + exit(AlethErrors::BadRlp); } ofstream fout; fout.open(toString(sha3(i.data()))); @@ -439,7 +425,7 @@ int main(int argc, char** argv) catch (...) { cerr << "Error: Invalid format; bad JSON." << endl; - exit(1); + exit(AlethErrors::InvalidJson); } RLPStream out; while (!v.empty()) @@ -484,7 +470,7 @@ int main(int argc, char** argv) default: cerr << "ERROR: Unsupported type in JSON." << endl; if (!lenience) - exit(1); + exit(AlethErrors::UnsupportedJsonType); } } putOut(out.out(), encoding, encrypt, quiet); @@ -496,8 +482,8 @@ int main(int argc, char** argv) catch (...) { cerr << "Error: Invalid format; bad RLP." << endl; - exit(1); + exit(AlethErrors::BadRlp); } - return 0; + return AlethErrors::Success; }