diff --git a/CMakeLists.txt b/CMakeLists.txt index 57f018dba..f351ae4a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -197,6 +197,7 @@ add_custom_target(BuildInfo.h ALL COMMAND bash ${CMAKE_CURRENT_SOURCE_DIR}/Build include_directories(${CMAKE_CURRENT_BINARY_DIR}) add_subdirectory(secp256k1) +add_subdirectory(libethcore) add_subdirectory(libethereum) add_subdirectory(test) add_subdirectory(eth) diff --git a/alethzero/CMakeLists.txt b/alethzero/CMakeLists.txt index 35bfa1f14..8ff762dda 100644 --- a/alethzero/CMakeLists.txt +++ b/alethzero/CMakeLists.txt @@ -9,6 +9,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) aux_source_directory(. SRC_LIST) include_directories(..) +link_directories(../libethcore) link_directories(../libethereum) link_directories(../libqethereum) diff --git a/alethzero/MainWin.h b/alethzero/MainWin.h index 162ae53a8..7e281c8c8 100644 --- a/alethzero/MainWin.h +++ b/alethzero/MainWin.h @@ -6,9 +6,9 @@ #include #include #include +#include #include #include -#include #include namespace Ui { diff --git a/eth/CMakeLists.txt b/eth/CMakeLists.txt index 6eea3b053..009dc3d47 100644 --- a/eth/CMakeLists.txt +++ b/eth/CMakeLists.txt @@ -2,7 +2,8 @@ cmake_policy(SET CMP0015 NEW) aux_source_directory(. SRC_LIST) -include_directories(../libethereum) +include_directories(..) +link_directories(../libethcore) link_directories(../libethereum) add_executable(eth ${SRC_LIST}) diff --git a/eth/main.cpp b/eth/main.cpp index cd58726a2..528efc4e2 100644 --- a/eth/main.cpp +++ b/eth/main.cpp @@ -24,13 +24,13 @@ #include #include #include -#include "Defaults.h" -#include "Client.h" -#include "PeerNetwork.h" -#include "BlockChain.h" -#include "State.h" -#include "FileSystem.h" -#include "Instruction.h" +#include +#include +#include +#include +#include +#include +#include #include "BuildInfo.h" using namespace std; using namespace eth; diff --git a/libethcore/CMakeLists.txt b/libethcore/CMakeLists.txt new file mode 100644 index 000000000..51376a3e6 --- /dev/null +++ b/libethcore/CMakeLists.txt @@ -0,0 +1,73 @@ +cmake_policy(SET CMP0015 NEW) + +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSTATICLIB") + +aux_source_directory(. SRC_LIST) + +set(EXECUTABLE ethcore) + +if(APPLE) + # set(CMAKE_INSTALL_PREFIX ../lib) + add_library(${EXECUTABLE} SHARED ${SRC_LIST}) +else() + add_library(${EXECUTABLE} ${SRC_LIST}) +endif() +if (UNIX) + FIND_PACKAGE(Boost 1.53 REQUIRED COMPONENTS thread date_time system filesystem program_options signals serialization chrono unit_test_framework locale) +endif() +file(GLOB HEADERS "*.h") + +include_directories(..) + +target_link_libraries(${EXECUTABLE} secp256k1) +target_link_libraries(${EXECUTABLE} miniupnpc) +target_link_libraries(${EXECUTABLE} leveldb) +target_link_libraries(${EXECUTABLE} gmp) + + +if(${TARGET_PLATFORM} STREQUAL "w64") + include_directories(/usr/x86_64-w64-mingw32/include/cryptopp) + target_link_libraries(${EXECUTABLE} cryptopp) + target_link_libraries(${EXECUTABLE} boost_system-mt-s) + target_link_libraries(${EXECUTABLE} boost_filesystem-mt-s) + target_link_libraries(${EXECUTABLE} boost_thread_win32-mt-s) + target_link_libraries(${EXECUTABLE} iphlpapi) + target_link_libraries(${EXECUTABLE} ws2_32) + target_link_libraries(${EXECUTABLE} mswsock) + target_link_libraries(${EXECUTABLE} shlwapi) +elseif (APPLE) + # Latest mavericks boost libraries only come with -mt + target_link_libraries(${EXECUTABLE} ${CRYPTOPP_LIBRARIES}) + target_link_libraries(${EXECUTABLE} boost_system-mt) + target_link_libraries(${EXECUTABLE} boost_filesystem-mt) + target_link_libraries(${EXECUTABLE} boost_thread-mt) + find_package(Threads REQUIRED) + target_link_libraries(${EXECUTABLE} ${CMAKE_THREAD_LIBS_INIT}) +elseif (UNIX) + target_link_libraries(${EXECUTABLE} ${CRYPTOPP_LIBRARIES}) + target_link_libraries(${EXECUTABLE} ${Boost_SYSTEM_LIBRARY}) + target_link_libraries(${EXECUTABLE} ${Boost_FILESYSTEM_LIBRARY}) + target_link_libraries(${EXECUTABLE} ${Boost_THREAD_LIBRARY}) + target_link_libraries(${EXECUTABLE} ${Boost_DATE_TIME_LIBRARY}) + target_link_libraries(${EXECUTABLE} leveldb) +# target_link_libraries(${EXECUTABLE} snappy) + target_link_libraries(${EXECUTABLE} ${CMAKE_THREAD_LIBS_INIT}) +else () + target_link_libraries(${EXECUTABLE} ${CRYPTOPP_LIBRARIES}) + target_link_libraries(${EXECUTABLE} boost_system) + target_link_libraries(${EXECUTABLE} boost_filesystem) + target_link_libraries(${EXECUTABLE} boost_thread) + find_package(Threads REQUIRED) + target_link_libraries(${EXECUTABLE} ${CMAKE_THREAD_LIBS_INIT}) +endif () + +if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + link_directories(/usr/local/lib) + include_directories(/usr/local/include) +endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") + +message("Installation path: ${CMAKE_INSTALL_PREFIX}") + +install( TARGETS ${EXECUTABLE} ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) +install( FILES ${HEADERS} DESTINATION include/${EXECUTABLE} ) + diff --git a/libethereum/Common.cpp b/libethcore/Common.cpp similarity index 100% rename from libethereum/Common.cpp rename to libethcore/Common.cpp diff --git a/libethereum/Common.h b/libethcore/Common.h similarity index 100% rename from libethereum/Common.h rename to libethcore/Common.h diff --git a/libethereum/CommonData.cpp b/libethcore/CommonData.cpp similarity index 100% rename from libethereum/CommonData.cpp rename to libethcore/CommonData.cpp diff --git a/libethereum/CommonData.h b/libethcore/CommonData.h similarity index 100% rename from libethereum/CommonData.h rename to libethcore/CommonData.h diff --git a/libethereum/CommonIO.cpp b/libethcore/CommonIO.cpp similarity index 100% rename from libethereum/CommonIO.cpp rename to libethcore/CommonIO.cpp diff --git a/libethereum/CommonIO.h b/libethcore/CommonIO.h similarity index 100% rename from libethereum/CommonIO.h rename to libethcore/CommonIO.h diff --git a/libethereum/CryptoHeaders.h b/libethcore/CryptoHeaders.h similarity index 97% rename from libethereum/CryptoHeaders.h rename to libethcore/CryptoHeaders.h index 9e8add0b6..4ff63f1d7 100644 --- a/libethereum/CryptoHeaders.h +++ b/libethcore/CryptoHeaders.h @@ -31,6 +31,6 @@ #include #include #include -#include +#include #pragma warning(pop) #pragma GCC diagnostic pop diff --git a/libethcore/Exceptions.h b/libethcore/Exceptions.h new file mode 100644 index 000000000..a15dcafba --- /dev/null +++ b/libethcore/Exceptions.h @@ -0,0 +1,27 @@ +#pragma once + +#include +#include "CommonIO.h" +#include "CommonData.h" +#include "FixedHash.h" + +namespace eth +{ + +class Exception: public std::exception +{ +public: + virtual std::string description() const { return typeid(*this).name(); } + virtual char const* what() const noexcept { return typeid(*this).name(); } +}; + +class BadHexCharacter: public Exception {}; + +class RLPException: public Exception {}; +class BadCast: public RLPException {}; +class BadRLP: public RLPException {}; +class NoNetworking: public Exception {}; +class NoUPnPDevice: public Exception {}; +class RootNotFound: public Exception {}; + +} diff --git a/libethereum/FileSystem.cpp b/libethcore/FileSystem.cpp similarity index 100% rename from libethereum/FileSystem.cpp rename to libethcore/FileSystem.cpp diff --git a/libethereum/FileSystem.h b/libethcore/FileSystem.h similarity index 100% rename from libethereum/FileSystem.h rename to libethcore/FileSystem.h diff --git a/libethcore/FixedHash.cpp b/libethcore/FixedHash.cpp new file mode 100644 index 000000000..bcb9af804 --- /dev/null +++ b/libethcore/FixedHash.cpp @@ -0,0 +1,65 @@ +/* + 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 FixedHash.cpp + * @author Gav Wood + * @date 2014 + */ + +#include "FixedHash.h" +#include "CryptoHeaders.h" + +using namespace std; +using namespace eth; + +std::string eth::sha3(std::string const& _input, bool _hex) +{ + if (!_hex) + { + string ret(32, '\0'); + sha3(bytesConstRef((byte const*)_input.data(), _input.size()), bytesRef((byte*)ret.data(), 32)); + return ret; + } + + uint8_t buf[32]; + sha3(bytesConstRef((byte const*)_input.data(), _input.size()), bytesRef((byte*)&(buf[0]), 32)); + std::string ret(64, '\0'); + for (unsigned int i = 0; i < 32; i++) + sprintf((char*)(ret.data())+i*2, "%02x", buf[i]); + return ret; +} + +void eth::sha3(bytesConstRef _input, bytesRef _output) +{ + CryptoPP::SHA3_256 ctx; + ctx.Update((byte*)_input.data(), _input.size()); + assert(_output.size() >= 32); + ctx.Final(_output.data()); +} + +bytes eth::sha3Bytes(bytesConstRef _input) +{ + bytes ret(32); + sha3(_input, &ret); + return ret; +} + +h256 eth::sha3(bytesConstRef _input) +{ + h256 ret; + sha3(_input, bytesRef(&ret[0], 32)); + return ret; +} diff --git a/libethereum/FixedHash.h b/libethcore/FixedHash.h similarity index 83% rename from libethereum/FixedHash.h rename to libethcore/FixedHash.h index 34dc26418..ab5b7ac78 100644 --- a/libethereum/FixedHash.h +++ b/libethcore/FixedHash.h @@ -186,6 +186,32 @@ inline h160 left160(h256 const& _t) return ret; } +// SHA-3 convenience routines. + +/// Calculate SHA3-256 hash of the given input and load it into the given output. +void sha3(bytesConstRef _input, bytesRef _output); + +/// Calculate SHA3-256 hash of the given input, possibly interpreting it as nibbles, and return the hash as a string filled with binary data. +std::string sha3(std::string const& _input, bool _isNibbles); + +/// Calculate SHA3-256 hash of the given input, returning as a byte array. +bytes sha3Bytes(bytesConstRef _input); + +/// Calculate SHA3-256 hash of the given input (presented as a binary string), returning as a byte array. +inline bytes sha3Bytes(std::string const& _input) { return sha3Bytes((std::string*)&_input); } + +/// Calculate SHA3-256 hash of the given input, returning as a byte array. +inline bytes sha3Bytes(bytes const& _input) { return sha3Bytes((bytes*)&_input); } + +/// Calculate SHA3-256 hash of the given input, returning as a 256-bit hash. +h256 sha3(bytesConstRef _input); + +/// Calculate SHA3-256 hash of the given input, returning as a 256-bit hash. +inline h256 sha3(bytes const& _input) { return sha3(bytesConstRef((bytes*)&_input)); } + +/// Calculate SHA3-256 hash of the given input (presented as a binary-filled string), returning as a 256-bit hash. +inline h256 sha3(std::string const& _input) { return sha3(bytesConstRef(_input)); } + } namespace std diff --git a/libethereum/Log.cpp b/libethcore/Log.cpp similarity index 100% rename from libethereum/Log.cpp rename to libethcore/Log.cpp diff --git a/libethereum/Log.h b/libethcore/Log.h similarity index 100% rename from libethereum/Log.h rename to libethcore/Log.h diff --git a/libethereum/RLP.cpp b/libethcore/RLP.cpp similarity index 100% rename from libethereum/RLP.cpp rename to libethcore/RLP.cpp diff --git a/libethereum/RLP.h b/libethcore/RLP.h similarity index 99% rename from libethereum/RLP.h rename to libethcore/RLP.h index 29783e1e9..e41ffd92a 100644 --- a/libethereum/RLP.h +++ b/libethcore/RLP.h @@ -31,6 +31,7 @@ #include "vector_ref.h" #include "Common.h" #include "Exceptions.h" +#include "FixedHash.h" namespace eth { diff --git a/libethereum/TrieCommon.cpp b/libethcore/TrieCommon.cpp similarity index 100% rename from libethereum/TrieCommon.cpp rename to libethcore/TrieCommon.cpp diff --git a/libethereum/TrieCommon.h b/libethcore/TrieCommon.h similarity index 100% rename from libethereum/TrieCommon.h rename to libethcore/TrieCommon.h diff --git a/libethereum/TrieDB.cpp b/libethcore/TrieDB.cpp similarity index 100% rename from libethereum/TrieDB.cpp rename to libethcore/TrieDB.cpp diff --git a/libethereum/TrieDB.h b/libethcore/TrieDB.h similarity index 99% rename from libethereum/TrieDB.h rename to libethcore/TrieDB.h index 97be0c278..db7d89634 100644 --- a/libethereum/TrieDB.h +++ b/libethcore/TrieDB.h @@ -23,8 +23,7 @@ #include #include -#include "Exceptions.h" -#include "CommonEth.h" +#include "Common.h" #include "Log.h" #include "TrieCommon.h" namespace ldb = leveldb; diff --git a/libethereum/UPnP.cpp b/libethcore/UPnP.cpp similarity index 100% rename from libethereum/UPnP.cpp rename to libethcore/UPnP.cpp index bcf769c0a..292444fc6 100644 --- a/libethereum/UPnP.cpp +++ b/libethcore/UPnP.cpp @@ -25,9 +25,9 @@ #include #include #include +#include "Exceptions.h" #include "Common.h" #include "Log.h" -#include "Exceptions.h" #include "UPnP.h" using namespace std; using namespace eth; diff --git a/libethereum/UPnP.h b/libethcore/UPnP.h similarity index 100% rename from libethereum/UPnP.h rename to libethcore/UPnP.h diff --git a/libethereum/vector_ref.h b/libethcore/vector_ref.h similarity index 100% rename from libethereum/vector_ref.h rename to libethcore/vector_ref.h diff --git a/libethereum/AddressState.h b/libethereum/AddressState.h index d4f37c555..154858e07 100644 --- a/libethereum/AddressState.h +++ b/libethereum/AddressState.h @@ -21,8 +21,8 @@ #pragma once -#include "Common.h" -#include "RLP.h" +#include +#include namespace eth { diff --git a/libethereum/BlockChain.cpp b/libethereum/BlockChain.cpp index d28474a9d..4fe68764e 100644 --- a/libethereum/BlockChain.cpp +++ b/libethereum/BlockChain.cpp @@ -22,13 +22,13 @@ #include "BlockChain.h" #include -#include "Common.h" -#include "RLP.h" +#include +#include +#include #include "Exceptions.h" #include "Dagger.h" #include "BlockInfo.h" #include "State.h" -#include "FileSystem.h" #include "Defaults.h" using namespace std; using namespace eth; diff --git a/libethereum/BlockChain.h b/libethereum/BlockChain.h index 4c1500b06..4c6f80d42 100644 --- a/libethereum/BlockChain.h +++ b/libethereum/BlockChain.h @@ -22,8 +22,8 @@ #pragma once #include +#include #include "CommonEth.h" -#include "Log.h" #include "AddressState.h" namespace ldb = leveldb; diff --git a/libethereum/BlockInfo.cpp b/libethereum/BlockInfo.cpp index 9e9ca48c8..56d98a9f0 100644 --- a/libethereum/BlockInfo.cpp +++ b/libethereum/BlockInfo.cpp @@ -19,10 +19,10 @@ * @date 2014 */ -#include "Common.h" +#include +#include #include "Dagger.h" #include "Exceptions.h" -#include "RLP.h" #include "State.h" #include "BlockInfo.h" using namespace std; diff --git a/libethereum/BlockInfo.h b/libethereum/BlockInfo.h index 28685d2d4..8b6fc3308 100644 --- a/libethereum/BlockInfo.h +++ b/libethereum/BlockInfo.h @@ -21,7 +21,7 @@ #pragma once -#include "Common.h" +#include #include "Transaction.h" namespace eth diff --git a/libethereum/CMakeLists.txt b/libethereum/CMakeLists.txt index bbbef8432..3cbdc2bed 100644 --- a/libethereum/CMakeLists.txt +++ b/libethereum/CMakeLists.txt @@ -4,59 +4,62 @@ set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSTATICLIB") aux_source_directory(. SRC_LIST) +set(EXECUTABLE ethereum) + if(APPLE) # set(CMAKE_INSTALL_PREFIX ../lib) - add_library(ethereum SHARED ${SRC_LIST}) + add_library(${EXECUTABLE} SHARED ${SRC_LIST}) else() - add_library(ethereum ${SRC_LIST}) + add_library(${EXECUTABLE} ${SRC_LIST}) endif() if (UNIX) FIND_PACKAGE(Boost 1.53 REQUIRED COMPONENTS thread date_time system filesystem program_options signals serialization chrono unit_test_framework locale) endif() file(GLOB HEADERS "*.h") -include_directories(../secp256k1) +include_directories(..) -target_link_libraries(ethereum secp256k1) -target_link_libraries(ethereum miniupnpc) -target_link_libraries(ethereum leveldb) -target_link_libraries(ethereum gmp) +target_link_libraries(${EXECUTABLE} ethcore) +target_link_libraries(${EXECUTABLE} secp256k1) +target_link_libraries(${EXECUTABLE} miniupnpc) +target_link_libraries(${EXECUTABLE} leveldb) +target_link_libraries(${EXECUTABLE} gmp) if(${TARGET_PLATFORM} STREQUAL "w64") include_directories(/usr/x86_64-w64-mingw32/include/cryptopp) - target_link_libraries(ethereum cryptopp) - target_link_libraries(ethereum boost_system-mt-s) - target_link_libraries(ethereum boost_filesystem-mt-s) - target_link_libraries(ethereum boost_thread_win32-mt-s) - target_link_libraries(ethereum iphlpapi) - target_link_libraries(ethereum ws2_32) - target_link_libraries(ethereum mswsock) - target_link_libraries(ethereum shlwapi) + target_link_libraries(${EXECUTABLE} cryptopp) + target_link_libraries(${EXECUTABLE} boost_system-mt-s) + target_link_libraries(${EXECUTABLE} boost_filesystem-mt-s) + target_link_libraries(${EXECUTABLE} boost_thread_win32-mt-s) + target_link_libraries(${EXECUTABLE} iphlpapi) + target_link_libraries(${EXECUTABLE} ws2_32) + target_link_libraries(${EXECUTABLE} mswsock) + target_link_libraries(${EXECUTABLE} shlwapi) elseif (APPLE) # Latest mavericks boost libraries only come with -mt - target_link_libraries(ethereum ${CRYPTOPP_LIBRARIES}) - target_link_libraries(ethereum boost_system-mt) - target_link_libraries(ethereum boost_filesystem-mt) - target_link_libraries(ethereum boost_thread-mt) + target_link_libraries(${EXECUTABLE} ${CRYPTOPP_LIBRARIES}) + target_link_libraries(${EXECUTABLE} boost_system-mt) + target_link_libraries(${EXECUTABLE} boost_filesystem-mt) + target_link_libraries(${EXECUTABLE} boost_thread-mt) find_package(Threads REQUIRED) - target_link_libraries(ethereum ${CMAKE_THREAD_LIBS_INIT}) + target_link_libraries(${EXECUTABLE} ${CMAKE_THREAD_LIBS_INIT}) elseif (UNIX) - target_link_libraries(ethereum ${CRYPTOPP_LIBRARIES}) - target_link_libraries(ethereum ${Boost_SYSTEM_LIBRARY}) - target_link_libraries(ethereum ${Boost_FILESYSTEM_LIBRARY}) - target_link_libraries(ethereum ${Boost_THREAD_LIBRARY}) - target_link_libraries(ethereum ${Boost_DATE_TIME_LIBRARY}) - target_link_libraries(ethereum leveldb) -# target_link_libraries(ethereum snappy) - target_link_libraries(ethereum ${CMAKE_THREAD_LIBS_INIT}) + target_link_libraries(${EXECUTABLE} ${CRYPTOPP_LIBRARIES}) + target_link_libraries(${EXECUTABLE} ${Boost_SYSTEM_LIBRARY}) + target_link_libraries(${EXECUTABLE} ${Boost_FILESYSTEM_LIBRARY}) + target_link_libraries(${EXECUTABLE} ${Boost_THREAD_LIBRARY}) + target_link_libraries(${EXECUTABLE} ${Boost_DATE_TIME_LIBRARY}) + target_link_libraries(${EXECUTABLE} leveldb) +# target_link_libraries(${EXECUTABLE} snappy) + target_link_libraries(${EXECUTABLE} ${CMAKE_THREAD_LIBS_INIT}) else () - target_link_libraries(ethereum ${CRYPTOPP_LIBRARIES}) - target_link_libraries(ethereum boost_system) - target_link_libraries(ethereum boost_filesystem) - target_link_libraries(ethereum boost_thread) + target_link_libraries(${EXECUTABLE} ${CRYPTOPP_LIBRARIES}) + target_link_libraries(${EXECUTABLE} boost_system) + target_link_libraries(${EXECUTABLE} boost_filesystem) + target_link_libraries(${EXECUTABLE} boost_thread) find_package(Threads REQUIRED) - target_link_libraries(ethereum ${CMAKE_THREAD_LIBS_INIT}) + target_link_libraries(${EXECUTABLE} ${CMAKE_THREAD_LIBS_INIT}) endif () if(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") @@ -66,6 +69,6 @@ endif(${CMAKE_SYSTEM_NAME} MATCHES "Darwin") message("Installation path: ${CMAKE_INSTALL_PREFIX}") -install( TARGETS ethereum ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) -install( FILES ${HEADERS} DESTINATION include/ethereum ) +install( TARGETS ${EXECUTABLE} ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) +install( FILES ${HEADERS} DESTINATION include/${EXECUTABLE} ) diff --git a/libethereum/Client.cpp b/libethereum/Client.cpp index b4c06279b..c19efbe8d 100644 --- a/libethereum/Client.cpp +++ b/libethereum/Client.cpp @@ -24,7 +24,7 @@ #include #include #include -#include "Common.h" +#include #include "Defaults.h" #include "PeerServer.h" using namespace std; diff --git a/libethereum/Client.h b/libethereum/Client.h index c7a87cf96..0089b8a23 100644 --- a/libethereum/Client.h +++ b/libethereum/Client.h @@ -24,7 +24,7 @@ #include #include #include -#include "Common.h" +#include #include "BlockChain.h" #include "TransactionQueue.h" #include "State.h" diff --git a/libethereum/CommonEth.cpp b/libethereum/CommonEth.cpp index 414be0aac..a6f7a09bc 100644 --- a/libethereum/CommonEth.cpp +++ b/libethereum/CommonEth.cpp @@ -20,9 +20,9 @@ */ #include "CommonEth.h" -#include "CryptoHeaders.h" -#include "Exceptions.h" #include +#include +#include "Exceptions.h" using namespace std; using namespace eth; @@ -148,42 +148,3 @@ KeyPair::KeyPair(h256 _sec): cout << "ADR: " << m_address << endl; #endif } - -std::string eth::sha3(std::string const& _input, bool _hex) -{ - if (!_hex) - { - string ret(32, '\0'); - sha3(bytesConstRef((byte const*)_input.data(), _input.size()), bytesRef((byte*)ret.data(), 32)); - return ret; - } - - uint8_t buf[32]; - sha3(bytesConstRef((byte const*)_input.data(), _input.size()), bytesRef((byte*)&(buf[0]), 32)); - std::string ret(64, '\0'); - for (unsigned int i = 0; i < 32; i++) - sprintf((char*)(ret.data())+i*2, "%02x", buf[i]); - return ret; -} - -void eth::sha3(bytesConstRef _input, bytesRef _output) -{ - CryptoPP::SHA3_256 ctx; - ctx.Update((byte*)_input.data(), _input.size()); - assert(_output.size() >= 32); - ctx.Final(_output.data()); -} - -bytes eth::sha3Bytes(bytesConstRef _input) -{ - bytes ret(32); - sha3(_input, &ret); - return ret; -} - -h256 eth::sha3(bytesConstRef _input) -{ - h256 ret; - sha3(_input, bytesRef(&ret[0], 32)); - return ret; -} diff --git a/libethereum/CommonEth.h b/libethereum/CommonEth.h index 33b8e8bb8..fd9b7a0ac 100644 --- a/libethereum/CommonEth.h +++ b/libethereum/CommonEth.h @@ -23,8 +23,8 @@ #pragma once -#include "Common.h" -#include "FixedHash.h" +#include +#include namespace eth { @@ -110,31 +110,4 @@ private: Address m_address; }; - -// SHA-3 convenience routines. - -/// Calculate SHA3-256 hash of the given input and load it into the given output. -void sha3(bytesConstRef _input, bytesRef _output); - -/// Calculate SHA3-256 hash of the given input, possibly interpreting it as nibbles, and return the hash as a string filled with binary data. -std::string sha3(std::string const& _input, bool _isNibbles); - -/// Calculate SHA3-256 hash of the given input, returning as a byte array. -bytes sha3Bytes(bytesConstRef _input); - -/// Calculate SHA3-256 hash of the given input (presented as a binary string), returning as a byte array. -inline bytes sha3Bytes(std::string const& _input) { return sha3Bytes((std::string*)&_input); } - -/// Calculate SHA3-256 hash of the given input, returning as a byte array. -inline bytes sha3Bytes(bytes const& _input) { return sha3Bytes((bytes*)&_input); } - -/// Calculate SHA3-256 hash of the given input, returning as a 256-bit hash. -h256 sha3(bytesConstRef _input); - -/// Calculate SHA3-256 hash of the given input, returning as a 256-bit hash. -inline h256 sha3(bytes const& _input) { return sha3(bytesConstRef((bytes*)&_input)); } - -/// Calculate SHA3-256 hash of the given input (presented as a binary-filled string), returning as a 256-bit hash. -inline h256 sha3(std::string const& _input) { return sha3(bytesConstRef(_input)); } - } diff --git a/libethereum/Dagger.cpp b/libethereum/Dagger.cpp index 31ddbd1bd..9b22a3cb3 100644 --- a/libethereum/Dagger.cpp +++ b/libethereum/Dagger.cpp @@ -23,8 +23,8 @@ #include #include #include -#include "CryptoHeaders.h" -#include "Common.h" +#include +#include #include "Dagger.h" using namespace std; using namespace std::chrono; diff --git a/libethereum/Dagger.h b/libethereum/Dagger.h index ec12ae193..af919ca49 100644 --- a/libethereum/Dagger.h +++ b/libethereum/Dagger.h @@ -23,7 +23,6 @@ #pragma once -#include "FixedHash.h" #include "CommonEth.h" #define FAKE_DAGGER 1 diff --git a/libethereum/Defaults.cpp b/libethereum/Defaults.cpp index 477bb87a7..e78156094 100644 --- a/libethereum/Defaults.cpp +++ b/libethereum/Defaults.cpp @@ -21,7 +21,7 @@ #include "Defaults.h" -#include "FileSystem.h" +#include using namespace std; using namespace eth; diff --git a/libethereum/Defaults.h b/libethereum/Defaults.h index 0d8e84515..e3b091f13 100644 --- a/libethereum/Defaults.h +++ b/libethereum/Defaults.h @@ -21,7 +21,7 @@ #pragma once -#include "Common.h" +#include namespace eth { diff --git a/libethereum/Exceptions.h b/libethereum/Exceptions.h index 49505b247..bdbbee75a 100644 --- a/libethereum/Exceptions.h +++ b/libethereum/Exceptions.h @@ -1,27 +1,10 @@ #pragma once -#include -#include "CommonIO.h" -#include "CommonData.h" -#include "FixedHash.h" +#include namespace eth { -class Exception: public std::exception -{ -public: - virtual std::string description() const { return typeid(*this).name(); } - virtual char const* what() const noexcept { return typeid(*this).name(); } -}; - -class BadHexCharacter: public Exception {}; -class NotEnoughCash: public Exception {}; - -class RLPException: public Exception {}; -class BadCast: public RLPException {}; -class BadRLP: public RLPException {}; - class VMException: public Exception {}; class StepsDone: public VMException {}; class BreakPointHit: public VMException {}; @@ -30,6 +13,8 @@ class OutOfGas: public VMException {}; class StackTooSmall: public VMException { public: StackTooSmall(u256 _req, u256 _got): req(_req), got(_got) {} u256 req; u256 got; }; class OperandOutOfRange: public VMException { public: OperandOutOfRange(u256 _min, u256 _max, u256 _got): mn(_min), mx(_max), got(_got) {} u256 mn; u256 mx; u256 got; }; +class NotEnoughCash: public Exception {}; + class GasPriceTooLow: public Exception {}; class NoSuchContract: public Exception {}; class ContractAddressCollision: public Exception {}; @@ -49,8 +34,5 @@ class InvalidNonce: public Exception { public: InvalidNonce(u256 _required = 0, class InvalidBlockNonce: public Exception { public: InvalidBlockNonce(h256 _h = h256(), h256 _n = h256(), u256 _d = 0): h(_h), n(_n), d(_d) {} h256 h; h256 n; u256 d; virtual std::string description() const { return "Invalid nonce (h: " + toString(h) + " n:" + toString(n) + " d:" + toString(d) + ")"; } }; class InvalidParentHash: public Exception {}; class InvalidContractAddress: public Exception {}; -class NoNetworking: public Exception {}; -class NoUPnPDevice: public Exception {}; -class RootNotFound: public Exception {}; } diff --git a/libethereum/ExtVMFace.h b/libethereum/ExtVMFace.h index 11d03722b..dd19b1c0a 100644 --- a/libethereum/ExtVMFace.h +++ b/libethereum/ExtVMFace.h @@ -21,7 +21,7 @@ #pragma once -#include "Common.h" +#include #include "FeeStructure.h" #include "BlockInfo.h" diff --git a/libethereum/FeeStructure.h b/libethereum/FeeStructure.h index f773ec4f6..c4f493954 100644 --- a/libethereum/FeeStructure.h +++ b/libethereum/FeeStructure.h @@ -21,7 +21,7 @@ #pragma once -#include "Common.h" +#include namespace eth { diff --git a/libethereum/FixedHash.cpp b/libethereum/FixedHash.cpp deleted file mode 100644 index 9d16cacb2..000000000 --- a/libethereum/FixedHash.cpp +++ /dev/null @@ -1,25 +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 FixedHash.cpp - * @author Gav Wood - * @date 2014 - */ - -#include "FixedHash.h" - -using namespace std; -using namespace eth; diff --git a/libethereum/Instruction.cpp b/libethereum/Instruction.cpp index 3fd81b695..3d7db5c9e 100644 --- a/libethereum/Instruction.cpp +++ b/libethereum/Instruction.cpp @@ -22,8 +22,8 @@ #include "Instruction.h" #include +#include #include "CommonEth.h" -#include "Log.h" using namespace std; using namespace eth; diff --git a/libethereum/Instruction.h b/libethereum/Instruction.h index d4396bbf2..7fddec181 100644 --- a/libethereum/Instruction.h +++ b/libethereum/Instruction.h @@ -21,7 +21,7 @@ #pragma once -#include "Common.h" +#include namespace eth { diff --git a/libethereum/PeerNetwork.h b/libethereum/PeerNetwork.h index 8f5dc1463..b5392acdd 100644 --- a/libethereum/PeerNetwork.h +++ b/libethereum/PeerNetwork.h @@ -27,8 +27,8 @@ #include #include #include -#include "Common.h" -#include "Log.h" +#include +#include namespace ba = boost::asio; namespace bi = boost::asio::ip; diff --git a/libethereum/PeerServer.cpp b/libethereum/PeerServer.cpp index 7448d5eb2..1784ef49a 100644 --- a/libethereum/PeerServer.cpp +++ b/libethereum/PeerServer.cpp @@ -34,12 +34,12 @@ #include #include #include +#include +#include #include "Exceptions.h" -#include "Common.h" #include "BlockChain.h" #include "BlockInfo.h" #include "TransactionQueue.h" -#include "UPnP.h" #include "PeerSession.h" using namespace std; using namespace eth; diff --git a/libethereum/PeerSession.cpp b/libethereum/PeerSession.cpp index e8719f1f2..f9283b887 100644 --- a/libethereum/PeerSession.cpp +++ b/libethereum/PeerSession.cpp @@ -22,8 +22,8 @@ #include "PeerSession.h" #include +#include #include "Exceptions.h" -#include "Common.h" #include "BlockChain.h" #include "BlockInfo.h" #include "PeerServer.h" diff --git a/libethereum/PeerSession.h b/libethereum/PeerSession.h index 0621f4f92..4e24f6ce9 100644 --- a/libethereum/PeerSession.h +++ b/libethereum/PeerSession.h @@ -25,7 +25,7 @@ #include #include #include -#include "RLP.h" +#include #include "CommonEth.h" #include "PeerNetwork.h" diff --git a/libethereum/State.cpp b/libethereum/State.cpp index 8c9ba5337..9a587915b 100644 --- a/libethereum/State.cpp +++ b/libethereum/State.cpp @@ -21,7 +21,7 @@ #include "State.h" -#include +#include #include #include #include diff --git a/libethereum/State.h b/libethereum/State.h index 82a34cdf8..e0dc6dae2 100644 --- a/libethereum/State.h +++ b/libethereum/State.h @@ -24,14 +24,14 @@ #include #include #include -#include "Common.h" -#include "RLP.h" +#include +#include +#include #include "TransactionQueue.h" #include "Exceptions.h" #include "BlockInfo.h" #include "AddressState.h" #include "Transaction.h" -#include "TrieDB.h" #include "FeeStructure.h" #include "Dagger.h" #include "ExtVMFace.h" diff --git a/libethereum/Transaction.cpp b/libethereum/Transaction.cpp index ca5c7ad93..21b162ed4 100644 --- a/libethereum/Transaction.cpp +++ b/libethereum/Transaction.cpp @@ -19,11 +19,11 @@ * @date 2014 */ -#include -#include "vector_ref.h" +#include +#include +#include #include "Exceptions.h" #include "Transaction.h" -#include "Log.h" using namespace std; using namespace eth; diff --git a/libethereum/Transaction.h b/libethereum/Transaction.h index e60b97891..7d557b6fa 100644 --- a/libethereum/Transaction.h +++ b/libethereum/Transaction.h @@ -21,8 +21,8 @@ #pragma once +#include #include "CommonEth.h" -#include "RLP.h" namespace eth { diff --git a/libethereum/TransactionQueue.cpp b/libethereum/TransactionQueue.cpp index 3d50e069f..3eb6a347b 100644 --- a/libethereum/TransactionQueue.cpp +++ b/libethereum/TransactionQueue.cpp @@ -19,9 +19,11 @@ * @date 2014 */ -#include "Log.h" -#include "Transaction.h" #include "TransactionQueue.h" + +#include +#include "Exceptions.h" +#include "Transaction.h" using namespace std; using namespace eth; diff --git a/libethereum/TransactionQueue.h b/libethereum/TransactionQueue.h index 89e889cc1..3736f392c 100644 --- a/libethereum/TransactionQueue.h +++ b/libethereum/TransactionQueue.h @@ -21,7 +21,7 @@ #pragma once -#include "Common.h" +#include #include "Transaction.h" namespace eth diff --git a/libqethereum/QEthereum.cpp b/libqethereum/QEthereum.cpp index 6456eb566..54ae9e9f1 100644 --- a/libqethereum/QEthereum.cpp +++ b/libqethereum/QEthereum.cpp @@ -1,9 +1,9 @@ #include #include +#include #include #include #include -#include #include #include "QEthereum.h" using namespace std; diff --git a/libqethereum/QEthereum.h b/libqethereum/QEthereum.h index aa3b593a4..713fa0092 100644 --- a/libqethereum/QEthereum.h +++ b/libqethereum/QEthereum.h @@ -2,7 +2,7 @@ #include #include -#include +#include namespace eth { class Client; diff --git a/neth/CMakeLists.txt b/neth/CMakeLists.txt index 99a284ffd..827e1586d 100644 --- a/neth/CMakeLists.txt +++ b/neth/CMakeLists.txt @@ -2,7 +2,8 @@ cmake_policy(SET CMP0015 NEW) aux_source_directory(. SRC_LIST) -include_directories(../libethereum) +include_directories(..) +link_directories(../libethcore) link_directories(../libethereum) add_executable(neth ${SRC_LIST}) diff --git a/neth/main.cpp b/neth/main.cpp index cb974acda..2c1a00914 100644 --- a/neth/main.cpp +++ b/neth/main.cpp @@ -30,13 +30,13 @@ #include #include #include -#include "Defaults.h" -#include "Client.h" -#include "PeerNetwork.h" -#include "BlockChain.h" -#include "State.h" -#include "FileSystem.h" -#include "Instruction.h" +#include +#include +#include +#include +#include +#include +#include #include "BuildInfo.h" using namespace std; using namespace eth; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 41f554c30..7fb86dbdb 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -2,8 +2,8 @@ cmake_policy(SET CMP0015 NEW) aux_source_directory(. SRC_LIST) -include_directories(../secp256k1) -include_directories(../libethereum) +include_directories(..) +link_directories(../libethcore) link_directories(../libethereum) add_executable(testeth ${SRC_LIST}) diff --git a/test/MemTrie.cpp b/test/MemTrie.cpp index 0a7d0ebe4..c9e4fd8f0 100644 --- a/test/MemTrie.cpp +++ b/test/MemTrie.cpp @@ -21,8 +21,8 @@ #include "MemTrie.h" -#include -#include +#include +#include using namespace std; using namespace eth; diff --git a/test/MemTrie.h b/test/MemTrie.h index 622ea531d..5c6a70276 100644 --- a/test/MemTrie.h +++ b/test/MemTrie.h @@ -21,8 +21,8 @@ #pragma once -#include -#include +#include +#include namespace eth { diff --git a/test/TestHelper.cpp b/test/TestHelper.cpp index 54cb84ccb..06f188a89 100644 --- a/test/TestHelper.cpp +++ b/test/TestHelper.cpp @@ -21,7 +21,7 @@ #include #include -#include +#include #include "TestHelper.h" namespace eth diff --git a/test/TrieHash.cpp b/test/TrieHash.cpp index 61840b0e8..b12b96dd3 100644 --- a/test/TrieHash.cpp +++ b/test/TrieHash.cpp @@ -21,8 +21,8 @@ #include "TrieHash.h" -#include -#include +#include +#include using namespace std; using namespace eth; diff --git a/test/TrieHash.h b/test/TrieHash.h index e69b2b7b3..f5e8564b4 100644 --- a/test/TrieHash.h +++ b/test/TrieHash.h @@ -21,8 +21,8 @@ #pragma once -#include -#include +#include +#include namespace eth { diff --git a/test/crypto.cpp b/test/crypto.cpp index 5dac1fced..720bc7ffc 100644 --- a/test/crypto.cpp +++ b/test/crypto.cpp @@ -21,11 +21,11 @@ */ #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include using namespace std; diff --git a/test/dagger.cpp b/test/dagger.cpp index 728c8382a..d21c59e97 100644 --- a/test/dagger.cpp +++ b/test/dagger.cpp @@ -21,8 +21,8 @@ */ #include -#include "Log.h" -#include "Dagger.h" +#include +#include using namespace std; using namespace std::chrono; using namespace eth; diff --git a/test/fork.cpp b/test/fork.cpp index 24e7be175..32b35d08c 100644 --- a/test/fork.cpp +++ b/test/fork.cpp @@ -22,9 +22,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include "TestHelper.h" using namespace std; using namespace eth; diff --git a/test/hexPrefix.cpp b/test/hexPrefix.cpp index a3de61d2e..6d3ed89fc 100644 --- a/test/hexPrefix.cpp +++ b/test/hexPrefix.cpp @@ -22,8 +22,8 @@ #include #include "JsonSpiritHeaders.h" -#include "TrieCommon.h" -#include "Log.h" +#include +#include #include using namespace std; diff --git a/test/main.cpp b/test/main.cpp index 97f32cced..7a2b8ab62 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -33,7 +33,7 @@ int vmTest(); int hexPrefixTest(); int peerTest(int argc, char** argv); -#include +#include using namespace eth; BOOST_AUTO_TEST_CASE(basic_tests) diff --git a/test/network.cpp b/test/network.cpp index 3e27ac6b9..216d518cf 100644 --- a/test/network.cpp +++ b/test/network.cpp @@ -22,9 +22,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include "TestHelper.h" using namespace std; using namespace eth; diff --git a/test/peer.cpp b/test/peer.cpp index 7a1f3248f..20f2d3225 100644 --- a/test/peer.cpp +++ b/test/peer.cpp @@ -23,8 +23,8 @@ #include #include #include -#include -#include +#include +#include using namespace std; using namespace eth; using boost::asio::ip::tcp; diff --git a/test/rlp.cpp b/test/rlp.cpp index 1271d7ff9..56fcd137c 100644 --- a/test/rlp.cpp +++ b/test/rlp.cpp @@ -23,9 +23,9 @@ #include #include #include "JsonSpiritHeaders.h" -#include -#include -#include +#include +#include +#include #include #include diff --git a/test/state.cpp b/test/state.cpp index 60d68b936..262bf6762 100644 --- a/test/state.cpp +++ b/test/state.cpp @@ -21,10 +21,10 @@ */ #include -#include -#include -#include -#include +#include +#include +#include +#include using namespace std; using namespace eth; diff --git a/test/trie.cpp b/test/trie.cpp index 785bcc728..55b6871ab 100644 --- a/test/trie.cpp +++ b/test/trie.cpp @@ -23,7 +23,7 @@ #include #include #include "JsonSpiritHeaders.h" -#include +#include #include "TrieHash.h" #include "MemTrie.h" #include diff --git a/test/txTest.cpp b/test/txTest.cpp index 02aa990d5..58fd11def 100644 --- a/test/txTest.cpp +++ b/test/txTest.cpp @@ -22,9 +22,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include "TestHelper.h" using namespace std; using namespace eth; diff --git a/test/vm.cpp b/test/vm.cpp index a3242b573..7d8501d35 100644 --- a/test/vm.cpp +++ b/test/vm.cpp @@ -21,11 +21,11 @@ */ #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include "JsonSpiritHeaders.h" #include diff --git a/walleth/CMakeLists.txt b/walleth/CMakeLists.txt index fbeb99c99..272a95719 100644 --- a/walleth/CMakeLists.txt +++ b/walleth/CMakeLists.txt @@ -9,6 +9,7 @@ set(CMAKE_INCLUDE_CURRENT_DIR ON) aux_source_directory(. SRC_LIST) include_directories(..) +link_directories(../libethcore) link_directories(../libethereum) link_directories(../libqethereum) diff --git a/walleth/MainWin.cpp b/walleth/MainWin.cpp index 3c498fdad..6b36099e2 100644 --- a/walleth/MainWin.cpp +++ b/walleth/MainWin.cpp @@ -7,10 +7,10 @@ #include #include #include +#include #include #include #include -#include #include #include "BuildInfo.h" #include "MainWin.h"