diff --git a/.gitignore b/.gitignore index 48f23ad..5e1bd14 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ build node_modules package-lock.json *.txt.user +external diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..8b7efce --- /dev/null +++ b/.npmignore @@ -0,0 +1,5 @@ +build +node_modules +package-lock.json +*.txt.user +import.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 75a74af..7a55a02 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,21 +26,17 @@ set(CLIENT_VERSION_REVISION 1) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/external/cmake) message(STATUS "-=-_-=- Building FloweeJS ${CLIENT_VERSION_MAJOR}-${CLIENT_VERSION_MINOR}.${CLIENT_VERSION_REVISION}") find_package(OpenSSL REQUIRED) message ("Using OpenSSL ${OPENSSL_VERSION}") -find_package(Qt5Core REQUIRED) - find_package(Boost 1.56.0 REQUIRED filesystem iostreams program_options system thread ) -find_package(Flowee REQUIRED) - - # Include N-API wrappers execute_process(COMMAND node -p "require('node-addon-api').include" @@ -50,9 +46,56 @@ execute_process(COMMAND node -p "require('node-addon-api').include" string(REPLACE "\n" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR}) string(REPLACE "\"" "" NODE_ADDON_API_DIR ${NODE_ADDON_API_DIR}) -include_directories(${NODE_ADDON_API_DIR} - ${CMAKE_JS_INC} + +# create config file +include(CheckSymbolExists) +find_path (HAVE_BYTESWAP_H byteswap.h) +check_symbol_exists(bswap_16 "byteswap.h" HAVE_DECL_BSWAP_16) +check_symbol_exists(bswap_32 "byteswap.h" HAVE_DECL_BSWAP_32) +check_symbol_exists(bswap_64 "byteswap.h" HAVE_DECL_BSWAP_64) +find_path (HAVE_ENDIAN_H endian.h) +find_path (HAVE_SYS_ENDIAN_H sys/endian.h) +check_symbol_exists(le16toh "endian.h" HAVE_DECL_LE16TOH) +check_symbol_exists(be16toh "endian.h" HAVE_DECL_BE16TOH) +check_symbol_exists(be32toh "endian.h" HAVE_DECL_BE32TOH) +check_symbol_exists(be64toh "endian.h" HAVE_DECL_BE64TOH) +check_symbol_exists(htobe16 "endian.h" HAVE_DECL_HTOBE16) +check_symbol_exists(htobe32 "endian.h" HAVE_DECL_HTOBE32) +check_symbol_exists(htobe64 "endian.h" HAVE_DECL_HTOBE64) +check_symbol_exists(htole16 "endian.h" HAVE_DECL_HTOLE16) +check_symbol_exists(htole32 "endian.h" HAVE_DECL_HTOLE32) +check_symbol_exists(htole64 "endian.h" HAVE_DECL_HTOLE64) +check_symbol_exists(le16toh "endian.h" HAVE_DECL_LE16TOH) +check_symbol_exists(le32toh "endian.h" HAVE_DECL_LE32TOH) +check_symbol_exists(le64toh "endian.h" HAVE_DECL_LE64TOH) + +set (WORDS_BIGENDIAN ${CMAKE_WORDS_BIGENDIAN}) +include (TestBigEndian) +test_big_endian(CMAKE_WORDS_BIGENDIAN) + +configure_file ( + "${CMAKE_SOURCE_DIR}/external/flowee-config.h.in" + ${CMAKE_BINARY_DIR}/config/flowee-config.h + @ONLY ) +add_definitions(-DHAVE_CONFIG_H) + +include_directories(${NODE_ADDON_API_DIR} + external + external/utils + external/crypto + external/interfaces + ${CMAKE_JS_INC} + ${CMAKE_BINARY_DIR} +) + +# include the flowee source files. +add_subdirectory (external) +add_subdirectory (external/crypto) + +# finally, build our plugin +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") + add_library(flowee SHARED ContextData.cpp @@ -61,11 +104,9 @@ add_library(flowee SHARED ) set_target_properties(flowee PROPERTIES PREFIX "" SUFFIX ".node") target_link_libraries(flowee - flowee_utils - flowee_apputils - flowee_networkmanager + flowee_lib + flowee_crypto ${Boost_LIBRARIES} - Qt5::Core ${CMAKE_JS_LIB} ) diff --git a/ContextData.cpp b/ContextData.cpp index 75ddd21..9e708c5 100644 --- a/ContextData.cpp +++ b/ContextData.cpp @@ -99,11 +99,9 @@ void contextData_hubConnectedCallback(Napi::Env env, Napi::Function jsCallback, } // likewise for the indexer -void contextData_IndexerConnectedCallback(Napi::Env env, Napi::Function jsCallback, Blockchain::Services *services) +void contextData_IndexerConnectedCallback(Napi::Env env, Napi::Function jsCallback, void *data) { - assert(services); - jsCallback.Call({ /*Napi::String::New(env, services )*/}); - delete services; + jsCallback.Call({ }); } Napi::Value contextData_connectIndexer(const Napi::CallbackInfo &info) @@ -176,11 +174,11 @@ void ContextData::initializeHubConnection(NetworkConnection /*connection*/, cons } } -void ContextData::initializeIndexerConnection(NetworkConnection /*connection*/, Blockchain::Services services) +void ContextData::initializeIndexerConnection(NetworkConnection /*connection*/) { if (m_onIndexerConnect.Acquire() == napi_ok) { - Blockchain::Services *s = new Blockchain::Services(services); - m_onIndexerConnect.NonBlockingCall(s, contextData_IndexerConnectedCallback); + void *data = nullptr; + m_onIndexerConnect.NonBlockingCall(data, contextData_IndexerConnectedCallback); m_onIndexerConnect.Release(); } } diff --git a/ContextData.h b/ContextData.h index 4f54032..020d03a 100644 --- a/ContextData.h +++ b/ContextData.h @@ -32,7 +32,7 @@ public: void connectIndexer(napi_env env, const std::string &hostname, int port); void initializeHubConnection(NetworkConnection connection, const std::string &hubVersion); - void initializeIndexerConnection(NetworkConnection connection, Blockchain::Services services); + void initializeIndexerConnection(NetworkConnection connection); static Napi::Value setOnConnectedHub(const Napi::CallbackInfo &info); static Napi::Value setOnConnectIndexer(const Napi::CallbackInfo &info); diff --git a/import.sh b/import.sh new file mode 100755 index 0000000..040dce9 --- /dev/null +++ b/import.sh @@ -0,0 +1,110 @@ +#!/bin/bash +cd `dirname $0` + +if test -z "$SOURCES_HUB" -o ! -d "$SOURCES_HUB" -o ! -d "$SOURCES_HUB/hub"; then + echo -e "ERROR: Please export SOURCES_HUB to the absolute path of thehub repo\n" + exit +fi + +sources=" + config/flowee-config.h.in + interfaces/NetworkEnums.h + interfaces/APIProtocol.h + apputils/Blockchain.cpp + apputils/Blockchain.h + apputils/Blockchain_p.h + networkmanager/NetworkConnection.cpp + networkmanager/NetworkConnection.h + networkmanager/NetworkEndPoint.h + networkmanager/NetworkException.cpp + networkmanager/NetworkException.h + networkmanager/NetworkManager.cpp + networkmanager/NetworkManager.h + networkmanager/NetworkManager_p.h + networkmanager/NetworkQueueFullError.cpp + networkmanager/NetworkQueueFullError.h + networkmanager/NetworkServiceBase.cpp + networkmanager/NetworkServiceBase.h + networkmanager/NetworkService.cpp + networkmanager/NetworkService.h + utils/utilstrencodings.h + utils/utilstrencodings.cpp + utils/chainparamsbase.h + utils/chainparamsbase.cpp + utils/WorkerThreads.h + utils/WorkerThreads.cpp + utils/uint256.h + utils/uint256.cpp + utils/tinyformat.h + utils/Logger.cpp + utils/Logger.h + utils/utiltime.h + utils/utiltime.cpp + utils/LogChannels.cpp + utils/LogChannels_p.h + utils/Message.cpp + utils/Message.h + utils/hash.h + utils/hash.cpp + utils/prevector.h + utils/serialize.h + utils/version.h + utils/WaitUntilFinishedHelper.h + utils/WaitUntilFinishedHelper.cpp + utils/amount.cpp + utils/amount.h + + interfaces/ + interfaces/boost_compat.h + streaming/ + utils/streaming/ConstBuffer.h + utils/streaming/ConstBuffer.cpp + utils/streaming/MessageBuilder.h + utils/streaming/MessageBuilder_p.h + utils/streaming/MessageBuilder.cpp + utils/streaming/MessageParser.h + utils/streaming/MessageParser.cpp + utils/streaming/BufferPool.h + utils/streaming/BufferPool.cpp + utils/streaming/streams.h + primitives/ + utils/primitives/FastTransaction.h + utils/primitives/FastTransaction.cpp + utils/primitives/TxIterator_p.h + utils/primitives/FastBlock.h + utils/primitives/FastBlock.cpp + utils/primitives/script.h + utils/primitives/script.cpp + utils/primitives/transaction.h + utils/primitives/transaction.cpp + utils/primitives/pubkey_utils.cpp + utils/primitives/pubkey_utils.h + utils/primitives/block.cpp + utils/primitives/block.h " + +rm -rf external +mkdir external +cat > external/CMakeLists.txt << END +cmake_minimum_required (VERSION 3.13) +project (flowee_lib) +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC") +set(CMAKE_CXX_STANDARD_REQUIRED ON) +add_library(flowee_lib STATIC +END +dir="" +for i in $sources +do + if test ! -f $SOURCES_HUB/libs/$i; then + dir=$i + mkdir -p external/$dir + else + cp $SOURCES_HUB/libs/$i external/$dir + a=`basename $i` + echo " $dir$a" >> external/CMakeLists.txt + fi +done + +echo ")" >> external/CMakeLists.txt + +cp -r $SOURCES_HUB/libs/crypto external/