├── .gitignore ├── BuildInfo.h.in ├── CMakeLists.txt ├── GPLV3_LICENSE ├── LICENSE ├── README.md ├── cmake ├── CMakeParseArguments.cmake ├── EthCompilerSettings.cmake ├── EthDependencies.cmake ├── EthExecutableHelper.cmake ├── EthUtils.cmake ├── FindCURL.cmake ├── FindCpuid.cmake ├── FindCryptoPP.cmake ├── FindEth.cmake ├── FindGmp.cmake ├── FindJsoncpp.cmake ├── FindLevelDB.cmake ├── FindMHD.cmake ├── FindMiniupnpc.cmake ├── FindOpenCL.cmake ├── FindPackageHandleStandardArgs.cmake ├── FindPackageMessage.cmake ├── FindReadline.cmake ├── FindWindowsSDK.cmake ├── Findjson_rpc_cpp.cmake ├── Findv8.cmake └── scripts │ ├── appdmg.cmake │ ├── buildinfo.cmake │ ├── configure.cmake │ ├── copydlls.cmake │ ├── jsonrpcstub.cmake │ ├── macdeployfix.sh │ ├── resource.hpp.in │ ├── resources.cmake │ └── runtest.cmake ├── ethminer ├── ADLUtils.cpp ├── ADLUtils.h ├── CMakeLists.txt ├── Common.cpp ├── Common.h ├── DataLogger.cpp ├── DataLogger.h ├── FarmClient.h ├── MinerAux.h ├── Misc.cpp ├── Misc.h ├── MultiLog.cpp ├── MultiLog.h ├── PhoneHome.h ├── ProgOpt.cpp ├── ProgOpt.h ├── SignTx.h ├── UDPSocket.cpp ├── UDPSocket.h ├── farm.json ├── ini_parser_ex.hpp ├── main.cpp ├── phonehome.json ├── secp256k1.c ├── secp256k1 │ ├── ecdsa.h │ ├── ecdsa_impl.h │ ├── eckey.h │ ├── eckey_impl.h │ ├── ecmult.h │ ├── ecmult_gen.h │ ├── ecmult_gen_impl.h │ ├── ecmult_impl.h │ ├── field.h │ ├── field_10x26.h │ ├── field_10x26_impl.h │ ├── field_5x52.h │ ├── field_5x52_asm.asm │ ├── field_5x52_asm_impl.h │ ├── field_5x52_impl.h │ ├── field_5x52_int128_impl.h │ ├── field_impl.h │ ├── group.h │ ├── group_impl.h │ ├── hash.h │ ├── hash_impl.h │ ├── libsecp256k1-config.h │ ├── num.h │ ├── num_gmp.h │ ├── num_gmp_impl.h │ ├── num_impl.h │ ├── scalar.h │ ├── scalar_4x64.h │ ├── scalar_4x64_impl.h │ ├── scalar_8x32.h │ ├── scalar_8x32_impl.h │ ├── scalar_impl.h │ ├── secp256k1.h │ └── util.h ├── speedfan.cpp └── speedfan.h ├── extdep ├── curl.exe ├── getstuff.bat ├── include │ └── amd_adl │ │ ├── adl_defines.h │ │ ├── adl_sdk.h │ │ └── adl_structures.h └── libcurl.dll ├── libdevcore ├── Assertions.h ├── Base64.cpp ├── Base64.h ├── CMakeLists.txt ├── Common.cpp ├── Common.h ├── CommonData.cpp ├── CommonData.h ├── CommonIO.cpp ├── CommonIO.h ├── CommonJS.cpp ├── CommonJS.h ├── Diff.h ├── Exceptions.h ├── FileSystem.cpp ├── FileSystem.h ├── FixedHash.cpp ├── FixedHash.h ├── Guards.cpp ├── Guards.h ├── Hash.cpp ├── Hash.h ├── Log.cpp ├── Log.h ├── MemoryDB.cpp ├── MemoryDB.h ├── RLP.cpp ├── RLP.h ├── RangeMask.cpp ├── RangeMask.h ├── SHA3.cpp ├── SHA3.h ├── StructuredLogger.cpp ├── StructuredLogger.h ├── Terminal.h ├── TransientDirectory.cpp ├── TransientDirectory.h ├── TrieCommon.cpp ├── TrieCommon.h ├── TrieDB.cpp ├── TrieDB.h ├── TrieHash.cpp ├── TrieHash.h ├── UndefMacros.h ├── Worker.cpp ├── Worker.h ├── boost_multiprecision_number_compare_bug_workaround.hpp ├── concurrent_queue.h ├── db.h ├── debugbreak.h ├── picosha2.h └── vector_ref.h ├── libethash-cl ├── CL │ └── cl.hpp ├── CMakeLists.txt ├── bin2h.cmake ├── ethash_cl_miner.cpp ├── ethash_cl_miner.h └── ethash_cl_miner_kernel.cl ├── libethash-cuda ├── CMakeLists.txt ├── cuda_helper.h ├── dagger_shared.cuh ├── dagger_shuffled.cuh ├── ethash_cuda_miner.cpp ├── ethash_cuda_miner.h ├── ethash_cuda_miner_kernel.cu ├── ethash_cuda_miner_kernel.h ├── ethash_cuda_miner_kernel_globals.h ├── fnv.cuh ├── keccak.cuh └── keccak_u64.cuh ├── libethash ├── CMakeLists.txt ├── compiler.h ├── data_sizes.h ├── endian.h ├── ethash.h ├── fnv.h ├── internal.c ├── internal.h ├── io.c ├── io.h ├── io_posix.c ├── io_win32.c ├── mmap.h ├── mmap_win32.c ├── sha3.c ├── sha3.h ├── sha3_cryptopp.cpp ├── sha3_cryptopp.h ├── util.c ├── util.h └── util_win32.c ├── libethcore ├── BlockInfo.cpp ├── BlockInfo.h ├── CMakeLists.txt ├── Common.cpp ├── Common.h ├── Ethash.cpp ├── Ethash.h ├── EthashAux.cpp ├── EthashAux.h ├── EthashCPUMiner.cpp ├── EthashCPUMiner.h ├── EthashCUDAMiner.cpp ├── EthashCUDAMiner.h ├── EthashGPUMiner.cpp ├── EthashGPUMiner.h ├── EthashSealEngine.cpp ├── EthashSealEngine.h ├── Exceptions.h ├── Farm.h ├── Miner.cpp ├── Miner.h ├── Params.cpp ├── Params.h ├── Sealer.cpp └── Sealer.h ├── libstratum ├── CMakeLists.txt ├── EthStratumClient.cpp └── EthStratumClient.h ├── release ├── build.bat ├── build.sh ├── list-devices.bat └── start-mining.bat └── tokenminer.ini /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | extdep/install 3 | extdep/download 4 | release/stage 5 | *.tar.gz 6 | *.zip 7 | linux-build/ 8 | -------------------------------------------------------------------------------- /BuildInfo.h.in: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define ETH_PROJECT_VERSION "@PROJECT_VERSION@" 4 | #define ETH_COMMIT_HASH @ETH_COMMIT_HASH@ 5 | #define ETH_CLEAN_REPO @ETH_CLEAN_REPO@ 6 | #define ETH_BUILD_TYPE @ETH_BUILD_TYPE@ 7 | #define ETH_BUILD_PLATFORM @ETH_BUILD_PLATFORM@ 8 | #define ETH_FATDB @ETH_FATDB@ 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /cmake/EthUtils.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # renames the file if it is different from its destination 3 | include(CMakeParseArguments) 4 | # 5 | macro(replace_if_different SOURCE DST) 6 | set(extra_macro_args ${ARGN}) 7 | set(options CREATE) 8 | set(one_value_args) 9 | set(multi_value_args) 10 | cmake_parse_arguments(REPLACE_IF_DIFFERENT "${options}" "${one_value_args}" "${multi_value_args}" "${extra_macro_args}") 11 | 12 | if (REPLACE_IF_DIFFERENT_CREATE AND (NOT (EXISTS "${DST}"))) 13 | file(WRITE "${DST}" "") 14 | endif() 15 | 16 | execute_process(COMMAND ${CMAKE_COMMAND} -E compare_files "${SOURCE}" "${DST}" RESULT_VARIABLE DIFFERENT) 17 | 18 | if (DIFFERENT) 19 | execute_process(COMMAND ${CMAKE_COMMAND} -E rename "${SOURCE}" "${DST}") 20 | else() 21 | execute_process(COMMAND ${CMAKE_COMMAND} -E remove "${SOURCE}") 22 | endif() 23 | endmacro() 24 | 25 | macro(eth_add_test NAME) 26 | 27 | # parse arguments here 28 | set(commands) 29 | set(current_command "") 30 | foreach (arg ${ARGN}) 31 | if (arg STREQUAL "ARGS") 32 | if (current_command) 33 | list(APPEND commands ${current_command}) 34 | endif() 35 | set(current_command "") 36 | else () 37 | set(current_command "${current_command} ${arg}") 38 | endif() 39 | endforeach(arg) 40 | list(APPEND commands ${current_command}) 41 | 42 | message(STATUS "test: ${NAME} | ${commands}") 43 | 44 | # create tests 45 | set(index 0) 46 | list(LENGTH commands count) 47 | while (index LESS count) 48 | list(GET commands ${index} test_arguments) 49 | 50 | set(run_test "--run_test=${NAME}") 51 | add_test(NAME "${NAME}.${index}" COMMAND testeth ${run_test} ${test_arguments}) 52 | 53 | math(EXPR index "${index} + 1") 54 | endwhile(index LESS count) 55 | 56 | # add target to run them 57 | add_custom_target("test.${NAME}" 58 | DEPENDS testeth 59 | WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} 60 | COMMAND ${CMAKE_COMMAND} -DETH_TEST_NAME="${NAME}" -DCTEST_COMMAND="${CTEST_COMMAND}" -P "${ETH_SCRIPTS_DIR}/runtest.cmake" 61 | ) 62 | 63 | endmacro() 64 | 65 | # Creates C resources file from files 66 | function(eth_add_resources RESOURCE_FILE OUT_FILE) 67 | include("${RESOURCE_FILE}") 68 | set(OUTPUT "${ETH_RESOURCE_LOCATION}/${ETH_RESOURCE_NAME}.hpp") 69 | set(${OUT_FILE} "${OUTPUT}" PARENT_SCOPE) 70 | 71 | set(filenames "${RESOURCE_FILE}") 72 | list(APPEND filenames "${ETH_SCRIPTS_DIR}/resources.cmake") 73 | foreach(resource ${ETH_RESOURCES}) 74 | list(APPEND filenames "${${resource}}") 75 | endforeach(resource) 76 | 77 | add_custom_command(OUTPUT ${OUTPUT} 78 | COMMAND ${CMAKE_COMMAND} -DETH_RES_FILE="${RESOURCE_FILE}" -P "${ETH_SCRIPTS_DIR}/resources.cmake" 79 | DEPENDS ${filenames} 80 | ) 81 | endfunction() 82 | -------------------------------------------------------------------------------- /cmake/FindCURL.cmake: -------------------------------------------------------------------------------- 1 | # Find CURL 2 | # 3 | # Find the curl includes and library 4 | # 5 | # if you nee to add a custom library search path, do it via via CMAKE_PREFIX_PATH 6 | # 7 | # This module defines 8 | # CURL_INCLUDE_DIRS, where to find header, etc. 9 | # CURL_LIBRARIES, the libraries needed to use curl. 10 | # CURL_FOUND, If false, do not try to use curl. 11 | 12 | # only look in default directories 13 | find_path( 14 | CURL_INCLUDE_DIR 15 | NAMES curl/curl.h 16 | DOC "curl include dir" 17 | ) 18 | 19 | find_library( 20 | CURL_LIBRARY 21 | # names from cmake's FindCURL 22 | NAMES curl curllib libcurl_imp curllib_static libcurl 23 | DOC "curl library" 24 | ) 25 | 26 | set(CURL_INCLUDE_DIRS ${CURL_INCLUDE_DIR}) 27 | set(CURL_LIBRARIES ${CURL_LIBRARY}) 28 | 29 | # debug library on windows 30 | # same naming convention as in qt (appending debug library with d) 31 | # boost is using the same "hack" as us with "optimized" and "debug" 32 | if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") 33 | 34 | find_library( 35 | CURL_LIBRARY_DEBUG 36 | NAMES curld libcurld 37 | DOC "curl debug library" 38 | ) 39 | 40 | set(CURL_LIBRARIES optimized ${CURL_LIBRARIES} debug ${CURL_LIBRARY_DEBUG}) 41 | 42 | # prepare dlls 43 | string(REPLACE ".lib" ".dll" CURL_DLL ${CURL_LIBRARY}) 44 | string(REPLACE "/lib/" "/bin/" CURL_DLL ${CURL_DLL}) 45 | string(REPLACE ".lib" ".dll" CURL_DLL_DEBUG ${CURL_LIBRARY_DEBUG}) 46 | string(REPLACE "/lib/" "/bin/" CURL_DLL_DEBUG ${CURL_DLL_DEBUG}) 47 | set(CURL_DLLS optimized ${CURL_DLL} debug ${CURL_DLL_DEBUG}) 48 | 49 | endif() 50 | 51 | # handle the QUIETLY and REQUIRED arguments and set CURL_FOUND to TRUE 52 | # if all listed variables are TRUE, hide their existence from configuration view 53 | include(FindPackageHandleStandardArgs) 54 | find_package_handle_standard_args(CURL DEFAULT_MSG 55 | CURL_INCLUDE_DIR CURL_LIBRARY) 56 | mark_as_advanced (CURL_INCLUDE_DIR CURL_LIBRARY) 57 | 58 | -------------------------------------------------------------------------------- /cmake/FindCpuid.cmake: -------------------------------------------------------------------------------- 1 | # Find libcpuid 2 | # 3 | # Find the libcpuid includes and library 4 | # 5 | # if you nee to add a custom library search path, do it via via CMAKE_PREFIX_PATH 6 | # 7 | # This module defines 8 | # CPUID_INCLUDE_DIRS, where to find header, etc. 9 | # CPUID_LIBRARIES, the libraries needed to use cpuid. 10 | # CPUID_FOUND, If false, do not try to use cpuid. 11 | 12 | # only look in default directories 13 | find_path( 14 | CPUID_INCLUDE_DIR 15 | NAMES libcpuid/libcpuid.h 16 | DOC "libcpuid include dir" 17 | ) 18 | 19 | find_library( 20 | CPUID_LIBRARY 21 | NAMES cpuid 22 | DOC "libcpuid library" 23 | ) 24 | 25 | set(CPUID_INCLUDE_DIRS ${CPUID_INCLUDE_DIR}) 26 | set(CPUID_LIBRARIES ${CPUID_LIBRARY}) 27 | 28 | # handle the QUIETLY and REQUIRED arguments and set CPUID_FOUND to TRUE 29 | # if all listed variables are TRUE, hide their existence from configuration view 30 | include(FindPackageHandleStandardArgs) 31 | find_package_handle_standard_args(cpuid DEFAULT_MSG CPUID_INCLUDE_DIR CPUID_LIBRARY) 32 | mark_as_advanced (CPUID_INCLUDE_DIR CPUID_LIBRARY) 33 | 34 | -------------------------------------------------------------------------------- /cmake/FindEth.cmake: -------------------------------------------------------------------------------- 1 | # Find ethereum 2 | # 3 | # Find the ethereum includes and library 4 | # 5 | # This module defines 6 | # ETH_CORE_LIBRARIES, the libraries needed to use ethereum. 7 | # ETH_FOUND, If false, do not try to use ethereum. 8 | # TODO: ETH_INCLUDE_DIRS 9 | 10 | set(CORE_LIBS web3jsonrpc;webthree;whisper;ethereum;evm;ethcore;lll;p2p;evmasm;devcrypto;evmcore;natspec;devcore;ethash-cl;ethash;secp256k1;scrypt;jsqrc) 11 | set(ALL_LIBS ${CORE_LIBS};evmjit;solidity;secp256k1) 12 | 13 | set(ETH_INCLUDE_DIRS ${ETH_INCLUDE_DIR}) 14 | set(ETH_CORE_LIBRARIES ${ETH_LIBRARY}) 15 | 16 | foreach (l ${ALL_LIBS}) 17 | string(TOUPPER ${l} L) 18 | find_library(ETH_${L}_LIBRARY 19 | NAMES ${l} 20 | PATH_SUFFIXES "lib${l}" "${l}" 21 | ) 22 | endforeach() 23 | 24 | foreach (l ${CORE_LIBS}) 25 | string(TOUPPER ${l} L) 26 | list(APPEND ETH_CORE_LIBRARIES ${ETH_${L}_LIBRARY}) 27 | endforeach() 28 | 29 | # handle the QUIETLY and REQUIRED arguments and set ETH_FOUND to TRUE 30 | # if all listed variables are TRUE, hide their existence from configuration view 31 | include(FindPackageHandleStandardArgs) 32 | find_package_handle_standard_args(ethereum DEFAULT_MSG 33 | ETH_CORE_LIBRARIES) 34 | mark_as_advanced (ETH_CORE_LIBRARIES) 35 | 36 | -------------------------------------------------------------------------------- /cmake/FindGmp.cmake: -------------------------------------------------------------------------------- 1 | # Find gmp 2 | # 3 | # Find the gmp includes and library 4 | # 5 | # if you nee to add a custom library search path, do it via via CMAKE_PREFIX_PATH 6 | # 7 | # This module defines 8 | # GMP_INCLUDE_DIRS, where to find header, etc. 9 | # GMP_LIBRARIES, the libraries needed to use gmp. 10 | # GMP_FOUND, If false, do not try to use gmp. 11 | 12 | # only look in default directories 13 | find_path( 14 | GMP_INCLUDE_DIR 15 | NAMES gmp.h 16 | DOC "gmp include dir" 17 | ) 18 | 19 | find_library( 20 | GMP_LIBRARY 21 | NAMES gmp 22 | DOC "gmp library" 23 | ) 24 | 25 | set(GMP_INCLUDE_DIRS ${GMP_INCLUDE_DIR}) 26 | set(GMP_LIBRARIES ${GMP_LIBRARY}) 27 | 28 | # handle the QUIETLY and REQUIRED arguments and set GMP_FOUND to TRUE 29 | # if all listed variables are TRUE, hide their existence from configuration view 30 | include(FindPackageHandleStandardArgs) 31 | find_package_handle_standard_args(gmp DEFAULT_MSG 32 | GMP_INCLUDE_DIR GMP_LIBRARY) 33 | mark_as_advanced (GMP_INCLUDE_DIR GMP_LIBRARY) 34 | 35 | -------------------------------------------------------------------------------- /cmake/FindJsoncpp.cmake: -------------------------------------------------------------------------------- 1 | # Find jsoncpp 2 | # 3 | # Find the jsoncpp includes and library 4 | # 5 | # if you nee to add a custom library search path, do it via via CMAKE_PREFIX_PATH 6 | # 7 | # This module defines 8 | # JSONCPP_INCLUDE_DIRS, where to find header, etc. 9 | # JSONCPP_LIBRARIES, the libraries needed to use jsoncpp. 10 | # JSONCPP_FOUND, If false, do not try to use jsoncpp. 11 | 12 | # only look in default directories 13 | find_path( 14 | JSONCPP_INCLUDE_DIR 15 | NAMES json/json.h 16 | PATH_SUFFIXES jsoncpp 17 | DOC "jsoncpp include dir" 18 | ) 19 | 20 | find_library( 21 | JSONCPP_LIBRARY 22 | NAMES jsoncpp 23 | DOC "jsoncpp library" 24 | ) 25 | 26 | set(JSONCPP_INCLUDE_DIRS ${JSONCPP_INCLUDE_DIR}) 27 | set(JSONCPP_LIBRARIES ${JSONCPP_LIBRARY}) 28 | 29 | # debug library on windows 30 | # same naming convention as in qt (appending debug library with d) 31 | # boost is using the same "hack" as us with "optimized" and "debug" 32 | if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") 33 | 34 | find_library( 35 | JSONCPP_LIBRARY_DEBUG 36 | NAMES jsoncppd 37 | DOC "jsoncpp debug library" 38 | ) 39 | 40 | set(JSONCPP_LIBRARIES optimized ${JSONCPP_LIBRARIES} debug ${JSONCPP_LIBRARY_DEBUG}) 41 | 42 | endif() 43 | 44 | # handle the QUIETLY and REQUIRED arguments and set JSONCPP_FOUND to TRUE 45 | # if all listed variables are TRUE, hide their existence from configuration view 46 | include(FindPackageHandleStandardArgs) 47 | find_package_handle_standard_args(jsoncpp DEFAULT_MSG 48 | JSONCPP_INCLUDE_DIR JSONCPP_LIBRARY) 49 | mark_as_advanced (JSONCPP_INCLUDE_DIR JSONCPP_LIBRARY) 50 | 51 | -------------------------------------------------------------------------------- /cmake/FindLevelDB.cmake: -------------------------------------------------------------------------------- 1 | # Find leveldb 2 | # 3 | # Find the leveldb includes and library 4 | # 5 | # if you nee to add a custom library search path, do it via via CMAKE_PREFIX_PATH 6 | # 7 | # This module defines 8 | # LEVELDB_INCLUDE_DIRS, where to find header, etc. 9 | # LEVELDB_LIBRARIES, the libraries needed to use leveldb. 10 | # LEVELDB_FOUND, If false, do not try to use leveldb. 11 | 12 | # only look in default directories 13 | find_path( 14 | LEVELDB_INCLUDE_DIR 15 | NAMES leveldb/db.h 16 | DOC "leveldb include dir" 17 | ) 18 | 19 | find_library( 20 | LEVELDB_LIBRARY 21 | NAMES leveldb 22 | DOC "leveldb library" 23 | ) 24 | 25 | set(LEVELDB_INCLUDE_DIRS ${LEVELDB_INCLUDE_DIR}) 26 | set(LEVELDB_LIBRARIES ${LEVELDB_LIBRARY}) 27 | 28 | # debug library on windows 29 | # same naming convention as in qt (appending debug library with d) 30 | # boost is using the same "hack" as us with "optimized" and "debug" 31 | if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") 32 | 33 | find_library( 34 | LEVELDB_LIBRARY_DEBUG 35 | NAMES leveldbd 36 | DOC "leveldb debug library" 37 | ) 38 | 39 | set(LEVELDB_LIBRARIES optimized ${LEVELDB_LIBRARIES} debug ${LEVELDB_LIBRARY_DEBUG}) 40 | 41 | endif() 42 | 43 | # handle the QUIETLY and REQUIRED arguments and set LEVELDB_FOUND to TRUE 44 | # if all listed variables are TRUE, hide their existence from configuration view 45 | include(FindPackageHandleStandardArgs) 46 | find_package_handle_standard_args(leveldb DEFAULT_MSG 47 | LEVELDB_INCLUDE_DIR LEVELDB_LIBRARY) 48 | mark_as_advanced (LEVELDB_INCLUDE_DIR LEVELDB_LIBRARY) 49 | 50 | -------------------------------------------------------------------------------- /cmake/FindMHD.cmake: -------------------------------------------------------------------------------- 1 | # Find microhttpd 2 | # 3 | # Find the microhttpd includes and library 4 | # 5 | # if you need to add a custom library search path, do it via via CMAKE_PREFIX_PATH 6 | # 7 | # This module defines 8 | # MHD_INCLUDE_DIRS, where to find header, etc. 9 | # MHD_LIBRARIES, the libraries needed to use jsoncpp. 10 | # MHD_FOUND, If false, do not try to use jsoncpp. 11 | 12 | find_path( 13 | MHD_INCLUDE_DIR 14 | NAMES microhttpd.h 15 | DOC "microhttpd include dir" 16 | ) 17 | 18 | find_library( 19 | MHD_LIBRARY 20 | NAMES microhttpd microhttpd-10 libmicrohttpd libmicrohttpd-dll 21 | DOC "microhttpd library" 22 | ) 23 | 24 | set(MHD_INCLUDE_DIRS ${MHD_INCLUDE_DIR}) 25 | set(MHD_LIBRARIES ${MHD_LIBRARY}) 26 | 27 | # debug library on windows 28 | # same naming convention as in QT (appending debug library with d) 29 | # boost is using the same "hack" as us with "optimized" and "debug" 30 | # official MHD project actually uses _d suffix 31 | if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") 32 | 33 | find_library( 34 | MHD_LIBRARY_DEBUG 35 | NAMES microhttpd_d microhttpd-10_d libmicrohttpd_d libmicrohttpd-dll_d 36 | DOC "mhd debug library" 37 | ) 38 | 39 | set(MHD_LIBRARIES optimized ${MHD_LIBRARIES} debug ${MHD_LIBRARY_DEBUG}) 40 | 41 | # prepare dlls 42 | string(REPLACE ".lib" ".dll" MHD_DLL ${MHD_LIBRARY}) 43 | string(REPLACE "/lib/" "/bin/" MHD_DLL ${MHD_DLL}) 44 | string(REPLACE ".lib" ".dll" MHD_DLL_DEBUG ${MHD_LIBRARY_DEBUG}) 45 | string(REPLACE "/lib/" "/bin/" MHD_DLL_DEBUG ${MHD_DLL_DEBUG}) 46 | set(MHD_DLLS optimized ${MHD_DLL} debug ${MHD_DLL_DEBUG}) 47 | 48 | endif() 49 | 50 | include(FindPackageHandleStandardArgs) 51 | find_package_handle_standard_args(mhd DEFAULT_MSG 52 | MHD_INCLUDE_DIR MHD_LIBRARY) 53 | 54 | mark_as_advanced(MHD_INCLUDE_DIR MHD_LIBRARY) 55 | -------------------------------------------------------------------------------- /cmake/FindMiniupnpc.cmake: -------------------------------------------------------------------------------- 1 | # Find miniupnpc 2 | # 3 | # Find the miniupnpc includes and library 4 | # 5 | # if you nee to add a custom library search path, do it via via CMAKE_PREFIX_PATH 6 | # 7 | # This module defines 8 | # MINIUPNPC_INCLUDE_DIRS, where to find header, etc. 9 | # MINIUPNPC_LIBRARIES, the libraries needed to use gmp. 10 | # MINIUPNPC_FOUND, If false, do not try to use gmp. 11 | 12 | # only look in default directories 13 | find_path( 14 | MINIUPNPC_INCLUDE_DIR 15 | NAMES miniupnpc/miniupnpc.h 16 | DOC "miniupnpc include dir" 17 | ) 18 | 19 | find_library( 20 | MINIUPNPC_LIBRARY 21 | NAMES miniupnpc 22 | DOC "miniupnpc library" 23 | ) 24 | 25 | set(MINIUPNPC_INCLUDE_DIRS ${MINIUPNPC_INCLUDE_DIR}) 26 | set(MINIUPNPC_LIBRARIES ${MINIUPNPC_LIBRARY}) 27 | 28 | # debug library on windows 29 | # same naming convention as in QT (appending debug library with d) 30 | # boost is using the same "hack" as us with "optimized" and "debug" 31 | if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") 32 | 33 | find_library( 34 | MINIUPNPC_LIBRARY_DEBUG 35 | NAMES miniupnpcd 36 | DOC "miniupnpc debug library" 37 | ) 38 | 39 | set(MINIUPNPC_LIBRARIES "iphlpapi" optimized ${MINIUPNPC_LIBRARIES} debug ${MINIUPNPC_LIBRARY_DEBUG}) 40 | 41 | endif() 42 | 43 | # handle the QUIETLY and REQUIRED arguments and set MINIUPNPC_FOUND to TRUE 44 | # if all listed variables are TRUE, hide their existence from configuration view 45 | include(FindPackageHandleStandardArgs) 46 | find_package_handle_standard_args(miniupnpc DEFAULT_MSG 47 | MINIUPNPC_INCLUDE_DIR MINIUPNPC_LIBRARY) 48 | mark_as_advanced (MINIUPNPC_INCLUDE_DIR MINIUPNPC_LIBRARY) 49 | 50 | -------------------------------------------------------------------------------- /cmake/FindPackageMessage.cmake: -------------------------------------------------------------------------------- 1 | #.rst: 2 | # FindPackageMessage 3 | # ------------------ 4 | # 5 | # 6 | # 7 | # FIND_PACKAGE_MESSAGE( "message for user" "find result details") 8 | # 9 | # This macro is intended to be used in FindXXX.cmake modules files. It 10 | # will print a message once for each unique find result. This is useful 11 | # for telling the user where a package was found. The first argument 12 | # specifies the name (XXX) of the package. The second argument 13 | # specifies the message to display. The third argument lists details 14 | # about the find result so that if they change the message will be 15 | # displayed again. The macro also obeys the QUIET argument to the 16 | # find_package command. 17 | # 18 | # Example: 19 | # 20 | # :: 21 | # 22 | # if(X11_FOUND) 23 | # FIND_PACKAGE_MESSAGE(X11 "Found X11: ${X11_X11_LIB}" 24 | # "[${X11_X11_LIB}][${X11_INCLUDE_DIR}]") 25 | # else() 26 | # ... 27 | # endif() 28 | 29 | #============================================================================= 30 | # Copyright 2008-2009 Kitware, Inc. 31 | # 32 | # Distributed under the OSI-approved BSD License (the "License"); 33 | # see accompanying file Copyright.txt for details. 34 | # 35 | # This software is distributed WITHOUT ANY WARRANTY; without even the 36 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 37 | # See the License for more information. 38 | #============================================================================= 39 | # (To distribute this file outside of CMake, substitute the full 40 | # License text for the above reference.) 41 | 42 | function(FIND_PACKAGE_MESSAGE pkg msg details) 43 | # Avoid printing a message repeatedly for the same find result. 44 | if(NOT ${pkg}_FIND_QUIETLY) 45 | string(REPLACE "\n" "" details "${details}") 46 | set(DETAILS_VAR FIND_PACKAGE_MESSAGE_DETAILS_${pkg}) 47 | if(NOT "${details}" STREQUAL "${${DETAILS_VAR}}") 48 | # The message has not yet been printed. 49 | message(STATUS "${msg}") 50 | 51 | # Save the find details in the cache to avoid printing the same 52 | # message again. 53 | set("${DETAILS_VAR}" "${details}" 54 | CACHE INTERNAL "Details about finding ${pkg}") 55 | endif() 56 | endif() 57 | endfunction() 58 | -------------------------------------------------------------------------------- /cmake/FindReadline.cmake: -------------------------------------------------------------------------------- 1 | # Find readline 2 | # 3 | # Find the readline includes and library 4 | # 5 | # if you nee to add a custom library search path, do it via via CMAKE_PREFIX_PATH 6 | # 7 | # This module defines 8 | # READLINE_INCLUDE_DIRS, where to find header, etc. 9 | # READLINE_LIBRARIES, the libraries needed to use readline. 10 | # READLINE_FOUND, If false, do not try to use readline. 11 | 12 | # only look in default directories 13 | find_path( 14 | READLINE_INCLUDE_DIR 15 | NAMES readline/readline.h 16 | DOC "readling include dir" 17 | ) 18 | 19 | find_library( 20 | READLINE_LIBRARY 21 | NAMES readline 22 | DOC "readline library" 23 | ) 24 | 25 | set(READLINE_INCLUDE_DIRS ${READLINE_INCLUDE_DIR}) 26 | set(READLINE_LIBRARIES ${READLINE_LIBRARY}) 27 | 28 | # handle the QUIETLY and REQUIRED arguments and set READLINE_FOUND to TRUE 29 | # if all listed variables are TRUE, hide their existence from configuration view 30 | include(FindPackageHandleStandardArgs) 31 | find_package_handle_standard_args(readline DEFAULT_MSG 32 | READLINE_INCLUDE_DIR READLINE_LIBRARY) 33 | mark_as_advanced (READLINE_INCLUDE_DIR READLINE_LIBRARY) 34 | 35 | -------------------------------------------------------------------------------- /cmake/Findv8.cmake: -------------------------------------------------------------------------------- 1 | # Find v8 2 | # 3 | # Find the v8 includes and library 4 | # 5 | # if you nee to add a custom library search path, do it via via CMAKE_PREFIX_PATH 6 | # 7 | # This module defines 8 | # V8_INCLUDE_DIRS, where to find header, etc. 9 | # V8_LIBRARIES, the libraries needed to use v8. 10 | # V8_FOUND, If false, do not try to use v8. 11 | 12 | # only look in default directories 13 | find_path( 14 | V8_INCLUDE_DIR 15 | NAMES v8.h 16 | DOC "v8 include dir" 17 | ) 18 | 19 | find_library( 20 | V8_LIBRARY 21 | NAMES v8 22 | DOC "v8 library" 23 | ) 24 | 25 | set(V8_INCLUDE_DIRS ${V8_INCLUDE_DIR}) 26 | set(V8_LIBRARIES ${V8_LIBRARY}) 27 | 28 | # debug library on windows 29 | # same naming convention as in qt (appending debug library with d) 30 | # boost is using the same "hack" as us with "optimized" and "debug" 31 | if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") 32 | 33 | find_library( 34 | V8_LIBRARY 35 | NAMES v8_base 36 | DOC "v8 base library" 37 | ) 38 | 39 | find_library( 40 | V8_NO_SNAPSHOT_LIBRARY 41 | NAMES v8_nosnapshot 42 | DOC "v8 nosnapshot library" 43 | ) 44 | 45 | set(V8_LIBRARIES ${V8_LIBRARY} ${V8_NO_SNAPSHOT_LIBRARY}) 46 | 47 | find_library( 48 | V8_LIBRARY_DEBUG 49 | NAMES v8_based 50 | DOC "v8 base library" 51 | ) 52 | 53 | find_library( 54 | V8_NO_SNAPSHOT_LIBRARY_DEBUG 55 | NAMES v8_nosnapshotd 56 | DOC "v8 nosnapshot library" 57 | ) 58 | 59 | set(V8_LIBRARIES "ws2_32" "winmm" optimized ${V8_LIBRARIES} debug ${V8_LIBRARY_DEBUG} ${V8_NO_SNAPSHOT_LIBRARY_DEBUG}) 60 | 61 | endif() 62 | 63 | # handle the QUIETLY and REQUIRED arguments and set V8_FOUND to TRUE 64 | # if all listed variables are TRUE, hide their existence from configuration view 65 | include(FindPackageHandleStandardArgs) 66 | find_package_handle_standard_args(v8 DEFAULT_MSG 67 | V8_INCLUDE_DIR V8_LIBRARY) 68 | mark_as_advanced (V8_INCLUDE_DIR V8_LIBRARY) 69 | 70 | -------------------------------------------------------------------------------- /cmake/scripts/appdmg.cmake: -------------------------------------------------------------------------------- 1 | 2 | if (NOT APP_DMG_EXE) 3 | message(FATAL_ERROR "Please install appdmg! https://github.com/LinusU/node-appdmg") 4 | endif() 5 | 6 | string(REPLACE "/Contents/MacOS" "" ETH_MIX_APP "${ETH_MIX_APP}") 7 | string(REPLACE "/Contents/MacOS" "" ETH_ALETHZERO_APP "${ETH_ALETHZERO_APP}") 8 | 9 | set(OUTFILE "${ETH_BUILD_DIR}/appdmg.json") 10 | 11 | configure_file(${APP_DMG_FILE} ${OUTFILE}) 12 | 13 | execute_process(COMMAND ${CMAKE_COMMAND} -E copy "${APP_DMG_ICON}" "${ETH_BUILD_DIR}/appdmg_icon.icns") 14 | execute_process(COMMAND ${CMAKE_COMMAND} -E copy "${APP_DMG_BACKGROUND}" "${ETH_BUILD_DIR}/appdmg_background.png") 15 | execute_process(COMMAND ${CMAKE_COMMAND} -E remove "${ETH_BUILD_DIR}/Ethereum.dmg") 16 | execute_process(COMMAND ${APP_DMG_EXE} ${OUTFILE} "${ETH_BUILD_DIR}/Ethereum.dmg") 17 | 18 | -------------------------------------------------------------------------------- /cmake/scripts/buildinfo.cmake: -------------------------------------------------------------------------------- 1 | # generates BuildInfo.h 2 | # 3 | # this module expects 4 | # ETH_SOURCE_DIR - main CMAKE_SOURCE_DIR 5 | # ETH_DST_DIR - main CMAKE_BINARY_DIR 6 | # ETH_BUILD_TYPE 7 | # ETH_BUILD_PLATFORM 8 | # 9 | # example usage: 10 | # cmake -DETH_SOURCE_DIR=. -DETH_DST_DIR=build -DETH_BUILD_TYPE=Debug -DETH_BUILD_PLATFORM=mac -P scripts/buildinfo.cmake 11 | 12 | if (ETH_FATDB) 13 | set(ETH_FATDB 1) 14 | else() 15 | set(ETH_FATDB 0) 16 | endif() 17 | 18 | if (NOT ETH_BUILD_TYPE) 19 | set(ETH_BUILD_TYPE "unknown") 20 | endif() 21 | 22 | if (NOT ETH_BUILD_PLATFORM) 23 | set(ETH_BUILD_PLATFORM "unknown") 24 | endif() 25 | 26 | execute_process( 27 | COMMAND git --git-dir=${ETH_SOURCE_DIR}/.git --work-tree=${ETH_SOURCE_DIR} rev-parse HEAD 28 | OUTPUT_VARIABLE ETH_COMMIT_HASH OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET 29 | ) 30 | 31 | if (NOT ETH_COMMIT_HASH) 32 | set(ETH_COMMIT_HASH 0) 33 | endif() 34 | 35 | execute_process( 36 | COMMAND git --git-dir=${ETH_SOURCE_DIR}/.git --work-tree=${ETH_SOURCE_DIR} diff --shortstat 37 | OUTPUT_VARIABLE ETH_LOCAL_CHANGES OUTPUT_STRIP_TRAILING_WHITESPACE ERROR_QUIET 38 | ) 39 | 40 | if (ETH_LOCAL_CHANGES) 41 | set(ETH_CLEAN_REPO 0) 42 | else() 43 | set(ETH_CLEAN_REPO 1) 44 | endif() 45 | 46 | set(INFILE "${ETH_SOURCE_DIR}/BuildInfo.h.in") 47 | set(TMPFILE "${ETH_DST_DIR}/BuildInfo.h.tmp") 48 | set(OUTFILE "${ETH_DST_DIR}/BuildInfo.h") 49 | 50 | configure_file("${INFILE}" "${TMPFILE}") 51 | 52 | include("${ETH_SOURCE_DIR}/cmake/EthUtils.cmake") 53 | replace_if_different("${TMPFILE}" "${OUTFILE}" CREATE) 54 | 55 | -------------------------------------------------------------------------------- /cmake/scripts/configure.cmake: -------------------------------------------------------------------------------- 1 | # adds possibility to run configure_file as buildstep 2 | # reference: 3 | # http://www.cmake.org/pipermail/cmake/2012-May/050227.html 4 | # 5 | # This module expects 6 | # INFILE 7 | # OUTFILE 8 | # other custom vars 9 | # 10 | # example usage: 11 | # cmake -DINFILE=blah.in -DOUTFILE=blah.out -Dvar1=value1 -Dvar2=value2 -P scripts/configure.cmake 12 | 13 | configure_file(${INFILE} ${OUTFILE}) 14 | 15 | -------------------------------------------------------------------------------- /cmake/scripts/copydlls.cmake: -------------------------------------------------------------------------------- 1 | # this module expects 2 | # DLLS 3 | # CONF 4 | # DESTINATION 5 | 6 | # example usage: 7 | # cmake -DDLL_DEBUG=xd.dll -DDLL_RELEASE=x.dll -DCONFIGURATION=Release -DDESTINATION=dest -P scripts/copydlls.cmake 8 | 9 | # this script is created cause we do not know configuration in multiconfiguration generators at cmake configure phase ;) 10 | 11 | if ("${CONF}" STREQUAL "Debug") 12 | set(DLL ${DLL_DEBUG}) 13 | else () 14 | set(DLL ${DLL_RELEASE}) 15 | endif() 16 | 17 | execute_process(COMMAND ${CMAKE_COMMAND} -E copy "${DLL}" "${DESTINATION}") 18 | 19 | -------------------------------------------------------------------------------- /cmake/scripts/jsonrpcstub.cmake: -------------------------------------------------------------------------------- 1 | # generates JSONRPC Stub Server && Client 2 | # 3 | # this script expects 4 | # ETH_SOURCE_DIR - main CMAKE_SOURCE_DIR 5 | # ETH_SPEC_PATH 6 | # ETH_SERVER_DIR 7 | # ETH_CLIENT_DIR 8 | # ETH_SERVER_NAME 9 | # ETH_CLIENT_NAME 10 | # ETH_JSON_RPC_STUB 11 | # 12 | # example usage: 13 | # cmake -DETH_SPEC_PATH=spec.json -DETH_SERVER_DIR=libweb3jsonrpc -DETH_CLIENT_DIR=test 14 | # -DETH_SERVER_NAME=AbstractWebThreeStubServer -DETH_CLIENT_NAME=WebThreeStubClient -DETH_JSON_RPC_STUB=/usr/local/bin/jsonrpcstub 15 | 16 | # by default jsonrpcstub produces files in lowercase, we want to stick to this 17 | string(TOLOWER ${ETH_SERVER_NAME} ETH_SERVER_NAME_LOWER) 18 | string(TOLOWER ${ETH_CLIENT_NAME} ETH_CLIENT_NAME_LOWER) 19 | 20 | # setup names 21 | set(SERVER_TMPFILE "${ETH_SERVER_DIR}/${ETH_SERVER_NAME_LOWER}.h.tmp") 22 | set(SERVER_OUTFILE "${ETH_SERVER_DIR}/${ETH_SERVER_NAME_LOWER}.h") 23 | set(CLIENT_TMPFILE "${ETH_CLIENT_DIR}/${ETH_CLIENT_NAME_LOWER}.h.tmp") 24 | set(CLIENT_OUTFILE "${ETH_CLIENT_DIR}/${ETH_CLIENT_NAME_LOWER}.h") 25 | 26 | # create tmp files 27 | execute_process( 28 | COMMAND ${ETH_JSON_RPC_STUB} ${ETH_SPEC_PATH} 29 | --cpp-server=${ETH_SERVER_NAME} --cpp-server-file=${SERVER_TMPFILE} 30 | --cpp-client=${ETH_CLIENT_NAME} --cpp-client-file=${CLIENT_TMPFILE} 31 | OUTPUT_VARIABLE ERR ERROR_QUIET 32 | ) 33 | 34 | # don't throw fatal error on jsonrpcstub error, someone might have old version of jsonrpcstub, 35 | # he does not need to upgrade it if he is not working on JSON RPC 36 | # show him warning instead 37 | if (ERR) 38 | message(WARNING "Your version of jsonrcpstub tool is not supported. Please upgrade it.") 39 | message(WARNING "${ERR}") 40 | else() 41 | include("${ETH_SOURCE_DIR}/cmake/EthUtils.cmake") 42 | replace_if_different("${SERVER_TMPFILE}" "${SERVER_OUTFILE}") 43 | replace_if_different("${CLIENT_TMPFILE}" "${CLIENT_OUTFILE}") 44 | endif() 45 | -------------------------------------------------------------------------------- /cmake/scripts/macdeployfix.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # solves problem with macdeployqt on Qt 5.4 RC and Qt 5.5 4 | # http://qt-project.org/forums/viewthread/50118 5 | 6 | BUILD_FOLDER_PATH=$1 7 | BUILD_QML_FOLDER_PATH="$BUILD_FOLDER_PATH/Resources/qml" 8 | BUILD_PLUGINS_FOLDER_PATH="$BUILD_FOLDER_PATH/PlugIns" 9 | 10 | if [ -d ${BUILD_QML_FOLDER_PATH} ]; then 11 | 12 | declare -a BROKEN_FILES; 13 | k=0; 14 | for j in $(find ${BUILD_QML_FOLDER_PATH} -name *.dylib); do 15 | BROKEN_FILES[${k}]=$j 16 | 17 | ((k=k+1)) 18 | done 19 | 20 | 21 | for i in "${BROKEN_FILES[@]}"; do 22 | REPLACE_STRING="$BUILD_FOLDER_PATH/" 23 | APP_CONTENT_FILE=${i//$REPLACE_STRING/""} 24 | IFS='/' read -a array <<< "$APP_CONTENT_FILE" 25 | LENGTH=${#array[@]} 26 | LAST_ITEM_INDEX=$((LENGTH-1)) 27 | FILE=${array[${LENGTH} - 1]} 28 | 29 | ORIGINE_PATH=$(find ${BUILD_PLUGINS_FOLDER_PATH} -name ${FILE}) 30 | ORIGINE_PATH=${ORIGINE_PATH//$REPLACE_STRING/""} 31 | s="" 32 | for((l=0;l<${LAST_ITEM_INDEX};l++)) do 33 | s=$s"../" 34 | done 35 | s=$s$ORIGINE_PATH 36 | echo "s: $s" 37 | 38 | REMOVE_BROKEN_ALIAS=$(rm -rf $i) 39 | RESULT=$(ln -s $s $i) 40 | done 41 | fi 42 | 43 | # replace framework links 44 | declare -a BROKEN_FRAMEWORKS; 45 | k=0; 46 | BUILD_FRAMEWORKS_FOLDER_PATH="$BUILD_FOLDER_PATH/Frameworks" 47 | for j in $(find ${BUILD_FRAMEWORKS_FOLDER_PATH} -name Qt*.framework); do 48 | BROKEN_FRAMEWORKS[${k}]=$j 49 | ((k=k+1)) 50 | done 51 | for i in "${BROKEN_FRAMEWORKS[@]}"; do 52 | FRAMEWORK_FILE=$i/$(basename -s ".framework" $i) 53 | otool -L $FRAMEWORK_FILE | grep -o /usr/.*Qt.*framework/\\w* | while read -a libs ; do 54 | install_name_tool -change ${libs[0]} @loader_path/../../../`basename ${libs[0]}`.framework/`basename ${libs[0]}` $FRAMEWORK_FILE 55 | done 56 | done 57 | 58 | declare -a BROKEN_PLUGINS; 59 | k=0; 60 | BUILD_PLUGINS_FOLDER_PATH="$BUILD_FOLDER_PATH/PlugIns" 61 | for j in $(find ${BUILD_PLUGINS_FOLDER_PATH} -name *.dylib); do 62 | BROKEN_PLUGINS[${k}]=$j 63 | ((k=k+1)) 64 | done 65 | for i in "${BROKEN_PLUGINS[@]}"; do 66 | FRAMEWORK_FILE=$i 67 | otool -L $FRAMEWORK_FILE | grep -o /usr/.*Qt.*framework/\\w* | while read -a libs ; do 68 | install_name_tool -change ${libs[0]} @loader_path/../../Frameworks/`basename ${libs[0]}`.framework/`basename ${libs[0]}` $FRAMEWORK_FILE 69 | done 70 | done 71 | 72 | -------------------------------------------------------------------------------- /cmake/scripts/resource.hpp.in: -------------------------------------------------------------------------------- 1 | // this file is autogenerated, do not modify!!! 2 | #pragma once 3 | 4 | #include 5 | #include 6 | 7 | namespace dev 8 | { 9 | namespace eth 10 | { 11 | 12 | class ${ETH_RESOURCE_NAME} 13 | { 14 | public: 15 | ${ETH_RESOURCE_NAME}() 16 | { 17 | ${ETH_RESULT_DATA} 18 | ${ETH_RESULT_INIT} 19 | } 20 | 21 | std::string loadResourceAsString(std::string _name) { return std::string(m_resources[_name], m_sizes[_name]); } 22 | 23 | private: 24 | std::map m_resources; 25 | std::map m_sizes; 26 | }; 27 | 28 | } 29 | } 30 | 31 | -------------------------------------------------------------------------------- /cmake/scripts/resources.cmake: -------------------------------------------------------------------------------- 1 | # based on: http://stackoverflow.com/questions/11813271/embed-resources-eg-shader-code-images-into-executable-library-with-cmake 2 | # 3 | # example: 4 | # cmake -DETH_RES_FILE=test.cmake -P resources.cmake 5 | # 6 | # where test.cmake is: 7 | # 8 | # # BEGIN OF cmake.test 9 | # 10 | # set(copydlls "copydlls.cmake") 11 | # set(conf "configure.cmake") 12 | # 13 | # # this three properties must be set! 14 | # 15 | # set(ETH_RESOURCE_NAME "EthResources") 16 | # set(ETH_RESOURCE_LOCATION "${CMAKE_CURRENT_SOURCE_DIR}") 17 | # set(ETH_RESOURCES "copydlls" "conf") 18 | # 19 | # # END of cmake.test 20 | # 21 | 22 | # should define ETH_RESOURCES 23 | include(${ETH_RES_FILE}) 24 | 25 | set(ETH_RESULT_DATA "") 26 | set(ETH_RESULT_INIT "") 27 | 28 | # resource is a name visible for cpp application 29 | foreach(resource ${ETH_RESOURCES}) 30 | 31 | # filename is the name of file which will be used in app 32 | set(filename ${${resource}}) 33 | 34 | # filedata is a file content 35 | file(READ ${filename} filedata HEX) 36 | 37 | # read full name of the file 38 | file(GLOB filename ${filename}) 39 | 40 | # Convert hex data for C compatibility 41 | string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1," filedata ${filedata}) 42 | 43 | # append static variables to result variable 44 | set(ETH_RESULT_DATA "${ETH_RESULT_DATA} static const unsigned char eth_${resource}[] = {\n // ${filename}\n ${filedata}\n};\n") 45 | 46 | # append init resources 47 | set(ETH_RESULT_INIT "${ETH_RESULT_INIT} m_resources[\"${resource}\"] = (char const*)eth_${resource};\n") 48 | set(ETH_RESULT_INIT "${ETH_RESULT_INIT} m_sizes[\"${resource}\"] = sizeof(eth_${resource});\n") 49 | 50 | endforeach(resource) 51 | 52 | set(ETH_DST_NAME "${ETH_RESOURCE_LOCATION}/${ETH_RESOURCE_NAME}") 53 | 54 | configure_file("${CMAKE_CURRENT_LIST_DIR}/resource.hpp.in" "${ETH_DST_NAME}.hpp.tmp") 55 | 56 | include("${CMAKE_CURRENT_LIST_DIR}/../EthUtils.cmake") 57 | replace_if_different("${ETH_DST_NAME}.hpp.tmp" "${ETH_DST_NAME}.hpp") 58 | -------------------------------------------------------------------------------- /cmake/scripts/runtest.cmake: -------------------------------------------------------------------------------- 1 | # Should be used to run ctest 2 | # 3 | # example usage: 4 | # cmake -DETH_TEST_NAME=TestInterfaceStub -DCTEST_COMMAND=/path/to/ctest -P scripts/runtest.cmake 5 | 6 | if (NOT CTEST_COMMAND) 7 | message(FATAL_ERROR "ctest could not be found!") 8 | endif() 9 | 10 | # verbosity is off, cause BOOST_MESSAGE is not thread safe and output is a trash 11 | # see https://codecrafter.wordpress.com/2012/11/01/c-unit-test-framework-adapter-part-3/ 12 | # 13 | # output might not be usefull cause of thread safety issue 14 | execute_process(COMMAND ${CTEST_COMMAND} --force-new-ctest-process -C Debug --output-on-failure -j 4 -R "${ETH_TEST_NAME}[.].*") 15 | 16 | -------------------------------------------------------------------------------- /ethminer/ADLUtils.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mining-visualizer/MVis-tokenminer/ae09b3f5314f202230dd812b5cd354a54bb140c6/ethminer/ADLUtils.cpp -------------------------------------------------------------------------------- /ethminer/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_policy(SET CMP0015 NEW) 2 | set(CMAKE_AUTOMOC OFF) 3 | 4 | aux_source_directory(. SRC_LIST) 5 | 6 | #set(SRC_LIST 7 | # ${SRC_LIST} 8 | # ${CMAKE_CURRENT_SOURCE_DIR}/secp256k1/secp256k1.c 9 | #) 10 | 11 | include_directories(BEFORE ..) 12 | include_directories(${Boost_INCLUDE_DIRS}) 13 | 14 | if (JSONRPC) 15 | include_directories(BEFORE ${JSONCPP_INCLUDE_DIRS}) 16 | include_directories(${JSON_RPC_CPP_INCLUDE_DIRS}) 17 | endif() 18 | 19 | if (ETHASHCUDA) 20 | include_directories(${CUDA_INCLUDE_DIRS}) 21 | endif () 22 | 23 | set(EXECUTABLE tokenminer) 24 | 25 | file(GLOB HEADERS "*.h") 26 | 27 | if (NOT DEFINED WIN32) 28 | list(REMOVE_ITEM SRC_LIST ./speedfan.cpp) 29 | list(REMOVE_ITEM HEADERS ./speedfan.h) 30 | endif() 31 | 32 | add_executable(${EXECUTABLE} ${SRC_LIST} ${HEADERS}) 33 | 34 | add_dependencies(${EXECUTABLE} BuildInfo.h) 35 | 36 | target_link_libraries(${EXECUTABLE} ${Boost_REGEX_LIBRARIES}) 37 | target_link_libraries(${EXECUTABLE} ${CMAKE_DL_LIBS}) 38 | 39 | if (JSONRPC) 40 | target_link_libraries(${EXECUTABLE} ${JSON_RPC_CPP_CLIENT_LIBRARIES}) 41 | target_link_libraries(${EXECUTABLE} ${CURL_LIBRARIES}) 42 | if (DEFINED WIN32 AND NOT DEFINED CMAKE_COMPILER_IS_MINGW) 43 | eth_copy_dlls(${EXECUTABLE} CURL_DLLS) 44 | endif() 45 | endif() 46 | 47 | target_link_libraries(${EXECUTABLE} ethcore) 48 | target_link_libraries(${EXECUTABLE} ethash) 49 | target_link_libraries(${EXECUTABLE} devcore) 50 | if (NOT MSVC) 51 | target_link_libraries(${EXECUTABLE} ${GMP_LIBRARIES}) 52 | endif() 53 | 54 | if (ETHSTRATUM) 55 | target_link_libraries(${EXECUTABLE} ethstratum) 56 | endif() 57 | 58 | if (DEFINED WIN32 AND NOT DEFINED CMAKE_COMPILER_IS_MINGW) 59 | eth_copy_dlls("${EXECUTABLE}" MHD_DLLS) 60 | eth_copy_dlls("${EXECUTABLE}" OpenCL_DLLS) 61 | endif() 62 | 63 | 64 | if (APPLE) 65 | install(TARGETS ${EXECUTABLE} DESTINATION bin) 66 | else() 67 | eth_install_executable(${EXECUTABLE}) 68 | endif() 69 | 70 | -------------------------------------------------------------------------------- /ethminer/Common.cpp: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | This file is part of mvis-ethereum. 4 | 5 | mvis-ethereum is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | mvis-ethereum is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with mvis-ethereum. If not, see . 17 | */ 18 | 19 | #include "Common.h" 20 | #include "MultiLog.h" 21 | 22 | using namespace std; 23 | using namespace boost; 24 | 25 | 26 | // static initializers 27 | boost::thread* TimerCallback::m_bt = nullptr; 28 | boost::asio::io_service* TimerCallback::m_ios = nullptr; 29 | boost::asio::io_service::work* TimerCallback::m_work; 30 | 31 | /*----------------------------------------------------------------------------------- 32 | * class TimerCallback 33 | *----------------------------------------------------------------------------------*/ 34 | void TimerCallback::Init() 35 | { 36 | // this needs to be called once before any timer callbacks are instantiated. 37 | static Mutex x_init; 38 | Guard l(x_init); 39 | 40 | // check if we've been called already. 41 | if (m_bt) return; 42 | 43 | // launch a thread to handle timer callbacks. 44 | m_ios = new boost::asio::io_service; 45 | m_bt = new boost::thread([&] () { 46 | for (;;) 47 | { 48 | try 49 | { 50 | m_work = new asio::io_service::work(*m_ios); 51 | m_ios->run(); 52 | break; 53 | } 54 | catch (std::exception& e) 55 | { 56 | LogB << "TimerCallback::Init io_service exception : " << e.what(); 57 | m_ios->reset(); 58 | } 59 | } 60 | }); 61 | } 62 | 63 | TimerCallback::TimerCallback(CallbackFn _cb) : isRunning(false), m_cb(_cb) 64 | { 65 | if (!m_ios) 66 | throw std::runtime_error("TimerCallback.constructor - boost::io_service has not been initialized"); 67 | m_timer = new asio::deadline_timer(*m_ios); 68 | } 69 | 70 | // rate is milliseconds 71 | void TimerCallback::start(long _rate) 72 | { 73 | isRunning = true; 74 | m_rate = _rate; 75 | m_timer->expires_from_now(posix_time::milliseconds(m_rate)); 76 | m_timer->async_wait(bind(&TimerCallback::callback, this, asio::placeholders::error)); 77 | } 78 | 79 | void TimerCallback::stop() 80 | { 81 | isRunning = false; 82 | m_timer->cancel(); 83 | } 84 | 85 | void TimerCallback::callback(const boost::system::error_code& e) 86 | { 87 | if (e == asio::error::operation_aborted) 88 | { 89 | isRunning = false; 90 | return; 91 | } 92 | m_timer->expires_at(m_timer->expires_at() + posix_time::milliseconds(m_rate)); 93 | m_timer->async_wait(bind(&TimerCallback::callback, this, asio::placeholders::error)); 94 | m_cb(m_data); 95 | } 96 | 97 | void TimerCallback::setData(void* _data) 98 | { 99 | m_data = _data; 100 | } 101 | 102 | 103 | int strToInt(std::string s, int defaultVal) 104 | { 105 | try 106 | { 107 | return std::stoi(s); 108 | } 109 | catch (...) 110 | { 111 | return defaultVal; 112 | } 113 | } 114 | 115 | bool isDigits(const std::string &_str) 116 | { 117 | return std::all_of(_str.begin(), _str.end(), ::isdigit); 118 | } 119 | 120 | bool isNumeric(const std::string &_str) 121 | { 122 | if (_str.empty()) 123 | return false; 124 | char* p; 125 | double converted = strtod(_str.c_str(), &p); 126 | return !(*p); 127 | } -------------------------------------------------------------------------------- /ethminer/Common.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | /* 5 | This file is part of mvis-ethereum. 6 | 7 | mvis-ethereum is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | mvis-ethereum is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with mvis-ethereum. If not, see . 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | using namespace dev; 27 | 28 | using SteadyClock = std::chrono::steady_clock; 29 | using SystemClock = std::chrono::system_clock; 30 | 31 | 32 | // this implements a periodic timer / callback function. be sure to call Init first. 33 | class TimerCallback 34 | { 35 | public: 36 | 37 | using CallbackFn = std::function; 38 | 39 | static void Init(); 40 | 41 | TimerCallback(CallbackFn _cb); 42 | // rate is milliseconds 43 | void start(long _rate); 44 | void stop(); 45 | void callback(const boost::system::error_code& e); 46 | void setData(void* _data); 47 | 48 | public: 49 | bool isRunning; 50 | 51 | private: 52 | 53 | static boost::thread* m_bt; 54 | static boost::asio::io_service* m_ios; 55 | static boost::asio::io_service::work* m_work; 56 | 57 | boost::asio::deadline_timer* m_timer; 58 | CallbackFn m_cb; 59 | long m_rate; 60 | void* m_data; 61 | 62 | }; // class TimerCallback 63 | 64 | 65 | #ifdef _WIN32 66 | 67 | class Timer 68 | { 69 | public: 70 | 71 | Timer() 72 | { 73 | QueryPerformanceFrequency(&m_frequency); 74 | restart(); 75 | } 76 | 77 | void restart() 78 | { 79 | QueryPerformanceCounter(&m_startTime); 80 | } 81 | 82 | double elapsedSeconds() const 83 | { 84 | LARGE_INTEGER endingTime; 85 | QueryPerformanceCounter(&endingTime); 86 | return (double)(endingTime.QuadPart - m_startTime.QuadPart) / m_frequency.QuadPart; 87 | } 88 | 89 | uint64_t elapsedMilliseconds() const 90 | { 91 | LARGE_INTEGER endingTime; 92 | QueryPerformanceCounter(&endingTime); 93 | return (endingTime.QuadPart - m_startTime.QuadPart) * 1000 / m_frequency.QuadPart; 94 | } 95 | 96 | uint64_t elapsedMicroseconds() const 97 | { 98 | LARGE_INTEGER endingTime; 99 | QueryPerformanceCounter(&endingTime); 100 | return (endingTime.QuadPart - m_startTime.QuadPart) * 1000000 / m_frequency.QuadPart; 101 | } 102 | 103 | private: 104 | LARGE_INTEGER m_startTime; 105 | LARGE_INTEGER m_frequency; 106 | }; 107 | 108 | #else 109 | 110 | class Timer 111 | { 112 | public: 113 | Timer() 114 | { 115 | restart(); 116 | } 117 | 118 | void restart() 119 | { 120 | m_t = std::chrono::high_resolution_clock::now(); 121 | } 122 | 123 | double elapsedSeconds() const 124 | { 125 | return std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - m_t).count() / 1000000.0; 126 | } 127 | 128 | uint64_t elapsedMilliseconds() const 129 | { 130 | return std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - m_t).count(); 131 | } 132 | 133 | uint64_t elapsedMicroseconds() const 134 | { 135 | return std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - m_t).count(); 136 | } 137 | 138 | private: 139 | std::chrono::high_resolution_clock::time_point m_t; 140 | }; 141 | 142 | #endif 143 | 144 | 145 | int strToInt(std::string s, int defaultVal); 146 | bool isDigits(const std::string &_str); 147 | bool isNumeric(const std::string &_str); -------------------------------------------------------------------------------- /ethminer/DataLogger.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | /* 5 | This file is part of mvis-ethereum. 6 | 7 | mvis-ethereum is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | mvis-ethereum is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with mvis-ethereum. If not, see . 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | using namespace std; 27 | 28 | 29 | class DataLogger 30 | { 31 | 32 | public: 33 | 34 | DataLogger(); 35 | void writeToDisk(); 36 | void recordBestHash(uint64_t _bh); 37 | void recordCloseHit(uint64_t _closeHit, unsigned _work, int _gpuMiner); 38 | void recordHashFault(int _gpuMiner); 39 | void recordSolution(unsigned _blockNumber, int _state, bool _stale, int _gpuMiner); 40 | int solutionCount(); 41 | int closeHitCount(); 42 | int hashFaultCount(); 43 | uint64_t retrieveBestHash(void); 44 | std::string retrieveBestHashDate(void); 45 | Json::Value retrieveCloseHits(bool _clear); 46 | Json::Value retrieveHashFaults(bool _clear); 47 | std::string retrieveLastSolution(void); 48 | Json::Value retrieveSolutions(bool _clear); 49 | std::string now(); 50 | 51 | void test(); 52 | 53 | private: 54 | Json::Value miningResults; 55 | std::string logfilePath(void); 56 | 57 | }; 58 | 59 | -------------------------------------------------------------------------------- /ethminer/Misc.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | /* 5 | This file is part of mvis-ethereum. 6 | 7 | mvis-ethereum is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | mvis-ethereum is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with mvis-ethereum. If not, see . 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | bool getlineEx(std::istream& is, std::string& t); 28 | boost::filesystem::path getAppDataFolder(void); 29 | std::string& LowerCase(std::string& _s); 30 | bool fileExists(std::string _path); 31 | void keccak256_0xBitcoin(dev::bytes& _challenge, dev::h160& _sender, dev::h256& _nonce, dev::bytes& _hash); 32 | uint64_t HexToInt(std::string _value); 33 | boost::filesystem::path getExecFolder(void); 34 | 35 | template 36 | void split(const std::string& s, char delim, Out result); 37 | std::vector split(const std::string& s, char delim); -------------------------------------------------------------------------------- /ethminer/MultiLog.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | /* 5 | This file is part of mvis-ethereum. 6 | 7 | mvis-ethereum is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | mvis-ethereum is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with mvis-ethereum. If not, see . 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | enum LogMode {LogOn, LogOff, LogFiltered}; 30 | 31 | class MultiLog 32 | { 33 | 34 | public: 35 | static void Init(); 36 | MultiLog(LogMode _screenMode, LogMode _diskMode); 37 | MultiLog(int _xpos, int _ypos); 38 | ~MultiLog(); 39 | 40 | public: 41 | template MultiLog& operator<<(T const& _t) { m_sstr << _t; return *this; } 42 | 43 | private: 44 | static void loadFilters(); 45 | static void trimLogFile(); 46 | // this is static due to multi-threading 47 | static void simpleDebugOut(std::ostream& _os, std::string const& _s, bool _time, bool _eol); 48 | int filterMatch(std::string _s); 49 | void clearYExtent(); 50 | static int getXY(int& x, int& y); 51 | static int getXPos(); 52 | static int getYPos(); 53 | void GotoXY(int x, int y); 54 | void clearLine(int _line); 55 | int getBufferHeight(); 56 | 57 | private: 58 | std::stringstream m_sstr; ///< The accrued log entry. 59 | LogMode m_screenMode; 60 | LogMode m_diskMode; 61 | bool m_positioned; 62 | int m_xpos, m_ypos; 63 | 64 | static boost::filesystem::path m_logFilename; 65 | static boost::filesystem::path m_filterFilename; 66 | static std::vector m_filters; 67 | static SteadyClock::time_point m_filterCheckTime; 68 | static std::time_t m_filterChangeTime; 69 | static Mutex x_screenOutput; 70 | static Mutex x_diskOutput; 71 | static Mutex x_filter; 72 | static std::ofstream m_file; 73 | static int m_currentYBase; 74 | static int m_currentYExtent; 75 | static int m_rogueCatcher; 76 | 77 | }; 78 | 79 | 80 | 81 | 82 | #define LogD MultiLog(LogOff, LogOn) // log to Disk only, no filtering 83 | #define LogF MultiLog(LogOff, LogFiltered) // log to disk only, Filtered 84 | #define LogB MultiLog(LogOn, LogOn) // log to Both screen & disk, no filtering 85 | #define LogS MultiLog(LogOn, LogOff) // screen only 86 | #define LogXY(x,y) MultiLog((x), (y)) // x and y are zero-based. 87 | 88 | std::string getTimeStr(); 89 | 90 | -------------------------------------------------------------------------------- /ethminer/PhoneHome.h: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is generated by jsonrpcstub, DO NOT CHANGE IT MANUALLY! 3 | */ 4 | 5 | #ifndef JSONRPC_CPP_STUB_PHONEHOME_H_ 6 | #define JSONRPC_CPP_STUB_PHONEHOME_H_ 7 | 8 | #include 9 | 10 | class PhoneHome : public jsonrpc::Client 11 | { 12 | public: 13 | PhoneHome(jsonrpc::IClientConnector &conn, jsonrpc::clientVersion_t type = jsonrpc::JSONRPC_CLIENT_V2) : jsonrpc::Client(conn, type) {} 14 | 15 | int report_benchmark(const std::string& param1, int param2) throw (jsonrpc::JsonRpcException) 16 | { 17 | Json::Value p; 18 | p.append(param1); 19 | p.append(param2); 20 | Json::Value result = this->CallMethod("report_benchmark",p); 21 | if (result.isInt()) 22 | return result.asInt(); 23 | else 24 | throw jsonrpc::JsonRpcException(jsonrpc::Errors::ERROR_CLIENT_INVALID_RESPONSE, result.toStyledString()); 25 | } 26 | }; 27 | 28 | #endif //JSONRPC_CPP_STUB_PHONEHOME_H_ 29 | -------------------------------------------------------------------------------- /ethminer/ProgOpt.cpp: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | This file is part of mvis-ethereum. 4 | 5 | mvis-ethereum is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | mvis-ethereum is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with mvis-ethereum. If not, see . 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | namespace pt = boost::property_tree; 27 | namespace fs = boost::filesystem; 28 | 29 | // static intializers 30 | pt::iptree *ProgOpt::m_tree; 31 | bool ProgOpt::m_updating = false; 32 | ProgOpt::defaults_t *ProgOpt::m_defaults; 33 | boost::filesystem::path ProgOpt::m_path; 34 | 35 | 36 | bool ProgOpt::Load(std::string _config) 37 | { 38 | m_tree = new pt::iptree; 39 | m_tree->clear(); 40 | 41 | m_defaults = new ProgOpt::defaults_t; 42 | m_defaults->clear(); 43 | 44 | if (_config != "" && !fileExists(_config)) 45 | { 46 | LogB << "ERROR! Invalid --config parameter : '" << _config << "'. File does not exist!"; 47 | return false; 48 | } 49 | 50 | if (_config != "") 51 | m_path = _config; 52 | else 53 | { 54 | // try current folder first 55 | m_path = getExecFolder(); 56 | m_path = m_path / "tokenminer.ini"; 57 | if (!fs::exists(m_path)) 58 | { 59 | // check %LocalAppData 60 | m_path = getAppDataFolder(); 61 | m_path = m_path / "tokenminer.ini"; 62 | if (!fs::exists(m_path)) 63 | { 64 | LogB << "Error! Tokenminer.ini settings file not found."; 65 | return false; 66 | } 67 | } 68 | } 69 | try 70 | { 71 | pt::read_ini_ex(m_path.generic_string(), *m_tree); 72 | 73 | // set up sensible defaults for various settings. note that emplace does 74 | // not overwrite existing values. 75 | m_defaults->emplace("ThermalProtection.TempProvider", "amd_adl"); 76 | m_defaults->emplace("ThermalProtection.ThrottleTemp", "80"); 77 | m_defaults->emplace("ThermalProtection.ShutDown", "20"); 78 | 79 | m_defaults->emplace("Node.Host", "127.0.0.1"); 80 | m_defaults->emplace("Node.RPCPort", "8545"); 81 | 82 | } 83 | catch (std::exception const& _e) 84 | { 85 | LogB << "Exception: ProgOpt::Load - " << _e.what(); 86 | return false; 87 | } 88 | 89 | return true; 90 | } 91 | 92 | void ProgOpt::Reload() 93 | { 94 | Load(m_path.generic_string()); 95 | } 96 | 97 | void ProgOpt::SaveToDisk() 98 | { 99 | pt::write_ini(m_path.string(), *m_tree); 100 | } 101 | 102 | std::string ProgOpt::Get(std::string _section, std::string _key, std::string _default) 103 | { 104 | return m_tree->get(_section + "." + _key, _default); 105 | } 106 | 107 | std::string ProgOpt::Get(std::string _section, std::string _key) 108 | { 109 | std::string defKey = _section + "." + _key; 110 | defaults_t::const_iterator def = m_defaults->find(defKey); 111 | if (def == m_defaults->end()) 112 | return m_tree->get(defKey, ""); 113 | else 114 | return m_tree->get(defKey, def->second); 115 | } 116 | 117 | void ProgOpt::Put(std::string _section, std::string _key, std::string _value) 118 | { 119 | m_tree->put(_section + "." + _key, _value); 120 | if (!m_updating) 121 | SaveToDisk(); 122 | } 123 | 124 | void ProgOpt::Put(std::string _section, std::string _key, uint64_t _value) 125 | { 126 | Put(_section, _key, boost::lexical_cast(_value)); 127 | } 128 | 129 | void ProgOpt::beginUpdating() 130 | { 131 | m_updating = true; 132 | } 133 | 134 | void ProgOpt::endUpdating() 135 | { 136 | m_updating = false; 137 | SaveToDisk(); 138 | } 139 | -------------------------------------------------------------------------------- /ethminer/ProgOpt.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | /* 4 | This file is part of mvis-ethereum. 5 | 6 | mvis-ethereum is free software: you can redistribute it and/or 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 | mvis-ethereum 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 mvis-ethereum. If not, see . 18 | */ 19 | 20 | #include 21 | #include 22 | #include 23 | 24 | class ProgOpt 25 | { 26 | 27 | public: 28 | 29 | static bool Load(std::string _config); 30 | static void Reload(); 31 | static void SaveToDisk(); 32 | static std::string Get(std::string _section, std::string _key, std::string _default); 33 | static std::string Get(std::string _section, std::string _key); 34 | static void Put(std::string _section, std::string _key, std::string _value); 35 | static void Put(std::string _section, std::string _key, uint64_t _value); 36 | static void beginUpdating(); 37 | static void endUpdating(); 38 | 39 | typedef std::unordered_map defaults_t; 40 | 41 | private: 42 | 43 | static boost::property_tree::iptree *m_tree; 44 | static defaults_t *m_defaults; 45 | static bool m_updating; 46 | static boost::filesystem::path m_path; 47 | }; 48 | -------------------------------------------------------------------------------- /ethminer/UDPSocket.h: -------------------------------------------------------------------------------- 1 | 2 | #pragma once 3 | 4 | /* 5 | This file is part of mvis-ethereum. 6 | 7 | mvis-ethereum is free software: you can redistribute it and/or modify 8 | it under the terms of the GNU General Public License as published by 9 | the Free Software Foundation, either version 3 of the License, or 10 | (at your option) any later version. 11 | 12 | mvis-ethereum is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 | GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with mvis-ethereum. If not, see . 19 | */ 20 | 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | 29 | class UDPSocket { 30 | public: 31 | 32 | using CommandRecvFn = boost::function; 33 | 34 | UDPSocket(unsigned _udpListen); 35 | ~UDPSocket(); 36 | void onCommandRecv(CommandRecvFn _handler); 37 | bool connected(); 38 | void send_packet(Json::Value _v); 39 | void send_packet(Json::Value _v, int _returnPort); 40 | void send_packet(Json::Value _v, int _returnPort, boost::asio::ip::udp::endpoint _endpoint); 41 | void setCallerAsClient(int _returnPort, int _minerId); 42 | bool isCallerClient(int _returnPort); 43 | void disconnect(std::string _returnType); 44 | 45 | private: 46 | 47 | void launchIOS(); 48 | void start_receive(); 49 | void handle_receive(const boost::system::error_code& error, std::size_t bytes_transferred); 50 | void handle_send(boost::shared_ptr message, const boost::system::error_code& error, std::size_t bytes_transferred); 51 | 52 | private: 53 | 54 | // event handler function 55 | CommandRecvFn m_onCommandRecv; 56 | 57 | static const int RECV_BUFF_SIZE = 512; 58 | 59 | boost::asio::io_service* m_ios; 60 | boost::asio::ip::udp::socket* m_socket; 61 | boost::asio::ip::udp::endpoint m_recv_endpoint; 62 | boost::array m_recv_buffer; 63 | 64 | int m_listenport; 65 | int m_connection_returnport = 5226; 66 | boost::asio::ip::udp::endpoint m_connection_endpoint; 67 | int m_minerId; 68 | // this does not refer to a socket connection, but rather to a miner connection. 69 | bool m_connected; 70 | 71 | }; 72 | 73 | 74 | -------------------------------------------------------------------------------- /ethminer/farm.json: -------------------------------------------------------------------------------- 1 | [ 2 | { "name": "eth_getWork", "params": [], "order": [], "returns": []}, 3 | { "name": "eth_submitWork", "params": ["", "", ""], "order": [], "returns": true}, 4 | { "name": "eth_submitHashrate", "params": ["", ""], "order": [], "returns": true}, 5 | { "name": "eth_awaitNewWork", "params": [], "order": [], "returns": []}, 6 | { "name": "eth_progress", "params": [], "order": [], "returns": true} 7 | ] 8 | -------------------------------------------------------------------------------- /ethminer/phonehome.json: -------------------------------------------------------------------------------- 1 | [ 2 | { "name": "report_benchmark", "params": [ "", 0 ], "order": [], "returns": 0 } 3 | ] 4 | -------------------------------------------------------------------------------- /ethminer/secp256k1/ecdsa.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_ECDSA_ 8 | #define _SECP256K1_ECDSA_ 9 | 10 | #include "scalar.h" 11 | #include "group.h" 12 | #include "ecmult.h" 13 | 14 | typedef struct { 15 | secp256k1_scalar_t r, s; 16 | } secp256k1_ecdsa_sig_t; 17 | 18 | static int secp256k1_ecdsa_sig_parse(secp256k1_ecdsa_sig_t *r, const unsigned char *sig, int size); 19 | static int secp256k1_ecdsa_sig_serialize(unsigned char *sig, int *size, const secp256k1_ecdsa_sig_t *a); 20 | static int secp256k1_ecdsa_sig_verify(const secp256k1_ecmult_context_t *ctx, const secp256k1_ecdsa_sig_t *sig, const secp256k1_ge_t *pubkey, const secp256k1_scalar_t *message); 21 | static int secp256k1_ecdsa_sig_sign(const secp256k1_ecmult_gen_context_t *ctx, secp256k1_ecdsa_sig_t *sig, const secp256k1_scalar_t *seckey, const secp256k1_scalar_t *message, const secp256k1_scalar_t *nonce, int *recid); 22 | static int secp256k1_ecdsa_sig_recover(const secp256k1_ecmult_context_t *ctx, const secp256k1_ecdsa_sig_t *sig, secp256k1_ge_t *pubkey, const secp256k1_scalar_t *message, int recid); 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /ethminer/secp256k1/eckey.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_ECKEY_ 8 | #define _SECP256K1_ECKEY_ 9 | 10 | #include "group.h" 11 | #include "scalar.h" 12 | #include "ecmult.h" 13 | #include "ecmult_gen.h" 14 | 15 | static int secp256k1_eckey_pubkey_parse(secp256k1_ge_t *elem, const unsigned char *pub, int size); 16 | static int secp256k1_eckey_pubkey_serialize(secp256k1_ge_t *elem, unsigned char *pub, int *size, int compressed); 17 | 18 | static int secp256k1_eckey_privkey_parse(secp256k1_scalar_t *key, const unsigned char *privkey, int privkeylen); 19 | static int secp256k1_eckey_privkey_serialize(const secp256k1_ecmult_gen_context_t *ctx, unsigned char *privkey, int *privkeylen, const secp256k1_scalar_t *key, int compressed); 20 | 21 | static int secp256k1_eckey_privkey_tweak_add(secp256k1_scalar_t *key, const secp256k1_scalar_t *tweak); 22 | static int secp256k1_eckey_pubkey_tweak_add(const secp256k1_ecmult_context_t *ctx, secp256k1_ge_t *key, const secp256k1_scalar_t *tweak); 23 | static int secp256k1_eckey_privkey_tweak_mul(secp256k1_scalar_t *key, const secp256k1_scalar_t *tweak); 24 | static int secp256k1_eckey_pubkey_tweak_mul(const secp256k1_ecmult_context_t *ctx, secp256k1_ge_t *key, const secp256k1_scalar_t *tweak); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /ethminer/secp256k1/ecmult.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_ECMULT_ 8 | #define _SECP256K1_ECMULT_ 9 | 10 | #include "num.h" 11 | #include "group.h" 12 | 13 | typedef struct { 14 | /* For accelerating the computation of a*P + b*G: */ 15 | secp256k1_ge_storage_t (*pre_g)[]; /* odd multiples of the generator */ 16 | #ifdef USE_ENDOMORPHISM 17 | secp256k1_ge_storage_t (*pre_g_128)[]; /* odd multiples of 2^128*generator */ 18 | #endif 19 | } secp256k1_ecmult_context_t; 20 | 21 | static void secp256k1_ecmult_context_init(secp256k1_ecmult_context_t *ctx); 22 | static void secp256k1_ecmult_context_build(secp256k1_ecmult_context_t *ctx); 23 | static void secp256k1_ecmult_context_clone(secp256k1_ecmult_context_t *dst, 24 | const secp256k1_ecmult_context_t *src); 25 | static void secp256k1_ecmult_context_clear(secp256k1_ecmult_context_t *ctx); 26 | static int secp256k1_ecmult_context_is_built(const secp256k1_ecmult_context_t *ctx); 27 | 28 | /** Double multiply: R = na*A + ng*G */ 29 | static void secp256k1_ecmult(const secp256k1_ecmult_context_t *ctx, secp256k1_gej_t *r, const secp256k1_gej_t *a, const secp256k1_scalar_t *na, const secp256k1_scalar_t *ng); 30 | 31 | #endif 32 | -------------------------------------------------------------------------------- /ethminer/secp256k1/ecmult_gen.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_ECMULT_GEN_ 8 | #define _SECP256K1_ECMULT_GEN_ 9 | 10 | #include "scalar.h" 11 | #include "group.h" 12 | 13 | typedef struct { 14 | /* For accelerating the computation of a*G: 15 | * To harden against timing attacks, use the following mechanism: 16 | * * Break up the multiplicand into groups of 4 bits, called n_0, n_1, n_2, ..., n_63. 17 | * * Compute sum(n_i * 16^i * G + U_i, i=0..63), where: 18 | * * U_i = U * 2^i (for i=0..62) 19 | * * U_i = U * (1-2^63) (for i=63) 20 | * where U is a point with no known corresponding scalar. Note that sum(U_i, i=0..63) = 0. 21 | * For each i, and each of the 16 possible values of n_i, (n_i * 16^i * G + U_i) is 22 | * precomputed (call it prec(i, n_i)). The formula now becomes sum(prec(i, n_i), i=0..63). 23 | * None of the resulting prec group elements have a known scalar, and neither do any of 24 | * the intermediate sums while computing a*G. 25 | */ 26 | secp256k1_ge_storage_t (*prec)[64][16]; /* prec[j][i] = 16^j * i * G + U_i */ 27 | secp256k1_scalar_t blind; 28 | secp256k1_gej_t initial; 29 | } secp256k1_ecmult_gen_context_t; 30 | 31 | static void secp256k1_ecmult_gen_context_init(secp256k1_ecmult_gen_context_t* ctx); 32 | static void secp256k1_ecmult_gen_context_build(secp256k1_ecmult_gen_context_t* ctx); 33 | static void secp256k1_ecmult_gen_context_clone(secp256k1_ecmult_gen_context_t *dst, 34 | const secp256k1_ecmult_gen_context_t* src); 35 | static void secp256k1_ecmult_gen_context_clear(secp256k1_ecmult_gen_context_t* ctx); 36 | static int secp256k1_ecmult_gen_context_is_built(const secp256k1_ecmult_gen_context_t* ctx); 37 | 38 | /** Multiply with the generator: R = a*G */ 39 | static void secp256k1_ecmult_gen(const secp256k1_ecmult_gen_context_t* ctx, secp256k1_gej_t *r, const secp256k1_scalar_t *a); 40 | 41 | static void secp256k1_ecmult_gen_blind(secp256k1_ecmult_gen_context_t *ctx, const unsigned char *seed32); 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /ethminer/secp256k1/field_10x26.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_FIELD_REPR_ 8 | #define _SECP256K1_FIELD_REPR_ 9 | 10 | #include 11 | 12 | typedef struct { 13 | /* X = sum(i=0..9, elem[i]*2^26) mod n */ 14 | uint32_t n[10]; 15 | #ifdef VERIFY 16 | int magnitude; 17 | int normalized; 18 | #endif 19 | } secp256k1_fe_t; 20 | 21 | /* Unpacks a constant into a overlapping multi-limbed FE element. */ 22 | #define SECP256K1_FE_CONST_INNER(d7, d6, d5, d4, d3, d2, d1, d0) { \ 23 | (d0) & 0x3FFFFFFUL, \ 24 | ((d0) >> 26) | ((d1) & 0xFFFFFUL) << 6, \ 25 | ((d1) >> 20) | ((d2) & 0x3FFFUL) << 12, \ 26 | ((d2) >> 14) | ((d3) & 0xFFUL) << 18, \ 27 | ((d3) >> 8) | ((d4) & 0x3) << 24, \ 28 | ((d4) >> 2) & 0x3FFFFFFUL, \ 29 | ((d4) >> 28) | ((d5) & 0x3FFFFFUL) << 4, \ 30 | ((d5) >> 22) | ((d6) & 0xFFFF) << 10, \ 31 | ((d6) >> 16) | ((d7) & 0x3FF) << 16, \ 32 | ((d7) >> 10) \ 33 | } 34 | 35 | #ifdef VERIFY 36 | #define SECP256K1_FE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {SECP256K1_FE_CONST_INNER((d7), (d6), (d5), (d4), (d3), (d2), (d1), (d0)), 1, 1} 37 | #else 38 | #define SECP256K1_FE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {SECP256K1_FE_CONST_INNER((d7), (d6), (d5), (d4), (d3), (d2), (d1), (d0))} 39 | #endif 40 | 41 | typedef struct { 42 | uint32_t n[8]; 43 | } secp256k1_fe_storage_t; 44 | 45 | #define SECP256K1_FE_STORAGE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {{ (d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7) }} 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /ethminer/secp256k1/field_5x52.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_FIELD_REPR_ 8 | #define _SECP256K1_FIELD_REPR_ 9 | 10 | #include 11 | 12 | typedef struct { 13 | /* X = sum(i=0..4, elem[i]*2^52) mod n */ 14 | uint64_t n[5]; 15 | #ifdef VERIFY 16 | int magnitude; 17 | int normalized; 18 | #endif 19 | } secp256k1_fe_t; 20 | 21 | /* Unpacks a constant into a overlapping multi-limbed FE element. */ 22 | #define SECP256K1_FE_CONST_INNER(d7, d6, d5, d4, d3, d2, d1, d0) { \ 23 | (d0) | ((uint64_t)(d1) & 0xFFFFFUL) << 32, \ 24 | ((d1) >> 20) | ((uint64_t)(d2)) << 12 | ((uint64_t)(d3) & 0xFFUL) << 44, \ 25 | ((d3) >> 8) | ((uint64_t)(d4) & 0xFFFFFFFUL) << 24, \ 26 | ((d4) >> 28) | ((uint64_t)(d5)) << 4 | ((uint64_t)(d6) & 0xFFFFUL) << 36, \ 27 | ((d6) >> 16) | ((uint64_t)(d7)) << 16 \ 28 | } 29 | 30 | #ifdef VERIFY 31 | #define SECP256K1_FE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {SECP256K1_FE_CONST_INNER((d7), (d6), (d5), (d4), (d3), (d2), (d1), (d0)), 1, 1} 32 | #else 33 | #define SECP256K1_FE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {SECP256K1_FE_CONST_INNER((d7), (d6), (d5), (d4), (d3), (d2), (d1), (d0))} 34 | #endif 35 | 36 | typedef struct { 37 | uint64_t n[4]; 38 | } secp256k1_fe_storage_t; 39 | 40 | #define SECP256K1_FE_STORAGE_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {{ \ 41 | (d0) | ((uint64_t)(d1)) << 32, \ 42 | (d2) | ((uint64_t)(d3)) << 32, \ 43 | (d4) | ((uint64_t)(d5)) << 32, \ 44 | (d6) | ((uint64_t)(d7)) << 32 \ 45 | }} 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /ethminer/secp256k1/hash.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_HASH_ 8 | #define _SECP256K1_HASH_ 9 | 10 | #include 11 | #include 12 | 13 | typedef struct { 14 | uint32_t s[32]; 15 | uint32_t buf[16]; /* In big endian */ 16 | size_t bytes; 17 | } secp256k1_sha256_t; 18 | 19 | static void secp256k1_sha256_initialize(secp256k1_sha256_t *hash); 20 | static void secp256k1_sha256_write(secp256k1_sha256_t *hash, const unsigned char *data, size_t size); 21 | static void secp256k1_sha256_finalize(secp256k1_sha256_t *hash, unsigned char *out32); 22 | 23 | typedef struct { 24 | secp256k1_sha256_t inner, outer; 25 | } secp256k1_hmac_sha256_t; 26 | 27 | static void secp256k1_hmac_sha256_initialize(secp256k1_hmac_sha256_t *hash, const unsigned char *key, size_t size); 28 | static void secp256k1_hmac_sha256_write(secp256k1_hmac_sha256_t *hash, const unsigned char *data, size_t size); 29 | static void secp256k1_hmac_sha256_finalize(secp256k1_hmac_sha256_t *hash, unsigned char *out32); 30 | 31 | typedef struct { 32 | unsigned char v[32]; 33 | unsigned char k[32]; 34 | int retry; 35 | } secp256k1_rfc6979_hmac_sha256_t; 36 | 37 | static void secp256k1_rfc6979_hmac_sha256_initialize(secp256k1_rfc6979_hmac_sha256_t *rng, const unsigned char *key, size_t keylen, const unsigned char *msg, size_t msglen, const unsigned char *rnd, size_t rndlen); 38 | static void secp256k1_rfc6979_hmac_sha256_generate(secp256k1_rfc6979_hmac_sha256_t *rng, unsigned char *out, size_t outlen); 39 | static void secp256k1_rfc6979_hmac_sha256_finalize(secp256k1_rfc6979_hmac_sha256_t *rng); 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /ethminer/secp256k1/num.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_NUM_ 8 | #define _SECP256K1_NUM_ 9 | 10 | #ifndef USE_NUM_NONE 11 | 12 | #if defined HAVE_CONFIG_H 13 | #include "libsecp256k1-config.h" 14 | #endif 15 | 16 | #if defined(USE_NUM_GMP) 17 | #include "num_gmp.h" 18 | #else 19 | #error "Please select num implementation" 20 | #endif 21 | 22 | /** Copy a number. */ 23 | static void secp256k1_num_copy(secp256k1_num_t *r, const secp256k1_num_t *a); 24 | 25 | /** Convert a number's absolute value to a binary big-endian string. 26 | * There must be enough place. */ 27 | static void secp256k1_num_get_bin(unsigned char *r, unsigned int rlen, const secp256k1_num_t *a); 28 | 29 | /** Set a number to the value of a binary big-endian string. */ 30 | static void secp256k1_num_set_bin(secp256k1_num_t *r, const unsigned char *a, unsigned int alen); 31 | 32 | /** Compute a modular inverse. The input must be less than the modulus. */ 33 | static void secp256k1_num_mod_inverse(secp256k1_num_t *r, const secp256k1_num_t *a, const secp256k1_num_t *m); 34 | 35 | /** Compare the absolute value of two numbers. */ 36 | static int secp256k1_num_cmp(const secp256k1_num_t *a, const secp256k1_num_t *b); 37 | 38 | /** Test whether two number are equal (including sign). */ 39 | static int secp256k1_num_eq(const secp256k1_num_t *a, const secp256k1_num_t *b); 40 | 41 | /** Add two (signed) numbers. */ 42 | static void secp256k1_num_add(secp256k1_num_t *r, const secp256k1_num_t *a, const secp256k1_num_t *b); 43 | 44 | /** Subtract two (signed) numbers. */ 45 | static void secp256k1_num_sub(secp256k1_num_t *r, const secp256k1_num_t *a, const secp256k1_num_t *b); 46 | 47 | /** Multiply two (signed) numbers. */ 48 | static void secp256k1_num_mul(secp256k1_num_t *r, const secp256k1_num_t *a, const secp256k1_num_t *b); 49 | 50 | /** Replace a number by its remainder modulo m. M's sign is ignored. The result is a number between 0 and m-1, 51 | even if r was negative. */ 52 | static void secp256k1_num_mod(secp256k1_num_t *r, const secp256k1_num_t *m); 53 | 54 | /** Right-shift the passed number by bits bits. */ 55 | static void secp256k1_num_shift(secp256k1_num_t *r, int bits); 56 | 57 | /** Check whether a number is zero. */ 58 | static int secp256k1_num_is_zero(const secp256k1_num_t *a); 59 | 60 | /** Check whether a number is strictly negative. */ 61 | static int secp256k1_num_is_neg(const secp256k1_num_t *a); 62 | 63 | /** Change a number's sign. */ 64 | static void secp256k1_num_negate(secp256k1_num_t *r); 65 | 66 | #endif 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /ethminer/secp256k1/num_gmp.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_NUM_REPR_ 8 | #define _SECP256K1_NUM_REPR_ 9 | 10 | #include 11 | 12 | #define NUM_LIMBS ((256+GMP_NUMB_BITS-1)/GMP_NUMB_BITS) 13 | 14 | typedef struct { 15 | mp_limb_t data[2*NUM_LIMBS]; 16 | int neg; 17 | int limbs; 18 | } secp256k1_num_t; 19 | 20 | #endif 21 | -------------------------------------------------------------------------------- /ethminer/secp256k1/num_impl.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_NUM_IMPL_H_ 8 | #define _SECP256K1_NUM_IMPL_H_ 9 | 10 | #if defined HAVE_CONFIG_H 11 | #include "libsecp256k1-config.h" 12 | #endif 13 | 14 | #include "num.h" 15 | 16 | #if defined(USE_NUM_GMP) 17 | #include "num_gmp_impl.h" 18 | #elif defined(USE_NUM_NONE) 19 | /* Nothing. */ 20 | #else 21 | #error "Please select num implementation" 22 | #endif 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /ethminer/secp256k1/scalar_4x64.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_SCALAR_REPR_ 8 | #define _SECP256K1_SCALAR_REPR_ 9 | 10 | #include 11 | 12 | /** A scalar modulo the group order of the secp256k1 curve. */ 13 | typedef struct { 14 | uint64_t d[4]; 15 | } secp256k1_scalar_t; 16 | 17 | #define SECP256K1_SCALAR_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {{((uint64_t)(d1)) << 32 | (d0), ((uint64_t)(d3)) << 32 | (d2), ((uint64_t)(d5)) << 32 | (d4), ((uint64_t)(d7)) << 32 | (d6)}} 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /ethminer/secp256k1/scalar_8x32.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_SCALAR_REPR_ 8 | #define _SECP256K1_SCALAR_REPR_ 9 | 10 | #include 11 | 12 | /** A scalar modulo the group order of the secp256k1 curve. */ 13 | typedef struct { 14 | uint32_t d[8]; 15 | } secp256k1_scalar_t; 16 | 17 | #define SECP256K1_SCALAR_CONST(d7, d6, d5, d4, d3, d2, d1, d0) {{(d0), (d1), (d2), (d3), (d4), (d5), (d6), (d7)}} 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /ethminer/secp256k1/util.h: -------------------------------------------------------------------------------- 1 | /********************************************************************** 2 | * Copyright (c) 2013, 2014 Pieter Wuille * 3 | * Distributed under the MIT software license, see the accompanying * 4 | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* 5 | **********************************************************************/ 6 | 7 | #ifndef _SECP256K1_UTIL_H_ 8 | #define _SECP256K1_UTIL_H_ 9 | 10 | #if defined HAVE_CONFIG_H 11 | #include "libsecp256k1-config.h" 12 | #endif 13 | 14 | #include 15 | #include 16 | #include 17 | 18 | #ifdef DETERMINISTIC 19 | #define TEST_FAILURE(msg) do { \ 20 | fprintf(stderr, "%s\n", msg); \ 21 | abort(); \ 22 | } while(0); 23 | #else 24 | #define TEST_FAILURE(msg) do { \ 25 | fprintf(stderr, "%s:%d: %s\n", __FILE__, __LINE__, msg); \ 26 | abort(); \ 27 | } while(0) 28 | #endif 29 | 30 | #ifdef HAVE_BUILTIN_EXPECT 31 | #define EXPECT(x,c) __builtin_expect((x),(c)) 32 | #else 33 | #define EXPECT(x,c) (x) 34 | #endif 35 | 36 | #ifdef DETERMINISTIC 37 | #define CHECK(cond) do { \ 38 | if (EXPECT(!(cond), 0)) { \ 39 | TEST_FAILURE("test condition failed"); \ 40 | } \ 41 | } while(0) 42 | #else 43 | #define CHECK(cond) do { \ 44 | if (EXPECT(!(cond), 0)) { \ 45 | TEST_FAILURE("test condition failed: " #cond); \ 46 | } \ 47 | } while(0) 48 | #endif 49 | 50 | /* Like assert(), but safe to use on expressions with side effects. */ 51 | #ifndef NDEBUG 52 | #define DEBUG_CHECK CHECK 53 | #else 54 | #define DEBUG_CHECK(cond) do { (void)(cond); } while(0) 55 | #endif 56 | 57 | /* Like DEBUG_CHECK(), but when VERIFY is defined instead of NDEBUG not defined. */ 58 | #ifdef VERIFY 59 | #define VERIFY_CHECK CHECK 60 | #else 61 | #define VERIFY_CHECK(cond) do { (void)(cond); } while(0) 62 | #endif 63 | 64 | static SECP256K1_INLINE void *checked_malloc(size_t size) { 65 | void *ret = malloc(size); 66 | CHECK(ret != NULL); 67 | return ret; 68 | } 69 | 70 | /* Macro for restrict, when available and not in a VERIFY build. */ 71 | #if defined(SECP256K1_BUILD) && defined(VERIFY) 72 | # define SECP256K1_RESTRICT 73 | #else 74 | # if (!defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L) ) 75 | # if SECP256K1_GNUC_PREREQ(3,0) 76 | # define SECP256K1_RESTRICT __restrict__ 77 | # elif (defined(_MSC_VER) && _MSC_VER >= 1400) 78 | # define SECP256K1_RESTRICT __restrict 79 | # else 80 | # define SECP256K1_RESTRICT 81 | # endif 82 | # else 83 | # define SECP256K1_RESTRICT restrict 84 | # endif 85 | #endif 86 | 87 | #if defined(_WIN32) 88 | # define I64FORMAT "I64d" 89 | # define I64uFORMAT "I64u" 90 | #else 91 | # define I64FORMAT "lld" 92 | # define I64uFORMAT "llu" 93 | #endif 94 | 95 | #if defined(HAVE___INT128) 96 | # if defined(__GNUC__) 97 | # define SECP256K1_GNUC_EXT __extension__ 98 | # else 99 | # define SECP256K1_GNUC_EXT 100 | # endif 101 | SECP256K1_GNUC_EXT typedef unsigned __int128 uint128_t; 102 | #endif 103 | 104 | #endif 105 | -------------------------------------------------------------------------------- /ethminer/speedfan.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* 4 | * SpeedFan Information Tool 1.0 5 | * 6 | * Retrieves temperature information from SpeedFan and outputs it to the console. 7 | * 8 | * (c) 2008, Christopher Vagnetoft 9 | * Free to use and reuse under the GNU Public License (GPL) v2. 10 | */ 11 | 12 | #include "speedfan.h" 13 | #include 14 | 15 | SpeedFan g_SpeedFan; 16 | 17 | void SpeedFan::getData(std::vector& _data, DataClass _class, int _count) 18 | { 19 | Guard l(x_temps); 20 | 21 | // speedfan gives temperatures multiplied by 100 22 | _data.clear(); 23 | HANDLE file = (HANDLE) CreateFile(filename, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); 24 | if (file == INVALID_HANDLE_VALUE) 25 | throw std::exception("Speedfan.getData : CreateFile failed with error ", GetLastError()); 26 | HANDLE filemap = (HANDLE) CreateFileMapping(file, NULL, PAGE_READWRITE, 0, nSize, mapname); 27 | if (filemap == NULL) 28 | throw std::exception("Speedfan.getData : CreateFileMapping failed with error ", GetLastError()); 29 | SFMemory* sfmemory = (SFMemory*) MapViewOfFile(filemap, FILE_MAP_READ, 0, 0, nSize); 30 | if (sfmemory == NULL) 31 | throw std::exception("Speedfan.getData : MapViewOfFile failed with error ", GetLastError()); 32 | 33 | if (sfmemory) 34 | { 35 | int* pt; 36 | 37 | if (_class == Temperatures) 38 | pt = sfmemory->temps; 39 | else if (_class == FanSpeeds) 40 | pt = sfmemory->fans; 41 | else 42 | pt = sfmemory->volts; 43 | 44 | for (int i = 0; i < std::min(_count, 32); i++) 45 | _data.push_back(*(pt++) / 100.0); 46 | } 47 | CloseHandle(filemap); 48 | CloseHandle(file); 49 | } 50 | 51 | -------------------------------------------------------------------------------- /ethminer/speedfan.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* 4 | * SpeedFan Information Tool 1.0 5 | * 6 | * Retrieves temperature information from SpeedFan and outputs it to the console. 7 | * 8 | * (c) 2008, Christopher Vagnetoft 9 | * Free to use and reuse under the GNU Public License (GPL) v2. 10 | */ 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | using namespace dev; 17 | 18 | class SpeedFan 19 | { 20 | 21 | public: 22 | 23 | enum DataClass 24 | { 25 | Temperatures, 26 | FanSpeeds, 27 | Voltages 28 | }; 29 | 30 | void getData(std::vector& _data, DataClass _class, int _count); 31 | 32 | private: 33 | 34 | // pragma pack is included here because the struct is a pascal Packed Record, 35 | // meaning that fields aren't aligned on a 4-byte boundary. 4 bytes fit 2 36 | // 2-byte records. 37 | #pragma pack(push, 1) 38 | 39 | // This is the struct we're using to access the shared memory. 40 | struct SFMemory 41 | { 42 | WORD version; 43 | WORD flags; 44 | int MemSize; 45 | int handle; 46 | WORD NumTemps; 47 | WORD NumFans; 48 | WORD NumVolts; 49 | signed int temps[32]; 50 | signed int fans[32]; 51 | signed int volts[32]; 52 | }; 53 | 54 | #pragma pack(pop) 55 | 56 | // Name of filename and memory map name to open. 57 | const char* filename = "SFSharedMemory_ALM"; 58 | const char* mapname = "SFSharedMemory_ALM"; 59 | 60 | UINT nSize = sizeof(SFMemory); 61 | mutable Mutex x_temps; 62 | 63 | }; 64 | 65 | extern SpeedFan g_SpeedFan; 66 | -------------------------------------------------------------------------------- /extdep/curl.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mining-visualizer/MVis-tokenminer/ae09b3f5314f202230dd812b5cd354a54bb140c6/extdep/curl.exe -------------------------------------------------------------------------------- /extdep/getstuff.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | REM get stuff! 3 | 4 | REM cd to the folder this file is in 5 | cd %~dp0 6 | 7 | echo Downloading dependencies 8 | 9 | if not exist download mkdir download 10 | if not exist install mkdir install 11 | if not exist install\windows mkdir install\windows 12 | 13 | set eth_server=https://github.com/ethereum/cpp-dependencies/releases/download/vc120 14 | 15 | call :download boost 1.55.0 %eth_server% 16 | call :download cryptopp 5.6.2 %eth_server% 17 | call :download jsoncpp 1.6.2 %eth_server% 18 | call :download json-rpc-cpp 0.5.0 %eth_server% 19 | call :download leveldb 1.2 %eth_server% 20 | call :download microhttpd 0.9.2 %eth_server% 21 | 22 | set mvis_server=https://github.com/mining-visualizer/dependencies/releases/download/vc120 23 | 24 | call :download curl 7.54.1 %mvis_server% 25 | call :download OpenCL 1 %mvis_server% 26 | call :download amd_adl 10.1 %mvis_server% 27 | 28 | echo. 29 | echo Operation is complete 30 | pause 31 | 32 | goto :EOF 33 | 34 | :download 35 | 36 | set eth_name=%1 37 | set eth_version=%2 38 | set server=%3 39 | 40 | cd download 41 | 42 | if not exist %eth_name%-%eth_version%-x64.tar.gz ( 43 | echo. 44 | echo Downloading %server%/%eth_name%-%eth_version%-x64.tar.gz ... 45 | echo. 46 | 47 | ..\curl -L -o %eth_name%-%eth_version%-x64.tar.gz %server%/%eth_name%-%eth_version%-x64.tar.gz 48 | ) 49 | if not exist %eth_name%-%eth_version% cmake -E tar -zxvf %eth_name%-%eth_version%-x64.tar.gz 50 | cmake -E copy_directory %eth_name%-%eth_version% ..\install\windows 51 | 52 | cd .. 53 | 54 | goto :EOF 55 | 56 | 57 | -------------------------------------------------------------------------------- /extdep/include/amd_adl/adl_sdk.h: -------------------------------------------------------------------------------- 1 | /// 2 | /// Copyright (c) 2008 - 2013 Advanced Micro Devices, Inc. 3 | 4 | /// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, 5 | /// EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED 6 | /// WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. 7 | 8 | /// \file adl_sdk.h 9 | /// \brief Contains the definition of the Memory Allocation Callback.\n Included in ADL SDK 10 | /// 11 | /// \n\n 12 | /// This file contains the definition of the Memory Allocation Callback.\n 13 | /// It also includes definitions of the respective structures and constants.\n 14 | /// This is the only header file to be included in a C/C++ project using ADL 15 | 16 | #ifndef ADL_SDK_H_ 17 | #define ADL_SDK_H_ 18 | 19 | #include "adl_structures.h" 20 | 21 | #if defined (LINUX) 22 | #define __stdcall 23 | #endif /* (LINUX) */ 24 | 25 | /// Memory Allocation Call back 26 | typedef void* ( __stdcall *ADL_MAIN_MALLOC_CALLBACK )( int ); 27 | 28 | 29 | #endif /* ADL_SDK_H_ */ 30 | -------------------------------------------------------------------------------- /extdep/libcurl.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mining-visualizer/MVis-tokenminer/ae09b3f5314f202230dd812b5cd354a54bb140c6/extdep/libcurl.dll -------------------------------------------------------------------------------- /libdevcore/Assertions.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** 18 | * @file Assertions.h 19 | * @author Christian 20 | * @date 2015 21 | * 22 | * Assertion handling. 23 | */ 24 | 25 | #pragma once 26 | 27 | #include "Exceptions.h" 28 | #include "debugbreak.h" 29 | 30 | namespace dev 31 | { 32 | 33 | #if defined(_MSC_VER) 34 | #define ETH_FUNC __FUNCSIG__ 35 | #elif defined(__GNUC__) 36 | #define ETH_FUNC __PRETTY_FUNCTION__ 37 | #else 38 | #define ETH_FUNC __func__ 39 | #endif 40 | 41 | #define asserts(A) ::dev::assertAux(A, #A, __LINE__, __FILE__, ETH_FUNC) 42 | #define assertsEqual(A, B) ::dev::assertEqualAux(A, B, #A, #B, __LINE__, __FILE__, ETH_FUNC) 43 | 44 | inline bool assertAux(bool _a, char const* _aStr, unsigned _line, char const* _file, char const* _func) 45 | { 46 | bool ret = _a; 47 | if (!ret) 48 | { 49 | std::cerr << "Assertion failed:" << _aStr << " [func=" << _func << ", line=" << _line << ", file=" << _file << "]" << std::endl; 50 | #if ETH_DEBUG 51 | debug_break(); 52 | #endif 53 | } 54 | return !ret; 55 | } 56 | 57 | template 58 | inline bool assertEqualAux(A const& _a, B const& _b, char const* _aStr, char const* _bStr, unsigned _line, char const* _file, char const* _func) 59 | { 60 | bool ret = _a == _b; 61 | if (!ret) 62 | { 63 | std::cerr << "Assertion failed: " << _aStr << " == " << _bStr << " [func=" << _func << ", line=" << _line << ", file=" << _file << "]" << std::endl; 64 | std::cerr << " Fail equality: " << _a << "==" << _b << std::endl; 65 | #if ETH_DEBUG 66 | debug_break(); 67 | #endif 68 | } 69 | return !ret; 70 | } 71 | 72 | /// Assertion that throws an exception containing the given description if it is not met. 73 | /// Use it as assertThrow(1 == 1, ExceptionType, "Mathematics is wrong."); 74 | /// Do NOT supply an exception object as the second parameter. 75 | #define assertThrow(_condition, _ExceptionType, _description) \ 76 | ::dev::assertThrowAux<_ExceptionType>(_condition, _description, __LINE__, __FILE__, ETH_FUNC) 77 | 78 | using errinfo_comment = boost::error_info; 79 | 80 | template 81 | inline void assertThrowAux( 82 | bool _condition, 83 | ::std::string const& _errorDescription, 84 | unsigned _line, 85 | char const* _file, 86 | char const* _function 87 | ) 88 | { 89 | if (!_condition) 90 | ::boost::throw_exception( 91 | _ExceptionType() << 92 | ::dev::errinfo_comment(_errorDescription) << 93 | ::boost::throw_function(_function) << 94 | ::boost::throw_file(_file) << 95 | ::boost::throw_line(_line) 96 | ); 97 | } 98 | 99 | template 100 | inline void assertThrowAux( 101 | void const* _pointer, 102 | ::std::string const& _errorDescription, 103 | unsigned _line, 104 | char const* _file, 105 | char const* _function 106 | ) 107 | { 108 | assertThrowAux<_ExceptionType>(_pointer != nullptr, _errorDescription, _line, _file, _function); 109 | } 110 | 111 | } 112 | -------------------------------------------------------------------------------- /libdevcore/Base64.h: -------------------------------------------------------------------------------- 1 | /* 2 | base64.cpp and base64.h 3 | 4 | Copyright (C) 2004-2008 René Nyffenegger 5 | 6 | This source code is provided 'as-is', without any express or implied 7 | warranty. In no event will the author be held liable for any damages 8 | arising from the use of this software. 9 | 10 | Permission is granted to anyone to use this software for any purpose, 11 | including commercial applications, and to alter it and redistribute it 12 | freely, subject to the following restrictions: 13 | 14 | 1. The origin of this source code must not be misrepresented; you must not 15 | claim that you wrote the original source code. If you use this source code 16 | in a product, an acknowledgment in the product documentation would be 17 | appreciated but is not required. 18 | 19 | 2. Altered source versions must be plainly marked as such, and must not be 20 | misrepresented as being the original source code. 21 | 22 | 3. This notice may not be removed or altered from any source distribution. 23 | 24 | René Nyffenegger rene.nyffenegger@adp-gmbh.ch 25 | */ 26 | /// Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c 27 | /// Originally by René Nyffenegger. 28 | /// DEVified by Gav Wood. 29 | #pragma once 30 | 31 | #include 32 | #include "Common.h" 33 | #include "FixedHash.h" 34 | 35 | namespace dev 36 | { 37 | 38 | std::string toBase64(bytesConstRef _in); 39 | bytes fromBase64(std::string const& _in); 40 | 41 | template inline std::string toBase36(FixedHash const& _h) 42 | { 43 | static char const* c_alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 44 | typename FixedHash::Arith a = _h; 45 | std::string ret; 46 | for (; a > 0; a /= 36) 47 | { 48 | unsigned r = (unsigned)(a - a / 36 * 36); // boost's % is broken 49 | ret = c_alphabet[r] + ret; 50 | } 51 | return ret; 52 | } 53 | 54 | template inline FixedHash fromBase36(std::string const& _h) 55 | { 56 | typename FixedHash::Arith ret = 0; 57 | for (char c: _h) 58 | ret = ret * 36 + (c < 'A' ? c - '0' : (c - 'A' + 10)); 59 | return ret; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /libdevcore/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_policy(SET CMP0015 NEW) 2 | set(CMAKE_AUTOMOC OFF) 3 | 4 | set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DSTATICLIB") 5 | 6 | aux_source_directory(. SRC_LIST) 7 | 8 | include_directories(BEFORE ${JSONCPP_INCLUDE_DIRS}) 9 | include_directories(BEFORE ..) 10 | include_directories(${Boost_INCLUDE_DIRS}) 11 | include_directories(${DB_INCLUDE_DIRS}) 12 | 13 | set(EXECUTABLE devcore) 14 | 15 | file(GLOB HEADERS "*.h") 16 | 17 | add_library(${EXECUTABLE} ${SRC_LIST} ${HEADERS}) 18 | 19 | target_link_libraries(${EXECUTABLE} ${Boost_THREAD_LIBRARIES}) 20 | target_link_libraries(${EXECUTABLE} ${Boost_RANDOM_LIBRARIES}) 21 | target_link_libraries(${EXECUTABLE} ${Boost_FILESYSTEM_LIBRARIES}) 22 | target_link_libraries(${EXECUTABLE} ${Boost_SYSTEM_LIBRARIES}) 23 | if (JSONRPC) 24 | target_link_libraries(${EXECUTABLE} ${JSONCPP_LIBRARIES}) 25 | endif() 26 | target_link_libraries(${EXECUTABLE} ${DB_LIBRARIES}) 27 | 28 | # transitive dependencies for windows executables 29 | if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") 30 | target_link_libraries(${EXECUTABLE} ${Boost_CHRONO_LIBRARIES}) 31 | target_link_libraries(${EXECUTABLE} ${Boost_DATE_TIME_LIBRARIES}) 32 | endif() 33 | 34 | if (APPLE) 35 | find_package(Threads REQUIRED) 36 | target_link_libraries(${EXECUTABLE} ${CMAKE_THREAD_LIBS_INIT}) 37 | elseif (UNIX) 38 | find_package(Threads REQUIRED) 39 | target_link_libraries(${EXECUTABLE} ${CMAKE_THREAD_LIBS_INIT}) 40 | endif() 41 | 42 | install( TARGETS ${EXECUTABLE} RUNTIME DESTINATION bin ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) 43 | install( FILES ${HEADERS} DESTINATION include/${EXECUTABLE} ) 44 | 45 | -------------------------------------------------------------------------------- /libdevcore/Common.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file Common.cpp 18 | * @author Gav Wood 19 | * @date 2014 20 | */ 21 | 22 | #include "Common.h" 23 | #include "Exceptions.h" 24 | #include "Log.h" 25 | #include "BuildInfo.h" 26 | using namespace std; 27 | using namespace dev; 28 | 29 | namespace dev 30 | { 31 | 32 | char const* Version = ETH_PROJECT_VERSION; 33 | 34 | const u256 UndefinedU256 = ~(u256)0; 35 | 36 | void InvariantChecker::checkInvariants(HasInvariants const* _this, char const* _fn, char const* _file, int _line, bool _pre) 37 | { 38 | if (!_this->invariants()) 39 | { 40 | cwarn << (_pre ? "Pre" : "Post") << "invariant failed in" << _fn << "at" << _file << ":" << _line; 41 | ::boost::exception_detail::throw_exception_(FailedInvariant(), _fn, _file, _line); 42 | } 43 | } 44 | 45 | struct TimerChannel: public LogChannel { static const char* name(); static const int verbosity = 0; }; 46 | 47 | #ifdef _WIN32 48 | const char* TimerChannel::name() { return EthRed " ! "; } 49 | #else 50 | const char* TimerChannel::name() { return EthRed " ⚡ "; } 51 | #endif 52 | 53 | TimerHelper::~TimerHelper() 54 | { 55 | auto e = std::chrono::high_resolution_clock::now() - m_t; 56 | if (!m_ms || e > chrono::milliseconds(m_ms)) 57 | { 58 | clog(TimerChannel) << m_id << chrono::duration_cast(e).count() << "ms"; 59 | } 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /libdevcore/CommonData.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file CommonData.cpp 18 | * @author Gav Wood 19 | * @date 2014 20 | */ 21 | 22 | #include "CommonData.h" 23 | #include 24 | #include 25 | #include "Exceptions.h" 26 | #include "Log.h" 27 | 28 | using namespace std; 29 | using namespace dev; 30 | 31 | std::string dev::escaped(std::string const& _s, bool _all) 32 | { 33 | static const map prettyEscapes{{'\r', 'r'}, {'\n', 'n'}, {'\t', 't'}, {'\v', 'v'}}; 34 | std::string ret; 35 | ret.reserve(_s.size() + 2); 36 | ret.push_back('"'); 37 | for (auto i: _s) 38 | if (i == '"' && !_all) 39 | ret += "\\\""; 40 | else if (i == '\\' && !_all) 41 | ret += "\\\\"; 42 | else if (prettyEscapes.count(i) && !_all) 43 | { 44 | ret += '\\'; 45 | ret += prettyEscapes.find(i)->second; 46 | } 47 | else if (i < ' ' || _all) 48 | { 49 | ret += "\\x"; 50 | ret.push_back("0123456789abcdef"[(uint8_t)i / 16]); 51 | ret.push_back("0123456789abcdef"[(uint8_t)i % 16]); 52 | } 53 | else 54 | ret.push_back(i); 55 | ret.push_back('"'); 56 | return ret; 57 | } 58 | 59 | std::string dev::randomWord() 60 | { 61 | static std::mt19937_64 s_eng(0); 62 | std::string ret(boost::random::uniform_int_distribution(1, 5)(s_eng), ' '); 63 | char const n[] = "qwertyuiop";//asdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890"; 64 | boost::random::uniform_int_distribution d(0, sizeof(n) - 2); 65 | for (char& c: ret) 66 | c = n[d(s_eng)]; 67 | return ret; 68 | } 69 | 70 | int dev::fromHex(char _i, WhenError _throw) 71 | { 72 | if (_i >= '0' && _i <= '9') 73 | return _i - '0'; 74 | if (_i >= 'a' && _i <= 'f') 75 | return _i - 'a' + 10; 76 | if (_i >= 'A' && _i <= 'F') 77 | return _i - 'A' + 10; 78 | if (_throw == WhenError::Throw) 79 | BOOST_THROW_EXCEPTION(BadHexCharacter() << errinfo_invalidSymbol(_i)); 80 | else 81 | return -1; 82 | } 83 | 84 | bytes dev::fromHex(std::string const& _s, WhenError _throw) 85 | { 86 | unsigned s = (_s[0] == '0' && _s[1] == 'x') ? 2 : 0; 87 | std::vector ret; 88 | ret.reserve((_s.size() - s + 1) / 2); 89 | 90 | if (_s.size() % 2) 91 | { 92 | int h = fromHex(_s[s++], WhenError::DontThrow); 93 | if (h != -1) 94 | ret.push_back(h); 95 | else if (_throw == WhenError::Throw) 96 | BOOST_THROW_EXCEPTION(BadHexCharacter()); 97 | else 98 | return bytes(); 99 | } 100 | for (unsigned i = s; i < _s.size(); i += 2) 101 | { 102 | int h = fromHex(_s[i], WhenError::DontThrow); 103 | int l = fromHex(_s[i + 1], WhenError::DontThrow); 104 | if (h != -1 && l != -1) 105 | ret.push_back((byte)(h * 16 + l)); 106 | else if (_throw == WhenError::Throw) 107 | BOOST_THROW_EXCEPTION(BadHexCharacter()); 108 | else 109 | return bytes(); 110 | } 111 | return ret; 112 | } 113 | 114 | bytes dev::asNibbles(bytesConstRef const& _s) 115 | { 116 | std::vector ret; 117 | ret.reserve(_s.size() * 2); 118 | for (auto i: _s) 119 | { 120 | ret.push_back(i / 16); 121 | ret.push_back(i % 16); 122 | } 123 | return ret; 124 | } 125 | 126 | std::string dev::toString(string32 const& _s) 127 | { 128 | std::string ret; 129 | for (unsigned i = 0; i < 32 && _s[i]; ++i) 130 | ret.push_back(_s[i]); 131 | return ret; 132 | } 133 | -------------------------------------------------------------------------------- /libdevcore/CommonJS.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file CommonJS.cpp 18 | * @authors: 19 | * Gav Wood 20 | * Marek Kotewicz 21 | * @date 2014 22 | */ 23 | 24 | #include "CommonJS.h" 25 | 26 | using namespace std; 27 | 28 | namespace dev 29 | { 30 | 31 | bytes jsToBytes(string const& _s) 32 | { 33 | if (_s.substr(0, 2) == "0x") 34 | // Hex 35 | return fromHex(_s.substr(2)); 36 | else if (_s.find_first_not_of("0123456789") == string::npos) 37 | // Decimal 38 | return toCompactBigEndian(bigint(_s)); 39 | else 40 | return bytes(); 41 | } 42 | 43 | bytes padded(bytes _b, unsigned _l) 44 | { 45 | while (_b.size() < _l) 46 | _b.insert(_b.begin(), 0); 47 | return asBytes(asString(_b).substr(_b.size() - max(_l, _l))); 48 | } 49 | 50 | bytes paddedRight(bytes _b, unsigned _l) 51 | { 52 | _b.resize(_l); 53 | return _b; 54 | } 55 | 56 | bytes unpadded(bytes _b) 57 | { 58 | auto p = asString(_b).find_last_not_of((char)0); 59 | _b.resize(p == string::npos ? 0 : (p + 1)); 60 | return _b; 61 | } 62 | 63 | bytes unpadLeft(bytes _b) 64 | { 65 | unsigned int i = 0; 66 | if (_b.size() == 0) 67 | return _b; 68 | 69 | while (i < _b.size() && _b[i] == byte(0)) 70 | i++; 71 | 72 | if (i != 0) 73 | _b.erase(_b.begin(), _b.begin() + i); 74 | return _b; 75 | } 76 | 77 | string fromRaw(h256 _n, unsigned* _inc) 78 | { 79 | if (_n) 80 | { 81 | string s((char const*)_n.data(), 32); 82 | auto l = s.find_first_of('\0'); 83 | if (!l) 84 | return ""; 85 | if (l != string::npos) 86 | { 87 | auto p = s.find_first_not_of('\0', l); 88 | if (!(p == string::npos || (_inc && p == 31))) 89 | return ""; 90 | if (_inc) 91 | *_inc = (byte)s[31]; 92 | s.resize(l); 93 | } 94 | for (auto i: s) 95 | if (i < 32) 96 | return ""; 97 | return s; 98 | } 99 | return ""; 100 | } 101 | 102 | } 103 | 104 | -------------------------------------------------------------------------------- /libdevcore/Diff.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file Diff.h 18 | * @author Gav Wood 19 | * @date 2014 20 | */ 21 | 22 | #pragma once 23 | 24 | namespace dev 25 | { 26 | 27 | enum class ExistDiff 28 | { 29 | Same, 30 | New, 31 | Dead 32 | }; 33 | 34 | template 35 | class Diff 36 | { 37 | public: 38 | Diff() {} 39 | Diff(T _from, T _to): m_from(_from), m_to(_to) {} 40 | 41 | T const& from() const { return m_from; } 42 | T const& to() const { return m_to; } 43 | 44 | explicit operator bool() const { return m_from != m_to; } 45 | 46 | private: 47 | T m_from; 48 | T m_to; 49 | }; 50 | 51 | } 52 | 53 | -------------------------------------------------------------------------------- /libdevcore/Exceptions.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file Exceptions.h 18 | * @author Gav Wood 19 | * @date 2014 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include "CommonData.h" 29 | #include "FixedHash.h" 30 | 31 | namespace dev 32 | { 33 | 34 | /// Base class for all exceptions. 35 | struct Exception: virtual std::exception, virtual boost::exception 36 | { 37 | Exception(std::string _message = std::string()): m_message(std::move(_message)) {} 38 | const char* what() const noexcept override { return m_message.empty() ? std::exception::what() : m_message.c_str(); } 39 | 40 | private: 41 | std::string m_message; 42 | }; 43 | 44 | #define DEV_SIMPLE_EXCEPTION(X) struct X: virtual Exception { const char* what() const noexcept override { return #X; } } 45 | 46 | /// Base class for all RLP exceptions. 47 | struct RLPException: virtual Exception { RLPException(std::string _message = std::string()): Exception(_message) {} }; 48 | #define DEV_SIMPLE_EXCEPTION_RLP(X) struct X: virtual RLPException { const char* what() const noexcept override { return #X; } } 49 | 50 | DEV_SIMPLE_EXCEPTION_RLP(BadCast); 51 | DEV_SIMPLE_EXCEPTION_RLP(BadRLP); 52 | DEV_SIMPLE_EXCEPTION_RLP(OversizeRLP); 53 | DEV_SIMPLE_EXCEPTION_RLP(UndersizeRLP); 54 | 55 | DEV_SIMPLE_EXCEPTION(BadHexCharacter); 56 | DEV_SIMPLE_EXCEPTION(NoNetworking); 57 | DEV_SIMPLE_EXCEPTION(NoUPnPDevice); 58 | DEV_SIMPLE_EXCEPTION(RootNotFound); 59 | struct BadRoot: virtual Exception { public: BadRoot(h256 const& _root): Exception("BadRoot " + _root.hex()), root(_root) {} h256 root; }; 60 | DEV_SIMPLE_EXCEPTION(FileError); 61 | DEV_SIMPLE_EXCEPTION(Overflow); 62 | DEV_SIMPLE_EXCEPTION(FailedInvariant); 63 | DEV_SIMPLE_EXCEPTION(ValueTooLarge); 64 | 65 | struct InterfaceNotSupported: virtual Exception { public: InterfaceNotSupported(std::string _f): Exception("Interface " + _f + " not supported.") {} }; 66 | struct ExternalFunctionFailure: virtual Exception { public: ExternalFunctionFailure(std::string _f): Exception("Function " + _f + "() failed.") {} }; 67 | 68 | // error information to be added to exceptions 69 | using errinfo_invalidSymbol = boost::error_info; 70 | using errinfo_wrongAddress = boost::error_info; 71 | using errinfo_comment = boost::error_info; 72 | using errinfo_required = boost::error_info; 73 | using errinfo_got = boost::error_info; 74 | using errinfo_min = boost::error_info; 75 | using errinfo_max = boost::error_info; 76 | using RequirementError = boost::tuple; 77 | using errinfo_hash256 = boost::error_info; 78 | using errinfo_required_h256 = boost::error_info; 79 | using errinfo_got_h256 = boost::error_info; 80 | using Hash256RequirementError = boost::tuple; 81 | using errinfo_extraData = boost::error_info; 82 | 83 | } 84 | -------------------------------------------------------------------------------- /libdevcore/FileSystem.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file FileSystem.cpp 18 | * @authors 19 | * Eric Lombrozo 20 | * Gav Wood 21 | * @date 2014 22 | */ 23 | 24 | #include "FileSystem.h" 25 | #include "Common.h" 26 | #include "Log.h" 27 | 28 | #if defined(_WIN32) 29 | #include 30 | #else 31 | #include 32 | #include 33 | #include 34 | #include 35 | #endif 36 | #include 37 | using namespace std; 38 | using namespace dev; 39 | 40 | std::string dev::getDataDir(std::string _prefix) 41 | { 42 | if (_prefix.empty()) 43 | _prefix = "ethereum"; 44 | #ifdef _WIN32 45 | _prefix[0] = toupper(_prefix[0]); 46 | char path[1024] = ""; 47 | if (SHGetSpecialFolderPathA(NULL, path, CSIDL_APPDATA, true)) 48 | return (boost::filesystem::path(path) / _prefix).string(); 49 | else 50 | { 51 | #ifndef _MSC_VER // todo? 52 | cwarn << "getDataDir(): SHGetSpecialFolderPathA() failed."; 53 | #endif 54 | BOOST_THROW_EXCEPTION(std::runtime_error("getDataDir() - SHGetSpecialFolderPathA() failed.")); 55 | } 56 | #else 57 | boost::filesystem::path dataDirPath; 58 | char const* homeDir = getenv("HOME"); 59 | if (!homeDir || strlen(homeDir) == 0) 60 | { 61 | struct passwd* pwd = getpwuid(getuid()); 62 | if (pwd) 63 | homeDir = pwd->pw_dir; 64 | } 65 | 66 | if (!homeDir || strlen(homeDir) == 0) 67 | dataDirPath = boost::filesystem::path("/"); 68 | else 69 | dataDirPath = boost::filesystem::path(homeDir); 70 | 71 | return (dataDirPath / ("." + _prefix)).string(); 72 | #endif 73 | } 74 | -------------------------------------------------------------------------------- /libdevcore/FileSystem.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file FileSystem.h 18 | * @authors 19 | * Eric Lombrozo 20 | * Gav Wood 21 | * @date 2014 22 | */ 23 | 24 | #pragma once 25 | 26 | #include 27 | #include 28 | 29 | namespace dev 30 | { 31 | 32 | /// @returns the path for user data. 33 | std::string getDataDir(std::string _prefix = "ethereum"); 34 | 35 | } 36 | -------------------------------------------------------------------------------- /libdevcore/FixedHash.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file FixedHash.cpp 18 | * @author Gav Wood 19 | * @date 2014 20 | */ 21 | 22 | #include "FixedHash.h" 23 | #include 24 | #include 25 | 26 | using namespace std; 27 | using namespace dev; 28 | 29 | boost::random_device dev::s_fixedHashEngine; 30 | 31 | h128 dev::fromUUID(std::string const& _uuid) 32 | { 33 | try 34 | { 35 | return h128(boost::replace_all_copy(_uuid, "-", "")); 36 | } 37 | catch (...) 38 | { 39 | return h128(); 40 | } 41 | } 42 | 43 | std::string dev::toUUID(h128 const& _uuid) 44 | { 45 | std::string ret = toHex(_uuid.ref()); 46 | for (unsigned i: {20, 16, 12, 8}) 47 | ret.insert(ret.begin() + i, '-'); 48 | return ret; 49 | } 50 | 51 | -------------------------------------------------------------------------------- /libdevcore/Guards.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file Guards.cpp 18 | * @author Gav Wood 19 | * @date 2014 20 | */ 21 | 22 | #include "Guards.h" 23 | using namespace std; 24 | using namespace dev; 25 | 26 | namespace dev 27 | { 28 | 29 | } 30 | -------------------------------------------------------------------------------- /libdevcore/Hash.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file Hash.h 18 | * @author Gav Wood 19 | * @date 2014 20 | * 21 | * The FixedHash fixed-size "hash" container type. 22 | */ 23 | 24 | #pragma once 25 | 26 | #include 27 | #include 28 | #include 29 | #include "SHA3.h" 30 | 31 | namespace dev 32 | { 33 | 34 | h256 sha256(bytesConstRef _input); 35 | 36 | h160 ripemd160(bytesConstRef _input); 37 | 38 | } 39 | -------------------------------------------------------------------------------- /libdevcore/MemoryDB.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file MemoryDB.h 18 | * @author Gav Wood 19 | * @date 2014 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include "SHA3.h" 31 | 32 | namespace dev 33 | { 34 | 35 | struct DBChannel: public LogChannel { static const char* name(); static const int verbosity = 18; }; 36 | struct DBWarn: public LogChannel { static const char* name(); static const int verbosity = 1; }; 37 | 38 | #define dbdebug clog(DBChannel) 39 | #define dbwarn clog(DBWarn) 40 | 41 | class MemoryDB 42 | { 43 | friend class EnforceRefs; 44 | 45 | public: 46 | MemoryDB() {} 47 | MemoryDB(MemoryDB const& _c) { operator=(_c); } 48 | 49 | MemoryDB& operator=(MemoryDB const& _c); 50 | 51 | void clear() { m_main.clear(); } // WARNING !!!! didn't originally clear m_refCount!!! 52 | std::unordered_map get() const; 53 | 54 | std::string lookup(h256 const& _h) const; 55 | bool exists(h256 const& _h) const; 56 | void insert(h256 const& _h, bytesConstRef _v); 57 | bool kill(h256 const& _h); 58 | void purge(); 59 | 60 | bytes lookupAux(h256 const& _h) const; 61 | void removeAux(h256 const& _h); 62 | void insertAux(h256 const& _h, bytesConstRef _v); 63 | 64 | h256Hash keys() const; 65 | 66 | protected: 67 | #if DEV_GUARDED_DB 68 | mutable SharedMutex x_this; 69 | #endif 70 | std::unordered_map> m_main; 71 | std::unordered_map> m_aux; 72 | 73 | mutable bool m_enforceRefs = false; 74 | }; 75 | 76 | class EnforceRefs 77 | { 78 | public: 79 | EnforceRefs(MemoryDB const& _o, bool _r): m_o(_o), m_r(_o.m_enforceRefs) { _o.m_enforceRefs = _r; } 80 | ~EnforceRefs() { m_o.m_enforceRefs = m_r; } 81 | 82 | private: 83 | MemoryDB const& m_o; 84 | bool m_r; 85 | }; 86 | 87 | inline std::ostream& operator<<(std::ostream& _out, MemoryDB const& _m) 88 | { 89 | for (auto const& i: _m.get()) 90 | { 91 | _out << i.first << ": "; 92 | _out << RLP(i.second); 93 | _out << " " << toHex(i.second); 94 | _out << std::endl; 95 | } 96 | return _out; 97 | } 98 | 99 | } 100 | -------------------------------------------------------------------------------- /libdevcore/RangeMask.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file RangeMask.cpp 18 | * @author Gav Wood 19 | * @date 2014 20 | */ 21 | 22 | #include "RangeMask.h" 23 | -------------------------------------------------------------------------------- /libdevcore/SHA3.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file SHA3.h 18 | * @author Gav Wood 19 | * @date 2014 20 | * 21 | * The FixedHash fixed-size "hash" container type. 22 | */ 23 | 24 | #pragma once 25 | 26 | #include 27 | #include 28 | #include 29 | 30 | namespace dev 31 | { 32 | 33 | // SHA-3 convenience routines. 34 | 35 | /// Calculate SHA3-256 hash of the given input and load it into the given output. 36 | /// @returns false if o_output.size() != 32. 37 | bool sha3(bytesConstRef _input, bytesRef o_output); 38 | 39 | /// Calculate SHA3-256 hash of the given input, returning as a 256-bit hash. 40 | inline h256 sha3(bytesConstRef _input) { h256 ret; sha3(_input, ret.ref()); return ret; } 41 | inline SecureFixedHash<32> sha3Secure(bytesConstRef _input) { SecureFixedHash<32> ret; sha3(_input, ret.writable().ref()); return ret; } 42 | 43 | /// Calculate SHA3-256 hash of the given input, returning as a 256-bit hash. 44 | inline h256 sha3(bytes const& _input) { return sha3(bytesConstRef(&_input)); } 45 | inline SecureFixedHash<32> sha3Secure(bytes const& _input) { return sha3Secure(bytesConstRef(&_input)); } 46 | 47 | /// Calculate SHA3-256 hash of the given input (presented as a binary-filled string), returning as a 256-bit hash. 48 | inline h256 sha3(std::string const& _input) { return sha3(bytesConstRef(_input)); } 49 | inline SecureFixedHash<32> sha3Secure(std::string const& _input) { return sha3Secure(bytesConstRef(_input)); } 50 | 51 | /// Calculate SHA3-256 hash of the given input (presented as a FixedHash), returns a 256-bit hash. 52 | template inline h256 sha3(FixedHash const& _input) { return sha3(_input.ref()); } 53 | template inline SecureFixedHash<32> sha3Secure(FixedHash const& _input) { return sha3Secure(_input.ref()); } 54 | 55 | /// Fully secure variants are equivalent for sha3 and sha3Secure. 56 | inline SecureFixedHash<32> sha3(bytesSec const& _input) { return sha3Secure(_input.ref()); } 57 | inline SecureFixedHash<32> sha3Secure(bytesSec const& _input) { return sha3Secure(_input.ref()); } 58 | template inline SecureFixedHash<32> sha3(SecureFixedHash const& _input) { return sha3Secure(_input.ref()); } 59 | template inline SecureFixedHash<32> sha3Secure(SecureFixedHash const& _input) { return sha3Secure(_input.ref()); } 60 | 61 | /// Calculate SHA3-256 hash of the given input, possibly interpreting it as nibbles, and return the hash as a string filled with binary data. 62 | inline std::string sha3(std::string const& _input, bool _isNibbles) { return asString((_isNibbles ? sha3(fromHex(_input)) : sha3(bytesConstRef(&_input))).asBytes()); } 63 | 64 | /// Calculate SHA3-256 MAC 65 | inline void sha3mac(bytesConstRef _secret, bytesConstRef _plain, bytesRef _output) { sha3(_secret.toBytes() + _plain.toBytes()).ref().populate(_output); } 66 | 67 | extern h256 EmptySHA3; 68 | 69 | extern h256 EmptyListSHA3; 70 | 71 | } 72 | -------------------------------------------------------------------------------- /libdevcore/TransientDirectory.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file TransientDirectory.cpp 18 | * @author Marek Kotewicz 19 | * @date 2015 20 | */ 21 | 22 | #include 23 | #include 24 | #include "Exceptions.h" 25 | #include "TransientDirectory.h" 26 | #include "CommonIO.h" 27 | #include "Log.h" 28 | using namespace std; 29 | using namespace dev; 30 | namespace fs = boost::filesystem; 31 | 32 | TransientDirectory::TransientDirectory(): 33 | TransientDirectory((boost::filesystem::temp_directory_path() / "eth_transient" / toString(FixedHash<4>::random())).string()) 34 | {} 35 | 36 | TransientDirectory::TransientDirectory(std::string const& _path): 37 | m_path(_path) 38 | { 39 | // we never ever want to delete a directory (including all its contents) that we did not create ourselves. 40 | if (boost::filesystem::exists(m_path)) 41 | BOOST_THROW_EXCEPTION(FileError()); 42 | 43 | fs::create_directories(m_path); 44 | DEV_IGNORE_EXCEPTIONS(fs::permissions(m_path, fs::owner_all)); 45 | } 46 | 47 | TransientDirectory::~TransientDirectory() 48 | { 49 | boost::system::error_code ec; 50 | fs::remove_all(m_path, ec); 51 | if (!ec) 52 | return; 53 | 54 | // In some cases, antivirus runnig on Windows will scan all the newly created directories. 55 | // As a consequence, directory is locked and can not be deleted immediately. 56 | // Retry after 10 milliseconds usually is successful. 57 | // This will help our tests run smoothly in such environment. 58 | this_thread::sleep_for(chrono::milliseconds(10)); 59 | 60 | ec.clear(); 61 | fs::remove_all(m_path, ec); 62 | if (!ec) 63 | { 64 | cwarn << "Failed to delete directory '" << m_path << "': " << ec.message(); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /libdevcore/TransientDirectory.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file TransientDirectory.h 18 | * @author Marek Kotewicz 19 | * @date 2015 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | 26 | namespace dev 27 | { 28 | 29 | /** 30 | * @brief temporary directory implementation 31 | * It creates temporary directory in the given path. On dealloc it removes the directory 32 | * @throws if the given path already exists, throws an exception 33 | */ 34 | class TransientDirectory 35 | { 36 | public: 37 | TransientDirectory(); 38 | TransientDirectory(std::string const& _path); 39 | ~TransientDirectory(); 40 | 41 | std::string const& path() const { return m_path; } 42 | 43 | private: 44 | std::string m_path; 45 | }; 46 | 47 | } 48 | -------------------------------------------------------------------------------- /libdevcore/TrieDB.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file TrieDB.cpp 18 | * @author Gav Wood 19 | * @date 2014 20 | */ 21 | 22 | #include 23 | #include "TrieDB.h" 24 | using namespace std; 25 | using namespace dev; 26 | 27 | h256 const dev::c_shaNull = sha3(rlp("")); 28 | h256 const dev::EmptyTrie = sha3(rlp("")); 29 | 30 | const char* TrieDBChannel::name() { return "-T-"; } 31 | -------------------------------------------------------------------------------- /libdevcore/TrieHash.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file TrieHash.h 18 | * @author Gav Wood 19 | * @date 2014 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | 27 | namespace dev 28 | { 29 | 30 | bytes rlp256(BytesMap const& _s); 31 | h256 hash256(BytesMap const& _s); 32 | 33 | h256 orderedTrieRoot(std::vector const& _data); 34 | 35 | template inline h256 trieRootOver(unsigned _itemCount, T const& _getKey, U const& _getValue) 36 | { 37 | BytesMap m; 38 | for (unsigned i = 0; i < _itemCount; ++i) 39 | m[_getKey(i)] = _getValue(i); 40 | return hash256(m); 41 | } 42 | 43 | h256 orderedTrieRoot(std::vector const& _data); 44 | h256 orderedTrieRoot(std::vector const& _data); 45 | 46 | } 47 | -------------------------------------------------------------------------------- /libdevcore/UndefMacros.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file UndefMacros.h 18 | * @author Lefteris 19 | * @date 2015 20 | * 21 | * This header should be used to #undef some really evil macros defined by 22 | * windows.h which result in conflict with our libsolidity/Token.h 23 | */ 24 | #pragma once 25 | 26 | #if defined(_MSC_VER) || defined(__MINGW32__) 27 | 28 | #undef DELETE 29 | #undef IN 30 | #undef VOID 31 | #undef THIS 32 | #undef CONST 33 | 34 | // Conflicting define on MinGW in windows.h 35 | // windows.h(19): #define interface struct 36 | #ifdef interface 37 | #undef interface 38 | #endif 39 | 40 | #elif defined(DELETE) || defined(IN) || defined(VOID) || defined(THIS) || defined(CONST) || defined(interface) 41 | 42 | #error "The preceding macros in this header file are reserved for V8's "\ 43 | "TOKEN_LIST. Please add a platform specific define above to undefine "\ 44 | "overlapping macros." 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /libdevcore/Worker.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file Worker.cpp 18 | * @author Gav Wood 19 | * @date 2014 20 | */ 21 | 22 | #include "Worker.h" 23 | 24 | #include 25 | #include 26 | #include "Log.h" 27 | #include "ethminer/MultiLog.h" 28 | 29 | using namespace std; 30 | using namespace dev; 31 | 32 | void Worker::startWorking() 33 | { 34 | LogF << "Worker::startWorking, startWorking for thread " << m_name; 35 | Guard l(x_work); 36 | if (m_work) 37 | { 38 | WorkerState ex = WorkerState::Stopped; 39 | m_state.compare_exchange_strong(ex, WorkerState::Starting); 40 | } 41 | else 42 | { 43 | m_state = WorkerState::Starting; 44 | m_work.reset(new thread([&]() 45 | { 46 | setThreadName(m_name.c_str()); 47 | LogF << "Worker::startWorking, Thread begins"; 48 | while (m_state != WorkerState::Killing) 49 | { 50 | WorkerState ex = WorkerState::Starting; 51 | bool ok = m_state.compare_exchange_strong(ex, WorkerState::Started); 52 | (void)ok; 53 | 54 | try 55 | { 56 | startedWorking(); 57 | workLoop(); 58 | doneWorking(); 59 | } 60 | catch (std::exception const& _e) 61 | { 62 | clog(WarnChannel) << "Exception thrown in Worker thread: " << _e.what(); 63 | } 64 | 65 | ex = m_state.exchange(WorkerState::Stopped); 66 | LogF << "Worker::startWorking, State: Stopped: Thread was " << (unsigned)ex; 67 | if (ex == WorkerState::Killing || ex == WorkerState::Starting) 68 | m_state.exchange(ex); 69 | 70 | DEV_TIMED_ABOVE("Worker stopping", 100) 71 | while (m_state == WorkerState::Stopped) 72 | this_thread::sleep_for(chrono::milliseconds(20)); 73 | } 74 | })); 75 | } 76 | DEV_TIMED_ABOVE("Start worker", 100) 77 | while (m_state == WorkerState::Starting) 78 | this_thread::sleep_for(chrono::microseconds(20)); 79 | } 80 | 81 | void Worker::stopWorking() 82 | { 83 | DEV_GUARDED(x_work) 84 | if (m_work) 85 | { 86 | WorkerState ex = WorkerState::Started; 87 | m_state.compare_exchange_strong(ex, WorkerState::Stopping); 88 | 89 | DEV_TIMED_ABOVE("Stop worker", 100) 90 | while (m_state != WorkerState::Stopped) 91 | this_thread::sleep_for(chrono::microseconds(20)); 92 | } 93 | } 94 | 95 | void Worker::terminate() 96 | { 97 | // cnote << "stopWorking for thread" << m_name; 98 | DEV_GUARDED(x_work) 99 | if (m_work) 100 | { 101 | m_state.exchange(WorkerState::Killing); 102 | 103 | DEV_TIMED_ABOVE("Terminate worker", 100) 104 | m_work->join(); 105 | 106 | m_work.reset(); 107 | } 108 | } 109 | 110 | void Worker::workLoop() 111 | { 112 | while (m_state == WorkerState::Started) 113 | { 114 | if (m_idleWaitMs) 115 | this_thread::sleep_for(chrono::milliseconds(m_idleWaitMs)); 116 | doWork(); 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /libdevcore/Worker.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file Worker.h 18 | * @author Gav Wood 19 | * @date 2014 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include 26 | #include 27 | #include "Guards.h" 28 | 29 | namespace dev 30 | { 31 | 32 | enum class IfRunning 33 | { 34 | Fail, 35 | Join, 36 | Detach 37 | }; 38 | 39 | enum class WorkerState 40 | { 41 | Starting, 42 | Started, 43 | Stopping, 44 | Stopped, 45 | Killing 46 | }; 47 | 48 | class Worker 49 | { 50 | protected: 51 | Worker(std::string const& _name = "anon", unsigned _idleWaitMs = 30): m_name(_name), m_idleWaitMs(_idleWaitMs) {} 52 | 53 | /// Move-constructor. 54 | Worker(Worker&& _m) { std::swap(m_name, _m.m_name); } 55 | 56 | /// Move-assignment. 57 | Worker& operator=(Worker&& _m) 58 | { 59 | assert(&_m != this); 60 | std::swap(m_name, _m.m_name); 61 | return *this; 62 | } 63 | 64 | virtual ~Worker() { terminate(); } 65 | 66 | /// Allows changing worker name if work is stopped. 67 | void setName(std::string _n) { if (!isWorking()) m_name = _n; } 68 | 69 | /// Starts worker thread; causes startedWorking() to be called. 70 | void startWorking(); 71 | 72 | /// Stop worker thread; causes call to stopWorking(). 73 | void stopWorking(); 74 | 75 | /// Returns if worker thread is present. 76 | bool isWorking() const { Guard l(x_work); return m_state == WorkerState::Started; } 77 | 78 | /// Called after thread is started from startWorking(). 79 | virtual void startedWorking() {} 80 | 81 | /// Called continuously following sleep for m_idleWaitMs. 82 | virtual void doWork() {} 83 | 84 | /// Overrides doWork(); should call shouldStop() often and exit when true. 85 | virtual void workLoop(); 86 | bool shouldStop() const { return m_state != WorkerState::Started; } 87 | 88 | /// Called when is to be stopped, just prior to thread being joined. 89 | virtual void doneWorking() {} 90 | 91 | /// Blocks caller into worker thread has finished. 92 | // void join() const { Guard l(x_work); try { if (m_work) m_work->join(); } catch (...) {} } 93 | 94 | private: 95 | /// Stop and never start again. 96 | void terminate(); 97 | 98 | std::string m_name; 99 | 100 | unsigned m_idleWaitMs = 0; 101 | 102 | mutable Mutex x_work; // Lock for the network existence. 103 | std::unique_ptr m_work; // The network thread. 104 | std::atomic m_state = {WorkerState::Starting}; 105 | }; 106 | 107 | } 108 | -------------------------------------------------------------------------------- /libdevcore/concurrent_queue.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | #pragma once 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | 24 | namespace dev 25 | { 26 | 27 | /// Concurrent queue. 28 | /// You can push and pop elements to/from the queue. Pop will block until the queue is not empty. 29 | /// The default backend (_QueueT) is std::queue. It can be changed to any type that has 30 | /// proper push(), pop(), empty() and front() methods. 31 | template> 32 | class concurrent_queue 33 | { 34 | public: 35 | template 36 | void push(_U&& _elem) 37 | { 38 | { 39 | std::lock_guard guard{x_mutex}; 40 | m_queue.push(std::forward<_U>(_elem)); 41 | } 42 | m_cv.notify_one(); 43 | } 44 | 45 | _T pop() 46 | { 47 | std::unique_lock lock{x_mutex}; 48 | m_cv.wait(lock, [this]{ return !m_queue.empty(); }); 49 | auto item = std::move(m_queue.front()); 50 | m_queue.pop(); 51 | return item; 52 | } 53 | 54 | private: 55 | _QueueT m_queue; 56 | std::mutex x_mutex; 57 | std::condition_variable m_cv; 58 | }; 59 | 60 | } 61 | -------------------------------------------------------------------------------- /libdevcore/db.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file DB.h 18 | * @author Gav Wood 19 | * @date 2014 20 | */ 21 | 22 | #pragma once 23 | 24 | #pragma warning(push) 25 | #pragma warning(disable: 4100 4267) 26 | #include 27 | #include 28 | namespace ldb = leveldb; 29 | #pragma warning(pop) 30 | #define DEV_LDB 1 31 | -------------------------------------------------------------------------------- /libethash-cl/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(EXECUTABLE ethash-cl) 2 | 3 | # A custom command and target to turn the OpenCL kernel into a byte array header 4 | # The normal build depends on it properly and if the kernel file is changed, then 5 | # a rebuild of libethash-cl should be triggered 6 | add_custom_command( 7 | OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/ethash_cl_miner_kernel.h 8 | COMMAND ${CMAKE_COMMAND} ARGS 9 | -DBIN2H_SOURCE_FILE="${CMAKE_CURRENT_SOURCE_DIR}/ethash_cl_miner_kernel.cl" 10 | -DBIN2H_VARIABLE_NAME=ethash_cl_miner_kernel 11 | -DBIN2H_HEADER_FILE="${CMAKE_CURRENT_BINARY_DIR}/ethash_cl_miner_kernel.h" 12 | -P "${CMAKE_CURRENT_SOURCE_DIR}/bin2h.cmake" 13 | COMMENT "Generating OpenCL Kernel Byte Array" 14 | DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/ethash_cl_miner_kernel.cl 15 | ) 16 | add_custom_target(clbin2h DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/ethash_cl_miner_kernel.h ${CMAKE_CURRENT_SOURCE_DIR}/ethash_cl_miner_kernel.cl) 17 | 18 | aux_source_directory(. SRC_LIST) 19 | file(GLOB OUR_HEADERS "*.h" "*.cl") 20 | set(HEADERS ${OUR_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/ethash_cl_miner_kernel.h) 21 | 22 | include_directories(${CMAKE_CURRENT_BINARY_DIR}) 23 | include_directories(${Boost_INCLUDE_DIRS}) 24 | include_directories(${JSONCPP_INCLUDE_DIRS}) 25 | include_directories(..) 26 | add_library(${EXECUTABLE} ${SRC_LIST} ${HEADERS}) 27 | target_include_directories(${EXECUTABLE} PUBLIC ${OpenCL_INCLUDE_DIR}) 28 | target_link_libraries(${EXECUTABLE} ${OpenCL_LIBRARIES} ethash) 29 | 30 | install( TARGETS ${EXECUTABLE} RUNTIME DESTINATION bin ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) 31 | install( FILES ${HEADERS} DESTINATION include/${EXECUTABLE} ) 32 | -------------------------------------------------------------------------------- /libethash-cl/bin2h.cmake: -------------------------------------------------------------------------------- 1 | # https://gist.github.com/sivachandran/3a0de157dccef822a230 2 | include(CMakeParseArguments) 3 | 4 | # Function to wrap a given string into multiple lines at the given column position. 5 | # Parameters: 6 | # VARIABLE - The name of the CMake variable holding the string. 7 | # AT_COLUMN - The column position at which string will be wrapped. 8 | function(WRAP_STRING) 9 | set(oneValueArgs VARIABLE AT_COLUMN) 10 | cmake_parse_arguments(WRAP_STRING "${options}" "${oneValueArgs}" "" ${ARGN}) 11 | 12 | string(LENGTH ${${WRAP_STRING_VARIABLE}} stringLength) 13 | math(EXPR offset "0") 14 | 15 | while(stringLength GREATER 0) 16 | 17 | if(stringLength GREATER ${WRAP_STRING_AT_COLUMN}) 18 | math(EXPR length "${WRAP_STRING_AT_COLUMN}") 19 | else() 20 | math(EXPR length "${stringLength}") 21 | endif() 22 | 23 | string(SUBSTRING ${${WRAP_STRING_VARIABLE}} ${offset} ${length} line) 24 | set(lines "${lines}\n${line}") 25 | 26 | math(EXPR stringLength "${stringLength} - ${length}") 27 | math(EXPR offset "${offset} + ${length}") 28 | endwhile() 29 | 30 | set(${WRAP_STRING_VARIABLE} "${lines}" PARENT_SCOPE) 31 | endfunction() 32 | 33 | # Script to embed contents of a file as byte array in C/C++ header file(.h). The header file 34 | # will contain a byte array and integer variable holding the size of the array. 35 | # Parameters 36 | # SOURCE_FILE - The path of source file whose contents will be embedded in the header file. 37 | # VARIABLE_NAME - The name of the variable for the byte array. The string "_SIZE" will be append 38 | # to this name and will be used a variable name for size variable. 39 | # HEADER_FILE - The path of header file. 40 | # APPEND - If specified appends to the header file instead of overwriting it 41 | # NULL_TERMINATE - If specified a null byte(zero) will be append to the byte array. This will be 42 | # useful if the source file is a text file and we want to use the file contents 43 | # as string. But the size variable holds size of the byte array without this 44 | # null byte. 45 | set(options APPEND NULL_TERMINATE) 46 | set(oneValueArgs SOURCE_FILE VARIABLE_NAME HEADER_FILE) 47 | # cmake_parse_arguments(BIN2H "${options}" "${oneValueArgs}" "" ${ARGN}) 48 | 49 | # reads source file contents as hex string 50 | file(READ ${BIN2H_SOURCE_FILE} hexString HEX) 51 | string(LENGTH ${hexString} hexStringLength) 52 | 53 | # appends null byte if asked 54 | if(BIN2H_NULL_TERMINATE) 55 | set(hexString "${hexString}00") 56 | endif() 57 | 58 | # wraps the hex string into multiple lines at column 32(i.e. 16 bytes per line) 59 | wrap_string(VARIABLE hexString AT_COLUMN 32) 60 | math(EXPR arraySize "${hexStringLength} / 2") 61 | 62 | # adds '0x' prefix and comma suffix before and after every byte respectively 63 | string(REGEX REPLACE "([0-9a-f][0-9a-f])" "0x\\1, " arrayValues ${hexString}) 64 | # removes trailing comma 65 | string(REGEX REPLACE ", $" "" arrayValues ${arrayValues}) 66 | 67 | # converts the variable name into proper C identifier 68 | IF (${CMAKE_VERSION} GREATER 2.8.10) # fix for legacy cmake 69 | string(MAKE_C_IDENTIFIER "${BIN2H_VARIABLE_NAME}" BIN2H_VARIABLE_NAME) 70 | ENDIF() 71 | string(TOUPPER "${BIN2H_VARIABLE_NAME}" BIN2H_VARIABLE_NAME) 72 | 73 | # declares byte array and the length variables 74 | set(arrayDefinition "const unsigned char ${BIN2H_VARIABLE_NAME}[] = { ${arrayValues} };") 75 | set(arraySizeDefinition "const size_t ${BIN2H_VARIABLE_NAME}_SIZE = ${arraySize};") 76 | 77 | set(declarations "${arrayDefinition}\n\n${arraySizeDefinition}\n\n") 78 | if(BIN2H_APPEND) 79 | file(APPEND ${BIN2H_HEADER_FILE} "${declarations}") 80 | else() 81 | file(WRITE ${BIN2H_HEADER_FILE} "${declarations}") 82 | endif() 83 | -------------------------------------------------------------------------------- /libethash-cuda/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(EXECUTABLE ethash-cuda) 2 | 3 | FIND_PACKAGE(CUDA REQUIRED) 4 | 5 | file(GLOB SRC_LIST "*.cpp" "*.cu") 6 | file(GLOB HEADERS "*.h" "*.cuh") 7 | 8 | set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};--disable-warnings;--ptxas-options=-v;-use_fast_math;-lineinfo) 9 | 10 | LIST(APPEND CUDA_NVCC_FLAGS_RELEASE -O3) 11 | LIST(APPEND CUDA_NVCC_FLAGS_DEBUG -G) 12 | 13 | if(COMPUTE AND (COMPUTE GREATER 0)) 14 | LIST(APPEND CUDA_NVCC_FLAGS -gencode arch=compute_${COMPUTE},code=sm_${COMPUTE}) 15 | else(COMPUTE AND (COMPUTE GREATER 0)) 16 | set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS};-gencode arch=compute_20,code=sm_20;-gencode arch=compute_30,code=sm_30;-gencode arch=compute_35,code=sm_35;-gencode arch=compute_50,code=sm_50;-gencode arch=compute_52,code=sm_52;-gencode arch=compute_61,code=sm_61) 17 | endif(COMPUTE AND (COMPUTE GREATER 0)) 18 | 19 | 20 | 21 | include_directories(${CMAKE_CURRENT_BINARY_DIR}) 22 | include_directories(${CUDA_INCLUDE_DIRS}) 23 | include_directories(..) 24 | CUDA_ADD_LIBRARY(${EXECUTABLE} STATIC ${SRC_LIST} ${HEADERS}) 25 | TARGET_LINK_LIBRARIES(${EXECUTABLE} ${CUDA_LIBRARIES} ethash) 26 | 27 | install( TARGETS ${EXECUTABLE} RUNTIME DESTINATION bin ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) 28 | install( FILES ${HEADERS} DESTINATION include/${EXECUTABLE} ) 29 | -------------------------------------------------------------------------------- /libethash-cuda/cuda_helper.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mining-visualizer/MVis-tokenminer/ae09b3f5314f202230dd812b5cd354a54bb140c6/libethash-cuda/cuda_helper.h -------------------------------------------------------------------------------- /libethash-cuda/dagger_shared.cuh: -------------------------------------------------------------------------------- 1 | #include "ethash_cuda_miner_kernel_globals.h" 2 | #include "ethash_cuda_miner_kernel.h" 3 | 4 | typedef union { 5 | uint4 uint4s[4]; 6 | uint64_t ulongs[8]; 7 | uint32_t uints[16]; 8 | } compute_hash_share; 9 | 10 | 11 | __device__ uint64_t compute_hash( 12 | uint64_t nonce 13 | ) 14 | { 15 | // sha3_512(header .. nonce) 16 | uint64_t state[25]; 17 | state[4] = nonce; 18 | keccak_f1600_init(state); 19 | 20 | // Threads work together in this phase in groups of 8. 21 | const int thread_id = threadIdx.x & (THREADS_PER_HASH - 1); 22 | const int hash_id = threadIdx.x >> 3; 23 | 24 | extern __shared__ compute_hash_share share[]; 25 | 26 | for (int i = 0; i < THREADS_PER_HASH; i++) 27 | { 28 | // share init with other threads 29 | if (i == thread_id) 30 | copy(share[hash_id].ulongs, state, 8); 31 | 32 | __syncthreads(); 33 | 34 | uint4 mix = share[hash_id].uint4s[thread_id & 3]; 35 | __syncthreads(); 36 | 37 | uint32_t *share0 = share[hash_id].uints; 38 | 39 | // share init0 40 | if (thread_id == 0) 41 | *share0 = mix.x; 42 | __syncthreads(); 43 | uint32_t init0 = *share0; 44 | 45 | for (uint32_t a = 0; a < ACCESSES; a += 4) 46 | { 47 | int t = bfe(a, 2u, 3u); 48 | 49 | for (uint32_t b = 0; b < 4; b++) 50 | { 51 | if (thread_id == t) { 52 | *share0 = fnv(init0 ^ (a + b), ((uint32_t *)&mix)[b]) % d_dag_size; 53 | } 54 | __syncthreads(); 55 | 56 | mix = fnv4(mix, d_dag[*share0].uint4s[thread_id]); 57 | } 58 | } 59 | 60 | share[hash_id].uints[thread_id] = fnv_reduce(mix); 61 | __syncthreads(); 62 | 63 | if (i == thread_id) 64 | copy(state + 8, share[hash_id].ulongs, 4); 65 | 66 | __syncthreads(); 67 | } 68 | 69 | // keccak_256(keccak_512(header..nonce) .. mix); 70 | return keccak_f1600_final(state); 71 | } -------------------------------------------------------------------------------- /libethash-cuda/dagger_shuffled.cuh: -------------------------------------------------------------------------------- 1 | #include "ethash_cuda_miner_kernel_globals.h" 2 | #include "ethash_cuda_miner_kernel.h" 3 | #include "cuda_helper.h" 4 | 5 | __device__ uint64_t compute_hash( 6 | uint64_t nonce 7 | ) 8 | { 9 | // sha3_512(header .. nonce) 10 | uint2 state[25]; 11 | 12 | state[4] = vectorize(nonce); 13 | 14 | keccak_f1600_init(state); 15 | 16 | // Threads work together in this phase in groups of 8. 17 | const int thread_id = threadIdx.x & (THREADS_PER_HASH - 1); 18 | const int mix_idx = thread_id & 3; 19 | 20 | uint4 mix; 21 | uint2 shuffle[8]; 22 | 23 | for (int i = 0; i < THREADS_PER_HASH; i++) 24 | { 25 | // share init among threads 26 | for (int j = 0; j < 8; j++) { 27 | shuffle[j].x = __shfl(state[j].x, i, THREADS_PER_HASH); 28 | shuffle[j].y = __shfl(state[j].y, i, THREADS_PER_HASH); 29 | } 30 | 31 | // ugly but avoids local reads/writes 32 | if (mix_idx < 2) { 33 | if (mix_idx == 0) 34 | mix = vectorize2(shuffle[0], shuffle[1]); 35 | else 36 | mix = vectorize2(shuffle[2], shuffle[3]); 37 | } 38 | else { 39 | if (mix_idx == 2) 40 | mix = vectorize2(shuffle[4], shuffle[5]); 41 | else 42 | mix = vectorize2(shuffle[6], shuffle[7]); 43 | } 44 | 45 | uint32_t init0 = __shfl(shuffle[0].x, 0, THREADS_PER_HASH); 46 | 47 | for (uint32_t a = 0; a < ACCESSES; a += 4) 48 | { 49 | int t = bfe(a, 2u, 3u); 50 | 51 | for (uint32_t b = 0; b < 4; b++) 52 | { 53 | if (thread_id == t) 54 | { 55 | shuffle[0].x = fnv(init0 ^ (a + b), ((uint32_t *)&mix)[b]) % d_dag_size; 56 | } 57 | shuffle[0].x = __shfl(shuffle[0].x, t, THREADS_PER_HASH); 58 | mix = fnv4(mix, d_dag[shuffle[0].x].uint4s[thread_id]); 59 | } 60 | } 61 | 62 | uint32_t thread_mix = fnv_reduce(mix); 63 | 64 | // update mix accross threads 65 | 66 | shuffle[0].x = __shfl(thread_mix, 0, THREADS_PER_HASH); 67 | shuffle[0].y = __shfl(thread_mix, 1, THREADS_PER_HASH); 68 | shuffle[1].x = __shfl(thread_mix, 2, THREADS_PER_HASH); 69 | shuffle[1].y = __shfl(thread_mix, 3, THREADS_PER_HASH); 70 | shuffle[2].x = __shfl(thread_mix, 4, THREADS_PER_HASH); 71 | shuffle[2].y = __shfl(thread_mix, 5, THREADS_PER_HASH); 72 | shuffle[3].x = __shfl(thread_mix, 6, THREADS_PER_HASH); 73 | shuffle[3].y = __shfl(thread_mix, 7, THREADS_PER_HASH); 74 | 75 | if (i == thread_id) { 76 | //move mix into state: 77 | state[8] = shuffle[0]; 78 | state[9] = shuffle[1]; 79 | state[10] = shuffle[2]; 80 | state[11] = shuffle[3]; 81 | } 82 | } 83 | 84 | // keccak_256(keccak_512(header..nonce) .. mix); 85 | return keccak_f1600_final(state); 86 | } -------------------------------------------------------------------------------- /libethash-cuda/ethash_cuda_miner.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | //#include 4 | 5 | #include 6 | #include 7 | #include 8 | #include "ethash_cuda_miner_kernel.h" 9 | 10 | class ethash_cuda_miner 11 | { 12 | public: 13 | 14 | struct search_hook 15 | { 16 | virtual ~search_hook(); // always a virtual destructor for a class with virtuals. 17 | 18 | // reports progress, return true to abort 19 | virtual bool found(uint64_t const* nonces, uint32_t count) = 0; 20 | virtual bool searched(uint32_t _count, uint64_t _hashSample, uint64_t _bestHash) = 0; 21 | }; 22 | 23 | public: 24 | ethash_cuda_miner(); 25 | 26 | static std::string platform_info(unsigned _deviceId = 0); 27 | static unsigned getNumDevices(); 28 | static void listDevices(); 29 | static bool configureGPU( 30 | int * _devices, 31 | unsigned _blockSize, 32 | unsigned _gridSize, 33 | unsigned _numStreams, 34 | unsigned _extraGPUMemory, 35 | unsigned _scheduleFlag, 36 | uint64_t _currentBlock 37 | ); 38 | 39 | bool init(ethash_light_t _light, uint8_t const* _lightData, uint64_t _lightSize, unsigned _deviceId, bool _cpyToHost, volatile void** hostDAG); 40 | 41 | void finish(); 42 | void search(uint8_t const* header, uint64_t target, search_hook& hook, bool _ethStratum, uint64_t _startN); 43 | 44 | /* -- default values -- */ 45 | /// Default value of the block size. Also known as workgroup size. 46 | static unsigned const c_defaultBlockSize; 47 | /// Default value of the grid size 48 | static unsigned const c_defaultGridSize; 49 | // default number of CUDA streams 50 | static unsigned const c_defaultNumStreams; 51 | 52 | private: 53 | hash32_t m_current_header; 54 | uint64_t m_current_target; 55 | uint64_t m_current_nonce; 56 | uint64_t m_starting_nonce; 57 | uint64_t m_current_index; 58 | 59 | uint32_t m_sharedBytes; 60 | 61 | volatile uint32_t ** m_search_buf; 62 | cudaStream_t * m_streams; 63 | 64 | /// The local work size for the search 65 | static unsigned s_blockSize; 66 | /// The initial global work size for the searches 67 | static unsigned s_gridSize; 68 | /// The number of CUDA streams 69 | static unsigned s_numStreams; 70 | /// CUDA schedule flag 71 | static unsigned s_scheduleFlag; 72 | 73 | /// GPU memory required for other things, like window rendering e.t.c. 74 | /// User can set it via the --cl-extragpu-mem argument. 75 | static unsigned s_extraRequiredGPUMem; 76 | }; -------------------------------------------------------------------------------- /libethash-cuda/ethash_cuda_miner_kernel.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETHASH_CUDA_MINER_KERNEL_H_ 2 | #define _ETHASH_CUDA_MINER_KERNEL_H_ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #define SEARCH_RESULT_BUFFER_SIZE 64 9 | #define ACCESSES 64 10 | #define THREADS_PER_HASH (128 / 16) 11 | 12 | typedef struct 13 | { 14 | uint4 uint4s[32 / sizeof(uint4)]; 15 | } hash32_t; 16 | 17 | typedef struct 18 | { 19 | uint4 uint4s[128 / sizeof(uint4)]; 20 | } hash128_t; 21 | 22 | typedef union { 23 | uint32_t words[64 / sizeof(uint32_t)]; 24 | uint2 uint2s[64 / sizeof(uint2)]; 25 | uint4 uint4s[64 / sizeof(uint4)]; 26 | } hash64_t; 27 | 28 | typedef union { 29 | uint32_t words[200 / sizeof(uint32_t)]; 30 | uint2 uint2s[200 / sizeof(uint2)]; 31 | uint4 uint4s[200 / sizeof(uint4)]; 32 | } hash200_t; 33 | 34 | void set_constants( 35 | hash128_t* _dag, 36 | uint32_t _dag_size, 37 | hash64_t * _light, 38 | uint32_t _light_size 39 | ); 40 | 41 | void set_header( 42 | hash32_t _header 43 | ); 44 | 45 | void set_target( 46 | uint64_t _target 47 | ); 48 | 49 | void run_ethash_search( 50 | uint32_t search_batch_size, 51 | uint32_t workgroup_size, 52 | uint32_t sharedbytes, 53 | cudaStream_t stream, 54 | volatile uint32_t* g_output, 55 | uint64_t start_nonce 56 | ); 57 | 58 | void ethash_generate_dag( 59 | uint64_t dag_size, 60 | uint32_t blocks, 61 | uint32_t threads, 62 | cudaStream_t stream, 63 | int device 64 | ); 65 | 66 | 67 | #define CUDA_SAFE_CALL(call) \ 68 | do { \ 69 | cudaError_t err = call; \ 70 | if (cudaSuccess != err) { \ 71 | const char * errorString = cudaGetErrorString(err); \ 72 | fprintf(stderr, \ 73 | "CUDA error in func '%s' at line %i : %s.\n", \ 74 | __FUNCTION__, __LINE__, errorString); \ 75 | throw std::runtime_error(errorString); \ 76 | } \ 77 | } while (0) 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /libethash-cuda/ethash_cuda_miner_kernel_globals.h: -------------------------------------------------------------------------------- 1 | #ifndef _ETHASH_CUDA_MINER_KERNEL_GLOBALS_H_ 2 | #define _ETHASH_CUDA_MINER_KERNEL_GLOBALS_H_ 3 | 4 | #define SHUFFLE_MIN_VER 300 5 | 6 | //#include "cuda_helper.h" 7 | 8 | __constant__ uint32_t d_dag_size; 9 | __constant__ hash128_t* d_dag; 10 | __constant__ uint32_t d_light_size; 11 | __constant__ hash64_t* d_light; 12 | __constant__ hash32_t d_header; 13 | __constant__ uint64_t d_target; 14 | 15 | #endif -------------------------------------------------------------------------------- /libethash-cuda/fnv.cuh: -------------------------------------------------------------------------------- 1 | 2 | #define FNV_PRIME 0x01000193 3 | 4 | #define fnv(x,y) ((x) * FNV_PRIME ^(y)) 5 | 6 | __device__ uint4 fnv4(uint4 a, uint4 b) 7 | { 8 | uint4 c; 9 | c.x = a.x * FNV_PRIME ^ b.x; 10 | c.y = a.y * FNV_PRIME ^ b.y; 11 | c.z = a.z * FNV_PRIME ^ b.z; 12 | c.w = a.w * FNV_PRIME ^ b.w; 13 | return c; 14 | } 15 | 16 | __device__ uint32_t fnv_reduce(uint4 v) 17 | { 18 | return fnv(fnv(fnv(v.x, v.y), v.z), v.w); 19 | } 20 | 21 | -------------------------------------------------------------------------------- /libethash/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(LIBRARY ethash) 2 | 3 | if (CPPETHEREUM) 4 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC") 5 | endif () 6 | 7 | set(CMAKE_BUILD_TYPE Release) 8 | 9 | if (NOT MSVC) 10 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99") 11 | endif() 12 | 13 | set(FILES util.h 14 | io.c 15 | internal.c 16 | ethash.h 17 | endian.h 18 | compiler.h 19 | fnv.h 20 | data_sizes.h) 21 | 22 | if (MSVC) 23 | list(APPEND FILES util_win32.c io_win32.c mmap_win32.c) 24 | else() 25 | list(APPEND FILES io_posix.c) 26 | endif() 27 | 28 | if (NOT CRYPTOPP_FOUND) 29 | find_package(CryptoPP 5.6.2) 30 | endif() 31 | 32 | if (CRYPTOPP_FOUND) 33 | add_definitions(-DWITH_CRYPTOPP) 34 | include_directories( ${CRYPTOPP_INCLUDE_DIRS} ) 35 | list(APPEND FILES sha3_cryptopp.cpp sha3_cryptopp.h) 36 | else() 37 | list(APPEND FILES sha3.c sha3.h) 38 | endif() 39 | 40 | add_library(${LIBRARY} ${FILES}) 41 | 42 | if (CRYPTOPP_FOUND) 43 | TARGET_LINK_LIBRARIES(${LIBRARY} ${CRYPTOPP_LIBRARIES}) 44 | endif() 45 | 46 | install( TARGETS ${LIBRARY} RUNTIME DESTINATION bin ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) 47 | -------------------------------------------------------------------------------- /libethash/compiler.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file compiler.h 18 | * @date 2014 19 | */ 20 | #pragma once 21 | 22 | // Visual Studio doesn't support the inline keyword in C mode 23 | #if defined(_MSC_VER) && !defined(__cplusplus) 24 | #define inline __inline 25 | #endif 26 | 27 | // pretend restrict is a standard keyword 28 | #if defined(_MSC_VER) 29 | #define restrict __restrict 30 | #else 31 | #define restrict __restrict__ 32 | #endif 33 | 34 | -------------------------------------------------------------------------------- /libethash/endian.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "compiler.h" 5 | 6 | #if defined(__MINGW32__) || defined(_WIN32) 7 | # define LITTLE_ENDIAN 1234 8 | # define BYTE_ORDER LITTLE_ENDIAN 9 | #elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) 10 | # include 11 | #elif defined(__OpenBSD__) || defined(__SVR4) 12 | # include 13 | #elif defined(__APPLE__) 14 | # include 15 | #elif defined( BSD ) && (BSD >= 199103) 16 | # include 17 | #elif defined( __QNXNTO__ ) && defined( __LITTLEENDIAN__ ) 18 | # define LITTLE_ENDIAN 1234 19 | # define BYTE_ORDER LITTLE_ENDIAN 20 | #elif defined( __QNXNTO__ ) && defined( __BIGENDIAN__ ) 21 | # define BIG_ENDIAN 1234 22 | # define BYTE_ORDER BIG_ENDIAN 23 | #else 24 | # include 25 | #endif 26 | 27 | #if defined(_WIN32) 28 | #include 29 | #define ethash_swap_u32(input_) _byteswap_ulong(input_) 30 | #define ethash_swap_u64(input_) _byteswap_uint64(input_) 31 | #elif defined(__APPLE__) 32 | #include 33 | #define ethash_swap_u32(input_) OSSwapInt32(input_) 34 | #define ethash_swap_u64(input_) OSSwapInt64(input_) 35 | #elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(__NetBSD__) 36 | #define ethash_swap_u32(input_) bswap32(input_) 37 | #define ethash_swap_u64(input_) bswap64(input_) 38 | #else // posix 39 | #include 40 | #define ethash_swap_u32(input_) __bswap_32(input_) 41 | #define ethash_swap_u64(input_) __bswap_64(input_) 42 | #endif 43 | 44 | 45 | #if LITTLE_ENDIAN == BYTE_ORDER 46 | 47 | #define fix_endian32(dst_ ,src_) dst_ = src_ 48 | #define fix_endian32_same(val_) 49 | #define fix_endian64(dst_, src_) dst_ = src_ 50 | #define fix_endian64_same(val_) 51 | #define fix_endian_arr32(arr_, size_) 52 | #define fix_endian_arr64(arr_, size_) 53 | 54 | #elif BIG_ENDIAN == BYTE_ORDER 55 | 56 | #define fix_endian32(dst_, src_) dst_ = ethash_swap_u32(src_) 57 | #define fix_endian32_same(val_) val_ = ethash_swap_u32(val_) 58 | #define fix_endian64(dst_, src_) dst_ = ethash_swap_u64(src_ 59 | #define fix_endian64_same(val_) val_ = ethash_swap_u64(val_) 60 | #define fix_endian_arr32(arr_, size_) \ 61 | do { \ 62 | for (unsigned i_ = 0; i_ < (size_), ++i_) { \ 63 | arr_[i_] = ethash_swap_u32(arr_[i_]); \ 64 | } \ 65 | while (0) 66 | #define fix_endian_arr64(arr_, size_) \ 67 | do { \ 68 | for (unsigned i_ = 0; i_ < (size_), ++i_) { \ 69 | arr_[i_] = ethash_swap_u64(arr_[i_]); \ 70 | } \ 71 | while (0) \ 72 | 73 | #else 74 | # error "endian not supported" 75 | #endif // BYTE_ORDER 76 | -------------------------------------------------------------------------------- /libethash/fnv.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file fnv.h 18 | * @author Matthew Wampler-Doty 19 | * @date 2015 20 | */ 21 | 22 | #pragma once 23 | #include 24 | #include "compiler.h" 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | #define FNV_PRIME 0x01000193 31 | 32 | static inline uint32_t fnv_hash(uint32_t const x, uint32_t const y) 33 | { 34 | return x * FNV_PRIME ^ y; 35 | } 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | -------------------------------------------------------------------------------- /libethash/io.c: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of ethash. 3 | 4 | ethash is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | ethash is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with ethash. If not, see . 16 | */ 17 | /** @file io.c 18 | * @author Lefteris Karapetsas 19 | * @date 2015 20 | */ 21 | #include "io.h" 22 | #include 23 | #include 24 | #include 25 | 26 | enum ethash_io_rc ethash_io_prepare( 27 | char const* dirname, 28 | ethash_h256_t const seedhash, 29 | FILE** output_file, 30 | uint64_t file_size, 31 | bool force_create 32 | ) 33 | { 34 | char mutable_name[DAG_MUTABLE_NAME_MAX_SIZE]; 35 | enum ethash_io_rc ret = ETHASH_IO_FAIL; 36 | // reset errno before io calls 37 | errno = 0; 38 | 39 | // assert directory exists 40 | if (!ethash_mkdir(dirname)) { 41 | ETHASH_CRITICAL("Could not create the ethash directory"); 42 | goto end; 43 | } 44 | 45 | ethash_io_mutable_name(ETHASH_REVISION, &seedhash, mutable_name); 46 | char* tmpfile = ethash_io_create_filename(dirname, mutable_name, strlen(mutable_name)); 47 | if (!tmpfile) { 48 | ETHASH_CRITICAL("Could not create the full DAG pathname"); 49 | goto end; 50 | } 51 | 52 | FILE *f; 53 | if (!force_create) { 54 | // try to open the file 55 | f = ethash_fopen(tmpfile, "rb+"); 56 | if (f) { 57 | size_t found_size; 58 | if (!ethash_file_size(f, &found_size)) { 59 | fclose(f); 60 | ETHASH_CRITICAL("Could not query size of DAG file: \"%s\"", tmpfile); 61 | goto free_memo; 62 | } 63 | if (file_size != found_size - ETHASH_DAG_MAGIC_NUM_SIZE) { 64 | fclose(f); 65 | ret = ETHASH_IO_MEMO_SIZE_MISMATCH; 66 | goto free_memo; 67 | } 68 | // compare the magic number, no need to care about endianess since it's local 69 | uint64_t magic_num; 70 | if (fread(&magic_num, ETHASH_DAG_MAGIC_NUM_SIZE, 1, f) != 1) { 71 | // I/O error 72 | fclose(f); 73 | ETHASH_CRITICAL("Could not read from DAG file: \"%s\"", tmpfile); 74 | ret = ETHASH_IO_MEMO_SIZE_MISMATCH; 75 | goto free_memo; 76 | } 77 | if (magic_num != ETHASH_DAG_MAGIC_NUM) { 78 | fclose(f); 79 | ret = ETHASH_IO_MEMO_SIZE_MISMATCH; 80 | goto free_memo; 81 | } 82 | ret = ETHASH_IO_MEMO_MATCH; 83 | goto set_file; 84 | } 85 | } 86 | 87 | // file does not exist, will need to be created 88 | f = ethash_fopen(tmpfile, "wb+"); 89 | if (!f) { 90 | ETHASH_CRITICAL("Could not create DAG file: \"%s\"", tmpfile); 91 | goto free_memo; 92 | } 93 | // make sure it's of the proper size 94 | if (ethash_fseek(f, file_size + ETHASH_DAG_MAGIC_NUM_SIZE - 1, SEEK_SET) != 0) { 95 | fclose(f); 96 | ETHASH_CRITICAL("Could not seek to the end of DAG file: \"%s\". Insufficient space?", tmpfile); 97 | goto free_memo; 98 | } 99 | if (fputc('\n', f) == EOF) { 100 | fclose(f); 101 | ETHASH_CRITICAL("Could not write in the end of DAG file: \"%s\". Insufficient space?", tmpfile); 102 | goto free_memo; 103 | } 104 | if (fflush(f) != 0) { 105 | fclose(f); 106 | ETHASH_CRITICAL("Could not flush at end of DAG file: \"%s\". Insufficient space?", tmpfile); 107 | goto free_memo; 108 | } 109 | ret = ETHASH_IO_MEMO_MISMATCH; 110 | goto set_file; 111 | 112 | ret = ETHASH_IO_MEMO_MATCH; 113 | set_file: 114 | *output_file = f; 115 | free_memo: 116 | free(tmpfile); 117 | end: 118 | return ret; 119 | } 120 | -------------------------------------------------------------------------------- /libethash/io_posix.c: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of ethash. 3 | 4 | ethash is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | ethash is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with ethash. If not, see . 16 | */ 17 | /** @file io_posix.c 18 | * @author Lefteris Karapetsas 19 | * @date 2015 20 | */ 21 | 22 | #include "io.h" 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | 32 | FILE* ethash_fopen(char const* file_name, char const* mode) 33 | { 34 | return fopen(file_name, mode); 35 | } 36 | 37 | int ethash_fseek(FILE* f, size_t offset, int origin) 38 | { 39 | return fseeko(f, offset, origin); 40 | } 41 | 42 | char* ethash_strncat(char* dest, size_t dest_size, char const* src, size_t count) 43 | { 44 | return strlen(dest) + count + 1 <= dest_size ? strncat(dest, src, count) : NULL; 45 | } 46 | 47 | bool ethash_mkdir(char const* dirname) 48 | { 49 | int rc = mkdir(dirname, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); 50 | return rc != -1 || errno == EEXIST; 51 | } 52 | 53 | int ethash_fileno(FILE *f) 54 | { 55 | return fileno(f); 56 | } 57 | 58 | char* ethash_io_create_filename( 59 | char const* dirname, 60 | char const* filename, 61 | size_t filename_length 62 | ) 63 | { 64 | size_t dirlen = strlen(dirname); 65 | size_t dest_size = dirlen + filename_length + 1; 66 | if (dirname[dirlen] != '/') { 67 | dest_size += 1; 68 | } 69 | char* name = malloc(dest_size); 70 | if (!name) { 71 | return NULL; 72 | } 73 | 74 | name[0] = '\0'; 75 | ethash_strncat(name, dest_size, dirname, dirlen); 76 | if (dirname[dirlen] != '/') { 77 | ethash_strncat(name, dest_size, "/", 1); 78 | } 79 | ethash_strncat(name, dest_size, filename, filename_length); 80 | return name; 81 | } 82 | 83 | bool ethash_file_size(FILE* f, size_t* ret_size) 84 | { 85 | struct stat st; 86 | int fd; 87 | if ((fd = fileno(f)) == -1 || fstat(fd, &st) != 0) { 88 | return false; 89 | } 90 | *ret_size = st.st_size; 91 | return true; 92 | } 93 | 94 | bool ethash_get_default_dirname(char* strbuf, size_t buffsize) 95 | { 96 | static const char dir_suffix[] = ".ethash/"; 97 | strbuf[0] = '\0'; 98 | char* home_dir = getenv("HOME"); 99 | if (!home_dir || strlen(home_dir) == 0) 100 | { 101 | struct passwd* pwd = getpwuid(getuid()); 102 | if (pwd) 103 | home_dir = pwd->pw_dir; 104 | } 105 | 106 | size_t len = strlen(home_dir); 107 | if (!ethash_strncat(strbuf, buffsize, home_dir, len)) { 108 | return false; 109 | } 110 | if (home_dir[len] != '/') { 111 | if (!ethash_strncat(strbuf, buffsize, "/", 1)) { 112 | return false; 113 | } 114 | } 115 | return ethash_strncat(strbuf, buffsize, dir_suffix, sizeof(dir_suffix)); 116 | } 117 | -------------------------------------------------------------------------------- /libethash/io_win32.c: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of ethash. 3 | 4 | ethash is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | ethash is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with ethash. If not, see . 16 | */ 17 | /** @file io_win32.c 18 | * @author Lefteris Karapetsas 19 | * @date 2015 20 | */ 21 | 22 | #include "io.h" 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | 31 | FILE* ethash_fopen(char const* file_name, char const* mode) 32 | { 33 | FILE* f; 34 | return fopen_s(&f, file_name, mode) == 0 ? f : NULL; 35 | } 36 | 37 | int ethash_fseek(FILE* f, size_t offset, int origin) 38 | { 39 | return _fseeki64(f, offset, origin); 40 | } 41 | 42 | char* ethash_strncat(char* dest, size_t dest_size, char const* src, size_t count) 43 | { 44 | return strncat_s(dest, dest_size, src, count) == 0 ? dest : NULL; 45 | } 46 | 47 | bool ethash_mkdir(char const* dirname) 48 | { 49 | int rc = _mkdir(dirname); 50 | return rc != -1 || errno == EEXIST; 51 | } 52 | 53 | int ethash_fileno(FILE* f) 54 | { 55 | return _fileno(f); 56 | } 57 | 58 | char* ethash_io_create_filename( 59 | char const* dirname, 60 | char const* filename, 61 | size_t filename_length 62 | ) 63 | { 64 | size_t dirlen = strlen(dirname); 65 | size_t dest_size = dirlen + filename_length + 1; 66 | if (dirname[dirlen] != '\\' || dirname[dirlen] != '/') { 67 | dest_size += 1; 68 | } 69 | char* name = malloc(dest_size); 70 | if (!name) { 71 | return NULL; 72 | } 73 | 74 | name[0] = '\0'; 75 | ethash_strncat(name, dest_size, dirname, dirlen); 76 | if (dirname[dirlen] != '\\' || dirname[dirlen] != '/') { 77 | ethash_strncat(name, dest_size, "\\", 1); 78 | } 79 | ethash_strncat(name, dest_size, filename, filename_length); 80 | return name; 81 | } 82 | 83 | bool ethash_file_size(FILE* f, size_t* ret_size) 84 | { 85 | struct _stat st; 86 | int fd; 87 | if ((fd = _fileno(f)) == -1 || _fstat(fd, &st) != 0) { 88 | return false; 89 | } 90 | *ret_size = st.st_size; 91 | return true; 92 | } 93 | 94 | bool ethash_get_default_dirname(char* strbuf, size_t buffsize) 95 | { 96 | static const char dir_suffix[] = "Ethash\\"; 97 | strbuf[0] = '\0'; 98 | if (!SUCCEEDED(SHGetFolderPathA(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, (CHAR*)strbuf))) { 99 | return false; 100 | } 101 | if (!ethash_strncat(strbuf, buffsize, "\\", 1)) { 102 | return false; 103 | } 104 | 105 | return ethash_strncat(strbuf, buffsize, dir_suffix, sizeof(dir_suffix)); 106 | } 107 | -------------------------------------------------------------------------------- /libethash/mmap.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of ethash. 3 | 4 | ethash is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | ethash is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with ethash. If not, see . 16 | */ 17 | /** @file mmap.h 18 | * @author Lefteris Karapetsas 19 | * @date 2015 20 | */ 21 | #pragma once 22 | #if defined(__MINGW32__) || defined(_WIN32) 23 | #include 24 | 25 | #define PROT_READ 0x1 26 | #define PROT_WRITE 0x2 27 | /* This flag is only available in WinXP+ */ 28 | #ifdef FILE_MAP_EXECUTE 29 | #define PROT_EXEC 0x4 30 | #else 31 | #define PROT_EXEC 0x0 32 | #define FILE_MAP_EXECUTE 0 33 | #endif 34 | 35 | #define MAP_SHARED 0x01 36 | #define MAP_PRIVATE 0x02 37 | #define MAP_ANONYMOUS 0x20 38 | #define MAP_ANON MAP_ANONYMOUS 39 | #define MAP_FAILED ((void *) -1) 40 | 41 | void* mmap(void* start, size_t length, int prot, int flags, int fd, off_t offset); 42 | void munmap(void* addr, size_t length); 43 | #else // posix, yay! ^_^ 44 | #include 45 | #endif 46 | 47 | 48 | -------------------------------------------------------------------------------- /libethash/mmap_win32.c: -------------------------------------------------------------------------------- 1 | /* mmap() replacement for Windows 2 | * 3 | * Author: Mike Frysinger 4 | * Placed into the public domain 5 | */ 6 | 7 | /* References: 8 | * CreateFileMapping: http://msdn.microsoft.com/en-us/library/aa366537(VS.85).aspx 9 | * CloseHandle: http://msdn.microsoft.com/en-us/library/ms724211(VS.85).aspx 10 | * MapViewOfFile: http://msdn.microsoft.com/en-us/library/aa366761(VS.85).aspx 11 | * UnmapViewOfFile: http://msdn.microsoft.com/en-us/library/aa366882(VS.85).aspx 12 | */ 13 | 14 | #include 15 | #include 16 | #include "mmap.h" 17 | 18 | #ifdef __USE_FILE_OFFSET64 19 | # define DWORD_HI(x) (x >> 32) 20 | # define DWORD_LO(x) ((x) & 0xffffffff) 21 | #else 22 | # define DWORD_HI(x) (0) 23 | # define DWORD_LO(x) (x) 24 | #endif 25 | 26 | void* mmap(void* start, size_t length, int prot, int flags, int fd, off_t offset) 27 | { 28 | if (prot & ~(PROT_READ | PROT_WRITE | PROT_EXEC)) 29 | return MAP_FAILED; 30 | if (fd == -1) { 31 | if (!(flags & MAP_ANON) || offset) 32 | return MAP_FAILED; 33 | } else if (flags & MAP_ANON) 34 | return MAP_FAILED; 35 | 36 | DWORD flProtect; 37 | if (prot & PROT_WRITE) { 38 | if (prot & PROT_EXEC) 39 | flProtect = PAGE_EXECUTE_READWRITE; 40 | else 41 | flProtect = PAGE_READWRITE; 42 | } else if (prot & PROT_EXEC) { 43 | if (prot & PROT_READ) 44 | flProtect = PAGE_EXECUTE_READ; 45 | else if (prot & PROT_EXEC) 46 | flProtect = PAGE_EXECUTE; 47 | } else 48 | flProtect = PAGE_READONLY; 49 | 50 | off_t end = length + offset; 51 | HANDLE mmap_fd, h; 52 | if (fd == -1) 53 | mmap_fd = INVALID_HANDLE_VALUE; 54 | else 55 | mmap_fd = (HANDLE)_get_osfhandle(fd); 56 | h = CreateFileMapping(mmap_fd, NULL, flProtect, DWORD_HI(end), DWORD_LO(end), NULL); 57 | if (h == NULL) 58 | return MAP_FAILED; 59 | 60 | DWORD dwDesiredAccess; 61 | if (prot & PROT_WRITE) 62 | dwDesiredAccess = FILE_MAP_WRITE; 63 | else 64 | dwDesiredAccess = FILE_MAP_READ; 65 | if (prot & PROT_EXEC) 66 | dwDesiredAccess |= FILE_MAP_EXECUTE; 67 | if (flags & MAP_PRIVATE) 68 | dwDesiredAccess |= FILE_MAP_COPY; 69 | void *ret = MapViewOfFile(h, dwDesiredAccess, DWORD_HI(offset), DWORD_LO(offset), length); 70 | if (ret == NULL) { 71 | ret = MAP_FAILED; 72 | } 73 | // since we are handling the file ourselves with fd, close the Windows Handle here 74 | CloseHandle(h); 75 | return ret; 76 | } 77 | 78 | void munmap(void* addr, size_t length) 79 | { 80 | UnmapViewOfFile(addr); 81 | } 82 | 83 | #undef DWORD_HI 84 | #undef DWORD_LO 85 | -------------------------------------------------------------------------------- /libethash/sha3.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #ifdef __cplusplus 4 | extern "C" { 5 | #endif 6 | 7 | #include "compiler.h" 8 | #include 9 | #include 10 | 11 | struct ethash_h256; 12 | 13 | #define decsha3(bits) \ 14 | int sha3_##bits(uint8_t*, size_t, uint8_t const*, size_t); 15 | 16 | decsha3(256) 17 | decsha3(512) 18 | 19 | static inline void SHA3_256(struct ethash_h256 const* ret, uint8_t const* data, size_t const size) 20 | { 21 | sha3_256((uint8_t*)ret, 32, data, size); 22 | } 23 | 24 | static inline void SHA3_512(uint8_t* ret, uint8_t const* data, size_t const size) 25 | { 26 | sha3_512(ret, 64, data, size); 27 | } 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | -------------------------------------------------------------------------------- /libethash/sha3_cryptopp.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of ethash. 3 | 4 | ethash is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | ethash is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with ethash. If not, see . 16 | */ 17 | 18 | /** @file sha3.cpp 19 | * @author Tim Hughes 20 | * @date 2015 21 | */ 22 | #include 23 | #include 24 | 25 | extern "C" { 26 | struct ethash_h256; 27 | typedef struct ethash_h256 ethash_h256_t; 28 | void SHA3_256(ethash_h256_t const* ret, uint8_t const* data, size_t size) 29 | { 30 | CryptoPP::SHA3_256().CalculateDigest((uint8_t*)ret, data, size); 31 | } 32 | 33 | void SHA3_512(uint8_t* const ret, uint8_t const* data, size_t size) 34 | { 35 | CryptoPP::SHA3_512().CalculateDigest(ret, data, size); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /libethash/sha3_cryptopp.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "compiler.h" 4 | #include 5 | #include 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | struct ethash_h256; 12 | 13 | void SHA3_256(struct ethash_h256 const* ret, uint8_t const* data, size_t size); 14 | void SHA3_512(uint8_t* const ret, uint8_t const* data, size_t size); 15 | 16 | #ifdef __cplusplus 17 | } 18 | #endif 19 | -------------------------------------------------------------------------------- /libethash/util.c: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file util.c 18 | * @author Tim Hughes 19 | * @date 2015 20 | */ 21 | #include 22 | #include 23 | #include "util.h" 24 | 25 | #ifdef _MSC_VER 26 | 27 | // foward declare without all of Windows.h 28 | __declspec(dllimport) void __stdcall OutputDebugStringA(const char* lpOutputString); 29 | 30 | void debugf(const char *str, ...) 31 | { 32 | va_list args; 33 | va_start(args, str); 34 | 35 | char buf[1<<16]; 36 | _vsnprintf_s(buf, sizeof(buf), sizeof(buf), str, args); 37 | buf[sizeof(buf)-1] = '\0'; 38 | OutputDebugStringA(buf); 39 | } 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /libethash/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of ethash. 3 | 4 | ethash is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | ethash is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with ethash. If not, see . 16 | */ 17 | /** @file util.h 18 | * @author Tim Hughes 19 | * @date 2015 20 | */ 21 | #pragma once 22 | #include 23 | #include "compiler.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | #ifdef _MSC_VER 30 | void debugf(char const* str, ...); 31 | #else 32 | #define debugf printf 33 | #endif 34 | 35 | static inline uint32_t min_u32(uint32_t a, uint32_t b) 36 | { 37 | return a < b ? a : b; 38 | } 39 | 40 | static inline uint32_t clamp_u32(uint32_t x, uint32_t min_, uint32_t max_) 41 | { 42 | return x < min_ ? min_ : (x > max_ ? max_ : x); 43 | } 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | -------------------------------------------------------------------------------- /libethash/util_win32.c: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file util.c 18 | * @author Tim Hughes 19 | * @date 2015 20 | */ 21 | #include 22 | #include 23 | #include "util.h" 24 | 25 | 26 | // foward declare without all of Windows.h 27 | __declspec(dllimport) void __stdcall OutputDebugStringA(char const* lpOutputString); 28 | 29 | void debugf(char const* str, ...) 30 | { 31 | va_list args; 32 | va_start(args, str); 33 | 34 | char buf[1<<16]; 35 | _vsnprintf_s(buf, sizeof(buf), sizeof(buf), str, args); 36 | buf[sizeof(buf)-1] = '\0'; 37 | OutputDebugStringA(buf); 38 | } 39 | -------------------------------------------------------------------------------- /libethcore/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_policy(SET CMP0015 NEW) 2 | set(CMAKE_AUTOMOC OFF) 3 | 4 | aux_source_directory(. SRC_LIST) 5 | 6 | include_directories(BEFORE ..) 7 | include_directories(${Boost_INCLUDE_DIRS}) 8 | include_directories(${JSONCPP_INCLUDE_DIRS}) 9 | 10 | if (CPUID_FOUND) 11 | include_directories(${Cpuid_INCLUDE_DIRS}) 12 | endif () 13 | 14 | if (ETHASHCUDA) 15 | include_directories(${CUDA_INCLUDE_DIRS}) 16 | endif () 17 | 18 | set(EXECUTABLE ethcore) 19 | 20 | file(GLOB HEADERS "*.h") 21 | 22 | add_library(${EXECUTABLE} ${SRC_LIST} ${HEADERS}) 23 | 24 | target_link_libraries(${EXECUTABLE} ethash) 25 | 26 | if (ETHASHCL) 27 | target_link_libraries(${EXECUTABLE} ethash-cl) 28 | endif () 29 | if (ETHASHCUDA) 30 | target_link_libraries(${EXECUTABLE} ethash-cuda) 31 | endif () 32 | if (CPUID_FOUND) 33 | target_link_libraries(${EXECUTABLE} ${CPUID_LIBRARIES}) 34 | endif () 35 | 36 | install( TARGETS ${EXECUTABLE} RUNTIME DESTINATION bin ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) 37 | install( FILES ${HEADERS} DESTINATION include/${EXECUTABLE} ) 38 | -------------------------------------------------------------------------------- /libethcore/Ethash.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file Ethash.h 18 | * @author Gav Wood 19 | * @date 2014 20 | * 21 | * A proof of work algorithm. 22 | */ 23 | 24 | #pragma once 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include "Common.h" 31 | #include "Miner.h" 32 | #include "Farm.h" 33 | #include "Sealer.h" 34 | 35 | class ethash_cl_miner; 36 | class ethash_cuda_miner; 37 | 38 | namespace dev 39 | { 40 | 41 | class RLP; 42 | class RLPStream; 43 | 44 | namespace eth 45 | { 46 | 47 | class BlockInfo; 48 | class EthashCLHook; 49 | class EthashCUDAHook; 50 | 51 | class Ethash 52 | { 53 | public: 54 | static std::string name(); 55 | static unsigned revision(); 56 | static SealEngineFace* createSealEngine(); 57 | 58 | using Nonce = h64; 59 | 60 | static void manuallySubmitWork(SealEngineFace* _engine, h256 const& _mixHash, Nonce _nonce); 61 | static bool isWorking(SealEngineFace* _engine); 62 | static WorkingProgress workingProgress(SealEngineFace* _engine); 63 | 64 | class BlockHeaderRaw: public BlockInfo 65 | { 66 | friend class EthashSealEngine; 67 | 68 | public: 69 | static const unsigned SealFields = 2; 70 | 71 | bool verify() const; 72 | bool preVerify() const; 73 | 74 | void prep(std::function const& _f = std::function()) const; 75 | h256 const& seedHash() const; 76 | Nonce const& nonce() const { return m_nonce; } 77 | h256 const& mixHash() const { return m_mixHash; } 78 | 79 | void setNonce(Nonce const& _n) { m_nonce = _n; noteDirty(); } 80 | void setMixHash(h256 const& _n) { m_mixHash = _n; noteDirty(); } 81 | 82 | StringHashMap jsInfo() const; 83 | 84 | protected: 85 | BlockHeaderRaw() = default; 86 | BlockHeaderRaw(BlockInfo const& _bi): BlockInfo(_bi) {} 87 | 88 | void populateFromHeader(RLP const& _header, Strictness _s); 89 | void populateFromParent(BlockHeaderRaw const& _parent); 90 | void verifyParent(BlockHeaderRaw const& _parent); 91 | void clear() { m_mixHash = h256(); m_nonce = Nonce(); } 92 | void noteDirty() const { m_seedHash = h256(); } 93 | void streamRLPFields(RLPStream& _s) const { _s << m_mixHash << m_nonce; } 94 | 95 | private: 96 | Nonce m_nonce; 97 | h256 m_mixHash; 98 | 99 | mutable h256 m_seedHash; 100 | mutable h256 m_hash; ///< SHA3 hash of the block header! Not serialised. 101 | }; 102 | using BlockHeader = BlockHeaderPolished; 103 | 104 | static void manuallySetWork(SealEngineFace* _engine, BlockHeader const& _work); 105 | 106 | // TODO: Move elsewhere (EthashAux?) 107 | static void ensurePrecomputed(unsigned _number); 108 | }; 109 | 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /libethcore/EthashCPUMiner.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file EthashCPUMiner.h 18 | * @author Gav Wood 19 | * @date 2014 20 | * 21 | * Determines the PoW algorithm. 22 | */ 23 | 24 | #pragma once 25 | 26 | #include "libdevcore/Worker.h" 27 | #include "EthashAux.h" 28 | #include "Miner.h" 29 | 30 | namespace dev 31 | { 32 | namespace eth 33 | { 34 | 35 | class EthashCPUMiner: public GenericMiner, Worker 36 | { 37 | public: 38 | EthashCPUMiner(Farm* _farm, unsigned _index); 39 | ~EthashCPUMiner(); 40 | 41 | static unsigned instances() { return s_numInstances > 0 ? s_numInstances : std::thread::hardware_concurrency(); } 42 | static std::string platformInfo(); 43 | static void listDevices() {} 44 | static bool configureGPU(unsigned, unsigned, unsigned, unsigned, unsigned, bool, unsigned, uint64_t) { return false; } 45 | static void setNumInstances(unsigned _instances) { s_numInstances = std::min(_instances, std::thread::hardware_concurrency()); } 46 | 47 | protected: 48 | void kickOff() override; 49 | void pause() override; 50 | 51 | private: 52 | void workLoop() override; 53 | static unsigned s_numInstances; 54 | }; 55 | 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /libethcore/EthashCUDAMiner.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file EthashCUDAMiner.h 18 | * @author Gav Wood 19 | * @date 2014 20 | * 21 | * Determines the PoW algorithm. 22 | */ 23 | 24 | #pragma once 25 | #if ETH_ETHASHCUDA || !ETH_TRUE 26 | 27 | #include "libdevcore/Worker.h" 28 | #include "EthashAux.h" 29 | #include "Miner.h" 30 | 31 | namespace dev 32 | { 33 | namespace eth 34 | { 35 | class EthashCUDAMiner : public GenericMiner, Worker 36 | { 37 | friend class dev::eth::EthashCUDAHook; 38 | 39 | public: 40 | EthashCUDAMiner(Farm* _farm, unsigned _index); 41 | ~EthashCUDAMiner(); 42 | 43 | static unsigned instances() 44 | { 45 | return s_numInstances > 0 ? s_numInstances : 1; 46 | } 47 | static std::string platformInfo(); 48 | static unsigned getNumDevices(); 49 | static void listDevices(); 50 | static bool configureGPU( 51 | unsigned _blockSize, 52 | unsigned _gridSize, 53 | unsigned _numStreams, 54 | unsigned _extraGPUMemory, 55 | unsigned _scheduleFlag, 56 | uint64_t _currentBlock, 57 | unsigned _dagLoadMode, 58 | unsigned _dagCreateDevice 59 | ); 60 | static void setNumInstances(unsigned _instances) 61 | { 62 | s_numInstances = std::min(_instances, getNumDevices()); 63 | } 64 | static void setDevices(unsigned * _devices, unsigned _selectedDeviceCount) 65 | { 66 | for (unsigned i = 0; i < _selectedDeviceCount; i++) 67 | { 68 | s_devices[i] = _devices[i]; 69 | } 70 | } 71 | protected: 72 | void kickOff() override; 73 | void pause() override; 74 | 75 | private: 76 | void workLoop() override; 77 | bool report(uint64_t _nonce); 78 | 79 | EthashCUDAHook* m_hook = nullptr; 80 | ethash_cuda_miner* m_miner = nullptr; 81 | 82 | h256 m_minerSeed; ///< Last seed in m_miner 83 | static unsigned s_platformId; 84 | static unsigned s_deviceId; 85 | static unsigned s_numInstances; 86 | static int s_devices[16]; 87 | 88 | }; 89 | } 90 | } 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /libethcore/EthashGPUMiner.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file EthashGPUMiner.h 18 | * @author Gav Wood 19 | * @date 2014 20 | * 21 | * Determines the PoW algorithm. 22 | */ 23 | 24 | #pragma once 25 | #if ETH_ETHASHCL || !ETH_TRUE 26 | 27 | #include "libdevcore/Worker.h" 28 | #include "EthashAux.h" 29 | #include "Miner.h" 30 | 31 | namespace dev 32 | { 33 | namespace eth 34 | { 35 | 36 | class EthashGPUMiner: public GenericMiner, Worker 37 | { 38 | friend class dev::eth::EthashCLHook; 39 | 40 | public: 41 | EthashGPUMiner(Farm* _farm, unsigned _index); 42 | ~EthashGPUMiner(); 43 | 44 | static unsigned instances() { return s_numInstances > 0 ? s_numInstances : 1; } 45 | static std::string platformInfo(); 46 | static unsigned getNumDevices(); 47 | static void listDevices(); 48 | static bool configureGPU( 49 | unsigned _localWorkSize, 50 | unsigned _globalWorkSizeMultiplier, 51 | unsigned _platformId, 52 | unsigned _deviceId, 53 | bool _allowCPU, 54 | unsigned _extraGPUMemory, 55 | uint64_t _currentBlock, 56 | unsigned _dagLoadMode, 57 | unsigned _dagCreateDevice 58 | ); 59 | static void setNumInstances(unsigned _instances) { s_numInstances = std::min(_instances, getNumDevices()); } 60 | static void setDevices(unsigned * _devices, unsigned _selectedDeviceCount) 61 | { 62 | for (unsigned i = 0; i < _selectedDeviceCount; i++) 63 | { 64 | s_devices[i] = _devices[i]; 65 | } 66 | } 67 | void setThrottle(int _percent); 68 | void checkHash(uint64_t _hash, uint64_t _nonce, h256 _header); 69 | 70 | protected: 71 | void kickOff() override; 72 | void pause() override; 73 | 74 | private: 75 | void workLoop() override; 76 | bool report(h256 _nonce); 77 | void resetBestHash(); 78 | 79 | EthashCLHook* m_hook = nullptr; 80 | ethash_cl_miner* m_miner = nullptr; 81 | 82 | h256 m_minerSeed; ///< Last seed in m_miner 83 | static unsigned s_platformId; 84 | static unsigned s_deviceId; 85 | static unsigned s_numInstances; 86 | static int s_devices[16]; 87 | 88 | }; 89 | 90 | } 91 | } 92 | 93 | #endif 94 | -------------------------------------------------------------------------------- /libethcore/EthashSealEngine.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file EthashSealEngine.cpp 18 | * @author Gav Wood 19 | * @date 2014 20 | * 21 | * Determines the PoW algorithm. 22 | */ 23 | 24 | #include "EthashSealEngine.h" 25 | #include "EthashCPUMiner.h" 26 | #include "EthashGPUMiner.h" 27 | #include "EthashCUDAMiner.h" 28 | using namespace std; 29 | using namespace dev; 30 | using namespace eth; 31 | 32 | EthashSealEngine::EthashSealEngine() 33 | { 34 | //map::SealerDescriptor> sealers; 35 | // sealers["cpu"] = GenericFarm::SealerDescriptor{&EthashCPUMiner::instances, [](GenericMiner::ConstructionInfo ci){ return new EthashCPUMiner(ci); }}; 36 | //#if ETH_ETHASHCL 37 | // sealers["opencl"] = GenericFarm::SealerDescriptor{&EthashGPUMiner::instances, [](GenericMiner::ConstructionInfo ci){ return new EthashGPUMiner(ci); }}; 38 | //#endif 39 | //#if ETH_ETHASHCUDA 40 | // sealers["cuda"] = GenericFarm::SealerDescriptor{ &EthashCUDAMiner::instances, [](GenericMiner::ConstructionInfo ci){ return new EthashCUDAMiner(ci); } }; 41 | //#endif 42 | //m_farm.setSealers(sealers); 43 | } 44 | 45 | strings EthashSealEngine::sealers() const 46 | { 47 | return { 48 | "cpu" 49 | #if ETH_ETHASHCL 50 | , "opencl" 51 | #endif 52 | #if ETH_ETHASHCUDA 53 | , "cuda" 54 | #endif 55 | }; 56 | } 57 | 58 | void EthashSealEngine::generateSeal(BlockInfo const& _bi) 59 | { 60 | m_sealing = Ethash::BlockHeader(_bi); 61 | //m_farm.setWork(m_sealing); 62 | //m_farm.start(m_sealer, false); 63 | //m_farm.setWork(m_sealing); // TODO: take out one before or one after... 64 | bytes shouldPrecompute = option("precomputeDAG"); 65 | if (!shouldPrecompute.empty() && shouldPrecompute[0] == 1) 66 | Ethash::ensurePrecomputed((unsigned)_bi.number()); 67 | } 68 | 69 | void EthashSealEngine::onSealGenerated(std::function const& _f) 70 | { 71 | // m_farm.onSolutionFound([=](EthashProofOfWork::Solution const& sol, int miner) 72 | // { 73 | //// cdebug << m_farm.work().seedHash << m_farm.work().headerHash << sol.nonce << EthashAux::eval(m_farm.work().seedHash, m_farm.work().headerHash, sol.nonce).value; 74 | // m_sealing.m_mixHash = sol.mixHash; 75 | // m_sealing.m_nonce = sol.nonce; 76 | // if (!m_sealing.preVerify()) 77 | // return false; 78 | // RLPStream ret; 79 | // m_sealing.streamRLP(ret); 80 | // _f(ret.out()); 81 | // return true; 82 | // }); 83 | } 84 | -------------------------------------------------------------------------------- /libethcore/EthashSealEngine.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file EthashSealEngine.h 18 | * @author Gav Wood 19 | * @date 2014 20 | * 21 | * Determines the PoW algorithm. 22 | */ 23 | 24 | #pragma once 25 | 26 | #include "Sealer.h" 27 | #include "Ethash.h" 28 | #include "EthashAux.h" 29 | 30 | namespace dev 31 | { 32 | namespace eth 33 | { 34 | 35 | class EthashSealEngine: public SealEngineBase 36 | { 37 | friend class Ethash; 38 | 39 | public: 40 | EthashSealEngine(); 41 | 42 | strings sealers() const override; 43 | void setSealer(std::string const& _sealer) override { m_sealer = _sealer; } 44 | void cancelGeneration() override { m_farm.stop(); } 45 | void generateSeal(BlockInfo const& _bi) override; 46 | void onSealGenerated(std::function const& _f) override; 47 | 48 | private: 49 | bool m_opencl = false; 50 | eth::GenericFarm m_farm; 51 | std::string m_sealer = "cpu"; 52 | Ethash::BlockHeader m_sealing; 53 | }; 54 | 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /libethcore/Exceptions.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file Exceptions.h 18 | * @author Gav Wood 19 | * @date 2014 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | #include "Common.h" 26 | 27 | namespace dev 28 | { 29 | namespace eth 30 | { 31 | 32 | // information to add to exceptions 33 | using errinfo_name = boost::error_info; 34 | using errinfo_field = boost::error_info; 35 | using errinfo_data = boost::error_info; 36 | using errinfo_nonce = boost::error_info; 37 | using errinfo_difficulty = boost::error_info; 38 | using errinfo_target = boost::error_info; 39 | using errinfo_seedHash = boost::error_info; 40 | using errinfo_mixHash = boost::error_info; 41 | using errinfo_ethashResult = boost::error_info>; 42 | using BadFieldError = boost::tuple; 43 | 44 | DEV_SIMPLE_EXCEPTION(OutOfGasBase); 45 | DEV_SIMPLE_EXCEPTION(OutOfGasIntrinsic); 46 | DEV_SIMPLE_EXCEPTION(NotEnoughAvailableSpace); 47 | DEV_SIMPLE_EXCEPTION(NotEnoughCash); 48 | DEV_SIMPLE_EXCEPTION(GasPriceTooLow); 49 | DEV_SIMPLE_EXCEPTION(BlockGasLimitReached); 50 | DEV_SIMPLE_EXCEPTION(FeeTooSmall); 51 | DEV_SIMPLE_EXCEPTION(TooMuchGasUsed); 52 | DEV_SIMPLE_EXCEPTION(ExtraDataTooBig); 53 | DEV_SIMPLE_EXCEPTION(InvalidSignature); 54 | DEV_SIMPLE_EXCEPTION(InvalidTransactionFormat); 55 | DEV_SIMPLE_EXCEPTION(InvalidBlockFormat); 56 | DEV_SIMPLE_EXCEPTION(InvalidUnclesHash); 57 | DEV_SIMPLE_EXCEPTION(TooManyUncles); 58 | DEV_SIMPLE_EXCEPTION(UncleTooOld); 59 | DEV_SIMPLE_EXCEPTION(UncleIsBrother); 60 | DEV_SIMPLE_EXCEPTION(UncleInChain); 61 | DEV_SIMPLE_EXCEPTION(InvalidStateRoot); 62 | DEV_SIMPLE_EXCEPTION(InvalidGasUsed); 63 | DEV_SIMPLE_EXCEPTION(InvalidTransactionsRoot); 64 | DEV_SIMPLE_EXCEPTION(InvalidDifficulty); 65 | DEV_SIMPLE_EXCEPTION(InvalidGasLimit); 66 | DEV_SIMPLE_EXCEPTION(InvalidReceiptsStateRoot); 67 | DEV_SIMPLE_EXCEPTION(InvalidTimestamp); 68 | DEV_SIMPLE_EXCEPTION(InvalidLogBloom); 69 | DEV_SIMPLE_EXCEPTION(InvalidNonce); 70 | DEV_SIMPLE_EXCEPTION(InvalidBlockHeaderItemCount); 71 | DEV_SIMPLE_EXCEPTION(InvalidBlockNonce); 72 | DEV_SIMPLE_EXCEPTION(InvalidParentHash); 73 | DEV_SIMPLE_EXCEPTION(InvalidUncleParentHash); 74 | DEV_SIMPLE_EXCEPTION(InvalidNumber); 75 | DEV_SIMPLE_EXCEPTION(BlockNotFound); 76 | 77 | DEV_SIMPLE_EXCEPTION(DatabaseAlreadyOpen); 78 | DEV_SIMPLE_EXCEPTION(DAGCreationFailure); 79 | DEV_SIMPLE_EXCEPTION(DAGComputeFailure); 80 | 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /libethcore/Miner.cpp: -------------------------------------------------------------------------------- 1 | #include "Miner.h" 2 | #include "EthashAux.h" 3 | 4 | using namespace dev; 5 | using namespace eth; 6 | 7 | template <> 8 | unsigned dev::eth::GenericMiner::s_dagLoadMode = 0; 9 | 10 | template <> 11 | volatile unsigned dev::eth::GenericMiner::s_dagLoadIndex = 0; 12 | 13 | template <> 14 | unsigned dev::eth::GenericMiner::s_dagCreateDevice = 0; 15 | 16 | template <> 17 | volatile void* dev::eth::GenericMiner::s_dagInHostMemory = NULL; 18 | 19 | 20 | -------------------------------------------------------------------------------- /libethcore/Params.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file Params.cpp 18 | * @author Gav Wood 19 | * @date 2014 20 | */ 21 | 22 | #include "Params.h" 23 | #include "Common.h" 24 | 25 | using namespace std; 26 | namespace dev 27 | { 28 | namespace eth 29 | { 30 | 31 | //--- BEGIN: AUTOGENERATED FROM github.com/ethereum/common/params.json 32 | u256 c_maximumExtraDataSize; 33 | u256 c_minGasLimit; 34 | u256 c_gasLimitBoundDivisor; 35 | u256 c_minimumDifficulty; 36 | u256 c_difficultyBoundDivisor; 37 | u256 c_durationLimit; 38 | u256 c_blockReward; 39 | u256 c_gasFloorTarget; 40 | //--- END: AUTOGENERATED FROM /feeStructure.json 41 | 42 | #if ETH_FRONTIER 43 | Network c_network = resetNetwork(Network::Frontier); 44 | #else 45 | Network c_network = resetNetwork(Network::Olympic); 46 | #endif 47 | 48 | Network resetNetwork(Network _n) 49 | { 50 | c_network = _n; 51 | c_maximumExtraDataSize = c_network == Network::Olympic ? 1024 : 32; 52 | switch(_n) 53 | { 54 | case Network::Turbo: 55 | c_minGasLimit = 100000000; 56 | break; 57 | case Network::Olympic: 58 | c_minGasLimit = 125000; 59 | break; 60 | case Network::Frontier: 61 | c_minGasLimit = 5000; 62 | break; 63 | } 64 | c_gasFloorTarget = 3141592; 65 | c_gasLimitBoundDivisor = 1024; 66 | c_minimumDifficulty = 131072; 67 | c_difficultyBoundDivisor = 2048; 68 | c_durationLimit = c_network == Network::Turbo ? 2 : c_network == Network::Olympic ? 8 : 13; 69 | c_blockReward = c_network == Network::Olympic ? (1500 * finney) : (5 * ether); 70 | return _n; 71 | } 72 | 73 | } 74 | } 75 | 76 | -------------------------------------------------------------------------------- /libethcore/Params.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file Params.h 18 | * @author Gav Wood 19 | * @date 2014 20 | */ 21 | 22 | #pragma once 23 | 24 | #include 25 | 26 | namespace dev 27 | { 28 | namespace eth 29 | { 30 | 31 | //--- BEGIN: AUTOGENERATED FROM /feeStructure.json 32 | extern u256 c_minGasLimit; 33 | extern u256 c_gasLimitBoundDivisor; 34 | extern u256 c_minimumDifficulty; 35 | extern u256 c_difficultyBoundDivisor; 36 | extern u256 c_durationLimit; 37 | extern u256 c_maximumExtraDataSize; 38 | extern u256 c_blockReward; 39 | extern u256 c_gasFloorTarget; 40 | //--- END: AUTOGENERATED FROM /feeStructure.json 41 | 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /libethcore/Sealer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file Sealer.cpp 18 | * @author Gav Wood 19 | * @date 2014 20 | */ 21 | 22 | #include "Sealer.h" 23 | using namespace std; 24 | using namespace dev; 25 | using namespace eth; 26 | 27 | -------------------------------------------------------------------------------- /libethcore/Sealer.h: -------------------------------------------------------------------------------- 1 | /* 2 | This file is part of cpp-ethereum. 3 | 4 | cpp-ethereum is free software: you can redistribute it and/or modify 5 | it under the terms of the GNU General Public License as published by 6 | the Free Software Foundation, either version 3 of the License, or 7 | (at your option) any later version. 8 | 9 | cpp-ethereum is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU General Public License for more details. 13 | 14 | You should have received a copy of the GNU General Public License 15 | along with cpp-ethereum. If not, see . 16 | */ 17 | /** @file Sealer.h 18 | * @author Gav Wood 19 | * @date 2014 20 | * 21 | * Determines the PoW algorithm. 22 | */ 23 | 24 | #pragma once 25 | 26 | #include 27 | #include 28 | #include 29 | #include "Common.h" 30 | 31 | namespace dev 32 | { 33 | namespace eth 34 | { 35 | 36 | class BlockInfo; 37 | 38 | class SealEngineFace 39 | { 40 | public: 41 | virtual ~SealEngineFace() {} 42 | 43 | virtual std::string name() const = 0; 44 | virtual unsigned revision() const = 0; 45 | virtual unsigned sealFields() const = 0; 46 | virtual bytes sealRLP() const = 0; 47 | 48 | bytes option(std::string const& _name) const { Guard l(x_options); return m_options.count(_name) ? m_options.at(_name) : bytes(); } 49 | bool setOption(std::string const& _name, bytes const& _value) { Guard l(x_options); try { if (onOptionChanging(_name, _value)) { m_options[_name] = _value; return true; } } catch (...) {} return false; } 50 | 51 | virtual strings sealers() const { return { "default" }; } 52 | virtual void setSealer(std::string const&) {} 53 | virtual void generateSeal(BlockInfo const& _bi) = 0; 54 | virtual void onSealGenerated(std::function const& _f) = 0; 55 | virtual void cancelGeneration() {} 56 | 57 | protected: 58 | virtual bool onOptionChanging(std::string const&, bytes const&) { return true; } 59 | void injectOption(std::string const& _name, bytes const& _value) { Guard l(x_options); m_options[_name] = _value; } 60 | 61 | private: 62 | mutable Mutex x_options; 63 | std::unordered_map m_options; 64 | }; 65 | 66 | template 67 | class SealEngineBase: public SealEngineFace 68 | { 69 | public: 70 | std::string name() const override { return Sealer::name(); } 71 | unsigned revision() const override { return Sealer::revision(); } 72 | unsigned sealFields() const override { return Sealer::BlockHeader::SealFields; } 73 | bytes sealRLP() const override { RLPStream s(sealFields()); s.appendRaw(typename Sealer::BlockHeader().sealFieldsRLP(), sealFields()); return s.out(); } 74 | }; 75 | 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /libstratum/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(EXECUTABLE ethstratum) 2 | 3 | aux_source_directory(. SRC_LIST) 4 | 5 | include_directories(..) 6 | include_directories(${Boost_INCLUDE_DIRS}) 7 | include_directories(${JSONCPP_INCLUDE_DIRS}) 8 | 9 | file(GLOB HEADERS "*.h") 10 | 11 | add_library(${EXECUTABLE} ${SRC_LIST} ${HEADERS}) 12 | target_link_libraries(${EXECUTABLE} ${Boost_SYSTEM_LIBRARY} ${Boost_THREAD_LIBRARY} ${Boost_REGEX_LIBRARY}) 13 | 14 | install( TARGETS ${EXECUTABLE} RUNTIME DESTINATION bin ARCHIVE DESTINATION lib LIBRARY DESTINATION lib ) 15 | install( FILES ${HEADERS} DESTINATION include/${EXECUTABLE} ) -------------------------------------------------------------------------------- /libstratum/EthStratumClient.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | This file is part of mvis-ethereum. 4 | 5 | mvis-ethereum is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | mvis-ethereum is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with mvis-ethereum. If not, see . 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include "BuildInfo.h" 29 | 30 | 31 | using namespace std; 32 | using namespace boost::asio; 33 | using boost::asio::ip::tcp; 34 | using namespace dev; 35 | using namespace dev::eth; 36 | 37 | 38 | class EthStratumClient 39 | { 40 | public: 41 | 42 | using WorkPackageFn = std::function; 43 | 44 | EthStratumClient( 45 | string const & url, 46 | int const & retries, 47 | int const & worktimeout, 48 | string const & userAcct 49 | ); 50 | ~EthStratumClient(); 51 | 52 | void restart(); 53 | bool isRunning(); 54 | bool isConnected(); 55 | void submitWork(h256 _nonce, bytes _hash, bytes _challenge, uint64_t _difficulty); 56 | void getWork(bytes& _challenge, h256& _target, uint64_t& _difficulty, string& _hashingAcct); 57 | void disconnect(); 58 | void switchAcct(string _newAcct); 59 | 60 | private: 61 | void connectStratum(); 62 | void launchIOS(); 63 | void reconnect(string msg); 64 | void readline(); 65 | void readResponse(const boost::system::error_code& ec, std::size_t bytes_transferred); 66 | void processReponse(Json::Value& responseObject); 67 | void writeStratum(Json::Value _json); 68 | void work_timeout_handler(const boost::system::error_code& ec); 69 | string streamBufToStr(boost::asio::streambuf &buff); 70 | void logJson(Json::Value _json); 71 | bool validInput(Json::Value _json); 72 | 73 | string m_url; 74 | 75 | bool m_authorized; // we're subscribed to the pool 76 | bool m_connected; // this refers to a TCP connection 77 | bool m_running; // the Boost::Asio worker thread is running & listening 78 | 79 | int m_retries = 0; 80 | int m_maxRetries; 81 | int m_worktimeout; 82 | bool m_failoverAvailable; 83 | bool m_verbose = true; 84 | 85 | boost::asio::io_service m_io_service; 86 | tcp::socket m_socket; 87 | 88 | boost::asio::streambuf m_requestBuffer; 89 | boost::asio::streambuf m_responseBuffer; 90 | 91 | boost::asio::deadline_timer * p_worktimer; 92 | boost::asio::deadline_timer * p_reconnect; 93 | 94 | int m_solutionMiner; 95 | 96 | h256 m_target; 97 | bytes m_challenge; 98 | uint64_t m_difficulty; 99 | std::string m_hashingAcct; 100 | std::string m_userAcct; 101 | std::string m_shareAcct; 102 | 103 | Mutex x_work; 104 | }; -------------------------------------------------------------------------------- /release/build.bat: -------------------------------------------------------------------------------- 1 | @ECHO OFF 2 | 3 | echo. 4 | echo. 5 | echo Did you remember to change the version number? 6 | echo. 7 | echo. 8 | pause 9 | 10 | REM the expression %~dp0 returns the drive and folder in which this batch file is located 11 | 12 | cd %~dp0 13 | 14 | 15 | "C:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" /m:3 "..\build\MVis-tokenminer.sln" /t:Build /p:Configuration=Release 16 | IF ERRORLEVEL 1 GOTO ERROR 17 | 18 | copy "..\tokenminer.ini" stage\tokenminer 19 | copy list-devices.bat stage\tokenminer 20 | copy start-mining.bat stage\tokenminer 21 | 22 | 23 | REM convert readme to html and copy to staging. see https://github.com/joeyespo/grip 24 | 25 | grip ../readme.md --export ./stage/readme.html 26 | 27 | 28 | REM Copy binaries 29 | 30 | copy "..\build\ethminer\release\tokenminer.exe" stage\tokenminer 31 | copy "..\build\ethminer\release\libcurl.dll" stage\tokenminer 32 | copy "..\build\ethminer\release\libmicrohttpd-dll.dll" stage\tokenminer 33 | copy "..\build\ethminer\release\OpenCL.dll" stage\tokenminer 34 | 35 | del *.zip 36 | powershell.exe -nologo -noprofile -command "& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::CreateFromDirectory('stage', 'mvis-tokenminer-ver-win64.zip'); }" 37 | 38 | echo. 39 | echo. 40 | echo ============================================= 41 | echo. 42 | echo. 43 | echo All Done! 44 | echo. 45 | echo. 46 | echo. 47 | echo. 48 | echo. 49 | goto OUT 50 | 51 | :ERROR 52 | 53 | echo. 54 | echo. 55 | echo ============================================= 56 | echo. 57 | echo. 58 | echo ERRORS WERE ENCOUNTERED !!! 59 | echo. 60 | echo. 61 | echo. 62 | echo. 63 | echo. 64 | 65 | :OUT 66 | pause -------------------------------------------------------------------------------- /release/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | cd ../build 4 | 5 | # compile 6 | 7 | make tokenminer 8 | 9 | if [ $? -ge 1 ] ; then 10 | echo "." 11 | echo "." 12 | echo "." 13 | echo "compilation error" 14 | echo "." 15 | echo "." 16 | echo "." 17 | exit 1 18 | fi 19 | 20 | cp libethcore/libethcore.so ../release/stage/bin 21 | cp libdevcore/libdevcore.so ../release/stage/bin 22 | cp libstratum/libethstratum.so ../release/stage/bin 23 | cp libethash-cl/libethash-cl.so ../release/stage/bin 24 | cp libethash/libethash.so ../release/stage/bin 25 | 26 | cp ethminer/tokenminer ../release/stage 27 | cp ../tokenminer.ini ../release/stage 28 | cp ../README.md ../release/stage 29 | cp ../INSTALL-LINUX ../release/stage 30 | 31 | cd ../release 32 | 33 | rm *.tar.gz 34 | tar -czf mvis-tokenminer-version-linux.tar.gz --directory=stage . 35 | 36 | if [ $? -ge 1 ] ; then 37 | echo "." 38 | echo "." 39 | echo "." 40 | echo "ERRORS WERE ENCOUNTERED!!!" 41 | echo "." 42 | echo "." 43 | echo "." 44 | exit 1 45 | fi 46 | 47 | echo "." 48 | echo "." 49 | echo "." 50 | echo "script completed successfully" 51 | echo "." 52 | echo "." 53 | echo "." 54 | -------------------------------------------------------------------------------- /release/list-devices.bat: -------------------------------------------------------------------------------- 1 | .\tokenminer.exe --list-devices -G 2 | pause 3 | -------------------------------------------------------------------------------- /release/start-mining.bat: -------------------------------------------------------------------------------- 1 | .\tokenminer.exe -G -P --opencl-platform 0 2 | pause 3 | --------------------------------------------------------------------------------