From 56af239e7929f4bc79f8d22faa117c12a51f065f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Bylica?= Date: Mon, 20 Mar 2017 22:25:35 +0100 Subject: [PATCH] Remove unused code --- ethminer/MinerAux.h | 1 - ethminer/main.cpp | 1 - libdevcore/Base64.cpp | 146 ------------------------------ libdevcore/CMakeLists.txt | 4 +- libdevcore/CommonIO.h | 1 - libdevcore/FileSystem.cpp | 73 --------------- libdevcore/FileSystem.h | 35 ------- libdevcore/StructuredLogger.h | 111 ----------------------- libdevcore/TransientDirectory.cpp | 66 -------------- libdevcore/TransientDirectory.h | 47 ---------- libdevcore/UndefMacros.h | 46 ---------- libethcore/Common.cpp | 1 - libethcore/Ethash.cpp | 1 - libethcore/EthashAux.cpp | 1 - 14 files changed, 2 insertions(+), 532 deletions(-) delete mode 100644 libdevcore/Base64.cpp delete mode 100644 libdevcore/FileSystem.cpp delete mode 100644 libdevcore/FileSystem.h delete mode 100644 libdevcore/StructuredLogger.h delete mode 100644 libdevcore/TransientDirectory.cpp delete mode 100644 libdevcore/TransientDirectory.h delete mode 100644 libdevcore/UndefMacros.h diff --git a/ethminer/MinerAux.h b/ethminer/MinerAux.h index fb1c4c7c1..b88f63275 100644 --- a/ethminer/MinerAux.h +++ b/ethminer/MinerAux.h @@ -33,7 +33,6 @@ #include #include -#include #include #include #include diff --git a/ethminer/main.cpp b/ethminer/main.cpp index 7b38f18c3..e3b2fb2be 100644 --- a/ethminer/main.cpp +++ b/ethminer/main.cpp @@ -35,7 +35,6 @@ #include #include #include -#include #include "MinerAux.h" using namespace std; using namespace dev; diff --git a/libdevcore/Base64.cpp b/libdevcore/Base64.cpp deleted file mode 100644 index 8ee2b29f7..000000000 --- a/libdevcore/Base64.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/* - base64.cpp and base64.h - - Copyright (C) 2004-2008 René Nyffenegger - - This source code is provided 'as-is', without any express or implied - warranty. In no event will the author be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this source code must not be misrepresented; you must not - claim that you wrote the original source code. If you use this source code - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original source code. - - 3. This notice may not be removed or altered from any source distribution. - - René Nyffenegger rene.nyffenegger@adp-gmbh.ch -*/ -/// Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c -/// Originally by René Nyffenegger, modified by some other guy and then devified by Gav Wood. - -#include "Base64.h" - -using namespace std; -using namespace dev; - -static inline bool is_base64(byte c) -{ - return (isalnum(c) || (c == '+') || (c == '/')); -} - -static inline byte find_base64_char_index(byte c) -{ - if ('A' <= c && c <= 'Z') return c - 'A'; - else if ('a' <= c && c <= 'z') return c - 'a' + 1 + find_base64_char_index('Z'); - else if ('0' <= c && c <= '9') return c - '0' + 1 + find_base64_char_index('z'); - else if (c == '+') return 1 + find_base64_char_index('9'); - else if (c == '/') return 1 + find_base64_char_index('+'); - else return 1 + find_base64_char_index('/'); -} - -string dev::toBase64(bytesConstRef _in) -{ - static const char base64_chars[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZ" - "abcdefghijklmnopqrstuvwxyz" - "0123456789+/"; - - string ret; - int i = 0; - int j = 0; - byte char_array_3[3]; - byte char_array_4[4]; - - auto buf = _in.data(); - auto bufLen = _in.size(); - - while (bufLen--) - { - char_array_3[i++] = *(buf++); - if (i == 3) - { - char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; - char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); - char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); - char_array_4[3] = char_array_3[2] & 0x3f; - - for (i = 0; i < 4; i++) - ret += base64_chars[char_array_4[i]]; - i = 0; - } - } - - if (i) - { - for (j = i; j < 3; j++) - char_array_3[j] = '\0'; - - char_array_4[0] = (char_array_3[0] & 0xfc) >> 2; - char_array_4[1] = ((char_array_3[0] & 0x03) << 4) + ((char_array_3[1] & 0xf0) >> 4); - char_array_4[2] = ((char_array_3[1] & 0x0f) << 2) + ((char_array_3[2] & 0xc0) >> 6); - char_array_4[3] = char_array_3[2] & 0x3f; - - for (j = 0; j < i + 1; j++) - ret += base64_chars[char_array_4[j]]; - - while (i++ < 3) - ret += '='; - } - - return ret; -} - -bytes dev::fromBase64(string const& encoded_string) -{ - auto in_len = encoded_string.size(); - int i = 0; - int j = 0; - int in_ = 0; - byte char_array_3[3]; - byte char_array_4[4]; - bytes ret; - - while (in_len-- && encoded_string[in_] != '=' && is_base64(encoded_string[in_])) - { - char_array_4[i++] = encoded_string[in_]; in_++; - if (i == 4) - { - for (i = 0; i < 4; i++) - char_array_4[i] = find_base64_char_index(char_array_4[i]); - - char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4); - char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2); - char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; - - for (i = 0; (i < 3); i++) - ret.push_back(char_array_3[i]); - i = 0; - } - } - - if (i) - { - for (j = i; j < 4; j++) - char_array_4[j] = 0; - - for (j = 0; j < 4; j++) - char_array_4[j] = find_base64_char_index(char_array_4[j]); - - char_array_3[0] = (char_array_4[0] << 2) + ((char_array_4[1] & 0x30) >> 4); - char_array_3[1] = ((char_array_4[1] & 0xf) << 4) + ((char_array_4[2] & 0x3c) >> 2); - char_array_3[2] = ((char_array_4[2] & 0x3) << 6) + char_array_4[3]; - - for (j = 0; j < i - 1; j++) - ret.push_back(char_array_3[j]); - } - - return ret; -} diff --git a/libdevcore/CMakeLists.txt b/libdevcore/CMakeLists.txt index 1ee3b7789..356f5a9c9 100644 --- a/libdevcore/CMakeLists.txt +++ b/libdevcore/CMakeLists.txt @@ -12,8 +12,8 @@ file(GLOB HEADERS "*.h") add_library(devcore ${SRC_LIST} ${HEADERS}) -target_link_libraries(${EXECUTABLE} ${Boost_THREAD_LIBRARIES}) -target_link_libraries(${EXECUTABLE} ${Boost_RANDOM_LIBRARIES}) +target_link_libraries(devcore ${Boost_THREAD_LIBRARIES}) +target_link_libraries(devcore ${Boost_RANDOM_LIBRARIES}) target_link_libraries(${EXECUTABLE} ${Boost_FILESYSTEM_LIBRARIES}) target_link_libraries(${EXECUTABLE} ${Boost_SYSTEM_LIBRARIES}) target_link_libraries(${EXECUTABLE} ${JSONCPP_LIBRARIES}) diff --git a/libdevcore/CommonIO.h b/libdevcore/CommonIO.h index 1b4af178e..ee880e8f1 100644 --- a/libdevcore/CommonIO.h +++ b/libdevcore/CommonIO.h @@ -37,7 +37,6 @@ #include #include #include "Common.h" -#include "Base64.h" namespace dev { diff --git a/libdevcore/FileSystem.cpp b/libdevcore/FileSystem.cpp deleted file mode 100644 index 5e19ab099..000000000 --- a/libdevcore/FileSystem.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/* - 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 FileSystem.cpp - * @authors - * Eric Lombrozo - * Gav Wood - * @date 2014 - */ - -#include "FileSystem.h" -#include "Common.h" -#include "Log.h" - -#if defined(_WIN32) -#include -#else -#include -#include -#include -#include -#endif -#include -using namespace std; -using namespace dev; - -std::string dev::getDataDir(std::string _prefix) -{ - if (_prefix.empty()) - _prefix = "ethereum"; -#ifdef _WIN32 - _prefix[0] = toupper(_prefix[0]); - char path[1024] = ""; - if (SHGetSpecialFolderPathA(NULL, path, CSIDL_APPDATA, true)) - return (boost::filesystem::path(path) / _prefix).string(); - else - { - #ifndef _MSC_VER // todo? - cwarn << "getDataDir(): SHGetSpecialFolderPathA() failed."; - #endif - BOOST_THROW_EXCEPTION(std::runtime_error("getDataDir() - SHGetSpecialFolderPathA() failed.")); - } -#else - boost::filesystem::path dataDirPath; - char const* homeDir = getenv("HOME"); - if (!homeDir || strlen(homeDir) == 0) - { - struct passwd* pwd = getpwuid(getuid()); - if (pwd) - homeDir = pwd->pw_dir; - } - - if (!homeDir || strlen(homeDir) == 0) - dataDirPath = boost::filesystem::path("/"); - else - dataDirPath = boost::filesystem::path(homeDir); - - return (dataDirPath / ("." + _prefix)).string(); -#endif -} diff --git a/libdevcore/FileSystem.h b/libdevcore/FileSystem.h deleted file mode 100644 index 6c8160a58..000000000 --- a/libdevcore/FileSystem.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - 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 FileSystem.h - * @authors - * Eric Lombrozo - * Gav Wood - * @date 2014 - */ - -#pragma once - -#include -#include - -namespace dev -{ - -/// @returns the path for user data. -std::string getDataDir(std::string _prefix = "ethereum"); - -} diff --git a/libdevcore/StructuredLogger.h b/libdevcore/StructuredLogger.h deleted file mode 100644 index 913d7b9b2..000000000 --- a/libdevcore/StructuredLogger.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - 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 StructuredLogger.h - * @author Lefteris Karapetsas - * @date 2015 - * - * A simple helper class for the structured logging - * The spec for the implemented log events is here: - * https://github.com/ethereum/system-testing/wiki/Log-Events - */ - -#pragma once - -#include -#include -#include - -namespace Json { class Value; } -namespace boost { namespace asio { namespace ip { templateclass basic_endpoint; class tcp; }}} -namespace bi = boost::asio::ip; - -namespace dev -{ - -// TODO: Make the output stream configurable. stdout, stderr, file e.t.c. -class StructuredLogger -{ -public: - /** - * Initializes the structured logger object - * @param _enabled Whether logging is on or off - * @param _timeFormat A time format string as described here: - * http://en.cppreference.com/w/cpp/chrono/c/strftime - * with which to display timestamps - */ - void initialize(bool _enabled, std::string const& _timeFormat, std::string const& _destinationURL = ""); - - static StructuredLogger& get() - { - static StructuredLogger instance; - return instance; - } - - static void starting(std::string const& _clientImpl, const char* _ethVersion); - static void stopping(std::string const& _clientImpl, const char* _ethVersion); - static void p2pConnected( - std::string const& _id, - bi::basic_endpoint const& _addr, - std::chrono::system_clock::time_point const& _ts, - std::string const& _remoteVersion, - unsigned int _numConnections - ); - static void p2pDisconnected( - std::string const& _id, - bi::basic_endpoint const& _addr, - unsigned int _numConnections - ); - static void minedNewBlock( - std::string const& _hash, - std::string const& _blockNumber, - std::string const& _chainHeadHash, - std::string const& _prevHash - ); - static void chainReceivedNewBlock( - std::string const& _hash, - std::string const& _blockNumber, - std::string const& _chainHeadHash, - std::string const& _remoteID, - std::string const& _prevHash - ); - static void chainNewHead( - std::string const& _hash, - std::string const& _blockNumber, - std::string const& _chainHeadHash, - std::string const& _prevHash - ); - static void transactionReceived(std::string const& _hash, std::string const& _remoteId); - // TODO: static void pendingQueueChanged(std::vector const& _hashes); - // TODO: static void miningStarted(); - // TODO: static void stillMining(unsigned _hashrate); - // TODO: static void miningStopped(); - -private: - // Singleton class. Private default ctor and no copying - StructuredLogger() = default; - StructuredLogger(StructuredLogger const&) = delete; - void operator=(StructuredLogger const&) = delete; - - void outputJson(Json::Value const& _value, std::string const& _name) const; - - bool m_enabled = false; - std::string m_timeFormat = "%Y-%m-%dT%H:%M:%S"; - - mutable std::ofstream m_out; -}; - -} diff --git a/libdevcore/TransientDirectory.cpp b/libdevcore/TransientDirectory.cpp deleted file mode 100644 index 106848a9d..000000000 --- a/libdevcore/TransientDirectory.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - 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 TransientDirectory.cpp - * @author Marek Kotewicz - * @date 2015 - */ - -#include -#include -#include "Exceptions.h" -#include "TransientDirectory.h" -#include "CommonIO.h" -#include "Log.h" -using namespace std; -using namespace dev; -namespace fs = boost::filesystem; - -TransientDirectory::TransientDirectory(): - TransientDirectory((boost::filesystem::temp_directory_path() / "eth_transient" / toString(FixedHash<4>::random())).string()) -{} - -TransientDirectory::TransientDirectory(std::string const& _path): - m_path(_path) -{ - // we never ever want to delete a directory (including all its contents) that we did not create ourselves. - if (boost::filesystem::exists(m_path)) - BOOST_THROW_EXCEPTION(FileError()); - - fs::create_directories(m_path); - DEV_IGNORE_EXCEPTIONS(fs::permissions(m_path, fs::owner_all)); -} - -TransientDirectory::~TransientDirectory() -{ - boost::system::error_code ec; - fs::remove_all(m_path, ec); - if (!ec) - return; - - // In some cases, antivirus runnig on Windows will scan all the newly created directories. - // As a consequence, directory is locked and can not be deleted immediately. - // Retry after 10 milliseconds usually is successful. - // This will help our tests run smoothly in such environment. - this_thread::sleep_for(chrono::milliseconds(10)); - - ec.clear(); - fs::remove_all(m_path, ec); - if (!ec) - { - cwarn << "Failed to delete directory '" << m_path << "': " << ec.message(); - } -} diff --git a/libdevcore/TransientDirectory.h b/libdevcore/TransientDirectory.h deleted file mode 100644 index 6c90982a3..000000000 --- a/libdevcore/TransientDirectory.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - 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 TransientDirectory.h - * @author Marek Kotewicz - * @date 2015 - */ - -#pragma once - -#include - -namespace dev -{ - -/** - * @brief temporary directory implementation - * It creates temporary directory in the given path. On dealloc it removes the directory - * @throws if the given path already exists, throws an exception - */ -class TransientDirectory -{ -public: - TransientDirectory(); - TransientDirectory(std::string const& _path); - ~TransientDirectory(); - - std::string const& path() const { return m_path; } - -private: - std::string m_path; -}; - -} diff --git a/libdevcore/UndefMacros.h b/libdevcore/UndefMacros.h deleted file mode 100644 index 91249523b..000000000 --- a/libdevcore/UndefMacros.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - 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 UndefMacros.h - * @author Lefteris - * @date 2015 - * - * This header should be used to #undef some really evil macros defined by - * windows.h which result in conflict with our libsolidity/Token.h - */ -#pragma once - -#if defined(_MSC_VER) || defined(__MINGW32__) - -#undef DELETE -#undef IN -#undef VOID -#undef THIS -#undef CONST - -// Conflicting define on MinGW in windows.h -// windows.h(19): #define interface struct -#ifdef interface -#undef interface -#endif - -#elif defined(DELETE) || defined(IN) || defined(VOID) || defined(THIS) || defined(CONST) || defined(interface) - -#error "The preceding macros in this header file are reserved for V8's "\ -"TOKEN_LIST. Please add a platform specific define above to undefine "\ -"overlapping macros." - -#endif diff --git a/libethcore/Common.cpp b/libethcore/Common.cpp index d9d14aa9d..1cb587817 100644 --- a/libethcore/Common.cpp +++ b/libethcore/Common.cpp @@ -21,7 +21,6 @@ #include "Common.h" #include -#include #include #include #include diff --git a/libethcore/Ethash.cpp b/libethcore/Ethash.cpp index a67343fef..3a4790561 100644 --- a/libethcore/Ethash.cpp +++ b/libethcore/Ethash.cpp @@ -32,7 +32,6 @@ #include #include #include -#include #include #include #include "BlockInfo.h" diff --git a/libethcore/EthashAux.cpp b/libethcore/EthashAux.cpp index d4467f4c3..1362e4fcc 100644 --- a/libethcore/EthashAux.cpp +++ b/libethcore/EthashAux.cpp @@ -30,7 +30,6 @@ #include #include #include -#include #include #include #include "BlockInfo.h"