├── API ├── CreditsCPlusPlusDemoCMake │ ├── CMakeLists.txt │ ├── README.md │ ├── ac.cpp │ ├── ac.h │ ├── build64.cmd │ ├── build64.sh │ ├── clean.cmd │ ├── clean.sh │ ├── client.cpp │ ├── client.h │ ├── common │ │ ├── base58.cpp │ │ ├── base58.h │ │ └── variant_aux.cpp │ ├── keys.cpp │ ├── keys.h │ ├── libsodium │ │ └── src │ │ │ └── libsodium │ │ │ └── crypto_stream │ │ │ └── chacha20 │ │ │ └── ref │ │ │ └── chacha20_ref.h │ ├── main.cpp │ ├── patches │ │ ├── msvc141_retargeting17134.patch │ │ ├── msvc141_retargeting17763.patch │ │ └── msvc142_retargeting.patch │ ├── runme.cmd │ ├── runme.sh │ └── thrift │ │ └── test │ │ └── threads │ │ └── ThreadsClient.cpp ├── CreditsCSharpDemo │ ├── Client.cs │ ├── CreditsCSAPIDemo.csproj │ ├── Keys.cs │ ├── Program.cs │ ├── Properties │ │ └── launchSettings.json │ ├── README.md │ ├── build-linux.sh │ ├── build-windows.cmd │ ├── clean.cmd │ ├── clean.sh │ ├── runme.cmd │ └── runme.sh ├── CreditsHighLevelAPI │ ├── Client │ │ ├── CMakeLists.txt │ │ ├── build64.cmd │ │ ├── build64.sh │ │ ├── clean.cmd │ │ ├── clean.sh │ │ ├── client.cpp │ │ ├── client.h │ │ ├── main.cpp │ │ ├── runme.cmd │ │ └── runme.sh │ ├── Readme.md │ ├── Server │ │ ├── CMakeLists.txt │ │ ├── ac.cpp │ │ ├── ac.h │ │ ├── build64.cmd │ │ ├── build64.sh │ │ ├── clean.cmd │ │ ├── clean.sh │ │ ├── client.cpp │ │ ├── client.h │ │ ├── common │ │ │ ├── base58.cpp │ │ │ ├── base58.h │ │ │ └── variant_aux.cpp │ │ ├── keys.cpp │ │ ├── keys.h │ │ ├── main.cpp │ │ ├── patches │ │ │ ├── msvc141_retargeting17134.patch │ │ │ ├── msvc141_retargeting17763.patch │ │ │ └── msvc142_retargeting.patch │ │ ├── runme.cmd │ │ ├── runme.sh │ │ └── server.cpp │ └── thrift │ │ └── hlapi.thrift ├── CreditsJSDemo │ ├── README.md │ ├── Util.js │ ├── base58.js │ ├── build.cmd │ ├── build.sh │ ├── clean.cmd │ ├── clean.sh │ ├── index.html │ ├── nacl.js │ └── thrift.js ├── CreditsPythonApiDemo │ ├── README.md │ ├── __init__.py │ ├── app.py │ ├── build-linux.sh │ ├── build-windows.cmd │ ├── clean.cmd │ ├── clean.sh │ ├── clientex.py │ ├── keys.py │ ├── runme.cmd │ ├── runme.sh │ └── transfer.py ├── CreditsRestApiCSharpDemo │ ├── Client.cs │ ├── Controllers │ │ └── CreditsController.cs │ ├── CreditsRestApiCSharpDemo.csproj │ ├── CreditsRestApiCSharpDemo.csproj.user │ ├── Keys.cs │ ├── Program.cs │ ├── Properties │ │ └── launchSettings.json │ ├── Readme.md │ ├── Startup.cs │ ├── appsettings.Development.json │ ├── appsettings.json │ ├── build-linux.sh │ ├── build-windows.cmd │ ├── clean.cmd │ ├── clean.sh │ ├── runme.cmd │ └── runme.sh ├── Readme.md └── capi │ ├── .gitignore │ ├── .mvn │ └── wrapper │ │ ├── MavenWrapperDownloader.java │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── credits │ │ │ ├── DemoApplication.java │ │ │ ├── model │ │ │ ├── DataResponseApiModel.java │ │ │ ├── RequestApiModel.java │ │ │ └── ResponseApiModel.java │ │ │ ├── rest │ │ │ └── CreditsRestController.java │ │ │ └── utils │ │ │ ├── Base58.java │ │ │ ├── ConverterException.java │ │ │ ├── CreditsException.java │ │ │ ├── CryptoException.java │ │ │ └── Ed25519.java │ └── resources │ │ └── application.properties │ └── test │ └── java │ └── com │ └── credits │ └── DemoApplicationTests.java ├── Docker ├── Readme.md ├── credits_docker_mainnet │ ├── Dockerfile │ ├── Readme.md │ ├── build.sh │ ├── clean.sh │ ├── common │ │ ├── clean_main_db.sh │ │ ├── clean_main_keys.sh │ │ └── run.sh │ ├── run.sh │ └── source │ │ └── runner.cpp └── credits_docker_testnet │ ├── Dockerfile │ ├── Readme.md │ ├── build.sh │ ├── clean.sh │ ├── common │ ├── clean_test_db.sh │ ├── clean_test_keys.sh │ └── run.sh │ ├── run.sh │ └── source │ └── runner.cpp ├── README.md ├── SmartContracts ├── Readme.md ├── Smart-kontrakt_Birzhevoj_aukcion.java └── sm_tracking the movement │ ├── Readme.md │ └── sm_tracking the movement.java └── Utils ├── Readme.md ├── cr-dev-book-windows ├── Readme.md ├── index.js └── package.json ├── cr-monitor-windows ├── Readme.md ├── index.js └── package.json └── cr-web-wallet-windows ├── Readme.md ├── index.js └── package.json /API/CreditsCPlusPlusDemoCMake/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5 FATAL_ERROR) 2 | 3 | set(CMAKE_CXX_STANDARD 17) 4 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 5 | set(libsodium_dir ${CMAKE_CURRENT_SOURCE_DIR}/libsodium/) 6 | 7 | if(WIN32) 8 | if(${MSVC_TOOLSET_VERSION} MATCHES 142 OR NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.20) 9 | set(libsodium_patch ${libsodium_dir}/../patches/msvc142_retargeting.patch) 10 | else() 11 | if(${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION} MATCHES 10.0.17763.0) 12 | set(libsodium_patch ${libsodium_dir}/../patches/msvc141_retargeting17763.patch) 13 | else() 14 | set(libsodium_patch ${libsodium_dir}/../patches/msvc141_retargeting17134.patch) 15 | endif() 16 | endif() 17 | 18 | execute_process(COMMAND git apply --ignore-space-change ${libsodium_patch} 19 | WORKING_DIRECTORY ${libsodium_dir}) 20 | 21 | if(CMAKE_BUILD_TYPE MATCHES Debug) 22 | set(msbuild_property "/p:Configuration=Debug") 23 | else() 24 | set(msbuild_property "/p:Configuration=Release") 25 | endif() 26 | 27 | set(msbuild_parallel "/m") 28 | set(msbuild_platform "/p:platform=x64") 29 | set(proj_to_build "libsodium.sln") 30 | set(disable_post_build "/p:PostBuildEventUseInBuild=false") 31 | 32 | execute_process(COMMAND ${CMAKE_VS_MSBUILD_COMMAND} ${msbuild_parallel} ${proj_to_build} ${msbuild_property} ${msbuild_platform} ${disable_post_build} 33 | WORKING_DIRECTORY ${libsodium_dir}) 34 | 35 | execute_process(COMMAND git apply --ignore-space-change ${libsodium_patch} -R 36 | WORKING_DIRECTORY ${libsodium_dir}) 37 | 38 | set(lb_lib_folder .) 39 | else() 40 | 41 | if(CMAKE_BUILD_TYPE MATCHES Debug) 42 | set(libsodium_lib_dir ${libsodium_dir}/Build/Debug/x64/) 43 | else() 44 | set(libsodium_lib_dir ${libsodium_dir}/Build/Release/x64/) 45 | endif() 46 | 47 | if(EXISTS ${libsodium_lib_dir}/lib/libsodium${CMAKE_STATIC_LIBRARY_SUFFIX}) 48 | message(STATUS "Libsodium lib has already been built") 49 | else() 50 | execute_process(COMMAND bash ./autogen.sh 51 | WORKING_DIRECTORY ${libsodium_dir}) 52 | execute_process(COMMAND ./configure --prefix=${libsodium_lib_dir} 53 | WORKING_DIRECTORY ${libsodium_dir}) 54 | execute_process(COMMAND make 55 | WORKING_DIRECTORY ${libsodium_dir}) 56 | execute_process(COMMAND make check 57 | WORKING_DIRECTORY ${libsodium_dir}) 58 | execute_process(COMMAND make install 59 | WORKING_DIRECTORY ${libsodium_dir}) 60 | endif() 61 | 62 | set(lb_lib_folder lib) 63 | endif() 64 | 65 | add_library(libsodium STATIC IMPORTED GLOBAL) 66 | set_property(TARGET libsodium PROPERTY IMPORTED_LOCATION_RELEASE 67 | ${libsodium_dir}/Build/Release/x64/${lb_lib_folder}/libsodium${CMAKE_STATIC_LIBRARY_SUFFIX}) 68 | set_property(TARGET libsodium PROPERTY IMPORTED_LOCATION_RELWITHDEBINFO 69 | ${libsodium_dir}/Build/Release/x64/${lb_lib_folder}/libsodium${CMAKE_STATIC_LIBRARY_SUFFIX}) 70 | set_property(TARGET libsodium PROPERTY IMPORTED_LOCATION_DEBUG 71 | ${libsodium_dir}/Build/Debug/x64/${lb_lib_folder}/libsodium${CMAKE_STATIC_LIBRARY_SUFFIX}) 72 | 73 | set_property(TARGET libsodium PROPERTY IMPORTED_LOCATION_RELSPAM 74 | ${libsodium_dir}/Build/Release/x64/${lb_lib_folder}/libsodium${CMAKE_STATIC_LIBRARY_SUFFIX}) 75 | set_property(TARGET libsodium PROPERTY IMPORTED_LOCATION_RELMONITOR 76 | ${libsodium_dir}/Build/Release/x64/${lb_lib_folder}/libsodium${CMAKE_STATIC_LIBRARY_SUFFIX}) 77 | set_property(TARGET libsodium PROPERTY IMPORTED_LOCATION_RELWALLET 78 | ${libsodium_dir}/Build/Release/x64/${lb_lib_folder}/libsodium${CMAKE_STATIC_LIBRARY_SUFFIX}) 79 | 80 | if (MSVC) 81 | add_definitions(-DNOMINMAX) 82 | endif() 83 | 84 | add_definitions(-DUSE_STD_THREAD) 85 | if (MSVC) 86 | option(BUILD_COMPILER "" OFF) 87 | endif(MSVC) 88 | option(WITH_BOOST_STATIC "" ON) 89 | option(BUILD_TESTING "" OFF) 90 | option(BUILD_TUTORIALS "" OFF) 91 | option(BUILD_EXAMPLES "" OFF) 92 | option(BUILD_PYTHON "" OFF) 93 | option(WITH_SHARED_LIB "" OFF) 94 | option(WITH_STATIC_LIB "" ON) 95 | option(WITH_C_GLIB "" OFF) 96 | option(WITH_JAVA "" OFF) 97 | option(WITH_PYTHON "" OFF) 98 | option(WITH_QT4 "" OFF) 99 | option(WITH_QT5 "" OFF) 100 | option(WITH_ZLIB "" OFF) 101 | option(WITH_STDTHREADS "" ON) 102 | option(WITH_LIBEVENT "" OFF) 103 | option(WITH_OPENSSL "" OFF) 104 | add_subdirectory(thrift) 105 | add_subdirectory(blake2) 106 | 107 | find_package(Boost 1.68 REQUIRED) 108 | 109 | include_directories(${Boost_INCLUDE_DIRS}) 110 | include_directories("./thrift/lib/cpp/src") 111 | include_directories("./libsodium/src/libsodium/include") 112 | include_directories("./blake2/sse") 113 | 114 | add_executable(main 115 | ./api/api_constants.h 116 | ./api/api_types.h 117 | ./api/API.h 118 | ./common/base58.h 119 | ./api/general_constants.h 120 | ./api/general_types.h 121 | client.h 122 | keys.h 123 | ac.h 124 | ./api/api_constants.cpp 125 | ./api/api_types.cpp 126 | ./api/API.cpp 127 | ./common/base58.cpp 128 | ./api/general_constants.cpp 129 | ./api/general_types.cpp 130 | ./common/variant_aux.cpp 131 | client.cpp 132 | keys.cpp 133 | ac.cpp 134 | main.cpp 135 | ) 136 | 137 | target_link_libraries(main ${Boost_LIBRARIES}) 138 | target_link_libraries(main blake2 libsodium) 139 | target_compile_definitions(main PUBLIC SODIUM_STATIC) 140 | target_link_libraries(main thrift_static) 141 | -------------------------------------------------------------------------------- /API/CreditsCPlusPlusDemoCMake/README.md: -------------------------------------------------------------------------------- 1 | ## CreditsCPlusPlusDemoCMake 2 | https://developers.credits.com/en/Articles/a_Using_Credits_API_in_C_(demo)_Cmake_Cross_platform 3 | 4 | A simple console C++ (CMake) application
5 | Using the public key of the wallet displays the balance. 6 | 7 | ## Requirements 8 | Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
9 | https://git-scm.com/ 10 | 11 | Boost is a set of libraries for the C++ programming language that provide support for tasks and structures such as linear algebra, pseudorandom number generation, multithreading, image processing, regular expressions, and unit testing. It contains over eighty individual libraries.
12 | https://www.boost.org/ 13 | 14 | CMake is an open-source, cross-platform family of tools designed to build, test and package software. CMake is used to control the software compilation process using simple platform and compiler independent configuration files, and generate native makefiles and workspaces that can be used in the compiler environment of your choice. The suite of CMake tools were created by Kitware in response to the need for a powerful, cross-platform build environment for open-source projects such as ITK and VTK.
15 | https://cmake.org/ 16 | 17 | The Apache Thrift software framework, for scalable cross-language services development, combines a software stack with a code generation engine to build services that work efficiently and seamlessly between C++, Java, Python, PHP, Ruby, Erlang, Perl, Haskell, C#, Cocoa, JavaScript, Node.js, Smalltalk, OCaml and Delphi and other languages.
18 | https://thrift.apache.org/ 19 | 20 | ## Transaction field(Length in bytes) 21 | Id (6 bytes)
22 | Source (32 bytes)
23 | Target (32 bytes)
24 | Amount.Integral (4 bytes)
25 | Amount.Fraction (8 bytes)
26 | Fee.Commission (2 bytes)
27 | Currency (1 bytes)
28 | 29 | ## Concern 30 | It is necessary to convert commission value from double to short. For example: 31 | 32 | ```shell 33 | // commission 34 | transaction.Fee = new AmountCommission(Fee(0.9)); 35 | 36 | short Fee(double value) 37 | { 38 | byte sign = (byte)(value < 0.0 ? 1 : 0); // sign 39 | int exp; // exponent 40 | long frac; // mantissa 41 | value = abs(value); 42 | double expf = value == 0.0 ? 0.0 : log10(value); 43 | int expi = int(expf >= 0 ? expf + 0.5 : expf - 0.5); 44 | value /= pow(10, expi); 45 | if (value >= 1.0) 46 | { 47 | value *= 0.1; 48 | ++expi; 49 | } 50 | exp = expi + 18; 51 | if (exp < 0 || exp > 28) 52 | { 53 | throw "exponent value exp out of range [0, 28]"; 54 | } 55 | frac = (long)round(value * 1024); 56 | return (short)(sign * 32768 + exp * 1024 + frac); 57 | } 58 | ``` 59 | 60 | ## Using: 61 | ### Build for Windows 62 | ```shell 63 | build64.cmd 64 | ``` 65 | 66 | ### The content of build64.cmd 67 | ```shell 68 | rmdir /S /Q build64 69 | rmdir /S /Q thrift-interface-definitions 70 | rmdir /S /Q thrift 71 | rmdir /S /Q api 72 | rmdir /S /Q libsodium 73 | 74 | git clone https://github.com/jedisct1/libsodium.git 75 | 76 | git clone https://github.com/CREDITSCOM/thrift-interface-definitions 77 | mkdir api 78 | thrift -r -gen cpp:no_skeleton,pure_enums,moveable_types -out .\api .\thrift-interface-definitions\api.thrift 79 | 80 | git clone https://github.com/CREDITSCOM/thrift 81 | cd thrift 82 | 83 | cd .. 84 | mkdir build64 85 | cd build64 86 | 87 | REM !!! change the BOOST place of this part of string, for example: -DBOOST_ROOT=d:\boost 88 | REM cmake .. -DBOOST_ROOT=d:\boost -DCMAKE_BUILD_TYPE=Debug -A x64 .. 89 | REM cmake --build . --config Debug 90 | 91 | REM !!! change the BOOST place of this part of string, for example: -DBOOST_ROOT=d:\boost 92 | cmake -DBOOST_ROOT=d:\boost -DCMAKE_BUILD_TYPE=Release -A x64 .. 93 | cmake --build . --config Release 94 | 95 | pause 96 | ``` 97 | 98 | ### Run 99 | ```shell 100 | run.cmd 101 | ``` 102 | 103 | ### The content of run.cmd 104 | ```shell 105 | .\build64\release\main.exe 106 | pause 107 | ``` 108 | 109 | ### Build for Linux: 110 | ```shell 111 | ./build64.sh 112 | ``` 113 | 114 | ### The content of build64.sh 115 | ```shell 116 | rm -r -f build64 117 | rm -r -f thrift-interface-definitions 118 | rm -r -f thrift 119 | rm -r -f api 120 | 121 | git clone https://github.com/jedisct1/libsodium.git 122 | 123 | git clone https://github.com/CREDITSCOM/thrift-interface-definitions 124 | mkdir api 125 | thrift -r -gen cpp:no_skeleton,pure_enums,moveable_types -out ./api ./thrift-interface-definitions/api.thrift 126 | 127 | git clone https://github.com/CREDITSCOM/thrift 128 | cd thrift 129 | 130 | cd .. 131 | mkdir build64 132 | cd build64 133 | 134 | cmake --build . --config Debug 135 | cmake --build . --config Release 136 | ``` 137 | 138 | ### Run 139 | ```shell 140 | ./runme.sh 141 | ``` 142 | 143 | ### The content of run.sh 144 | ```shell 145 | ./build64/main 146 | ``` 147 | -------------------------------------------------------------------------------- /API/CreditsCPlusPlusDemoCMake/ac.cpp: -------------------------------------------------------------------------------- 1 | #include "ac.h" 2 | #include 3 | #include "common/base58.h" 4 | #include "api/API.h" 5 | 6 | general::Address ac::address(const char* sa) 7 | { 8 | std::vector evec; 9 | DecodeBase58(sa, evec); 10 | //std::string dst(evec.size(), 0); 11 | //memcpy((void*)dst.c_str(), &(evec[0]), evec.size()); 12 | std::string dst(evec.begin(), evec.end()); 13 | return dst; 14 | } 15 | -------------------------------------------------------------------------------- /API/CreditsCPlusPlusDemoCMake/ac.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "api/API.h" 4 | 5 | class ac 6 | { 7 | public: 8 | static general::Address address(const char* sa); 9 | }; 10 | 11 | -------------------------------------------------------------------------------- /API/CreditsCPlusPlusDemoCMake/build64.cmd: -------------------------------------------------------------------------------- 1 | rmdir /S /Q build64 2 | rmdir /S /Q thrift-interface-definitions 3 | rmdir /S /Q thrift 4 | rmdir /S /Q api 5 | rmdir /S /Q libsodium 6 | rmdir /S /Q blake2 7 | 8 | git clone https://github.com/jedisct1/libsodium.git 9 | git clone https://github.com/CREDITSCOM/blake2.git 10 | 11 | git clone https://github.com/CREDITSCOM/thrift-interface-definitions 12 | mkdir api 13 | thrift -r -gen cpp:no_skeleton,pure_enums,moveable_types -out .\api .\thrift-interface-definitions\api.thrift 14 | 15 | git clone https://github.com/CREDITSCOM/thrift 16 | cd thrift 17 | 18 | cd .. 19 | mkdir build64 20 | cd build64 21 | 22 | cmake .. -DBOOST_ROOT=d:\boost -DCMAKE_BUILD_TYPE=Debug -A x64 .. 23 | cmake --build . --config Debug 24 | 25 | rem cmake -DBOOST_ROOT=d:\boost -DCMAKE_BUILD_TYPE=Release -A x64 .. 26 | rem cmake --build . --config Release 27 | 28 | pause -------------------------------------------------------------------------------- /API/CreditsCPlusPlusDemoCMake/build64.sh: -------------------------------------------------------------------------------- 1 | rm -r -f build64 2 | rm -r -f thrift-interface-definitions 3 | rm -r -f thrift 4 | rm -r -f api 5 | rm -r -f blake2 6 | 7 | git clone https://github.com/jedisct1/libsodium.git 8 | git clone https://github.com/CREDITSCOM/blake2.git 9 | 10 | git clone https://github.com/jedisct1/libsodium.git 11 | 12 | git clone https://github.com/CREDITSCOM/thrift-interface-definitions 13 | mkdir api 14 | thrift -r -gen cpp:no_skeleton,pure_enums,moveable_types -out ./api ./thrift-interface-definitions/api.thrift 15 | 16 | git clone https://github.com/CREDITSCOM/thrift 17 | cd thrift 18 | 19 | cd .. 20 | mkdir build64 21 | cd build64 22 | 23 | cmake .. 24 | cmake --build . --config Debug 25 | cmake --build . --config Release 26 | 27 | cmake .. -DCMAKE_BUILD_TYPE=Debug -A x64 .. 28 | cmake --build . --config Debug 29 | 30 | # cmake -DCMAKE_BUILD_TYPE=Release -A x64 .. 31 | # cmake --build . --config Release 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /API/CreditsCPlusPlusDemoCMake/clean.cmd: -------------------------------------------------------------------------------- 1 | rmdir /S /Q build64 2 | rmdir /S /Q thrift-interface-definitions 3 | rmdir /S /Q thrift 4 | rmdir /S /Q api 5 | rmdir /S /Q libsodium 6 | rmdir /S /Q blake2 7 | -------------------------------------------------------------------------------- /API/CreditsCPlusPlusDemoCMake/clean.sh: -------------------------------------------------------------------------------- 1 | rm -r -f build64 2 | rm -r -f thrift-interface-definitions 3 | rm -r -f thrift 4 | rm -r -f api 5 | rm -r -f blake2 6 | -------------------------------------------------------------------------------- /API/CreditsCPlusPlusDemoCMake/client.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "api/API.h" 15 | #include "keys.h" 16 | 17 | #define SIGNATURE_LEN 64 18 | 19 | class client 20 | { 21 | private: 22 | std::shared_ptr m_socket; 23 | std::shared_ptr m_transport; 24 | std::shared_ptr m_protocol; 25 | std::shared_ptr m_api; 26 | 27 | std::unique_ptr m_keys; 28 | 29 | void connect(); 30 | void disconnect(); 31 | short fee(double value); 32 | std::unique_ptr make_transaction_with_smart_contract(std::string code, double fee_value); 33 | std::unique_ptr make_transaction(int32_t integral, int32_t fraction, double fee_value); 34 | template 35 | void cp(std::vector& arr, T& value, int16_t size, bool reverse); 36 | 37 | void get_transaction(); 38 | 39 | public: 40 | client(std::string ip, int port); 41 | ~client(); 42 | 43 | void set_keys(const std::string& publicKey, const std::string& privateKey, const std::string& targetKey); 44 | 45 | void wallet_balance_get(); 46 | void transfer_coins(int32_t integral, int32_t fraction, double fee_value); 47 | void deploy_smart(std::string code, double fee_value); 48 | }; 49 | 50 | -------------------------------------------------------------------------------- /API/CreditsCPlusPlusDemoCMake/common/base58.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2017 The Bitcoin Core developers 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include "base58.h" 6 | 7 | #include 8 | #include 9 | 10 | /** All alphanumeric characters except for "0", "I", "O", and "l" */ 11 | static const char* pszBase58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; 12 | static const int8_t mapBase58[256] = { 13 | -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, 14 | -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, 15 | -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, 16 | -1, 0, 1, 2, 3, 4, 5, 6, 7, 8,-1,-1,-1,-1,-1,-1, 17 | -1, 9,10,11,12,13,14,15, 16,-1,17,18,19,20,21,-1, 18 | 22,23,24,25,26,27,28,29, 30,31,32,-1,-1,-1,-1,-1, 19 | -1,33,34,35,36,37,38,39, 40,41,42,43,-1,44,45,46, 20 | 47,48,49,50,51,52,53,54, 55,56,57,-1,-1,-1,-1,-1, 21 | -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, 22 | -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, 23 | -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, 24 | -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, 25 | -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, 26 | -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, 27 | -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, 28 | -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, 29 | }; 30 | 31 | bool DecodeBase58(const char* psz, std::vector& vch) 32 | { 33 | // Skip leading spaces. 34 | while (*psz && isspace(*psz)) 35 | psz++; 36 | // Skip and count leading '1's. 37 | int zeroes = 0; 38 | int length = 0; 39 | while (*psz == '1') { 40 | zeroes++; 41 | psz++; 42 | } 43 | // Allocate enough space in big-endian base256 representation. 44 | int size = strlen(psz) * 733 / 1000 + 1; // log(58) / log(256), rounded up. 45 | std::vector b256(size); 46 | // Process the characters. 47 | static_assert(sizeof(mapBase58) / sizeof(mapBase58[0]) == 256, "mapBase58.size() should be 256"); // guarantee not out of range 48 | while (*psz && !isspace(*psz)) { 49 | // Decode base58 character 50 | int carry = mapBase58[(uint8_t)*psz]; 51 | if (carry == -1) // Invalid b58 character 52 | return false; 53 | int i = 0; 54 | for (std::vector::reverse_iterator it = b256.rbegin(); (carry != 0 || i < length) && (it != b256.rend()); ++it, ++i) { 55 | carry += 58 * (*it); 56 | *it = carry % 256; 57 | carry /= 256; 58 | } 59 | assert(carry == 0); 60 | length = i; 61 | psz++; 62 | } 63 | // Skip trailing spaces. 64 | while (isspace(*psz)) 65 | psz++; 66 | if (*psz != 0) 67 | return false; 68 | // Skip leading zeroes in b256. 69 | std::vector::iterator it = b256.begin() + (size - length); 70 | while (it != b256.end() && *it == 0) 71 | it++; 72 | // Copy result into output vector. 73 | vch.reserve(zeroes + (b256.end() - it)); 74 | vch.assign(zeroes, 0x00); 75 | while (it != b256.end()) 76 | vch.push_back(*(it++)); 77 | return true; 78 | } 79 | 80 | std::string EncodeBase58(const unsigned char* pbegin, const unsigned char* pend) 81 | { 82 | // Skip & count leading zeroes. 83 | int zeroes = 0; 84 | int length = 0; 85 | while (pbegin != pend && *pbegin == 0) { 86 | pbegin++; 87 | zeroes++; 88 | } 89 | // Allocate enough space in big-endian base58 representation. 90 | int size = (pend - pbegin) * 138 / 100 + 1; // log(256) / log(58), rounded up. 91 | std::vector b58(size); 92 | // Process the bytes. 93 | while (pbegin != pend) { 94 | int carry = *pbegin; 95 | int i = 0; 96 | // Apply "b58 = b58 * 256 + ch". 97 | for (std::vector::reverse_iterator it = b58.rbegin(); (carry != 0 || i < length) && (it != b58.rend()); it++, i++) { 98 | carry += 256 * (*it); 99 | *it = carry % 58; 100 | carry /= 58; 101 | } 102 | 103 | assert(carry == 0); 104 | length = i; 105 | pbegin++; 106 | } 107 | // Skip leading zeroes in base58 result. 108 | std::vector::iterator it = b58.begin() + (size - length); 109 | while (it != b58.end() && *it == 0) 110 | it++; 111 | // Translate the result into a string. 112 | std::string str; 113 | str.reserve(zeroes + (b58.end() - it)); 114 | str.assign(zeroes, '1'); 115 | while (it != b58.end()) 116 | str += pszBase58[*(it++)]; 117 | return str; 118 | } 119 | 120 | std::string EncodeBase58(const std::vector& vch) 121 | { 122 | return EncodeBase58(vch.data(), vch.data() + vch.size()); 123 | } 124 | 125 | bool DecodeBase58(const std::string& str, std::vector& vchRet) 126 | { 127 | return DecodeBase58(str.c_str(), vchRet); 128 | } -------------------------------------------------------------------------------- /API/CreditsCPlusPlusDemoCMake/common/base58.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2009-2010 Satoshi Nakamoto 2 | // Copyright (c) 2009-2017 The Bitcoin Core developers 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 | * Why base-58 instead of standard base-64 encoding? 8 | * - Don't want 0OIl characters that look the same in some fonts and 9 | * could be used to create visually identical looking data. 10 | * - A string with non-alphanumeric characters is not as easily accepted as input. 11 | * - E-mail usually won't line-break if there's no punctuation to break at. 12 | * - Double-clicking selects the whole string as one word if it's all alphanumeric. 13 | */ 14 | #ifndef BITCOIN_BASE58_H 15 | #define BITCOIN_BASE58_H 16 | 17 | #include 18 | #include 19 | 20 | /** 21 | * Encode a byte sequence as a base58-encoded string. 22 | * pbegin and pend cannot be nullptr, unless both are. 23 | */ 24 | std::string EncodeBase58(const unsigned char* pbegin, const unsigned char* pend); 25 | 26 | /** 27 | * Encode a byte vector as a base58-encoded string 28 | */ 29 | std::string EncodeBase58(const std::vector& vch); 30 | 31 | /** 32 | * Decode a base58-encoded string (psz) into a byte vector (vchRet). 33 | * return true if decoding is successful. 34 | * psz cannot be nullptr. 35 | */ 36 | bool DecodeBase58(const char* psz, std::vector& vchRet); 37 | 38 | /** 39 | * Decode a base58-encoded string (str) into a byte vector (vchRet). 40 | * return true if decoding is successful. 41 | */ 42 | bool DecodeBase58(const std::string& str, std::vector& vchRet); 43 | 44 | #endif // BITCOIN_BASE58_H 45 | -------------------------------------------------------------------------------- /API/CreditsCPlusPlusDemoCMake/common/variant_aux.cpp: -------------------------------------------------------------------------------- 1 | #include "../api/general_types.h" 2 | #include 3 | 4 | namespace general { 5 | 6 | bool operator<(const _Variant__isset& a, const _Variant__isset& b) { 7 | auto ta = std::tie(a.v_boolean, a.v_double, a.v_short, a.v_int, a.v_long, a.v_byte, a.v_list, a.v_map, a.v_set, a.v_string); 8 | decltype(ta) tb = 9 | std::tie(b.v_boolean, b.v_double, b.v_short, b.v_int, b.v_long, b.v_byte, b.v_list, b.v_map, b.v_set, b.v_string); 10 | return ta < tb; 11 | } 12 | 13 | bool Variant::operator<(const Variant& that) const { 14 | const Variant &a = *this, &b = that; 15 | if (a.__isset < b.__isset) { 16 | return true; 17 | } 18 | if (b.__isset < a.__isset) { 19 | return false; 20 | } 21 | if (a.__isset.v_boolean) { 22 | return a.v_boolean < b.v_boolean; 23 | } 24 | if (a.__isset.v_double) { 25 | return a.v_double < b.v_double; 26 | } 27 | if (a.__isset.v_short) { 28 | return a.v_short < b.v_short; 29 | } 30 | if (a.__isset.v_int) { 31 | return a.v_int < b.v_int; 32 | } 33 | if (a.__isset.v_long) { 34 | return a.v_long < b.v_long; 35 | } 36 | if (a.__isset.v_byte) { 37 | return a.v_byte < b.v_byte; 38 | } 39 | if (a.__isset.v_string) { 40 | return a.v_string < b.v_string; 41 | } 42 | if (a.__isset.v_list) { 43 | return std::lexicographical_compare(a.v_list.begin(), a.v_list.end(), b.v_list.begin(), b.v_list.end()); 44 | } 45 | if (a.__isset.v_set) { 46 | return std::lexicographical_compare(a.v_set.begin(), a.v_set.end(), b.v_set.begin(), b.v_set.end()); 47 | } 48 | if (a.__isset.v_map) { 49 | return std::lexicographical_compare(a.v_map.begin(), a.v_map.end(), b.v_map.begin(), b.v_map.end()); 50 | } 51 | assert(false); 52 | return false; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /API/CreditsCPlusPlusDemoCMake/keys.cpp: -------------------------------------------------------------------------------- 1 | #include "ac.h" 2 | #include "keys.h" 3 | #include "common/base58.h" 4 | 5 | keys::keys(const char* publicKey, const char* privateKey, const char* targetPublicKey) 6 | { 7 | m_publicKeyAddress = ac::address(publicKey); 8 | m_privateKeyAddress = ac::address(privateKey); 9 | m_targetPublicKeyAddress = ac::address(targetPublicKey); 10 | } 11 | 12 | const general::Address& keys::PublicKeyAddress() 13 | { 14 | return m_publicKeyAddress; 15 | } 16 | 17 | const general::Address& keys::PrivateKeyAddress() 18 | { 19 | return m_privateKeyAddress; 20 | } 21 | 22 | const general::Address& keys::TargetPublicKeyAddress() 23 | { 24 | return m_targetPublicKeyAddress; 25 | } 26 | -------------------------------------------------------------------------------- /API/CreditsCPlusPlusDemoCMake/keys.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "api/API.h" 4 | 5 | class keys 6 | { 7 | general::Address m_publicKeyAddress; 8 | general::Address m_privateKeyAddress; 9 | general::Address m_targetPublicKeyAddress; 10 | 11 | public: 12 | keys(const char* publicKey, const char* privateKey, const char* targetPublicKey); 13 | 14 | const char* PublicKey(); 15 | const char* PrivateKey(); 16 | const char* TargetPublicKey(); 17 | const general::Address& PublicKeyAddress(); 18 | const general::Address& PrivateKeyAddress(); 19 | const general::Address& TargetPublicKeyAddress(); 20 | }; 21 | 22 | -------------------------------------------------------------------------------- /API/CreditsCPlusPlusDemoCMake/libsodium/src/libsodium/crypto_stream/chacha20/ref/chacha20_ref.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | 4 | #include "../stream_chacha20.h" 5 | #include "crypto_stream_chacha20.h" 6 | 7 | extern struct crypto_stream_chacha20_implementation 8 | crypto_stream_chacha20_ref_implementation; 9 | -------------------------------------------------------------------------------- /API/CreditsCPlusPlusDemoCMake/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "api/API.h" 15 | #include "keys.h" 16 | #include "client.h" 17 | 18 | using namespace std; 19 | using namespace apache::thrift::transport; 20 | using namespace apache::thrift::protocol; 21 | using namespace api; 22 | using namespace general; 23 | 24 | int main(int argc, char* argv[]) 25 | { 26 | if (argc != 6) 27 | { 28 | cout << "Usage: main.exe NodeIpAddress NodePort YourPublicKey YourPrivateKey TargetPublicKey" << std::endl; 29 | return 1; 30 | } 31 | 32 | auto c = make_unique(argv[1], atoi(argv[2])); 33 | c->set_keys(argv[3], argv[4], argv[5]); 34 | 35 | cout << " ****** Credits API Demo C++ ******" << endl; 36 | 37 | cout << "****** Wallet Get Balance ******" << endl; 38 | c->wallet_balance_get(); 39 | cout << endl << " ****** End ******" << endl << endl; 40 | 41 | cout << "****** Transfer Coins ******" << endl; 42 | c->transfer_coins(1, 0, 0.9); 43 | cout << endl << " ****** End ******" << endl << endl; 44 | 45 | cout << endl << "****** Deploy Smart Contract ******" << endl; 46 | c->deploy_smart("", 1); 47 | cout << endl << " ****** End ******" << endl << endl; 48 | } 49 | 50 | -------------------------------------------------------------------------------- /API/CreditsCPlusPlusDemoCMake/patches/msvc141_retargeting17134.patch: -------------------------------------------------------------------------------- 1 | diff --git a/libsodium.vcxproj b/libsodium.vcxproj 2 | index eec2a525..62f1ffe1 100644 3 | --- a/libsodium.vcxproj 4 | +++ b/libsodium.vcxproj 5 | @@ -1,5 +1,5 @@ 6 |  7 | - 8 | + 9 | 10 | 11 | DebugDLL 12 | @@ -38,6 +38,7 @@ 13 | {A185B162-6CB6-4502-B03F-B56F7699A8D9} 14 | Win32Proj 15 | libsodium 16 | + 10.0.17134.0 17 | 18 | 19 | 20 | @@ -45,56 +46,56 @@ 21 | true 22 | MultiByte 23 | false 24 | - v140 25 | + v141 26 | 27 | 28 | DynamicLibrary 29 | true 30 | MultiByte 31 | false 32 | - v140 33 | + v141 34 | 35 | 36 | StaticLibrary 37 | true 38 | MultiByte 39 | false 40 | - v140 41 | + v141 42 | 43 | 44 | DynamicLibrary 45 | true 46 | MultiByte 47 | false 48 | - v140 49 | + v141 50 | 51 | 52 | StaticLibrary 53 | false 54 | true 55 | MultiByte 56 | - v140 57 | + v141 58 | 59 | 60 | DynamicLibrary 61 | false 62 | true 63 | MultiByte 64 | - v140 65 | + v141 66 | 67 | 68 | StaticLibrary 69 | false 70 | true 71 | MultiByte 72 | - v140 73 | + v141 74 | 75 | 76 | DynamicLibrary 77 | false 78 | true 79 | MultiByte 80 | - v140 81 | + v141 82 | 83 | 84 | 85 | @@ -559,4 +560,4 @@ 86 | 87 | 88 | 89 | - 90 | + 91 | \ No newline at end of file 92 | diff --git a/libsodium.vcxproj.filters b/libsodium.vcxproj.filters 93 | index 8325e43c..d43187c1 100644 94 | --- a/libsodium.vcxproj.filters 95 | +++ b/libsodium.vcxproj.filters 96 | @@ -716,5 +716,13 @@ 97 | 98 | Header Files 99 | 100 | + 101 | + Header Files 102 | + 103 | + 104 | + 105 | + 106 | + Resource Files 107 | + 108 | 109 | - 110 | + 111 | \ No newline at end of file 112 | -------------------------------------------------------------------------------- /API/CreditsCPlusPlusDemoCMake/patches/msvc141_retargeting17763.patch: -------------------------------------------------------------------------------- 1 | diff --git a/libsodium.vcxproj b/libsodium.vcxproj 2 | index eec2a525..62f1ffe1 100644 3 | --- a/libsodium.vcxproj 4 | +++ b/libsodium.vcxproj 5 | @@ -1,5 +1,5 @@ 6 |  7 | - 8 | + 9 | 10 | 11 | DebugDLL 12 | @@ -38,6 +38,7 @@ 13 | {A185B162-6CB6-4502-B03F-B56F7699A8D9} 14 | Win32Proj 15 | libsodium 16 | + 10.0.17763.0 17 | 18 | 19 | 20 | @@ -45,56 +46,56 @@ 21 | true 22 | MultiByte 23 | false 24 | - v140 25 | + v141 26 | 27 | 28 | DynamicLibrary 29 | true 30 | MultiByte 31 | false 32 | - v140 33 | + v141 34 | 35 | 36 | StaticLibrary 37 | true 38 | MultiByte 39 | false 40 | - v140 41 | + v141 42 | 43 | 44 | DynamicLibrary 45 | true 46 | MultiByte 47 | false 48 | - v140 49 | + v141 50 | 51 | 52 | StaticLibrary 53 | false 54 | true 55 | MultiByte 56 | - v140 57 | + v141 58 | 59 | 60 | DynamicLibrary 61 | false 62 | true 63 | MultiByte 64 | - v140 65 | + v141 66 | 67 | 68 | StaticLibrary 69 | false 70 | true 71 | MultiByte 72 | - v140 73 | + v141 74 | 75 | 76 | DynamicLibrary 77 | false 78 | true 79 | MultiByte 80 | - v140 81 | + v141 82 | 83 | 84 | 85 | @@ -559,4 +560,4 @@ 86 | 87 | 88 | 89 | - 90 | + 91 | \ No newline at end of file 92 | diff --git a/libsodium.vcxproj.filters b/libsodium.vcxproj.filters 93 | index 8325e43c..d43187c1 100644 94 | --- a/libsodium.vcxproj.filters 95 | +++ b/libsodium.vcxproj.filters 96 | @@ -716,5 +716,13 @@ 97 | 98 | Header Files 99 | 100 | + 101 | + Header Files 102 | + 103 | + 104 | + 105 | + 106 | + Resource Files 107 | + 108 | 109 | - 110 | + 111 | \ No newline at end of file 112 | -------------------------------------------------------------------------------- /API/CreditsCPlusPlusDemoCMake/patches/msvc142_retargeting.patch: -------------------------------------------------------------------------------- 1 | diff --git a/libsodium.vcxproj b/libsodium.vcxproj 2 | index 63d5f956..e2d028d9 100644 3 | --- a/libsodium.vcxproj 4 | +++ b/libsodium.vcxproj 5 | @@ -45,56 +45,56 @@ 6 | true 7 | MultiByte 8 | false 9 | - v140 10 | + v142 11 | 12 | 13 | DynamicLibrary 14 | true 15 | MultiByte 16 | false 17 | - v140 18 | + v142 19 | 20 | 21 | StaticLibrary 22 | true 23 | MultiByte 24 | false 25 | - v140 26 | + v142 27 | 28 | 29 | DynamicLibrary 30 | true 31 | MultiByte 32 | false 33 | - v140 34 | + v142 35 | 36 | 37 | StaticLibrary 38 | false 39 | true 40 | MultiByte 41 | - v140 42 | + v142 43 | 44 | 45 | DynamicLibrary 46 | false 47 | true 48 | MultiByte 49 | - v140 50 | + v142 51 | 52 | 53 | StaticLibrary 54 | false 55 | true 56 | MultiByte 57 | - v140 58 | + v142 59 | 60 | 61 | DynamicLibrary 62 | false 63 | true 64 | MultiByte 65 | - v140 66 | + v142 67 | 68 | 69 | 70 | @@ -560,4 +560,4 @@ 71 | 72 | 73 | 74 | - 75 | + 76 | \ No newline at end of file 77 | diff --git a/libsodium.vcxproj.filters b/libsodium.vcxproj.filters 78 | index b4a4ea96..467dd988 100644 79 | --- a/libsodium.vcxproj.filters 80 | +++ b/libsodium.vcxproj.filters 81 | @@ -719,5 +719,13 @@ 82 | 83 | Header Files 84 | 85 | + 86 | + Header Files 87 | + 88 | + 89 | + 90 | + 91 | + Resource Files 92 | + 93 | 94 | - 95 | + 96 | \ No newline at end of file 97 | -------------------------------------------------------------------------------- /API/CreditsCPlusPlusDemoCMake/runme.cmd: -------------------------------------------------------------------------------- 1 | .\build64\release\main.exe 2 | pause -------------------------------------------------------------------------------- /API/CreditsCPlusPlusDemoCMake/runme.sh: -------------------------------------------------------------------------------- 1 | ./build64/main -------------------------------------------------------------------------------- /API/CreditsCPlusPlusDemoCMake/thrift/test/threads/ThreadsClient.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | // This autogenerated skeleton file illustrates how to build a server. 21 | // You should copy it to another filename to avoid overwriting it. 22 | 23 | #include "ThreadsTest.h" 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #if _WIN32 32 | #include 33 | #endif 34 | 35 | using boost::shared_ptr; 36 | using namespace apache::thrift; 37 | using namespace apache::thrift::protocol; 38 | using namespace apache::thrift::transport; 39 | using namespace apache::thrift::server; 40 | using namespace apache::thrift::concurrency; 41 | 42 | int main(int argc, char **argv) { 43 | #if _WIN32 44 | transport::TWinsockSingleton::create(); 45 | #endif 46 | int port = 9090; 47 | std::string host = "localhost"; 48 | 49 | shared_ptr transport(new TSocket(host, port)); 50 | shared_ptr protocol(new TBinaryProtocol(transport)); 51 | 52 | transport->open(); 53 | 54 | ThreadsTestClient client(protocol); 55 | int val; 56 | val = client.threadOne(5); 57 | fprintf(stderr, "%d\n", val); 58 | val = client.stop(); 59 | fprintf(stderr, "%d\n", val); 60 | val = client.threadTwo(5); 61 | fprintf(stderr, "%d\n", val); 62 | 63 | transport->close(); 64 | 65 | fprintf(stderr, "done.\n"); 66 | 67 | return 0; 68 | } 69 | 70 | -------------------------------------------------------------------------------- /API/CreditsCSharpDemo/CreditsCSAPIDemo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | Exe 4 | netcoreapp2.2 5 | 40 6 | D:\Dev\GitHub\Examples\API\CreditsCSharpDemo\Backup\ 7 | 15.0 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /API/CreditsCSharpDemo/Keys.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace CreditsCSAPIDemo 6 | { 7 | public class Keys 8 | { 9 | public string PublicKey { get; set; } 10 | public string PrivateKey { get; set; } 11 | public string TargetKey { get; set; } 12 | public byte[] PublicKeyBytes 13 | { 14 | get 15 | { 16 | return PublicKey != null ? SimpleBase.Base58.Bitcoin.Decode(PublicKey).ToArray() : null; 17 | } 18 | } 19 | public byte[] PrivateKeyBytes 20 | { 21 | get 22 | { 23 | return PrivateKey != null ? SimpleBase.Base58.Bitcoin.Decode(PrivateKey).ToArray() : null; 24 | } 25 | } 26 | public byte[] TargetKeyBytes 27 | { 28 | get 29 | { 30 | return TargetKey != null ? SimpleBase.Base58.Bitcoin.Decode(TargetKey).ToArray() : null; 31 | } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /API/CreditsCSharpDemo/Program.cs: -------------------------------------------------------------------------------- 1 | using Chaos.NaCl; 2 | using NodeApi; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Diagnostics; 6 | using System.IO; 7 | using Thrift.Protocol; 8 | using Thrift.Transport; 9 | using SauceControl.Blake2Fast; 10 | using System.Text; 11 | 12 | namespace CreditsCSAPIDemo 13 | { 14 | class Program 15 | { 16 | static void Main(string[] args) 17 | { 18 | Console.WriteLine("Credits API Simple Demo"); 19 | 20 | if(args.Length != 5) 21 | { 22 | Console.WriteLine("Usage: CreditsCSAPIDemo NodeIpAddress NodePort YourPublicKey YourPrivateKey TargetPublicKey"); 23 | return; 24 | } 25 | 26 | using (var client = new Client(args[0], Convert.ToInt32(args[1]), args[2], args[3], args[4])) 27 | { 28 | var balance = client.WalletGetBalance(); 29 | Console.WriteLine($"[{client.keys.PublicKey}] Balance: {balance.Balance.ToString()}"); 30 | 31 | //Console.WriteLine("Result of the transfer coins:"); 32 | //Console.WriteLine(client.TransferCoins(1, 0, 2.0)); 33 | 34 | //Console.WriteLine(client.DeploySmartContract("")); 35 | } 36 | 37 | Console.WriteLine("Press [Enter] to exit..."); 38 | Console.ReadLine(); 39 | } 40 | 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /API/CreditsCSharpDemo/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "profiles": { 3 | "CreditsCSAPIDemo": { 4 | "commandName": "Project", 5 | "commandLineArgs": "165.22.250.42 9090 5B3YXqDTcWQFGAqEJQJP3Bg1ZK8FFtHtgCiFLT5VAxpe 3rUevsW5xfob6qDxWMDFwwTQCq39SYhzstuyfUGSDvF2QHBRyPD8fSk49wFXaPk3GztfxtuU85QHfMV3ozfqa7rN H5ptdUUfjJBGiK2X3gN2EzNYxituCUUnXv2tiMdQKP3b" 6 | } 7 | } 8 | } -------------------------------------------------------------------------------- /API/CreditsCSharpDemo/README.md: -------------------------------------------------------------------------------- 1 | ## CreditsCSharpDemo 2 | https://developers.credits.com/en/Articles/a_Using_of_Credits_API_in_C_(demo) 3 | 4 | A simple console C# (.NET Core) application.
5 | Using the public key of the wallet displays the balance.
6 | Allows to create a transaction (transfer coins from the current wallet to the specified one) and execute it. 7 | 8 | ## Requirements 9 | 10 | Git is a free and open source distributed version of control system designed to handle everything from small to very large projects with speed and efficiency.
11 | https://git-scm.com/ 12 | 13 | .NET is a free, cross-platform, open source developer platform designed to build many different types of applications. With .NET, you can use multiple languages, editors, and libraries to build for web, mobile, desktop, gaming, and IoT.
14 | https://dotnet.microsoft.com/download 15 | 16 | The Apache Thrift software framework is designed for development of scalable cross-language services. It combines a software stack with a code generation engine in order to build services that interact efficiently and seamlessly with C++, Java, Python, PHP, Ruby, Erlang, Perl, Haskell, C#, Cocoa, JavaScript, Node.js,Smalltalk, OCaml and Delphi and other languages.
17 | https://thrift.apache.org/ 18 | 19 | ## Creation and execution of transactions with Credits API support (in C#) 20 | https://developers.credits.com/en/Articles/a_Creating_and_execution_of_transaction_C_ 21 | 22 | ## Transaction field(Length in bytes) 23 | Id (6 bytes)
24 | Source (32 bytes)
25 | Target (32 bytes)
26 | Amount.Integral (4 bytes)
27 | Amount.Fraction (8 bytes)
28 | Fee.Commission (2 bytes)
29 | Currency (1 bytes)
30 | 31 | ## Which transaction fields must be filled 32 | ```shell 33 | //Create a transaction (transfer from a wallet to another wallet) 34 | var transaction = new Transaction(); 35 | 36 | //Internal transaction number (id) 37 | transaction.Id = client.WalletTransactionsCountGet(sourceKeys.PublicKeyBytes).LastTransactionInnerId + 1; 38 | 39 | //Original/input/initial wallet byte array 40 | transaction.Source = sourceKeys.PublicKeyBytes; 41 | 42 | //Target wallet byte array 43 | transaction.Target = targetKeys.PublicKeyBytes; 44 | 45 | //Quantity of transferable coins 46 | transaction.Amount = new Amount(1, 0); 47 | 48 | //Commission 49 | transaction.Fee = new AmountCommission(Fee(0.9)); 50 | 51 | transaction.Currency = 1; 52 | ``` 53 | 54 | Field completion for transaction signature
55 | It is necessary create a byte array with a size of 85 bytes
56 | Last element of the array is filled out with zero (0).
57 | 58 | ## Concern 59 | It is necessary to convert commission value from double to short. For example: 60 | 61 | ```shell 62 | // commission 63 | transaction.Fee = new AmountCommission(Fee(0.9)); 64 | 65 | private short Fee(Double value) 66 | { 67 | byte sign = (byte)(value < 0.0 ? 1 : 0); // sign 68 | int exp; // exponent 69 | long frac; // mantissa 70 | value = Math.Abs(value); 71 | double expf = value == 0.0 ? 0.0 : Math.Log10(value); 72 | int expi = Convert.ToInt32(expf >= 0 ? expf + 0.5 : expf - 0.5); 73 | value /= Math.Pow(10, expi); 74 | if (value >= 1.0) 75 | { 76 | value *= 0.1; 77 | ++expi; 78 | } 79 | exp = expi + 18; 80 | if (exp < 0 || exp > 28) 81 | { 82 | throw new Exception($"exponent value {exp} out of range [0, 28]"); 83 | } 84 | frac = (long)Math.Round(value * 1024); 85 | return (short)(sign * 32768 + exp * 1024 + frac); 86 | } 87 | ``` 88 | 89 | ## Using: 90 | ### Build for Windows 91 | ```shell 92 | build-windows.cmd 93 | ``` 94 | 95 | ### The content of build-windows.cmd 96 | ```shell 97 | git clone https://github.com/CREDITSCOM/thrift-interface-definitions 98 | thrift -gen csharp -out . .\thrift-interface-definitions\general.thrift 99 | thrift -gen csharp -out . .\thrift-interface-definitions\api.thrift 100 | dotnet add package apache-thrift-netcore --version 0.9.3.2 101 | dotnet add package SimpleBase --version 1.8.0 102 | pause 103 | ``` 104 | 105 | ### Run 106 | ```shell 107 | run.cmd 108 | ``` 109 | 110 | ### The content of run.cmd 111 | ```shell 112 | dotnet run 113 | pause 114 | ``` 115 | 116 | ### Build for Linux: 117 | ```shell 118 | ./build-linux.sh 119 | ``` 120 | 121 | ### The content of build-linux.sh 122 | ```shell 123 | git clone https://github.com/CREDITSCOM/thrift-interface-definitions 124 | thrift -gen csharp -out . ./thrift-interface-definitions/general.thrift 125 | thrift -gen csharp -out . ./thrift-interface-definitions/api.thrift 126 | dotnet add package apache-thrift-netcore --version 0.9.3.2 127 | dotnet add package SimpleBase --version 1.8.0 128 | ``` 129 | 130 | ### Run 131 | ```shell 132 | ./runme.sh 133 | ``` 134 | 135 | ### The content of runme.sh 136 | ```shell 137 | dotnet run 138 | ``` 139 | -------------------------------------------------------------------------------- /API/CreditsCSharpDemo/build-linux.sh: -------------------------------------------------------------------------------- 1 | git clone https://github.com/CREDITSCOM/thrift-interface-definitions 2 | thrift -gen csharp -out . ./thrift-interface-definitions/general.thrift 3 | thrift -gen csharp -out . ./thrift-interface-definitions/api.thrift 4 | dotnet add package apache-thrift-netcore --version 0.9.3.2 5 | dotnet add package SimpleBase --version 1.8.0 6 | -------------------------------------------------------------------------------- /API/CreditsCSharpDemo/build-windows.cmd: -------------------------------------------------------------------------------- 1 | git clone https://github.com/CREDITSCOM/thrift-interface-definitions 2 | thrift -gen csharp -out . .\thrift-interface-definitions\general.thrift 3 | thrift -gen csharp -out . .\thrift-interface-definitions\api.thrift 4 | dotnet add package apache-thrift-netcore --version 0.9.3.2 5 | dotnet add package SimpleBase --version 1.8.0 6 | pause -------------------------------------------------------------------------------- /API/CreditsCSharpDemo/clean.cmd: -------------------------------------------------------------------------------- 1 | rmdir /S /Q bin 2 | rmdir /S /Q thrift-interface-definitions 3 | rmdir /S /Q obj 4 | rmdir /S /Q NodeApi 5 | del Annotation.cs 6 | del Amount.cs 7 | del APIResponse.cs 8 | del ByteCodeObject.cs 9 | del MethodArgument.cs 10 | del MethodDescription.cs 11 | del Variant.cs 12 | del ClassObject.cs 13 | del object.cs 14 | -------------------------------------------------------------------------------- /API/CreditsCSharpDemo/clean.sh: -------------------------------------------------------------------------------- 1 | rm -r -f bin 2 | rm -r -f thrift-interface-definitions 3 | rm -r -f obj 4 | rm -r -f NodeApi 5 | 6 | rm Annotation.cs 7 | rm Amount.cs 8 | rm APIResponse.cs 9 | rm ByteCodeObject.cs 10 | rm MethodArgument.cs 11 | rm MethodDescription.cs 12 | rm Variant.cs 13 | rm ClassObject.cs 14 | rm object.cs 15 | -------------------------------------------------------------------------------- /API/CreditsCSharpDemo/runme.cmd: -------------------------------------------------------------------------------- 1 | dotnet run 2 | pause -------------------------------------------------------------------------------- /API/CreditsCSharpDemo/runme.sh: -------------------------------------------------------------------------------- 1 | dotnet run -------------------------------------------------------------------------------- /API/CreditsHighLevelAPI/Client/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5 FATAL_ERROR) 2 | 3 | set(CMAKE_CXX_STANDARD 17) 4 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 5 | 6 | if (MSVC) 7 | add_definitions(-DNOMINMAX) 8 | endif() 9 | 10 | add_definitions(-DUSE_STD_THREAD) 11 | if (MSVC) 12 | option(BUILD_COMPILER "" OFF) 13 | endif(MSVC) 14 | option(WITH_BOOST_STATIC "" ON) 15 | option(BUILD_TESTING "" OFF) 16 | option(BUILD_TUTORIALS "" OFF) 17 | option(BUILD_EXAMPLES "" OFF) 18 | option(BUILD_PYTHON "" OFF) 19 | option(WITH_SHARED_LIB "" OFF) 20 | option(WITH_STATIC_LIB "" ON) 21 | option(WITH_C_GLIB "" OFF) 22 | option(WITH_JAVA "" OFF) 23 | option(WITH_PYTHON "" OFF) 24 | option(WITH_QT4 "" OFF) 25 | option(WITH_QT5 "" OFF) 26 | option(WITH_ZLIB "" OFF) 27 | option(WITH_STDTHREADS "" ON) 28 | option(WITH_LIBEVENT "" OFF) 29 | option(WITH_OPENSSL "" OFF) 30 | add_subdirectory(thrift) 31 | 32 | find_package(Boost 1.70 REQUIRED) 33 | 34 | include_directories(${Boost_INCLUDE_DIRS}) 35 | include_directories("./thrift/lib/cpp/src") 36 | 37 | add_executable(main 38 | client.h 39 | client.cpp 40 | ./hlapi/hlapi_constants.h 41 | ./hlapi/hlapi_types.h 42 | ./hlapi/API.h 43 | ./hlapi/hlapi_constants.cpp 44 | ./hlapi/hlapi_types.cpp 45 | ./hlapi/Api.cpp 46 | main.cpp 47 | ) 48 | 49 | target_link_libraries(main ${Boost_LIBRARIES}) 50 | target_link_libraries(main thrift_static) 51 | -------------------------------------------------------------------------------- /API/CreditsHighLevelAPI/Client/build64.cmd: -------------------------------------------------------------------------------- 1 | rmdir /S /Q build64 2 | rmdir /S /Q thrift-interface-definitions 3 | rmdir /S /Q thrift 4 | rmdir /S /Q api 5 | rmdir /S /Q hlapi 6 | 7 | mkdir hlapi 8 | thrift -r -gen cpp:no_skeleton,pure_enums,moveable_types -out .\hlapi ..\thrift\hlapi.thrift 9 | 10 | git clone https://github.com/CREDITSCOM/thrift 11 | cd thrift 12 | 13 | cd .. 14 | mkdir build64 15 | cd build64 16 | 17 | cmake .. -DCMAKE_BUILD_TYPE=Debug -A x64 .. 18 | cmake --build . --config Debug 19 | 20 | rem cmake -DBOOST_ROOT=d:\boost -DCMAKE_BUILD_TYPE=Release -A x64 .. 21 | rem cmake --build . --config Release 22 | 23 | pause -------------------------------------------------------------------------------- /API/CreditsHighLevelAPI/Client/build64.sh: -------------------------------------------------------------------------------- 1 | rm -r -f build64 2 | rm -r -f thrift-interface-definitions 3 | rm -r -f thrift 4 | rm -r -f api 5 | rm -r -f blake2 6 | 7 | git clone https://github.com/jedisct1/libsodium.git 8 | git clone https://github.com/CREDITSCOM/blake2.git 9 | 10 | git clone https://github.com/jedisct1/libsodium.git 11 | 12 | git clone https://github.com/CREDITSCOM/thrift-interface-definitions 13 | mkdir api 14 | thrift -r -gen cpp:no_skeleton,pure_enums,moveable_types -out ./api ./thrift-interface-definitions/api.thrift 15 | 16 | git clone https://github.com/CREDITSCOM/thrift 17 | cd thrift 18 | 19 | cd .. 20 | mkdir build64 21 | cd build64 22 | 23 | cmake .. 24 | cmake --build . --config Debug 25 | cmake --build . --config Release 26 | 27 | cmake .. -DCMAKE_BUILD_TYPE=Debug -A x64 .. 28 | cmake --build . --config Debug 29 | 30 | # cmake -DCMAKE_BUILD_TYPE=Release -A x64 .. 31 | # cmake --build . --config Release 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /API/CreditsHighLevelAPI/Client/clean.cmd: -------------------------------------------------------------------------------- 1 | rmdir /S /Q build64 2 | rmdir /S /Q thrift-interface-definitions 3 | rmdir /S /Q thrift 4 | rmdir /S /Q api 5 | rmdir /S /Q hlapi 6 | -------------------------------------------------------------------------------- /API/CreditsHighLevelAPI/Client/clean.sh: -------------------------------------------------------------------------------- 1 | rm -r -f build64 2 | rm -r -f thrift-interface-definitions 3 | rm -r -f thrift 4 | rm -r -f api 5 | rm -r -f blake2 6 | -------------------------------------------------------------------------------- /API/CreditsHighLevelAPI/Client/client.cpp: -------------------------------------------------------------------------------- 1 | #include "client.h" 2 | 3 | using namespace apache::thrift::transport; 4 | using namespace apache::thrift::protocol; 5 | 6 | client::client(std::string ip, int port) 7 | { 8 | m_socket = std::shared_ptr(new TSocket(ip, port)); 9 | m_transport = std::shared_ptr(new TBufferedTransport(m_socket)); 10 | m_protocol = std::shared_ptr(new TBinaryProtocol(m_transport)); 11 | m_api = std::shared_ptr(new hlapi::api::ApiClient(m_protocol)); 12 | } 13 | 14 | client::~client() 15 | { 16 | disconnect(); 17 | } 18 | 19 | void client::set_keys(const keys& ks) 20 | { 21 | m_keys = ks; 22 | } 23 | 24 | void client::wallet_balance() 25 | { 26 | try 27 | { 28 | connect(); 29 | hlapi::api::Amount am; 30 | m_api->GetBalance(am, m_keys.public_key); 31 | am.printTo(std::cout); 32 | disconnect(); 33 | } 34 | catch (const std::exception& ex) 35 | { 36 | std::cout << ex.what() << std::endl; 37 | } 38 | } 39 | 40 | void client::transfer_coins(int32_t integral, int32_t fraction, double fee_value) 41 | { 42 | try 43 | { 44 | connect(); 45 | std::string message{}; 46 | m_api->TransferCoins(message, m_keys.public_key, m_keys.private_key, m_keys.target_key, integral, fraction, fee_value); 47 | if (message.length() != 0) std::cout << message << std::endl; 48 | disconnect(); 49 | } 50 | catch (const std::exception ex) 51 | { 52 | std::cout << ex.what() << std::endl; 53 | } 54 | } 55 | 56 | void client::deploy_smart_contract(std::string code, double fee_value) 57 | { 58 | try 59 | { 60 | connect(); 61 | std::string message{}; 62 | m_api->DeploySmartContract(message, m_keys.public_key, m_keys.private_key, m_keys.target_key, code, fee_value); 63 | if (message.length() != 0) std::cout << message << std::endl; 64 | disconnect(); 65 | } 66 | catch (const std::exception ex) 67 | { 68 | std::cout << ex.what() << std::endl; 69 | } 70 | } 71 | 72 | void client::connect() 73 | { 74 | try 75 | { 76 | if (!m_transport->isOpen()) 77 | m_transport->open(); 78 | } 79 | catch (const std::exception ex) 80 | { 81 | std::cout << ex.what() << std::endl; 82 | } 83 | } 84 | 85 | void client::disconnect() 86 | { 87 | try 88 | { 89 | if(m_transport->isOpen()) 90 | m_transport->close(); 91 | } 92 | catch (const std::exception ex) 93 | { 94 | std::cout << ex.what() << std::endl; 95 | } 96 | } 97 | 98 | -------------------------------------------------------------------------------- /API/CreditsHighLevelAPI/Client/client.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include "hlapi/API.h" 14 | 15 | struct keys 16 | { 17 | std::string public_key; 18 | std::string private_key; 19 | std::string target_key; 20 | }; 21 | 22 | class client 23 | { 24 | private: 25 | std::shared_ptr m_socket; 26 | std::shared_ptr m_transport; 27 | std::shared_ptr m_protocol; 28 | std::shared_ptr m_api; 29 | 30 | keys m_keys; 31 | 32 | void connect(); 33 | void disconnect(); 34 | 35 | public: 36 | client(std::string ip, int port); 37 | ~client(); 38 | 39 | void set_keys(const keys& ks); 40 | 41 | void wallet_balance(); 42 | void transfer_coins(int32_t integral, int32_t fraction, double fee_value); 43 | void deploy_smart_contract(std::string code, double fee_value); 44 | }; 45 | 46 | -------------------------------------------------------------------------------- /API/CreditsHighLevelAPI/Client/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "client.h" 13 | 14 | using namespace std; 15 | using namespace apache::thrift::transport; 16 | using namespace apache::thrift::protocol; 17 | using namespace hlapi::api; 18 | 19 | void pr(const std::string& message) 20 | { 21 | std::cout << message << std::endl; 22 | } 23 | 24 | int main(int argc, char* argv[]) 25 | { 26 | pr("Example C++ client for Credits HLAPI"); 27 | 28 | client cl{ "127.0.0.1", 9099 }; 29 | 30 | keys ks{ 31 | "35SR5JC6DA9pPd9xYQ7oRvvCgJKK7teLoMwDMBmEN45Q", 32 | "tvkphPU2Y6svC38FaWuer8zF2F7DsfNkqMsko76uL8Rdv5oztCqmcEwKWi5NbDgtsy7QDNe9vXhkHFQTATNFksc", 33 | "DXEiDtU7NHz8YdQEzugBXh3oqaVQ6nGHMkFPwLtnvZSG" }; 34 | 35 | cl.set_keys(ks); 36 | 37 | pr("Wallet Balance Get"); 38 | cl.wallet_balance(); 39 | pr(""); 40 | 41 | pr("Transfer Coins"); 42 | cl.transfer_coins(1, 0, 0.9); 43 | pr(""); 44 | 45 | pr("Deploy Smart Contract"); 46 | cl.deploy_smart_contract("" /* here must be a smart contract code */, 0.9); 47 | pr(""); 48 | 49 | } 50 | 51 | -------------------------------------------------------------------------------- /API/CreditsHighLevelAPI/Client/runme.cmd: -------------------------------------------------------------------------------- 1 | .\build64\release\main.exe 2 | pause -------------------------------------------------------------------------------- /API/CreditsHighLevelAPI/Client/runme.sh: -------------------------------------------------------------------------------- 1 | ./build64/main -------------------------------------------------------------------------------- /API/CreditsHighLevelAPI/Readme.md: -------------------------------------------------------------------------------- 1 | ## CreditsHighLevelAPI (C++) 2 | A simple demo of the Credits High level API 3 | This one includes a server and a client application 4 | -------------------------------------------------------------------------------- /API/CreditsHighLevelAPI/Server/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.5 FATAL_ERROR) 2 | 3 | set(CMAKE_CXX_STANDARD 17) 4 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 5 | set(libsodium_dir ${CMAKE_CURRENT_SOURCE_DIR}/libsodium/) 6 | 7 | if(WIN32) 8 | if(${MSVC_TOOLSET_VERSION} MATCHES 142 OR NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19.20) 9 | set(libsodium_patch ${libsodium_dir}/../patches/msvc142_retargeting.patch) 10 | else() 11 | if(${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION} MATCHES 10.0.17763.0) 12 | set(libsodium_patch ${libsodium_dir}/../patches/msvc141_retargeting17763.patch) 13 | else() 14 | set(libsodium_patch ${libsodium_dir}/../patches/msvc141_retargeting17134.patch) 15 | endif() 16 | endif() 17 | 18 | execute_process(COMMAND git apply --ignore-space-change ${libsodium_patch} 19 | WORKING_DIRECTORY ${libsodium_dir}) 20 | 21 | if(CMAKE_BUILD_TYPE MATCHES Debug) 22 | set(msbuild_property "/p:Configuration=Debug") 23 | else() 24 | set(msbuild_property "/p:Configuration=Release") 25 | endif() 26 | 27 | set(msbuild_parallel "/m") 28 | set(msbuild_platform "/p:platform=x64") 29 | set(proj_to_build "libsodium.sln") 30 | set(disable_post_build "/p:PostBuildEventUseInBuild=false") 31 | 32 | execute_process(COMMAND ${CMAKE_VS_MSBUILD_COMMAND} ${msbuild_parallel} ${proj_to_build} ${msbuild_property} ${msbuild_platform} ${disable_post_build} 33 | WORKING_DIRECTORY ${libsodium_dir}) 34 | 35 | execute_process(COMMAND git apply --ignore-space-change ${libsodium_patch} -R 36 | WORKING_DIRECTORY ${libsodium_dir}) 37 | 38 | set(lb_lib_folder .) 39 | else() 40 | 41 | if(CMAKE_BUILD_TYPE MATCHES Debug) 42 | set(libsodium_lib_dir ${libsodium_dir}/Build/Debug/x64/) 43 | else() 44 | set(libsodium_lib_dir ${libsodium_dir}/Build/Release/x64/) 45 | endif() 46 | 47 | if(EXISTS ${libsodium_lib_dir}/lib/libsodium${CMAKE_STATIC_LIBRARY_SUFFIX}) 48 | message(STATUS "Libsodium lib has already been built") 49 | else() 50 | execute_process(COMMAND bash ./autogen.sh 51 | WORKING_DIRECTORY ${libsodium_dir}) 52 | execute_process(COMMAND ./configure --prefix=${libsodium_lib_dir} 53 | WORKING_DIRECTORY ${libsodium_dir}) 54 | execute_process(COMMAND make 55 | WORKING_DIRECTORY ${libsodium_dir}) 56 | execute_process(COMMAND make check 57 | WORKING_DIRECTORY ${libsodium_dir}) 58 | execute_process(COMMAND make install 59 | WORKING_DIRECTORY ${libsodium_dir}) 60 | endif() 61 | 62 | set(lb_lib_folder lib) 63 | endif() 64 | 65 | add_library(libsodium STATIC IMPORTED GLOBAL) 66 | set_property(TARGET libsodium PROPERTY IMPORTED_LOCATION_RELEASE 67 | ${libsodium_dir}/Build/Release/x64/${lb_lib_folder}/libsodium${CMAKE_STATIC_LIBRARY_SUFFIX}) 68 | set_property(TARGET libsodium PROPERTY IMPORTED_LOCATION_RELWITHDEBINFO 69 | ${libsodium_dir}/Build/Release/x64/${lb_lib_folder}/libsodium${CMAKE_STATIC_LIBRARY_SUFFIX}) 70 | set_property(TARGET libsodium PROPERTY IMPORTED_LOCATION_DEBUG 71 | ${libsodium_dir}/Build/Debug/x64/${lb_lib_folder}/libsodium${CMAKE_STATIC_LIBRARY_SUFFIX}) 72 | 73 | set_property(TARGET libsodium PROPERTY IMPORTED_LOCATION_RELSPAM 74 | ${libsodium_dir}/Build/Release/x64/${lb_lib_folder}/libsodium${CMAKE_STATIC_LIBRARY_SUFFIX}) 75 | set_property(TARGET libsodium PROPERTY IMPORTED_LOCATION_RELMONITOR 76 | ${libsodium_dir}/Build/Release/x64/${lb_lib_folder}/libsodium${CMAKE_STATIC_LIBRARY_SUFFIX}) 77 | set_property(TARGET libsodium PROPERTY IMPORTED_LOCATION_RELWALLET 78 | ${libsodium_dir}/Build/Release/x64/${lb_lib_folder}/libsodium${CMAKE_STATIC_LIBRARY_SUFFIX}) 79 | 80 | if (MSVC) 81 | add_definitions(-DNOMINMAX) 82 | endif() 83 | 84 | add_definitions(-DUSE_STD_THREAD) 85 | if (MSVC) 86 | option(BUILD_COMPILER "" OFF) 87 | endif(MSVC) 88 | option(WITH_BOOST_STATIC "" ON) 89 | option(BUILD_TESTING "" OFF) 90 | option(BUILD_TUTORIALS "" OFF) 91 | option(BUILD_EXAMPLES "" OFF) 92 | option(BUILD_PYTHON "" OFF) 93 | option(WITH_SHARED_LIB "" OFF) 94 | option(WITH_STATIC_LIB "" ON) 95 | option(WITH_C_GLIB "" OFF) 96 | option(WITH_JAVA "" OFF) 97 | option(WITH_PYTHON "" OFF) 98 | option(WITH_QT4 "" OFF) 99 | option(WITH_QT5 "" OFF) 100 | option(WITH_ZLIB "" OFF) 101 | option(WITH_STDTHREADS "" ON) 102 | option(WITH_LIBEVENT "" OFF) 103 | option(WITH_OPENSSL "" OFF) 104 | add_subdirectory(thrift) 105 | add_subdirectory(blake2) 106 | 107 | find_package(Boost 1.68 REQUIRED) 108 | 109 | include_directories(${Boost_INCLUDE_DIRS}) 110 | include_directories("./thrift/lib/cpp/src") 111 | include_directories("./libsodium/src/libsodium/include") 112 | include_directories("./blake2/sse") 113 | 114 | add_executable(server 115 | ./api/api_constants.h 116 | ./api/api_types.h 117 | ./api/API.h 118 | ./common/base58.h 119 | ./api/general_constants.h 120 | ./api/general_types.h 121 | ./hlapi/hlapi_constants.h 122 | ./hlapi/hlapi_types.h 123 | ./hlapi/API.h 124 | client.h 125 | keys.h 126 | ac.h 127 | ./api/api_constants.cpp 128 | ./api/api_types.cpp 129 | ./api/Api.cpp 130 | ./common/base58.cpp 131 | ./api/general_constants.cpp 132 | ./api/general_types.cpp 133 | ./common/variant_aux.cpp 134 | ./hlapi/hlapi_constants.cpp 135 | ./hlapi/hlapi_types.cpp 136 | ./hlapi/Api.cpp 137 | client.cpp 138 | keys.cpp 139 | ac.cpp 140 | server.cpp 141 | ) 142 | 143 | target_link_libraries(server ${Boost_LIBRARIES}) 144 | target_link_libraries(server blake2 libsodium) 145 | target_compile_definitions(server PUBLIC SODIUM_STATIC) 146 | target_link_libraries(server thrift_static) 147 | -------------------------------------------------------------------------------- /API/CreditsHighLevelAPI/Server/ac.cpp: -------------------------------------------------------------------------------- 1 | #include "ac.h" 2 | #include 3 | #include "common/base58.h" 4 | #include "api/API.h" 5 | 6 | general::Address ac::address(const char* sa) 7 | { 8 | std::vector evec; 9 | DecodeBase58(sa, evec); 10 | //std::string dst(evec.size(), 0); 11 | //memcpy((void*)dst.c_str(), &(evec[0]), evec.size()); 12 | std::string dst(evec.begin(), evec.end()); 13 | return dst; 14 | } 15 | -------------------------------------------------------------------------------- /API/CreditsHighLevelAPI/Server/ac.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "api/API.h" 4 | 5 | class ac 6 | { 7 | public: 8 | static general::Address address(const char* sa); 9 | }; 10 | 11 | -------------------------------------------------------------------------------- /API/CreditsHighLevelAPI/Server/build64.cmd: -------------------------------------------------------------------------------- 1 | rmdir /S /Q build64 2 | rmdir /S /Q hlapi 3 | rmdir /S /Q thrift 4 | rmdir /S /Q api 5 | rmdir /S /Q libsodium 6 | rmdir /S /Q blake2 7 | 8 | git clone https://github.com/jedisct1/libsodium.git 9 | git clone https://github.com/CREDITSCOM/blake2.git 10 | 11 | git clone https://github.com/CREDITSCOM/thrift-interface-definitions 12 | mkdir api 13 | thrift -r -gen cpp:no_skeleton,pure_enums,moveable_types -out .\api .\thrift-interface-definitions\api.thrift 14 | 15 | mkdir hlapi 16 | thrift -r -gen cpp:no_skeleton,pure_enums,moveable_types -out .\hlapi ..\thrift\hlapi.thrift 17 | 18 | git clone https://github.com/CREDITSCOM/thrift 19 | cd thrift 20 | 21 | cd .. 22 | mkdir build64 23 | cd build64 24 | 25 | cmake .. -DCMAKE_BUILD_TYPE=Debug -A x64 .. 26 | cmake --build . --config Debug 27 | 28 | rem cmake -DBOOST_ROOT=d:\boost -DCMAKE_BUILD_TYPE=Release -A x64 .. 29 | rem cmake --build . --config Release 30 | 31 | pause -------------------------------------------------------------------------------- /API/CreditsHighLevelAPI/Server/build64.sh: -------------------------------------------------------------------------------- 1 | rm -r -f build64 2 | rm -r -f thrift-interface-definitions 3 | rm -r -f thrift 4 | rm -r -f api 5 | rm -r -f blake2 6 | 7 | git clone https://github.com/jedisct1/libsodium.git 8 | git clone https://github.com/CREDITSCOM/blake2.git 9 | 10 | git clone https://github.com/jedisct1/libsodium.git 11 | 12 | git clone https://github.com/CREDITSCOM/thrift-interface-definitions 13 | mkdir api 14 | thrift -r -gen cpp:no_skeleton,pure_enums,moveable_types -out ./api ./thrift-interface-definitions/api.thrift 15 | 16 | mkdir hlapi 17 | thrift -r -gen cpp:no_skeleton,pure_enums,moveable_types -out .\hlapi ..\thrift\hlapi.thrift 18 | 19 | git clone https://github.com/CREDITSCOM/thrift 20 | cd thrift 21 | 22 | cd .. 23 | mkdir build64 24 | cd build64 25 | 26 | cmake .. 27 | cmake --build . --config Debug 28 | cmake --build . --config Release 29 | 30 | cmake .. -DCMAKE_BUILD_TYPE=Debug -A x64 .. 31 | cmake --build . --config Debug 32 | 33 | # cmake -DCMAKE_BUILD_TYPE=Release -A x64 .. 34 | # cmake --build . --config Release 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /API/CreditsHighLevelAPI/Server/clean.cmd: -------------------------------------------------------------------------------- 1 | rmdir /S /Q build64 2 | rmdir /S /Q thrift-interface-definitions 3 | rmdir /S /Q thrift 4 | rmdir /S /Q api 5 | rmdir /S /Q hlapi 6 | rmdir /S /Q libsodium 7 | rmdir /S /Q blake2 8 | -------------------------------------------------------------------------------- /API/CreditsHighLevelAPI/Server/clean.sh: -------------------------------------------------------------------------------- 1 | rm -r -f build64 2 | rm -r -f thrift-interface-definitions 3 | rm -r -f thrift 4 | rm -r -f api 5 | rm -r -f hlapi 6 | rm -r -f blake2 7 | -------------------------------------------------------------------------------- /API/CreditsHighLevelAPI/Server/client.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "api/API.h" 15 | #include "keys.h" 16 | 17 | #define SIGNATURE_LEN 64 18 | 19 | class client 20 | { 21 | private: 22 | std::shared_ptr m_socket; 23 | std::shared_ptr m_transport; 24 | std::shared_ptr m_protocol; 25 | std::shared_ptr m_api; 26 | 27 | std::unique_ptr m_keys; 28 | 29 | void connect(); 30 | void disconnect(); 31 | short fee(double value); 32 | std::unique_ptr make_transaction_with_smart_contract(std::string code, double fee_value); 33 | std::unique_ptr make_transaction(int32_t integral, int64_t fraction, double fee_value); 34 | template 35 | void cp(std::vector& arr, T& value, int16_t size, bool reverse); 36 | 37 | public: 38 | client(std::string ip, int port); 39 | ~client(); 40 | 41 | void set_keys(const std::string& publicKey, const std::string& privateKey, const std::string& targetKey); 42 | 43 | std::unique_ptr wallet_balance_get(); 44 | void transfer_coins(int32_t integral, int64_t fraction, double fee_value); 45 | void deploy_smart(std::string code, double fee_value); 46 | }; 47 | 48 | -------------------------------------------------------------------------------- /API/CreditsHighLevelAPI/Server/common/base58.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2014-2017 The Bitcoin Core developers 2 | // Distributed under the MIT software license, see the accompanying 3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 | 5 | #include "base58.h" 6 | 7 | #include 8 | #include 9 | 10 | /** All alphanumeric characters except for "0", "I", "O", and "l" */ 11 | static const char* pszBase58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; 12 | static const int8_t mapBase58[256] = { 13 | -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, 14 | -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, 15 | -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, 16 | -1, 0, 1, 2, 3, 4, 5, 6, 7, 8,-1,-1,-1,-1,-1,-1, 17 | -1, 9,10,11,12,13,14,15, 16,-1,17,18,19,20,21,-1, 18 | 22,23,24,25,26,27,28,29, 30,31,32,-1,-1,-1,-1,-1, 19 | -1,33,34,35,36,37,38,39, 40,41,42,43,-1,44,45,46, 20 | 47,48,49,50,51,52,53,54, 55,56,57,-1,-1,-1,-1,-1, 21 | -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, 22 | -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, 23 | -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, 24 | -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, 25 | -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, 26 | -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, 27 | -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, 28 | -1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1, 29 | }; 30 | 31 | bool DecodeBase58(const char* psz, std::vector& vch) 32 | { 33 | // Skip leading spaces. 34 | while (*psz && isspace(*psz)) 35 | psz++; 36 | // Skip and count leading '1's. 37 | int zeroes = 0; 38 | int length = 0; 39 | while (*psz == '1') { 40 | zeroes++; 41 | psz++; 42 | } 43 | // Allocate enough space in big-endian base256 representation. 44 | int size = strlen(psz) * 733 / 1000 + 1; // log(58) / log(256), rounded up. 45 | std::vector b256(size); 46 | // Process the characters. 47 | static_assert(sizeof(mapBase58) / sizeof(mapBase58[0]) == 256, "mapBase58.size() should be 256"); // guarantee not out of range 48 | while (*psz && !isspace(*psz)) { 49 | // Decode base58 character 50 | int carry = mapBase58[(uint8_t)*psz]; 51 | if (carry == -1) // Invalid b58 character 52 | return false; 53 | int i = 0; 54 | for (std::vector::reverse_iterator it = b256.rbegin(); (carry != 0 || i < length) && (it != b256.rend()); ++it, ++i) { 55 | carry += 58 * (*it); 56 | *it = carry % 256; 57 | carry /= 256; 58 | } 59 | assert(carry == 0); 60 | length = i; 61 | psz++; 62 | } 63 | // Skip trailing spaces. 64 | while (isspace(*psz)) 65 | psz++; 66 | if (*psz != 0) 67 | return false; 68 | // Skip leading zeroes in b256. 69 | std::vector::iterator it = b256.begin() + (size - length); 70 | while (it != b256.end() && *it == 0) 71 | it++; 72 | // Copy result into output vector. 73 | vch.reserve(zeroes + (b256.end() - it)); 74 | vch.assign(zeroes, 0x00); 75 | while (it != b256.end()) 76 | vch.push_back(*(it++)); 77 | return true; 78 | } 79 | 80 | std::string EncodeBase58(const unsigned char* pbegin, const unsigned char* pend) 81 | { 82 | // Skip & count leading zeroes. 83 | int zeroes = 0; 84 | int length = 0; 85 | while (pbegin != pend && *pbegin == 0) { 86 | pbegin++; 87 | zeroes++; 88 | } 89 | // Allocate enough space in big-endian base58 representation. 90 | int size = (pend - pbegin) * 138 / 100 + 1; // log(256) / log(58), rounded up. 91 | std::vector b58(size); 92 | // Process the bytes. 93 | while (pbegin != pend) { 94 | int carry = *pbegin; 95 | int i = 0; 96 | // Apply "b58 = b58 * 256 + ch". 97 | for (std::vector::reverse_iterator it = b58.rbegin(); (carry != 0 || i < length) && (it != b58.rend()); it++, i++) { 98 | carry += 256 * (*it); 99 | *it = carry % 58; 100 | carry /= 58; 101 | } 102 | 103 | assert(carry == 0); 104 | length = i; 105 | pbegin++; 106 | } 107 | // Skip leading zeroes in base58 result. 108 | std::vector::iterator it = b58.begin() + (size - length); 109 | while (it != b58.end() && *it == 0) 110 | it++; 111 | // Translate the result into a string. 112 | std::string str; 113 | str.reserve(zeroes + (b58.end() - it)); 114 | str.assign(zeroes, '1'); 115 | while (it != b58.end()) 116 | str += pszBase58[*(it++)]; 117 | return str; 118 | } 119 | 120 | std::string EncodeBase58(const std::vector& vch) 121 | { 122 | return EncodeBase58(vch.data(), vch.data() + vch.size()); 123 | } 124 | 125 | bool DecodeBase58(const std::string& str, std::vector& vchRet) 126 | { 127 | return DecodeBase58(str.c_str(), vchRet); 128 | } -------------------------------------------------------------------------------- /API/CreditsHighLevelAPI/Server/common/base58.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2009-2010 Satoshi Nakamoto 2 | // Copyright (c) 2009-2017 The Bitcoin Core developers 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 | * Why base-58 instead of standard base-64 encoding? 8 | * - Don't want 0OIl characters that look the same in some fonts and 9 | * could be used to create visually identical looking data. 10 | * - A string with non-alphanumeric characters is not as easily accepted as input. 11 | * - E-mail usually won't line-break if there's no punctuation to break at. 12 | * - Double-clicking selects the whole string as one word if it's all alphanumeric. 13 | */ 14 | #ifndef BITCOIN_BASE58_H 15 | #define BITCOIN_BASE58_H 16 | 17 | #include 18 | #include 19 | 20 | /** 21 | * Encode a byte sequence as a base58-encoded string. 22 | * pbegin and pend cannot be nullptr, unless both are. 23 | */ 24 | std::string EncodeBase58(const unsigned char* pbegin, const unsigned char* pend); 25 | 26 | /** 27 | * Encode a byte vector as a base58-encoded string 28 | */ 29 | std::string EncodeBase58(const std::vector& vch); 30 | 31 | /** 32 | * Decode a base58-encoded string (psz) into a byte vector (vchRet). 33 | * return true if decoding is successful. 34 | * psz cannot be nullptr. 35 | */ 36 | bool DecodeBase58(const char* psz, std::vector& vchRet); 37 | 38 | /** 39 | * Decode a base58-encoded string (str) into a byte vector (vchRet). 40 | * return true if decoding is successful. 41 | */ 42 | bool DecodeBase58(const std::string& str, std::vector& vchRet); 43 | 44 | #endif // BITCOIN_BASE58_H 45 | -------------------------------------------------------------------------------- /API/CreditsHighLevelAPI/Server/common/variant_aux.cpp: -------------------------------------------------------------------------------- 1 | #include "../api/general_types.h" 2 | #include 3 | 4 | namespace general { 5 | 6 | bool operator<(const _Variant__isset& a, const _Variant__isset& b) { 7 | auto ta = std::tie(a.v_boolean, a.v_double, a.v_short, a.v_int, a.v_long, a.v_byte, a.v_list, a.v_map, a.v_set, a.v_string); 8 | decltype(ta) tb = 9 | std::tie(b.v_boolean, b.v_double, b.v_short, b.v_int, b.v_long, b.v_byte, b.v_list, b.v_map, b.v_set, b.v_string); 10 | return ta < tb; 11 | } 12 | 13 | bool Variant::operator<(const Variant& that) const { 14 | const Variant &a = *this, &b = that; 15 | if (a.__isset < b.__isset) { 16 | return true; 17 | } 18 | if (b.__isset < a.__isset) { 19 | return false; 20 | } 21 | if (a.__isset.v_boolean) { 22 | return a.v_boolean < b.v_boolean; 23 | } 24 | if (a.__isset.v_double) { 25 | return a.v_double < b.v_double; 26 | } 27 | if (a.__isset.v_short) { 28 | return a.v_short < b.v_short; 29 | } 30 | if (a.__isset.v_int) { 31 | return a.v_int < b.v_int; 32 | } 33 | if (a.__isset.v_long) { 34 | return a.v_long < b.v_long; 35 | } 36 | if (a.__isset.v_byte) { 37 | return a.v_byte < b.v_byte; 38 | } 39 | if (a.__isset.v_string) { 40 | return a.v_string < b.v_string; 41 | } 42 | if (a.__isset.v_list) { 43 | return std::lexicographical_compare(a.v_list.begin(), a.v_list.end(), b.v_list.begin(), b.v_list.end()); 44 | } 45 | if (a.__isset.v_set) { 46 | return std::lexicographical_compare(a.v_set.begin(), a.v_set.end(), b.v_set.begin(), b.v_set.end()); 47 | } 48 | if (a.__isset.v_map) { 49 | return std::lexicographical_compare(a.v_map.begin(), a.v_map.end(), b.v_map.begin(), b.v_map.end()); 50 | } 51 | assert(false); 52 | return false; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /API/CreditsHighLevelAPI/Server/keys.cpp: -------------------------------------------------------------------------------- 1 | #include "ac.h" 2 | #include "keys.h" 3 | #include "common/base58.h" 4 | 5 | keys::keys(const char* publicKey, const char* privateKey, const char* targetPublicKey) 6 | { 7 | m_publicKeyAddress = ac::address(publicKey); 8 | m_privateKeyAddress = ac::address(privateKey); 9 | m_targetPublicKeyAddress = ac::address(targetPublicKey); 10 | } 11 | 12 | const general::Address& keys::PublicKeyAddress() 13 | { 14 | return m_publicKeyAddress; 15 | } 16 | 17 | const general::Address& keys::PrivateKeyAddress() 18 | { 19 | return m_privateKeyAddress; 20 | } 21 | 22 | const general::Address& keys::TargetPublicKeyAddress() 23 | { 24 | return m_targetPublicKeyAddress; 25 | } 26 | -------------------------------------------------------------------------------- /API/CreditsHighLevelAPI/Server/keys.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "api/API.h" 4 | 5 | class keys 6 | { 7 | general::Address m_publicKeyAddress; 8 | general::Address m_privateKeyAddress; 9 | general::Address m_targetPublicKeyAddress; 10 | 11 | public: 12 | keys(const char* publicKey, const char* privateKey, const char* targetPublicKey); 13 | 14 | const char* PublicKey(); 15 | const char* PrivateKey(); 16 | const char* TargetPublicKey(); 17 | const general::Address& PublicKeyAddress(); 18 | const general::Address& PrivateKeyAddress(); 19 | const general::Address& TargetPublicKeyAddress(); 20 | }; 21 | 22 | -------------------------------------------------------------------------------- /API/CreditsHighLevelAPI/Server/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "api/API.h" 15 | #include "keys.h" 16 | #include "client.h" 17 | 18 | using namespace std; 19 | using namespace apache::thrift::transport; 20 | using namespace apache::thrift::protocol; 21 | using namespace api; 22 | using namespace general; 23 | 24 | int main(int argc, char* argv[]) 25 | { 26 | if (argc != 6) 27 | { 28 | cout << "Usage: main.exe NodeIpAddress NodePort YourPublicKey YourPrivateKey TargetPublicKey" << std::endl; 29 | return 1; 30 | } 31 | 32 | auto c = make_unique(argv[1], atoi(argv[2])); 33 | c->set_keys(argv[3], argv[4], argv[5]); 34 | 35 | cout << " ****** Credits API Demo C++ ******" << endl; 36 | 37 | cout << "****** Wallet Get Balance ******" << endl; 38 | c->wallet_balance_get(); 39 | cout << endl << " ****** End ******" << endl << endl; 40 | 41 | cout << "****** Transfer Coins ******" << endl; 42 | c->transfer_coins(1, 0, 0.9); 43 | cout << endl << " ****** End ******" << endl << endl; 44 | 45 | cout << endl << "****** Deploy Smart Contract ******" << endl; 46 | c->deploy_smart("", 1); 47 | cout << endl << " ****** End ******" << endl << endl; 48 | } 49 | 50 | -------------------------------------------------------------------------------- /API/CreditsHighLevelAPI/Server/patches/msvc141_retargeting17134.patch: -------------------------------------------------------------------------------- 1 | diff --git a/libsodium.vcxproj b/libsodium.vcxproj 2 | index eec2a525..62f1ffe1 100644 3 | --- a/libsodium.vcxproj 4 | +++ b/libsodium.vcxproj 5 | @@ -1,5 +1,5 @@ 6 |  7 | - 8 | + 9 | 10 | 11 | DebugDLL 12 | @@ -38,6 +38,7 @@ 13 | {A185B162-6CB6-4502-B03F-B56F7699A8D9} 14 | Win32Proj 15 | libsodium 16 | + 10.0.17134.0 17 | 18 | 19 | 20 | @@ -45,56 +46,56 @@ 21 | true 22 | MultiByte 23 | false 24 | - v140 25 | + v141 26 | 27 | 28 | DynamicLibrary 29 | true 30 | MultiByte 31 | false 32 | - v140 33 | + v141 34 | 35 | 36 | StaticLibrary 37 | true 38 | MultiByte 39 | false 40 | - v140 41 | + v141 42 | 43 | 44 | DynamicLibrary 45 | true 46 | MultiByte 47 | false 48 | - v140 49 | + v141 50 | 51 | 52 | StaticLibrary 53 | false 54 | true 55 | MultiByte 56 | - v140 57 | + v141 58 | 59 | 60 | DynamicLibrary 61 | false 62 | true 63 | MultiByte 64 | - v140 65 | + v141 66 | 67 | 68 | StaticLibrary 69 | false 70 | true 71 | MultiByte 72 | - v140 73 | + v141 74 | 75 | 76 | DynamicLibrary 77 | false 78 | true 79 | MultiByte 80 | - v140 81 | + v141 82 | 83 | 84 | 85 | @@ -559,4 +560,4 @@ 86 | 87 | 88 | 89 | - 90 | + 91 | \ No newline at end of file 92 | diff --git a/libsodium.vcxproj.filters b/libsodium.vcxproj.filters 93 | index 8325e43c..d43187c1 100644 94 | --- a/libsodium.vcxproj.filters 95 | +++ b/libsodium.vcxproj.filters 96 | @@ -716,5 +716,13 @@ 97 | 98 | Header Files 99 | 100 | + 101 | + Header Files 102 | + 103 | + 104 | + 105 | + 106 | + Resource Files 107 | + 108 | 109 | - 110 | + 111 | \ No newline at end of file 112 | -------------------------------------------------------------------------------- /API/CreditsHighLevelAPI/Server/patches/msvc141_retargeting17763.patch: -------------------------------------------------------------------------------- 1 | diff --git a/libsodium.vcxproj b/libsodium.vcxproj 2 | index eec2a525..62f1ffe1 100644 3 | --- a/libsodium.vcxproj 4 | +++ b/libsodium.vcxproj 5 | @@ -1,5 +1,5 @@ 6 |  7 | - 8 | + 9 | 10 | 11 | DebugDLL 12 | @@ -38,6 +38,7 @@ 13 | {A185B162-6CB6-4502-B03F-B56F7699A8D9} 14 | Win32Proj 15 | libsodium 16 | + 10.0.17763.0 17 | 18 | 19 | 20 | @@ -45,56 +46,56 @@ 21 | true 22 | MultiByte 23 | false 24 | - v140 25 | + v141 26 | 27 | 28 | DynamicLibrary 29 | true 30 | MultiByte 31 | false 32 | - v140 33 | + v141 34 | 35 | 36 | StaticLibrary 37 | true 38 | MultiByte 39 | false 40 | - v140 41 | + v141 42 | 43 | 44 | DynamicLibrary 45 | true 46 | MultiByte 47 | false 48 | - v140 49 | + v141 50 | 51 | 52 | StaticLibrary 53 | false 54 | true 55 | MultiByte 56 | - v140 57 | + v141 58 | 59 | 60 | DynamicLibrary 61 | false 62 | true 63 | MultiByte 64 | - v140 65 | + v141 66 | 67 | 68 | StaticLibrary 69 | false 70 | true 71 | MultiByte 72 | - v140 73 | + v141 74 | 75 | 76 | DynamicLibrary 77 | false 78 | true 79 | MultiByte 80 | - v140 81 | + v141 82 | 83 | 84 | 85 | @@ -559,4 +560,4 @@ 86 | 87 | 88 | 89 | - 90 | + 91 | \ No newline at end of file 92 | diff --git a/libsodium.vcxproj.filters b/libsodium.vcxproj.filters 93 | index 8325e43c..d43187c1 100644 94 | --- a/libsodium.vcxproj.filters 95 | +++ b/libsodium.vcxproj.filters 96 | @@ -716,5 +716,13 @@ 97 | 98 | Header Files 99 | 100 | + 101 | + Header Files 102 | + 103 | + 104 | + 105 | + 106 | + Resource Files 107 | + 108 | 109 | - 110 | + 111 | \ No newline at end of file 112 | -------------------------------------------------------------------------------- /API/CreditsHighLevelAPI/Server/patches/msvc142_retargeting.patch: -------------------------------------------------------------------------------- 1 | diff --git a/libsodium.vcxproj b/libsodium.vcxproj 2 | index 63d5f956..e2d028d9 100644 3 | --- a/libsodium.vcxproj 4 | +++ b/libsodium.vcxproj 5 | @@ -45,56 +45,56 @@ 6 | true 7 | MultiByte 8 | false 9 | - v140 10 | + v142 11 | 12 | 13 | DynamicLibrary 14 | true 15 | MultiByte 16 | false 17 | - v140 18 | + v142 19 | 20 | 21 | StaticLibrary 22 | true 23 | MultiByte 24 | false 25 | - v140 26 | + v142 27 | 28 | 29 | DynamicLibrary 30 | true 31 | MultiByte 32 | false 33 | - v140 34 | + v142 35 | 36 | 37 | StaticLibrary 38 | false 39 | true 40 | MultiByte 41 | - v140 42 | + v142 43 | 44 | 45 | DynamicLibrary 46 | false 47 | true 48 | MultiByte 49 | - v140 50 | + v142 51 | 52 | 53 | StaticLibrary 54 | false 55 | true 56 | MultiByte 57 | - v140 58 | + v142 59 | 60 | 61 | DynamicLibrary 62 | false 63 | true 64 | MultiByte 65 | - v140 66 | + v142 67 | 68 | 69 | 70 | @@ -560,4 +560,4 @@ 71 | 72 | 73 | 74 | - 75 | + 76 | \ No newline at end of file 77 | diff --git a/libsodium.vcxproj.filters b/libsodium.vcxproj.filters 78 | index b4a4ea96..467dd988 100644 79 | --- a/libsodium.vcxproj.filters 80 | +++ b/libsodium.vcxproj.filters 81 | @@ -719,5 +719,13 @@ 82 | 83 | Header Files 84 | 85 | + 86 | + Header Files 87 | + 88 | + 89 | + 90 | + 91 | + Resource Files 92 | + 93 | 94 | - 95 | + 96 | \ No newline at end of file 97 | -------------------------------------------------------------------------------- /API/CreditsHighLevelAPI/Server/runme.cmd: -------------------------------------------------------------------------------- 1 | .\build64\release\server.exe 2 | pause -------------------------------------------------------------------------------- /API/CreditsHighLevelAPI/Server/runme.sh: -------------------------------------------------------------------------------- 1 | ./build64/main -------------------------------------------------------------------------------- /API/CreditsHighLevelAPI/Server/server.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | #include 14 | #include 15 | #include 16 | 17 | #include "hlapi/Api.h" 18 | #include "client.h" 19 | 20 | using namespace std; 21 | using namespace apache::thrift; 22 | using namespace apache::thrift::concurrency; 23 | using namespace apache::thrift::protocol; 24 | using namespace apache::thrift::transport; 25 | using namespace apache::thrift::server; 26 | 27 | class ApiHandler : public hlapi::api::ApiIf { 28 | public: 29 | ApiHandler() {} 30 | 31 | void Hello(std::string& _return) 32 | { 33 | std::cout << "Hello()" << std::endl; 34 | _return = "Hello"; 35 | } 36 | 37 | void GetBalance(hlapi::api::Amount& _return, const std::string& publicKey) 38 | { 39 | try 40 | { 41 | std::cout << "GetBalance()" << std::endl; 42 | 43 | client cl{ "127.0.0.1", 9090 }; 44 | cl.set_keys(publicKey, "", ""); 45 | auto wbg = cl.wallet_balance_get(); 46 | 47 | _return.integral = wbg->balance.integral; 48 | _return.fraction = wbg->balance.fraction; 49 | 50 | std::cout << std::endl; 51 | std::cout << "GetBalance is OK" << std::endl; 52 | } 53 | catch (const std::exception& ex) 54 | { 55 | std::cout << ex.what() << std::endl; 56 | _return.message = ex.what(); 57 | } 58 | } 59 | 60 | void TransferCoins(std::string& _return, const std::string& publicKey, const std::string& privateKey, const std::string& targetKey, const int32_t integral, const int64_t fraction, const double fee) 61 | { 62 | try 63 | { 64 | std::cout << "TransferCoins()" << std::endl; 65 | 66 | client cl{ "127.0.0.1", 9090 }; 67 | cl.set_keys(publicKey, privateKey, targetKey); 68 | cl.transfer_coins(integral, fraction, fee); 69 | 70 | std::cout << std::endl; 71 | std::cout << "TransferCoins is OK" << std::endl; 72 | } 73 | catch (const std::exception& ex) 74 | { 75 | std::cout << ex.what() << std::endl; 76 | _return = ex.what(); 77 | } 78 | } 79 | 80 | void DeploySmartContract(std::string& _return, const std::string& publicKey, const std::string& privateKey, const std::string& targetKey, const std::string& code, const double fee) 81 | { 82 | try 83 | { 84 | std::cout << "DeploySmartContract()" << std::endl; 85 | 86 | client cl{ "127.0.0.1", 9090 }; 87 | cl.set_keys(publicKey, privateKey, targetKey); 88 | cl.deploy_smart(code, fee); 89 | 90 | std::cout << std::endl; 91 | std::cout << "DeploySmartContract is OK" << std::endl; 92 | } 93 | catch (const std::exception& ex) 94 | { 95 | std::cout << ex.what() << std::endl; 96 | _return = ex.what(); 97 | } 98 | } 99 | }; 100 | 101 | class ApiCloneFactory : virtual public hlapi::api::ApiIfFactory { 102 | public: 103 | virtual ~ApiCloneFactory() {} 104 | virtual hlapi::api::ApiIf* getHandler(const ::apache::thrift::TConnectionInfo& connInfo) 105 | { 106 | stdcxx::shared_ptr sock = stdcxx::dynamic_pointer_cast(connInfo.transport); 107 | cout << "Incoming connection\n"; 108 | cout << "\tSocketInfo: " << sock->getSocketInfo() << "\n"; 109 | cout << "\tPeerHost: " << sock->getPeerHost() << "\n"; 110 | cout << "\tPeerAddress: " << sock->getPeerAddress() << "\n"; 111 | cout << "\tPeerPort: " << sock->getPeerPort() << "\n"; 112 | return new ApiHandler; 113 | } 114 | virtual void releaseHandler(hlapi::api::ApiIf* handler) { 115 | delete handler; 116 | } 117 | }; 118 | 119 | int main() 120 | { 121 | //TThreadedServer server( 122 | // stdcxx::make_shared(stdcxx::make_shared()), 123 | // stdcxx::make_shared(9099), //port 124 | // stdcxx::make_shared(), 125 | // stdcxx::make_shared()); 126 | 127 | // if you don't need per-connection state, do the following instead 128 | //TThreadedServer server( 129 | // stdcxx::make_shared(stdcxx::make_shared()), 130 | // stdcxx::make_shared(9099), //port 131 | // stdcxx::make_shared(), 132 | // stdcxx::make_shared()); 133 | 134 | /** 135 | * Here are some alternate server types... 136 | 137 | // This server only allows one connection at a time, but spawns no threads 138 | TSimpleServer server( 139 | stdcxx::make_shared(stdcxx::make_shared()), 140 | stdcxx::make_shared(9099), 141 | stdcxx::make_shared(), 142 | stdcxx::make_shared()); 143 | 144 | */ 145 | 146 | const int workerCount = 4; 147 | 148 | stdcxx::shared_ptr threadManager = 149 | ThreadManager::newSimpleThreadManager(workerCount); 150 | threadManager->threadFactory( 151 | stdcxx::make_shared()); 152 | threadManager->start(); 153 | 154 | // This server allows "workerCount" connection at a time, and reuses threads 155 | TThreadPoolServer server( 156 | stdcxx::make_shared(stdcxx::make_shared()), 157 | stdcxx::make_shared(9099), 158 | stdcxx::make_shared(), 159 | stdcxx::make_shared(), 160 | threadManager); 161 | 162 | 163 | cout << "Starting the server..." << endl; 164 | server.serve(); 165 | cout << "Done." << endl; 166 | return 0; 167 | } -------------------------------------------------------------------------------- /API/CreditsHighLevelAPI/thrift/hlapi.thrift: -------------------------------------------------------------------------------- 1 | namespace cpp hlapi.api 2 | namespace java hlapi.api 3 | namespace php hlapi.api 4 | namespace netcore hlapi.api 5 | namespace netcore hlapi.api 6 | namespace js hlapi.api 7 | 8 | struct Amount 9 | { 10 | 1: i32 integral, 11 | 2: i64 fraction, 12 | 3: string message 13 | } 14 | 15 | service Api 16 | { 17 | string Hello() 18 | Amount GetBalance(1: string publicKey) 19 | string TransferCoins(1: string publicKey, 2: string privateKey, 3: string targetKey, 4: i32 integral, 5: i64 fraction, 6: double fee) 20 | string DeploySmartContract(1: string publicKey, 2: string privateKey, 3: string targetKey, 4: string code, 5: double fee) 21 | } -------------------------------------------------------------------------------- /API/CreditsJSDemo/README.md: -------------------------------------------------------------------------------- 1 | ## CreditsJSDemo 2 | https://developers.credits.com/en/Articles/a_Using_of_Credits_API_in_JS_(demo) 3 | 4 | A simple console JS application
5 | Using the public key of the wallet displays the balance. 6 | 7 | ## Requirements 8 | Git is a free and open source distributed version of control system designed to handle everything from small to very large projects with speed and efficiency.
9 | https://git-scm.com/ 10 | 11 | ## Transaction field(Length in bytes) 12 | Id (6 bytes)
13 | Source (32 bytes)
14 | Target (32 bytes)
15 | Amount.Integral (4 bytes)
16 | Amount.Fraction (8 bytes)
17 | Fee.Commission (2 bytes)
18 | Currency (1 bytes)
19 | 20 | ## Which transaction fields must be filled 21 | ```shell 22 | var tran = new Transaction(); 23 | 24 | //Internal transaction number (id) 25 | let res = this.client().WalletTransactionsCountGet(this.publicKeyByte); 26 | if (res.status.code === 0) { 27 | tran.id = res.lastTransactionInnerId + 1; 28 | } 29 | else { 30 | return null; 31 | } 32 | 33 | //Original/input/initial wallet byte array 34 | tran.source = this.publicKeyByte; 35 | //Target wallet byte array 36 | tran.target = this.targetKeyByte; 37 | //Quantity of transferable coins 38 | tran.amount = new Amount({integral: amountVal, fraction: 0}); 39 | 40 | let F = this.fee(feeValue); 41 | let FE = this.numbToBits(F.exp); 42 | while (FE.length < 5){ 43 | FE = "0" + FE; 44 | } 45 | let FM = this.numbToBits(F.man); 46 | while (FM.length < 10) { 47 | FM = "0" + FM; 48 | } 49 | 50 | //Commission 51 | tran.fee = new AmountCommission({ 52 | commission: this.bitsToNumb("0" + FE + FM) 53 | }); 54 | 55 | tran.currency = 1; 56 | ``` 57 | 58 | Field completion for transaction signature
59 | It is necessary create a byte array with a size of 85 bytes
60 | Last element of the array is filled out with zero (0).
61 | 62 | ## Concern 63 | It is necessary to convert commission value from double to short. For example: 64 | ```shell 65 | 66 | fee(v) { 67 | let s = v > 0 ? 0 : 1; 68 | v = Math.abs(v); 69 | let exp = v === 0 ? 0 : Math.log10(v); 70 | exp = Math.floor(exp >= 0 ? exp + 0.5 : exp - 0.5); 71 | v /= Math.pow(10, exp); 72 | if (v >= 1) { 73 | v *= 0.1; 74 | ++exp; 75 | } 76 | v = Number((v * 1024).toFixed(0)); 77 | return { exp: exp + 18, man: v === 1024 ? 1023 : v }; 78 | } 79 | ``` 80 | 81 | ## Using: 82 | ### Build for Windows 83 | ```shell 84 | build.cmd 85 | ``` 86 | 87 | ### The content of build.cmd 88 | ```shell 89 | rmdir /S /Q build64 90 | rmdir /S /Q CS-API 91 | rmdir /S /Q thrift 92 | rmdir /S /Q api 93 | rmdir /S /Q general 94 | 95 | git clone https://github.com/CREDITSCOM/thrift-interface-definitions 96 | mkdir api 97 | mkdir general 98 | thrift.exe -gen js -out .\api .\thrift-interface-definitions\api.thrift 99 | thrift.exe -gen js -out .\general .\thrift-interface-definitions\general.thrift 100 | ``` 101 | 102 | ### Run 103 | Opem the index.html int the favorite browser 104 | 105 | ### Build for Linux: 106 | ```shell 107 | ./build.sh 108 | ``` 109 | 110 | ### The content of build.sh 111 | ```shell 112 | rm -r -f CS-API 113 | rm -r -f api 114 | rm -r -f general 115 | 116 | git clone https://github.com/CREDITSCOM/thrift-interface-definitions 117 | mkdir api 118 | mkdir general 119 | thrift -gen js -out .\api .\thrift-interface-definitions\api.thrift 120 | thrift -gen js -out .\general .\thrift-interface-definitions\general.thrift 121 | ``` 122 | 123 | ### Run 124 | Open the index.html in the your favorite browser 125 | -------------------------------------------------------------------------------- /API/CreditsJSDemo/base58.js: -------------------------------------------------------------------------------- 1 | function to_b58( 2 | B, //Uint8Array raw byte input 3 | ) { 4 | var A = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; 5 | var d = [], //the array for storing the stream of base58 digits 6 | s = "", //the result string variable that will be returned 7 | i, //the iterator variable for the byte input 8 | j, //the iterator variable for the base58 digit array (d) 9 | c, //the carry amount variable that is used to overflow from the current base58 digit to the next base58 digit 10 | n; //a temporary placeholder variable for the current base58 digit 11 | for(i in B) { //loop through each byte in the input stream 12 | j = 0, //reset the base58 digit iterator 13 | c = B[i]; //set the initial carry amount equal to the current byte amount 14 | s += c || s.length ^ i ? "" : 1; //prepend the result string with a "1" (0 in base58) if the byte stream is zero and non-zero bytes haven't been seen yet (to ensure correct decode length) 15 | while(j in d || c) { //start looping through the digits until there are no more digits and no carry amount 16 | n = d[j]; //set the placeholder for the current base58 digit 17 | n = n ? n * 256 + c : c; //shift the current base58 one byte and add the carry amount (or just add the carry amount if this is a new digit) 18 | c = n / 58 | 0; //find the new carry amount (floored integer of current digit divided by 58) 19 | d[j] = n % 58; //reset the current base58 digit to the remainder (the carry amount will pass on the overflow) 20 | j++ //iterate to the next base58 digit 21 | } 22 | } 23 | while(j--) //since the base58 digits are backwards, loop through them in reverse order 24 | s += A[d[j]]; //lookup the character associated with each base58 digit 25 | return s //return the final base58 string 26 | } 27 | 28 | 29 | function from_b58( 30 | S, //Base58 encoded string input 31 | ) { 32 | var A = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"; 33 | var d = [], //the array for storing the stream of decoded bytes 34 | b = [], //the result byte array that will be returned 35 | i, //the iterator variable for the base58 string 36 | j, //the iterator variable for the byte array (d) 37 | c, //the carry amount variable that is used to overflow from the current byte to the next byte 38 | n; //a temporary placeholder variable for the current byte 39 | for(i in S) { //loop through each base58 character in the input string 40 | j = 0, //reset the byte iterator 41 | c = A.indexOf( S[i] ); //set the initial carry amount equal to the current base58 digit 42 | if(c < 0) //see if the base58 digit lookup is invalid (-1) 43 | return undefined; //if invalid base58 digit, bail out and return undefined 44 | c || b.length ^ i ? i : b.push(0); //prepend the result array with a zero if the base58 digit is zero and non-zero characters haven't been seen yet (to ensure correct decode length) 45 | while(j in d || c) { //start looping through the bytes until there are no more bytes and no carry amount 46 | n = d[j]; //set the placeholder for the current byte 47 | n = n ? n * 58 + c : c; //shift the current byte 58 units and add the carry amount (or just add the carry amount if this is a new byte) 48 | c = n >> 8; //find the new carry amount (1-byte shift of current byte value) 49 | d[j] = n % 256; //reset the current byte to the remainder (the carry amount will pass on the overflow) 50 | j++ //iterate to the next byte 51 | } 52 | } 53 | while(j--) //since the byte array is backwards, loop through it in reverse order 54 | b.push( d[j] ); //append each byte to the result 55 | return new Uint8Array(b) //return the final byte array in Uint8Array format 56 | } -------------------------------------------------------------------------------- /API/CreditsJSDemo/build.cmd: -------------------------------------------------------------------------------- 1 | rmdir /S /Q thrift-interface-definitions 2 | rmdir /S /Q thrift 3 | rmdir /S /Q api 4 | rmdir /S /Q general 5 | 6 | git clone https://github.com/CREDITSCOM/thrift-interface-definitions 7 | mkdir api 8 | mkdir general 9 | thrift.exe -gen js -out .\api .\thrift-interface-definitions\api.thrift 10 | thrift.exe -gen js -out .\general .\thrift-interface-definitions\general.thrift 11 | -------------------------------------------------------------------------------- /API/CreditsJSDemo/build.sh: -------------------------------------------------------------------------------- 1 | rm -r -f thrift-interface-definitions 2 | rm -r -f api 3 | rm -r -f general 4 | 5 | git clone https://github.com/CREDITSCOM/thrift-interface-definitions 6 | mkdir api 7 | mkdir general 8 | thrift -gen js -out .\api .\thrift-interface-definitions\api.thrift 9 | thrift -gen js -out .\general .\thrift-interface-definitions\general.thrift 10 | -------------------------------------------------------------------------------- /API/CreditsJSDemo/clean.cmd: -------------------------------------------------------------------------------- 1 | rmdir /S /Q thrift-interface-definitions 2 | rmdir /S /Q api 3 | rmdir /S /Q general 4 | -------------------------------------------------------------------------------- /API/CreditsJSDemo/clean.sh: -------------------------------------------------------------------------------- 1 | rm -r -f thrift-interface-definitions 2 | rm -r -f api 3 | rm -r -f general 4 | -------------------------------------------------------------------------------- /API/CreditsJSDemo/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | CREDITS API JS Demo 17 | 50 | 51 | 52 |

Public Key

53 |
54 |

Empty

55 | 56 |

Balance

57 |
58 |

0

59 | 60 |

Transaction State

61 |
62 |

0

63 | 64 | 65 | -------------------------------------------------------------------------------- /API/CreditsPythonApiDemo/README.md: -------------------------------------------------------------------------------- 1 | ## CreditsPythonApiDemo 2 | https://developers.credits.com/en/Articles/a_Using_of_Credits_API_in_Python_3_(demo) 3 | 4 | A simple console Python application
5 | Using the public key of the wallet displays the balance. 6 | 7 | ## Requirements 8 | Git is a free and open source distributed version of control system designed to handle everything from small to very large projects with speed and efficiency.
9 | https://git-scm.com/ 10 | 11 | Python is a programming language that lets you work quickly and integrate systems more effectively.
12 | https://www.python.org/ 13 | 14 | The Apache Thrift software framework is designed for development of scalable cross-language services. It combines a software stack with a code generation engine in order to build services that interact efficiently and seamlessly with C++, Java, Python, PHP, Ruby, Erlang, Perl, Haskell, C#, Cocoa, JavaScript, Node.js, Smalltalk, OCaml and Delphi and other languages.
15 | https://thrift.apache.org/ 16 | 17 | ## Transaction field(Length in bytes) 18 | Id (6 bytes)
19 | Source (32 bytes)
20 | Target (32 bytes)
21 | Amount.Integral (4 bytes)
22 | Amount.Fraction (8 bytes)
23 | Fee.Commission (2 bytes)
24 | Currency (1 bytes)
25 | 26 | ## Concern 27 | It is necessary to convert commission value from double to short. For example: 28 | 29 | ```shell 30 | // commission 31 | tr.fee.commission = self.__fee(0.9) 32 | 33 | def __fee(self, value): 34 | sign = 0 35 | if value < 0.0: 36 | value = 1 37 | value = abs(value) 38 | expf = 0 39 | if value != 0.0: 40 | expf = math.log10(value) 41 | if expf >= 0: 42 | expf = expf + .5 43 | else: 44 | expf = expf - .5 45 | expi = int(expf) 46 | value /= math.pow(10, expi) 47 | if value >= 1.0: 48 | value *= 0.1 49 | expi = expi + 1 50 | exp = expi + 18 51 | if exp < 0 or exp > 28: 52 | print('exponent value {0} out of range [0, 28]'.format(exp)) 53 | return -1 54 | frac = round(value * 1024) 55 | return sign * 32768 + exp * 1024 + frac 56 | ``` 57 | 58 | ## Using: 59 | ### Build for Windows 60 | ```shell 61 | build-windows.cmd 62 | ``` 63 | 64 | ### The content of build-windows.cmd 65 | ```shell 66 | rmdir /S /Q thrift-interface-definitions 67 | rmdir /S /Q api 68 | rmdir /S /Q general 69 | rmdir /S /Q env 70 | 71 | git clone https://github.com/CREDITSCOM/thrift-interface-definitions 72 | thrift -gen py -out . .\thrift-interface-definitions\general.thrift 73 | thrift -gen py -out . .\thrift-interface-definitions\api.thrift 74 | python -m venv env 75 | call env\Scripts\activate.bat 76 | pip install thrift 77 | pip install base58 78 | pip install ed25519 79 | call env\Scripts\deactivate.bat 80 | pause 81 | ``` 82 | 83 | ### Run 84 | ```shell 85 | run.cmd 86 | ``` 87 | 88 | ### The content of run.cmd 89 | ```shell 90 | call env\Scripts\activate.bat 91 | python app.py 92 | call env\Scripts\deactivate.bat 93 | pause 94 | ``` 95 | 96 | ### Build for Linux: 97 | ```shell 98 | ./build-linux.sh 99 | ``` 100 | ### The content of build-linux.sh 101 | ```shell 102 | git clone https://github.com/CREDITSCOM/thrift-interface-definitions 103 | thrift -gen py -out . ./thrift-interface-definitions/general.thrift 104 | thrift -gen py -out . ./thrift-interface-definitions/api.thrift 105 | python3 -m venv env 106 | chmod +x env/bin/activate 107 | env/bin/activate 108 | pip3 install thrift 109 | pip3 install base58 110 | pip3 install ed25519 111 | env/bin/deactivate 112 | ``` 113 | 114 | ### Run 115 | ```shell 116 | ./runme.sh 117 | ``` 118 | ### The content of runme.sh 119 | ```shell 120 | env/bin/activate 121 | python3 app.py 122 | env/bin/deactivate 123 | ``` 124 | -------------------------------------------------------------------------------- /API/CreditsPythonApiDemo/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CREDITSCOM/examples/57e9a3c433be653c9106fa1bcbf947d1d03bf0b7/API/CreditsPythonApiDemo/__init__.py -------------------------------------------------------------------------------- /API/CreditsPythonApiDemo/app.py: -------------------------------------------------------------------------------- 1 | import sys 2 | from keys import Keys 3 | from clientex import ClientEx 4 | 5 | 6 | def main(): 7 | if len(sys.argv) != 5: 8 | print('Welcome to the Credits API Python Demo') 9 | print('Usage: app.py NodeIpAddress:Port YourPublicKey YourPrivateKey TargetPublicKey') 10 | print('') 11 | return 12 | 13 | keys = Keys(sys.argv[2], sys.argv[3], sys.argv[4]) 14 | 15 | # try: 16 | # client = ClientEx(sys.argv[1].split(':')) 17 | # print(client.wallet_balance_get(keys.public_key_bytes)) 18 | # client.execute_transaction(keys) 19 | # client.close() 20 | # 21 | # except: 22 | # print("Oops. Unexpected error.") 23 | 24 | client = ClientEx(sys.argv[1].split(':')) 25 | print(client.wallet_balance_get(keys.public_key_bytes)) 26 | client.transfer_coins(1, 0, 0.9, keys) 27 | #client.deploy_smart_contract('', 0.9, keys) 28 | 29 | client.close() 30 | 31 | if __name__ == '__main__': 32 | main() 33 | -------------------------------------------------------------------------------- /API/CreditsPythonApiDemo/build-linux.sh: -------------------------------------------------------------------------------- 1 | git clone https://github.com/CREDITSCOM/thrift-interface-definitions 2 | thrift -gen py -out . ./thrift-interface-definitions/general.thrift 3 | thrift -gen py -out . ./thrift-interface-definitions/api.thrift 4 | python3 -m venv env 5 | chmod +x env/bin/activate 6 | env/bin/activate 7 | pip3 install thrift 8 | pip3 install base58 9 | pip3 install ed25519 10 | env/bin/deactivate 11 | -------------------------------------------------------------------------------- /API/CreditsPythonApiDemo/build-windows.cmd: -------------------------------------------------------------------------------- 1 | rmdir /S /Q thrift-interface-definitions 2 | rmdir /S /Q api 3 | rmdir /S /Q general 4 | rmdir /S /Q env 5 | 6 | git clone https://github.com/CREDITSCOM/thrift-interface-definitions 7 | thrift -gen py -out . .\thrift-interface-definitions\general.thrift 8 | thrift -gen py -out . .\thrift-interface-definitions\api.thrift 9 | c:\Python38-32\python -m venv env 10 | call env\Scripts\activate.bat 11 | pip install thrift 12 | pip install base58 13 | pip install ed25519 14 | call env\Scripts\deactivate.bat 15 | pause -------------------------------------------------------------------------------- /API/CreditsPythonApiDemo/clean.cmd: -------------------------------------------------------------------------------- 1 | rmdir /S /Q thrift-interface-definitions 2 | rmdir /S /Q api 3 | rmdir /S /Q general 4 | rmdir /S /Q env -------------------------------------------------------------------------------- /API/CreditsPythonApiDemo/clean.sh: -------------------------------------------------------------------------------- 1 | rm -r -f build64 2 | rm -r -f thrift-interface-definitions 3 | rm -r -f thrift 4 | rm -r -f api 5 | -------------------------------------------------------------------------------- /API/CreditsPythonApiDemo/clientex.py: -------------------------------------------------------------------------------- 1 | import hashlib 2 | import math 3 | from struct import pack 4 | 5 | import ed25519 6 | from thrift.protocol.TBinaryProtocol import TBinaryProtocol 7 | from thrift.transport.TSocket import TSocket 8 | 9 | from api.API import Client, Transaction, AmountCommission, SmartContractInvocation, SmartContractDeploy 10 | from general.ttypes import Amount, ByteCodeObject 11 | 12 | 13 | class ClientEx: 14 | 15 | def __init__(self, address): 16 | self.tr = TSocket(address[0], address[1]) 17 | self.protocol = TBinaryProtocol(self.tr) 18 | self.client = Client(self.protocol) 19 | self.tr.open() 20 | 21 | def close(self): 22 | self.tr.close() 23 | 24 | def wallet_balance_get(self, pub_key_bytes): 25 | return self.client.WalletBalanceGet(pub_key_bytes) 26 | 27 | def __fee(self, value): 28 | sign = 0 29 | if value < 0.0: 30 | value = 1 31 | value = abs(value) 32 | expf = 0 33 | if value != 0.0: 34 | expf = math.log10(value) 35 | if expf >= 0: 36 | expf = expf + .5 37 | else: 38 | expf = expf - .5 39 | expi = int(expf) 40 | value /= math.pow(10, expi) 41 | if value >= 1.0: 42 | value *= 0.1 43 | expi = expi + 1 44 | exp = expi + 18 45 | if exp < 0 or exp > 28: 46 | print('exponent value {0} out of range [0, 28]'.format(exp)) 47 | return -1 48 | frac = round(value * 1024) 49 | return sign * 32768 + exp * 1024 + frac 50 | 51 | def transfer_coins(self, integral, fraction, fee, keys): 52 | res = self.client.TransactionFlow(self.create_transaction(integral, fraction, fee, keys)) 53 | print(res) 54 | 55 | def create_transaction(self, integral, fraction, fee, keys): 56 | tr = Transaction() 57 | tr.id = self.client.WalletTransactionsCountGet(keys.public_key_bytes).lastTransactionInnerId + 1 58 | tr.source = keys.public_key_bytes 59 | tr.target = keys.target_public_key_bytes 60 | tr.amount = Amount() 61 | tr.amount.integral = integral 62 | tr.amount.fraction = fraction 63 | tr.currency = 1 64 | 65 | tr.fee = AmountCommission() 66 | tr.fee.commission = self.__fee(fee) 67 | 68 | serial_transaction = pack('=6s32s32slqhbb', # '=' - without alignment' 69 | bytearray(tr.id.to_bytes(6, 'little')), # 6s - 6 byte InnerID (char[] C Type) 70 | tr.source, # 32s - 32 byte source public key (char[] C Type) 71 | tr.target, # 32s - 32 byte target pyblic key (char[] C Type) 72 | tr.amount.integral, # i - 4 byte integer(int C Type) 73 | tr.amount.fraction, # q - 8 byte integer(long long C Type) 74 | tr.fee.commission, # h - 2 byte integer (short C Type) 75 | tr.currency, # b - 1 byte integer (signed char C Type) 76 | 0 # b - 1 byte userfield_num 77 | ) 78 | 79 | signing_key = ed25519.SigningKey(keys.private_key_bytes) 80 | sign = signing_key.sign(serial_transaction) 81 | tr.signature = sign 82 | 83 | return tr 84 | 85 | def deploy_smart_contract(self, code, fee, keys): 86 | res = self.client.TransactionFlow(self.create_transaction_with_smart_contract(code, fee, keys)) 87 | print(res) 88 | 89 | def create_transaction_with_smart_contract(self, code, fee, keys): 90 | 91 | if code == "": 92 | code = 'import com.credits.scapi.annotations.*; import com.credits.scapi.v0.*; public class ' \ 93 | 'MySmartContract extends SmartContract { public MySmartContract() {} public String hello2(String ' \ 94 | 'say) { return \"Hello\" + say; } }'; 95 | 96 | tr = Transaction() 97 | tr.id = self.client.WalletTransactionsCountGet(keys.public_key_bytes).lastTransactionInnerId + 1 98 | tr.source = keys.public_key_bytes 99 | tr.target = keys.target_public_key_bytes 100 | tr.amount = Amount() 101 | tr.amount.integral = 0 102 | tr.amount.fraction = 0 103 | tr.currency = 1 104 | 105 | tr.fee = AmountCommission() 106 | tr.fee.commission = self.__fee(fee) 107 | 108 | serial_transaction = pack('=6s32s32slqhbb', # '=' - without alignment' 109 | bytearray(tr.id.to_bytes(6, 'little')), # 6s - 6 byte InnerID (char[] C Type) 110 | tr.source, # 32s - 32 byte source public key (char[] C Type) 111 | tr.target, # 32s - 32 byte target pyblic key (char[] C Type) 112 | tr.amount.integral, # i - 4 byte integer(int C Type) 113 | tr.amount.fraction, # q - 8 byte integer(long long C Type) 114 | tr.fee.commission, # h - 2 byte integer (short C Type) 115 | tr.currency, # b - 1 byte integer (signed char C Type) 116 | 1 # b - 1 byte userfield_num 117 | ) 118 | 119 | target = pack('=6s', bytearray(tr.id.to_bytes(6, 'little'))) 120 | byte_code = self.client.SmartContractCompile(code) 121 | if byte_code.status.code == 0: 122 | for bco in byte_code.byteCodeObjects: 123 | target = target + bco.byteCode 124 | else: 125 | print(byte_code.Status.Message) 126 | return 'compile error' 127 | 128 | tr.smartContract = SmartContractInvocation() 129 | tr.smartContract.smartContractDeploy = SmartContractDeploy() 130 | tr.smartContract.smartContractDeploy.sourceCode = code 131 | 132 | tr.smartContract.ForgetNewState = False 133 | tr.target = hashlib.blake2s(target).hexdigest() 134 | 135 | uf = bytearray(b'\x11\x00\x01\x00\x00\x00\x00\x015\x00\x02\x12\x00\x00\x00\x00\x15\x00\x03\x11\x00\x00\x00\x00\x02\x00\x04\x00\x12\x00\x05\x11\x00\x01') 136 | 137 | uf = uf + pack('=6s', self.reverse(len(code))) 138 | uf = uf + bytearray(code.encode()) 139 | uf = uf + bytearray(b'\x15\x00\x02\x12') 140 | uf = uf + self.reverse(len(byte_code.byteCodeObjects)) 141 | 142 | for bco in byte_code.byteCodeObjects: 143 | uf = uf + b'1101' 144 | uf = uf + self.reverse(len(bco.name)) 145 | uf = uf + bytearray(bco.name.encode()) 146 | uf = uf + b'1102' 147 | uf = uf + self.reverse(len(bco.byteCode)) 148 | uf = uf + bco.byteCode 149 | 150 | nbco = ByteCodeObject() 151 | nbco.name = bco.name 152 | nbco.byteCode = bco.byteCode 153 | 154 | tr.smartContract.smartContractDeploy.byteCodeObjects = [nbco] 155 | 156 | uf = uf + b'\x00' 157 | 158 | uf = uf + b'\x11\x00\x03\x00\x00\x00\x00\x08\x00\x04\x00\x00\x00\x00\x00' 159 | uf = uf + b'\x00' 160 | 161 | serial_transaction = serial_transaction + self.reverse(len(uf)) 162 | serial_transaction = serial_transaction + uf 163 | 164 | signing_key = ed25519.SigningKey(keys.private_key_bytes) 165 | sign = signing_key.sign(serial_transaction) 166 | tr.signature = sign 167 | 168 | return tr 169 | 170 | def reverse(self, a): 171 | a = a.to_bytes(6, 'little') 172 | a = bytearray(a) 173 | a.reverse() 174 | return a 175 | 176 | -------------------------------------------------------------------------------- /API/CreditsPythonApiDemo/keys.py: -------------------------------------------------------------------------------- 1 | import base58 2 | 3 | 4 | class Keys: 5 | def __init__(self, public_key, private_key, target_public_key): 6 | self.public_key = public_key 7 | self.private_key = private_key 8 | self.target_public_key = target_public_key 9 | self.public_key_bytes = base58.b58decode(public_key) 10 | self.private_key_bytes = base58.b58decode(private_key) 11 | self.target_public_key_bytes = base58.b58decode(target_public_key) 12 | 13 | -------------------------------------------------------------------------------- /API/CreditsPythonApiDemo/runme.cmd: -------------------------------------------------------------------------------- 1 | call env\Scripts\activate.bat 2 | python app.py 87.215.4.9:9090 35SR5JC6DA9pPd9xYQ7oRvvCgJKK7teLoMwDMBmEN45Q tvkphPU2Y6svC38FaWuer8zF2F7DsfNkqMsko76uL8Rdv5oztCqmcEwKWi5NbDgtsy7QDNe9vXhkHFQTATNFksc DXEiDtU7NHz8YdQEzugBXh3oqaVQ6nGHMkFPwLtnvZSG 3 | call env\Scripts\deactivate.bat 4 | 5 | pause -------------------------------------------------------------------------------- /API/CreditsPythonApiDemo/runme.sh: -------------------------------------------------------------------------------- 1 | env/bin/activate 2 | python3 app.py 3 | env/bin/deactivate -------------------------------------------------------------------------------- /API/CreditsRestApiCSharpDemo/Client.cs: -------------------------------------------------------------------------------- 1 | using Chaos.NaCl; 2 | using NodeApi; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Text; 6 | using Thrift.Protocol; 7 | using Thrift.Transport; 8 | 9 | namespace CreditsCSAPIDemo 10 | { 11 | class Client : IDisposable 12 | { 13 | TSocket transport; 14 | TBinaryProtocol protocol; 15 | API.Client api; 16 | public Keys keys; 17 | 18 | public Client(string ip, int port, string publicKey, string privateKey, string targetKey) 19 | { 20 | transport = new TSocket(ip, port); 21 | protocol = new TBinaryProtocol(transport); 22 | api = new API.Client(protocol); 23 | transport.Open(); 24 | 25 | keys = new Keys(); 26 | keys.PublicKey = publicKey; 27 | keys.PrivateKey = privateKey; 28 | keys.TargetKey = targetKey; 29 | } 30 | 31 | public void Dispose() 32 | { 33 | transport.Close(); 34 | } 35 | 36 | public WalletBalanceGetResult WalletGetBalance() 37 | { 38 | return api.WalletBalanceGet(keys.PublicKeyBytes); 39 | } 40 | 41 | public TransactionFlowResult TransferCoins(int integral, long fraction, double fee) 42 | { 43 | return api.TransactionFlow(CreateTransaction(integral, fraction, fee)); 44 | } 45 | 46 | public TransactionFlowResult DeploySmartContract(string smCode) 47 | { 48 | return api.TransactionFlow(CreateTransactionWithSmartContract(smCode)); 49 | } 50 | 51 | private Transaction CreateTransaction(int integral, long fraction, double fee) 52 | { 53 | var transaction = new Transaction(); 54 | transaction.Id = api.WalletTransactionsCountGet(keys.PublicKeyBytes).LastTransactionInnerId + 1; 55 | transaction.Source = keys.PublicKeyBytes; 56 | transaction.Target = keys.TargetKeyBytes; 57 | transaction.Amount = new Amount(integral, fraction); 58 | transaction.Fee = new AmountCommission(Fee(fee)); 59 | transaction.Currency = 1; 60 | 61 | var bytes = new byte[86]; 62 | Array.Copy(BitConverter.GetBytes(transaction.Id), 0, bytes, 0, 6); 63 | Array.Copy(transaction.Source, 0, bytes, 6, 32); 64 | Array.Copy(transaction.Target, 0, bytes, 38, 32); 65 | Array.Copy(BitConverter.GetBytes(transaction.Amount.Integral), 0, bytes, 70, 4); 66 | Array.Copy(BitConverter.GetBytes(transaction.Amount.Fraction), 0, bytes, 74, 8); 67 | Array.Copy(BitConverter.GetBytes(transaction.Fee.Commission), 0, bytes, 82, 2); 68 | bytes[84] = 1; 69 | bytes[85] = 0; 70 | 71 | var signature = Ed25519.Sign(bytes, keys.PrivateKeyBytes); 72 | var verifyResult = Ed25519.Verify(signature, bytes, keys.PublicKeyBytes); 73 | if (!verifyResult) throw new Exception("Signature could not be verified"); 74 | 75 | transaction.Signature = signature; 76 | return transaction; 77 | } 78 | 79 | private byte[] Reverse(byte[] arr) 80 | { 81 | Array.Reverse(arr, 0, arr.Length); 82 | return arr; 83 | } 84 | 85 | private Transaction CreateTransactionWithSmartContract(string smCode) 86 | { 87 | if (smCode == "") 88 | smCode = 89 | "import com.credits.scapi.annotations.*; import com.credits.scapi.v0.*; public class MySmartContract extends SmartContract { public MySmartContract() {} public String hello2(String say) { return \"Hello\" + say; } }"; 90 | 91 | var transaction = new Transaction(); 92 | transaction.Id = api.WalletTransactionsCountGet(keys.PublicKeyBytes).LastTransactionInnerId + 1; 93 | transaction.Source = keys.PublicKeyBytes; 94 | //transaction.Target = keys.PublicKeyBytes; 95 | transaction.Amount = new Amount(0, 0); 96 | transaction.Fee = new AmountCommission(Fee(1.0)); 97 | transaction.Currency = 1; 98 | 99 | var tarr = new byte[6]; 100 | List target = new List(transaction.Source); 101 | Array.Copy(BitConverter.GetBytes(transaction.Id), 0, tarr, 0, 6); 102 | target.AddRange(tarr); 103 | var byteCode = api.SmartContractCompile(smCode); 104 | if (byteCode.Status.Code == 0) 105 | { 106 | for (int i = 0; i < byteCode.ByteCodeObjects.Count; i++) 107 | { 108 | target.AddRange(byteCode.ByteCodeObjects[i].ByteCode); 109 | } 110 | } 111 | else 112 | { 113 | Console.WriteLine(byteCode.Status.Message); 114 | return null; 115 | } 116 | 117 | transaction.SmartContract = new SmartContractInvocation(); 118 | transaction.SmartContract.SmartContractDeploy = new SmartContractDeploy() 119 | { 120 | SourceCode = smCode, 121 | }; 122 | transaction.SmartContract.ForgetNewState = false; 123 | transaction.Target = SauceControl.Blake2Fast.Blake2s.ComputeHash(target.ToArray()); 124 | 125 | var bytes = new List(); 126 | 127 | Array.Copy(BitConverter.GetBytes(transaction.Id), 0, tarr, 0, 6); 128 | bytes.AddRange(tarr); 129 | bytes.AddRange(transaction.Source); 130 | bytes.AddRange(transaction.Target); 131 | bytes.AddRange(BitConverter.GetBytes(transaction.Amount.Integral)); 132 | bytes.AddRange(BitConverter.GetBytes(transaction.Amount.Fraction)); 133 | bytes.AddRange(BitConverter.GetBytes(transaction.Fee.Commission)); 134 | bytes.Add(1); 135 | bytes.Add(1); 136 | 137 | var uf = new List(); 138 | uf.AddRange(new byte[] { 11, 0, 1, 0, 0, 0, 0, 15, 0, 2, 12, 0, 0, 0, 0, 15, 0, 3, 11, 0, 0, 0, 0, 2, 0, 4, 0, 12, 0, 5, 11, 0, 1 }); 139 | 140 | uf.AddRange(Reverse(BitConverter.GetBytes(smCode.Length))); //reverse ??? 141 | 142 | uf.AddRange(Encoding.Default.GetBytes(smCode)); 143 | uf.AddRange(new byte[] { 15, 0, 2, 12 }); 144 | uf.AddRange(Reverse(BitConverter.GetBytes(byteCode.ByteCodeObjects.Count))); //reverse ??? 145 | 146 | foreach (var bco in byteCode.ByteCodeObjects) 147 | { 148 | 149 | uf.AddRange(new byte[] { 11, 0, 1 }); 150 | uf.AddRange(Reverse(BitConverter.GetBytes(bco.Name.Length))); //reverse ??? 151 | uf.AddRange(Encoding.Default.GetBytes(bco.Name)); 152 | uf.AddRange(new byte[] { 11, 0, 2 }); 153 | uf.AddRange(Reverse(BitConverter.GetBytes(bco.ByteCode.Length))); //reverse ??? 154 | uf.AddRange(bco.ByteCode); 155 | transaction.SmartContract.SmartContractDeploy.ByteCodeObjects = new List() 156 | { 157 | new ByteCodeObject() 158 | { 159 | Name = bco.Name, 160 | ByteCode = bco.ByteCode 161 | } 162 | }; 163 | 164 | uf.Add(0); 165 | } 166 | 167 | uf.AddRange(new byte[] { 11, 0, 3, 0, 0, 0, 0, 8, 0, 4, 0, 0, 0, 0, 0 }); 168 | uf.Add(0); 169 | 170 | bytes.AddRange(BitConverter.GetBytes(uf.Count)); //reverse ??? 171 | bytes.AddRange(uf.ToArray()); 172 | 173 | var signature = Ed25519.Sign(bytes.ToArray(), keys.PrivateKeyBytes); 174 | var verifyResult = Ed25519.Verify(signature, bytes.ToArray(), keys.PublicKeyBytes); 175 | if (!verifyResult) throw new Exception("Signature could not be verified"); 176 | 177 | foreach (var i in signature) 178 | { 179 | Console.Write(i); 180 | Console.Write(" "); 181 | } 182 | 183 | transaction.Signature = signature; 184 | return transaction; 185 | } 186 | 187 | private short Fee(Double value) 188 | { 189 | byte sign = (byte)(value < 0.0 ? 1 : 0); // sign 190 | int exp; // exponent 191 | long frac; // mantissa 192 | value = Math.Abs(value); 193 | double expf = value == 0.0 ? 0.0 : Math.Log10(value); 194 | int expi = Convert.ToInt32(expf >= 0 ? expf + 0.5 : expf - 0.5); 195 | value /= Math.Pow(10, expi); 196 | if (value >= 1.0) 197 | { 198 | value *= 0.1; 199 | ++expi; 200 | } 201 | exp = expi + 18; 202 | if (exp < 0 || exp > 28) 203 | { 204 | throw new Exception($"exponent value {exp} out of range [0, 28]"); 205 | } 206 | frac = (long)Math.Round(value * 1024); 207 | return (short)(sign * 32768 + exp * 1024 + frac); 208 | } 209 | } 210 | } 211 | -------------------------------------------------------------------------------- /API/CreditsRestApiCSharpDemo/Controllers/CreditsController.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using CreditsCSAPIDemo; 6 | using Microsoft.AspNetCore.Mvc; 7 | using NodeApi; 8 | 9 | namespace CreditsRestApiCSharpDemo.Controllers 10 | { 11 | [Route("api/[controller]")] 12 | [ApiController] 13 | public class CreditsController : ControllerBase 14 | { 15 | [HttpGet("{publicKey}")] 16 | public ActionResult GetBalance(string publicKey) 17 | { 18 | using (var client = new Client("127.0.0.1", 9091, publicKey, "", "")) 19 | { 20 | return client.WalletGetBalance(); 21 | } 22 | } 23 | 24 | [HttpGet("{integral}/{fraction}/{fee}/{publicKey}/{privateKey}/{targetKey}")] 25 | public ActionResult TransferCoins(int integral, long fraction, double fee, string publicKey, string privateKey, string targetKey) 26 | { 27 | using (var client = new Client("127.0.0.1", 9091, publicKey, privateKey, targetKey)) 28 | { 29 | return client.TransferCoins(integral, fraction, fee); 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /API/CreditsRestApiCSharpDemo/CreditsRestApiCSharpDemo.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp2.2 5 | InProcess 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /API/CreditsRestApiCSharpDemo/CreditsRestApiCSharpDemo.csproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | ProjectDebugger 5 | 6 | 7 | CreditsRestApiCSharpDemo 8 | 9 | -------------------------------------------------------------------------------- /API/CreditsRestApiCSharpDemo/Keys.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace CreditsCSAPIDemo 6 | { 7 | public class Keys 8 | { 9 | public string PublicKey { get; set; } 10 | public string PrivateKey { get; set; } 11 | public string TargetKey { get; set; } 12 | public byte[] PublicKeyBytes 13 | { 14 | get 15 | { 16 | return PublicKey != null ? SimpleBase.Base58.Bitcoin.Decode(PublicKey).ToArray() : null; 17 | } 18 | } 19 | public byte[] PrivateKeyBytes 20 | { 21 | get 22 | { 23 | return PrivateKey != null ? SimpleBase.Base58.Bitcoin.Decode(PrivateKey).ToArray() : null; 24 | } 25 | } 26 | public byte[] TargetKeyBytes 27 | { 28 | get 29 | { 30 | return TargetKey != null ? SimpleBase.Base58.Bitcoin.Decode(TargetKey).ToArray() : null; 31 | } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /API/CreditsRestApiCSharpDemo/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Threading.Tasks; 6 | using Microsoft.AspNetCore; 7 | using Microsoft.AspNetCore.Hosting; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.Logging; 10 | 11 | namespace CreditsRestApiCSharpDemo 12 | { 13 | public class Program 14 | { 15 | public static void Main(string[] args) 16 | { 17 | CreateWebHostBuilder(args).Build().Run(); 18 | } 19 | 20 | public static IWebHostBuilder CreateWebHostBuilder(string[] args) => 21 | WebHost.CreateDefaultBuilder(args) 22 | .UseStartup(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /API/CreditsRestApiCSharpDemo/Properties/launchSettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "http://json.schemastore.org/launchsettings.json", 3 | "iisSettings": { 4 | "windowsAuthentication": false, 5 | "anonymousAuthentication": true, 6 | "iisExpress": { 7 | "applicationUrl": "http://localhost:55609", 8 | "sslPort": 0 9 | } 10 | }, 11 | "profiles": { 12 | "IIS Express": { 13 | "commandName": "IISExpress", 14 | "launchBrowser": true, 15 | "launchUrl": "api/values", 16 | "environmentVariables": { 17 | "ASPNETCORE_ENVIRONMENT": "Development" 18 | } 19 | }, 20 | "CreditsRestApiCSharpDemo": { 21 | "commandName": "Project", 22 | "launchBrowser": true, 23 | "launchUrl": "api/values", 24 | "applicationUrl": "http://localhost:5000", 25 | "environmentVariables": { 26 | "ASPNETCORE_ENVIRONMENT": "Development" 27 | } 28 | } 29 | } 30 | } -------------------------------------------------------------------------------- /API/CreditsRestApiCSharpDemo/Readme.md: -------------------------------------------------------------------------------- 1 | ## CreditsRestApiCSharpDemo (C#) 2 | A simple demo of the Credits HTTP Rest Api 3 | -------------------------------------------------------------------------------- /API/CreditsRestApiCSharpDemo/Startup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Builder; 6 | using Microsoft.AspNetCore.Hosting; 7 | using Microsoft.AspNetCore.Mvc; 8 | using Microsoft.Extensions.Configuration; 9 | using Microsoft.Extensions.DependencyInjection; 10 | using Microsoft.Extensions.Logging; 11 | using Microsoft.Extensions.Options; 12 | 13 | namespace CreditsRestApiCSharpDemo 14 | { 15 | public class Startup 16 | { 17 | public Startup(IConfiguration configuration) 18 | { 19 | Configuration = configuration; 20 | } 21 | 22 | public IConfiguration Configuration { get; } 23 | 24 | // This method gets called by the runtime. Use this method to add services to the container. 25 | public void ConfigureServices(IServiceCollection services) 26 | { 27 | services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); 28 | } 29 | 30 | // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. 31 | public void Configure(IApplicationBuilder app, IHostingEnvironment env) 32 | { 33 | if (env.IsDevelopment()) 34 | { 35 | app.UseDeveloperExceptionPage(); 36 | } 37 | 38 | app.UseMvc(); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /API/CreditsRestApiCSharpDemo/appsettings.Development.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Debug", 5 | "System": "Information", 6 | "Microsoft": "Information" 7 | } 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /API/CreditsRestApiCSharpDemo/appsettings.json: -------------------------------------------------------------------------------- 1 | { 2 | "Logging": { 3 | "LogLevel": { 4 | "Default": "Warning" 5 | } 6 | }, 7 | "AllowedHosts": "*" 8 | } 9 | -------------------------------------------------------------------------------- /API/CreditsRestApiCSharpDemo/build-linux.sh: -------------------------------------------------------------------------------- 1 | git clone https://github.com/CREDITSCOM/thrift-interface-definitions 2 | thrift -gen csharp -out . ./thrift-interface-definitions/general.thrift 3 | thrift -gen csharp -out . ./thrift-interface-definitions/api.thrift 4 | dotnet add package apache-thrift-netcore --version 0.9.3.2 5 | dotnet add package SimpleBase --version 1.8.0 6 | -------------------------------------------------------------------------------- /API/CreditsRestApiCSharpDemo/build-windows.cmd: -------------------------------------------------------------------------------- 1 | git clone https://github.com/CREDITSCOM/thrift-interface-definitions 2 | thrift -gen csharp -out . .\thrift-interface-definitions\general.thrift 3 | thrift -gen csharp -out . .\thrift-interface-definitions\api.thrift 4 | dotnet add package apache-thrift-netcore --version 0.9.3.2 5 | dotnet add package SimpleBase --version 1.8.0 6 | pause -------------------------------------------------------------------------------- /API/CreditsRestApiCSharpDemo/clean.cmd: -------------------------------------------------------------------------------- 1 | rmdir /S /Q bin 2 | rmdir /S /Q thrift-interface-definitions 3 | rmdir /S /Q obj 4 | rmdir /S /Q NodeApi 5 | del Annotation.cs 6 | del Amount.cs 7 | del APIResponse.cs 8 | del ByteCodeObject.cs 9 | del MethodArgument.cs 10 | del MethodDescription.cs 11 | del Variant.cs 12 | del ClassObject.cs 13 | del object.cs 14 | -------------------------------------------------------------------------------- /API/CreditsRestApiCSharpDemo/clean.sh: -------------------------------------------------------------------------------- 1 | rm -r -f bin 2 | rm -r -f thrift-interface-definitions 3 | rm -r -f obj 4 | rm -r -f NodeApi 5 | 6 | rm Annotation.cs 7 | rm Amount.cs 8 | rm APIResponse.cs 9 | rm ByteCodeObject.cs 10 | rm MethodArgument.cs 11 | rm MethodDescription.cs 12 | rm Variant.cs 13 | rm ClassObject.cs 14 | rm object.cs 15 | -------------------------------------------------------------------------------- /API/CreditsRestApiCSharpDemo/runme.cmd: -------------------------------------------------------------------------------- 1 | dotnet run 2 | pause -------------------------------------------------------------------------------- /API/CreditsRestApiCSharpDemo/runme.sh: -------------------------------------------------------------------------------- 1 | dotnet run -------------------------------------------------------------------------------- /API/Readme.md: -------------------------------------------------------------------------------- 1 | # API (Linux/Windows) 2 | 3 | ## CreditsCPlusPlusDemoCMake 4 | 5 | A simple console C++ (CMake) application 6 | Using the public key of the wallet displays the balance. 7 | 8 | ## CreditsCSharpDemo 9 | A simple console C# (.NET Core) application.
10 | Using the public key of the wallet displays the balance.
11 | Allows to create a transaction (transfer coins from the current wallet to the specified one) and execute it. 12 | 13 | ## CreditsJSDemo 14 | A simple console JS application
15 | Using the public key of the wallet displays the balance. 16 | 17 | ## CreditsPythonApiDemo 18 | A simple console Python application
19 | Using the public key of the wallet displays the balance. 20 | 21 | ## CreditsHighLevelAPI (C++) 22 | A simple demo of the Credits High level API 23 | This one includes a server and a client application 24 | 25 | ## CreditsRestApiCSharpDemo (C#) 26 | A simple demo of the Credits HTTP Rest Api 27 | -------------------------------------------------------------------------------- /API/capi/.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/** 5 | !**/src/test/** 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | 30 | ### VS Code ### 31 | .vscode/ 32 | -------------------------------------------------------------------------------- /API/capi/.mvn/wrapper/MavenWrapperDownloader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2012-2019 the original author or authors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * https://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | import java.net.*; 17 | import java.io.*; 18 | import java.nio.channels.*; 19 | import java.util.Properties; 20 | 21 | public class MavenWrapperDownloader { 22 | 23 | private static final String WRAPPER_VERSION = "0.5.5"; 24 | /** 25 | * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. 26 | */ 27 | private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" 28 | + WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; 29 | 30 | /** 31 | * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to 32 | * use instead of the default one. 33 | */ 34 | private static final String MAVEN_WRAPPER_PROPERTIES_PATH = 35 | ".mvn/wrapper/maven-wrapper.properties"; 36 | 37 | /** 38 | * Path where the maven-wrapper.jar will be saved to. 39 | */ 40 | private static final String MAVEN_WRAPPER_JAR_PATH = 41 | ".mvn/wrapper/maven-wrapper.jar"; 42 | 43 | /** 44 | * Name of the property which should be used to override the default download url for the wrapper. 45 | */ 46 | private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; 47 | 48 | public static void main(String args[]) { 49 | System.out.println("- Downloader started"); 50 | File baseDirectory = new File(args[0]); 51 | System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); 52 | 53 | // If the maven-wrapper.properties exists, read it and check if it contains a custom 54 | // wrapperUrl parameter. 55 | File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); 56 | String url = DEFAULT_DOWNLOAD_URL; 57 | if(mavenWrapperPropertyFile.exists()) { 58 | FileInputStream mavenWrapperPropertyFileInputStream = null; 59 | try { 60 | mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); 61 | Properties mavenWrapperProperties = new Properties(); 62 | mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); 63 | url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); 64 | } catch (IOException e) { 65 | System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); 66 | } finally { 67 | try { 68 | if(mavenWrapperPropertyFileInputStream != null) { 69 | mavenWrapperPropertyFileInputStream.close(); 70 | } 71 | } catch (IOException e) { 72 | // Ignore ... 73 | } 74 | } 75 | } 76 | System.out.println("- Downloading from: " + url); 77 | 78 | File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); 79 | if(!outputFile.getParentFile().exists()) { 80 | if(!outputFile.getParentFile().mkdirs()) { 81 | System.out.println( 82 | "- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); 83 | } 84 | } 85 | System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); 86 | try { 87 | downloadFileFromURL(url, outputFile); 88 | System.out.println("Done"); 89 | System.exit(0); 90 | } catch (Throwable e) { 91 | System.out.println("- Error downloading"); 92 | e.printStackTrace(); 93 | System.exit(1); 94 | } 95 | } 96 | 97 | private static void downloadFileFromURL(String urlString, File destination) throws Exception { 98 | if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { 99 | String username = System.getenv("MVNW_USERNAME"); 100 | char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); 101 | Authenticator.setDefault(new Authenticator() { 102 | @Override 103 | protected PasswordAuthentication getPasswordAuthentication() { 104 | return new PasswordAuthentication(username, password); 105 | } 106 | }); 107 | } 108 | URL website = new URL(urlString); 109 | ReadableByteChannel rbc; 110 | rbc = Channels.newChannel(website.openStream()); 111 | FileOutputStream fos = new FileOutputStream(destination); 112 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); 113 | fos.close(); 114 | rbc.close(); 115 | } 116 | 117 | } 118 | -------------------------------------------------------------------------------- /API/capi/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CREDITSCOM/examples/57e9a3c433be653c9106fa1bcbf947d1d03bf0b7/API/capi/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /API/capi/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.2/apache-maven-3.6.2-bin.zip 2 | wrapperUrl=https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar 3 | -------------------------------------------------------------------------------- /API/capi/mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM https://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 50 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar" 124 | 125 | FOR /F "tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( 126 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 127 | ) 128 | 129 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 130 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 131 | if exist %WRAPPER_JAR% ( 132 | if "%MVNW_VERBOSE%" == "true" ( 133 | echo Found %WRAPPER_JAR% 134 | ) 135 | ) else ( 136 | if not "%MVNW_REPOURL%" == "" ( 137 | SET DOWNLOAD_URL="%MVNW_REPOURL%/io/takari/maven-wrapper/0.5.5/maven-wrapper-0.5.5.jar" 138 | ) 139 | if "%MVNW_VERBOSE%" == "true" ( 140 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 141 | echo Downloading from: %DOWNLOAD_URL% 142 | ) 143 | 144 | powershell -Command "&{"^ 145 | "$webclient = new-object System.Net.WebClient;"^ 146 | "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ 147 | "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ 148 | "}"^ 149 | "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ 150 | "}" 151 | if "%MVNW_VERBOSE%" == "true" ( 152 | echo Finished downloading %WRAPPER_JAR% 153 | ) 154 | ) 155 | @REM End of extension 156 | 157 | @REM Provide a "standardized" way to retrieve the CLI args that will 158 | @REM work with both Windows and non-Windows executions. 159 | set MAVEN_CMD_LINE_ARGS=%* 160 | 161 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 162 | if ERRORLEVEL 1 goto error 163 | goto end 164 | 165 | :error 166 | set ERROR_CODE=1 167 | 168 | :end 169 | @endlocal & set ERROR_CODE=%ERROR_CODE% 170 | 171 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 172 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 173 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 174 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 175 | :skipRcPost 176 | 177 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 178 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 179 | 180 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 181 | 182 | exit /B %ERROR_CODE% 183 | -------------------------------------------------------------------------------- /API/capi/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | org.springframework.boot 7 | spring-boot-starter-parent 8 | 2.2.2.RELEASE 9 | 10 | 11 | com.credits 12 | credits.capi 13 | 0.0.1-SNAPSHOT 14 | capi 15 | Credits REST API 16 | 17 | 18 | 11 19 | 20 | 21 | 22 | 23 | org.springframework.boot 24 | spring-boot-starter 25 | 26 | 27 | 28 | org.projectlombok 29 | lombok 30 | 1.18.10 31 | provided 32 | 33 | 34 | 35 | com.google.code.gson 36 | gson 37 | 2.8.6 38 | 39 | 40 | 41 | net.i2p.crypto 42 | eddsa 43 | 0.3.0 44 | 45 | 46 | 47 | org.springframework.boot 48 | spring-boot-starter-test 49 | test 50 | 51 | 52 | org.junit.vintage 53 | junit-vintage-engine 54 | 55 | 56 | 57 | 58 | org.springframework.boot 59 | spring-boot-starter-web 60 | 61 | 62 | 63 | 64 | 65 | 66 | org.springframework.boot 67 | spring-boot-maven-plugin 68 | 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /API/capi/src/main/java/com/credits/DemoApplication.java: -------------------------------------------------------------------------------- 1 | package com.credits; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | 6 | @SpringBootApplication 7 | public class DemoApplication { 8 | 9 | public static void main(String[] args) { 10 | SpringApplication.run(DemoApplication.class, args); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /API/capi/src/main/java/com/credits/model/DataResponseApiModel.java: -------------------------------------------------------------------------------- 1 | package com.credits.model; 2 | 3 | import lombok.Getter; 4 | import lombok.Setter; 5 | import lombok.ToString; 6 | 7 | @Getter 8 | @Setter 9 | @ToString 10 | public class DataResponseApiModel { 11 | 12 | private String publicKey; 13 | 14 | private String transactionPackagedStr; 15 | 16 | } 17 | -------------------------------------------------------------------------------- /API/capi/src/main/java/com/credits/model/RequestApiModel.java: -------------------------------------------------------------------------------- 1 | package com.credits.model; 2 | 3 | import lombok.Getter; 4 | import lombok.Setter; 5 | import lombok.ToString; 6 | 7 | import java.math.BigDecimal; 8 | 9 | @Getter 10 | @Setter 11 | @ToString 12 | public class RequestApiModel { 13 | 14 | private String networkAlias; 15 | 16 | private String MethodApi; 17 | 18 | private String publicKey; 19 | 20 | private BigDecimal amount; 21 | 22 | private BigDecimal fee; 23 | 24 | private String receiverPublicKey; 25 | 26 | private String tokenPublicKey; 27 | 28 | private String tokenMethod; 29 | 30 | private String smartContractSource; 31 | 32 | private String userData; 33 | 34 | private String transactionSignature; 35 | 36 | private Boolean needPack; 37 | 38 | } 39 | -------------------------------------------------------------------------------- /API/capi/src/main/java/com/credits/model/ResponseApiModel.java: -------------------------------------------------------------------------------- 1 | package com.credits.model; 2 | 3 | import lombok.Getter; 4 | import lombok.Setter; 5 | import lombok.ToString; 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | 8 | import java.math.BigDecimal; 9 | 10 | @Getter 11 | @Setter 12 | @ToString 13 | public class ResponseApiModel { 14 | 15 | private Long transactionInnerId; 16 | 17 | private Boolean success; 18 | 19 | private String message; 20 | 21 | private String messageError; 22 | 23 | private BigDecimal amount; 24 | 25 | @Autowired 26 | private DataResponseApiModel dataResponse; 27 | 28 | } 29 | -------------------------------------------------------------------------------- /API/capi/src/main/java/com/credits/rest/CreditsRestController.java: -------------------------------------------------------------------------------- 1 | package com.credits.rest; 2 | 3 | import com.credits.model.DataResponseApiModel; 4 | import com.credits.model.RequestApiModel; 5 | import com.credits.model.ResponseApiModel; 6 | import com.credits.utils.Ed25519; 7 | import com.google.gson.Gson; 8 | import org.springframework.http.HttpStatus; 9 | import org.springframework.http.MediaType; 10 | import org.springframework.http.ResponseEntity; 11 | import org.springframework.web.bind.annotation.PathVariable; 12 | import org.springframework.web.bind.annotation.RequestMapping; 13 | import org.springframework.web.bind.annotation.RequestMethod; 14 | import org.springframework.web.bind.annotation.RestController; 15 | 16 | import java.math.BigDecimal; 17 | import java.net.URI; 18 | import java.net.http.HttpClient; 19 | import java.net.http.HttpRequest; 20 | import java.net.http.HttpResponse; 21 | 22 | @RestController 23 | @RequestMapping("/api") 24 | public class CreditsRestController { 25 | 26 | private ResponseEntity SendRequest(RequestApiModel model) { 27 | var client = HttpClient.newHttpClient(); 28 | 29 | var httpRequest = HttpRequest.newBuilder() 30 | .uri(URI.create("http://apinode.credits.com/api/monitor/getdata")) 31 | .header("Content-Type", "application/json") 32 | .header("AuthKey", "87cbdd85-b2e0-4cb9-aebf-1fe87bf3afdd") 33 | .POST(HttpRequest.BodyPublishers.ofString(new Gson().toJson(model))) 34 | .build(); 35 | 36 | try{ 37 | var response = client.send(httpRequest, HttpResponse.BodyHandlers.ofString()); 38 | return new ResponseEntity<>(new Gson().fromJson(response.body(), ResponseApiModel.class), HttpStatus.BAD_REQUEST); 39 | 40 | }catch(Exception e){ 41 | return new ResponseEntity<>(HttpStatus.BAD_REQUEST); 42 | } 43 | 44 | } 45 | 46 | @RequestMapping(path = "getBalance", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) 47 | public ResponseEntity GetBalance() { 48 | var model = new RequestApiModel(); 49 | model.setPublicKey("Fn2tJrj7TU73cqkwTzaSkbRypYK5xhWEKqrad3nEeBkX"); 50 | model.setMethodApi("GetBalance"); 51 | model.setNetworkAlias("MainNet"); 52 | 53 | return SendRequest(model); 54 | } 55 | 56 | @RequestMapping(path = "transferToken", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE) 57 | public void TransferToken() { 58 | 59 | var privateKey = "ohPH5zghdzmRDxd978r7y6r8YFoTcKm1MgW2gzik3omCuZLysjwNjTd9hnGREFyQHqhShoU4ri7q748UgdwZpzA"; 60 | 61 | var model = new RequestApiModel(); 62 | model.setPublicKey("FeFjpcsfHErXPk5HkfVcwH6zYaRT2xNytDTeSjfuVywt"); 63 | model.setReceiverPublicKey("DM79n9Lbvm3XhBf1LwyBHESaRmJEJez2YiL549ArcHDC"); 64 | model.setTokenPublicKey("FY8J5uSb2D3qX3iwUSvcUSGvrBGAvsrXxKxMQdFfpdmm"); 65 | model.setAmount(new BigDecimal(0.51)); 66 | model.setMethodApi("TransferToken"); 67 | model.setFee(new BigDecimal(0.1)); 68 | model.setNeedPack(true); 69 | 70 | var res1 = SendRequest(model); 71 | 72 | 73 | 74 | var crypt = Ed25519.sign(res1.getBody().getDataResponse().getTransactionPackagedStr().getBytes(), privateKey.getBytes()); 75 | 76 | } 77 | 78 | public void TransferCs() { 79 | 80 | } 81 | 82 | public void SmartDeploy() { 83 | 84 | } 85 | 86 | public void SmartMethodExecute() { 87 | 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /API/capi/src/main/java/com/credits/utils/Base58.java: -------------------------------------------------------------------------------- 1 | package com.credits.utils; 2 | 3 | import com.credits.utils.ConverterException; 4 | 5 | import java.util.Arrays; 6 | 7 | /** 8 | * Base58 encoder 9 | * 10 | * The basic idea of the encoding is to treat the data bytes as a large number represented using 11 | * base-256 digits, convert the number to be represented using base-58 digits, preserve the exact 12 | * number of leading zeros (which are otherwise lost during the mathematical operations on the 13 | * numbers), and finally represent the resulting base-58 digits as alphanumeric ASCII characters. 14 | */ 15 | public class Base58 { 16 | public static final char[] ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz".toCharArray(); 17 | private static final char ENCODED_ZERO = ALPHABET[0]; 18 | private static final int[] INDEXES = new int[128]; 19 | static { 20 | Arrays.fill(INDEXES, -1); 21 | for (int i = 0; i < ALPHABET.length; i++) { 22 | INDEXES[ALPHABET[i]] = i; 23 | } 24 | } 25 | 26 | /** 27 | * Encodes the given bytes as a base58 string (no checksum is appended). 28 | * 29 | * @param input the bytes to encode 30 | * @return the base58-encoded string 31 | */ 32 | public static String encode(byte[] input) { 33 | if (input.length == 0) { 34 | return ""; 35 | } 36 | // Count leading zeros. 37 | int zeros = 0; 38 | while (zeros < input.length && input[zeros] == 0) { 39 | ++zeros; 40 | } 41 | // Convert base-256 digits to base-58 digits (plus conversion to ASCII characters) 42 | input = Arrays.copyOf(input, input.length); // since we modifyObject it in-place 43 | char[] encoded = new char[input.length * 2]; // upper bound 44 | int outputStart = encoded.length; 45 | for (int inputStart = zeros; inputStart < input.length; ) { 46 | encoded[--outputStart] = ALPHABET[divmod(input, inputStart, 256, 58)]; 47 | if (input[inputStart] == 0) { 48 | ++inputStart; // optimization - skip leading zeros 49 | } 50 | } 51 | // Preserve exactly as many leading encoded zeros in output as there were leading zeros in input. 52 | while (outputStart < encoded.length && encoded[outputStart] == ENCODED_ZERO) { 53 | ++outputStart; 54 | } 55 | while (--zeros >= 0) { 56 | encoded[--outputStart] = ENCODED_ZERO; 57 | } 58 | // Return encoded string (including encoded leading zeros). 59 | return new String(encoded, outputStart, encoded.length - outputStart); 60 | } 61 | 62 | 63 | /** 64 | * Decodes the given base58 string into the original data bytes. 65 | * 66 | * @param input the base58-encoded string to decode 67 | * @return the decoded data bytes 68 | */ 69 | public static byte[] decode(String input) throws ConverterException { 70 | if (input.length() == 0) { 71 | return new byte[0]; 72 | } 73 | // Convert the base58-encoded ASCII chars to a base58 byte sequence (base58 digits). 74 | byte[] input58 = new byte[input.length()]; 75 | for (int i = 0; i < input.length(); ++i) { 76 | char c = input.charAt(i); 77 | int digit = c < 128 ? INDEXES[c] : -1; 78 | if (digit < 0) { 79 | throw new ConverterException("Given string id not a valid base58 string"); 80 | } 81 | input58[i] = (byte) digit; 82 | } 83 | // Count leading zeros. 84 | int zeros = 0; 85 | while (zeros < input58.length && input58[zeros] == 0) { 86 | ++zeros; 87 | } 88 | // Convert base-58 digits to base-256 digits. 89 | byte[] decoded = new byte[input.length()]; 90 | int outputStart = decoded.length; 91 | for (int inputStart = zeros; inputStart < input58.length; ) { 92 | decoded[--outputStart] = divmod(input58, inputStart, 58, 256); 93 | if (input58[inputStart] == 0) { 94 | ++inputStart; // optimization - skip leading zeros 95 | } 96 | } 97 | // Ignore extra leading zeroes that were added during the calculation. 98 | while (outputStart < decoded.length && decoded[outputStart] == 0) { 99 | ++outputStart; 100 | } 101 | // Return decoded data (including original number of leading zeros). 102 | return Arrays.copyOfRange(decoded, outputStart - zeros, decoded.length); 103 | } 104 | 105 | /** 106 | * Divides a number, represented as an array of bytes each containing a single digit 107 | * in the specified base, by the given divisor. The given number is modified in-place 108 | * to contain the quotient, and the return value is the remainder. 109 | * 110 | * @param number the number to divide 111 | * @param firstDigit the index within the array of the first non-zero digit 112 | * (this is used for optimization by skipping the leading zeros) 113 | * @param base the base in which the number's digits are represented (up to 256) 114 | * @param divisor the number to divide by (up to 256) 115 | * @return the remainder of the division operation 116 | */ 117 | private static byte divmod(byte[] number, int firstDigit, int base, int divisor) { 118 | // this is just long division which accounts for the base of the input digits 119 | int remainder = 0; 120 | for (int i = firstDigit; i < number.length; i++) { 121 | int digit = (int) number[i] & 0xFF; 122 | int temp = remainder * base + digit; 123 | number[i] = (byte) (temp / divisor); 124 | remainder = temp % divisor; 125 | } 126 | return (byte) remainder; 127 | } 128 | } -------------------------------------------------------------------------------- /API/capi/src/main/java/com/credits/utils/ConverterException.java: -------------------------------------------------------------------------------- 1 | package com.credits.utils; 2 | 3 | 4 | import com.credits.utils.CreditsException; 5 | 6 | /** 7 | * Created by Igor Goryunov on 19.10.2018 8 | */ 9 | public class ConverterException extends CreditsException { 10 | 11 | public ConverterException(String errorMessage) { 12 | super(errorMessage); 13 | } 14 | 15 | public ConverterException(Exception e) { 16 | super(e); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /API/capi/src/main/java/com/credits/utils/CreditsException.java: -------------------------------------------------------------------------------- 1 | package com.credits.utils; 2 | 3 | /** 4 | * Created by Rustem.Saidaliyev on 27.03.2018. 5 | */ 6 | public class CreditsException extends RuntimeException { 7 | 8 | public CreditsException(String errorMessage) { 9 | super(errorMessage); 10 | } 11 | 12 | public CreditsException(Exception e) { 13 | super(e); 14 | } 15 | 16 | public CreditsException(String errorMessage, Throwable e) { 17 | super(e); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /API/capi/src/main/java/com/credits/utils/CryptoException.java: -------------------------------------------------------------------------------- 1 | package com.credits.utils; 2 | 3 | 4 | import com.credits.utils.CreditsException; 5 | 6 | /** 7 | * Created by Rustem.Saidaliyev on 27.03.2018. 8 | */ 9 | public class CryptoException extends CreditsException { 10 | 11 | public CryptoException(String errorMessage) { 12 | super(errorMessage); 13 | } 14 | 15 | public CryptoException(Exception e) { 16 | super(e); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /API/capi/src/main/java/com/credits/utils/Ed25519.java: -------------------------------------------------------------------------------- 1 | package com.credits.utils; 2 | 3 | import net.i2p.crypto.eddsa.EdDSAEngine; 4 | import net.i2p.crypto.eddsa.EdDSAPublicKey; 5 | import net.i2p.crypto.eddsa.KeyPairGenerator; 6 | import net.i2p.crypto.eddsa.spec.EdDSANamedCurveTable; 7 | import net.i2p.crypto.eddsa.spec.EdDSAParameterSpec; 8 | import net.i2p.crypto.eddsa.spec.EdDSAPublicKeySpec; 9 | import org.slf4j.Logger; 10 | import org.slf4j.LoggerFactory; 11 | 12 | import java.math.BigDecimal; 13 | import java.nio.charset.StandardCharsets; 14 | import java.security.InvalidKeyException; 15 | import java.security.KeyPair; 16 | import java.security.PrivateKey; 17 | import java.security.PublicKey; 18 | import java.security.SignatureException; 19 | 20 | /** 21 | * Утилита генерации публичных, приватных ключей, подписи 22 | * на базе ED25519 23 | *

24 | * Created by Rustem Saidaliyev on 14-Mar-18. 25 | */ 26 | public class Ed25519 { 27 | 28 | private static final Logger LOGGER = LoggerFactory.getLogger(Ed25519.class); 29 | 30 | private static final KeyPairGenerator KEY_PAIR_GENERATOR = new KeyPairGenerator(); 31 | 32 | public static final String ED_25519 = "Ed25519"; 33 | 34 | public static KeyPair generateKeyPair() { 35 | synchronized (KEY_PAIR_GENERATOR) { 36 | return KEY_PAIR_GENERATOR.generateKeyPair(); 37 | } 38 | } 39 | 40 | public static byte[] sign(byte[] data, PrivateKey privateKey) throws CryptoException { 41 | 42 | EdDSAEngine edDSAEngine = new EdDSAEngine(); 43 | try { 44 | edDSAEngine.initSign(privateKey); 45 | return edDSAEngine.signOneShot(data); 46 | } catch (InvalidKeyException | SignatureException e) { 47 | throw new CryptoException(e); 48 | } 49 | } 50 | 51 | public static Boolean verify(byte[] data, byte[] signature, PublicKey publicKey) throws CryptoException { 52 | 53 | EdDSAEngine edDSAEngine = new EdDSAEngine(); 54 | try { 55 | edDSAEngine.initVerify(publicKey); 56 | return edDSAEngine.verifyOneShot(data, signature); 57 | } catch (InvalidKeyException | SignatureException e) { 58 | throw new CryptoException(e); 59 | } 60 | } 61 | 62 | public static PublicKey bytesToPublicKey(byte[] bytes) { 63 | EdDSAParameterSpec spec = EdDSANamedCurveTable.getByName(ED_25519); 64 | EdDSAPublicKeySpec key = new EdDSAPublicKeySpec(bytes, spec); 65 | return new EdDSAPublicKey(key); 66 | } 67 | 68 | // public static PrivateKey bytesToPrivateKey(byte[] bytes) { 69 | // 70 | // byte[] seedByteArr = Utils.parseSubArray(bytes, 0, 32); // seed 71 | // EdDSAParameterSpec spec = EdDSANamedCurveTable.getByName(ED_25519); 72 | // EdDSAPrivateKeySpec key = new EdDSAPrivateKeySpec(seedByteArr, spec); 73 | // return new EdDSAPrivateKey(key); 74 | // } 75 | 76 | // public static String generateSignOfTransaction(String innerId, String source, String target, BigDecimal amount, 77 | // BigDecimal balance, byte currency, PrivateKey privateKey) 78 | // throws ConverterException, CryptoException { 79 | // 80 | // Amount amountValue = NodePojoConverter.bigDecimalToAmount(amount); 81 | // 82 | // Integer amountIntegral = amountValue.getIntegral(); 83 | // Long amountFraction = amountValue.getFraction(); 84 | // 85 | // Amount balanceValue = NodePojoConverter.bigDecimalToAmount(balance); 86 | // 87 | // Integer balanceIntegral = balanceValue.getIntegral(); 88 | // Long balanceFraction = balanceValue.getFraction(); 89 | // 90 | // String transaction = 91 | // String.format("%s|%s|%s|%s:%s|%s:%s|%s", innerId, source, target, GeneralConverter.toString(amountIntegral), 92 | // GeneralConverter.toString(amountFraction), GeneralConverter.toString(balanceIntegral), 93 | // GeneralConverter.toString(balanceFraction), currency); 94 | // 95 | // LOGGER.debug("Signing the message [{}]", transaction); 96 | // byte[] signature; 97 | // signature = Ed25519.sign(transaction.getBytes(StandardCharsets.US_ASCII), privateKey); 98 | // 99 | // return GeneralConverter.encodeToBASE58(signature); 100 | // } 101 | // 102 | // public static byte[] publicKeyToBytes(PublicKey publicKey) { 103 | // EdDSAPublicKey edDSAPublicKey = (EdDSAPublicKey) publicKey; 104 | // return edDSAPublicKey.getAbyte(); 105 | // } 106 | // 107 | // public static byte[] privateKeyToBytes(PrivateKey privateKey) { 108 | // EdDSAPrivateKey edDSAPrivateKey = (EdDSAPrivateKey) privateKey; 109 | // return Utils.concatenateArrays(edDSAPrivateKey.getSeed(), edDSAPrivateKey.getAbyte()); 110 | // } 111 | } -------------------------------------------------------------------------------- /API/capi/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /API/capi/src/test/java/com/credits/DemoApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.credits; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | 6 | @SpringBootTest 7 | class DemoApplicationTests { 8 | 9 | @Test 10 | void contextLoads() { 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Docker/Readme.md: -------------------------------------------------------------------------------- 1 | # Docker (Linux/Windows) 2 | 3 | ## credits_docker_mainnet 4 | Using Credits (version 4_2_410) in Docker 5 | 6 | ## credits_docker_testnet 7 | Using Credits (version 4.2.417) in Docker 8 | 9 | -------------------------------------------------------------------------------- /Docker/credits_docker_mainnet/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:18.04 2 | 3 | # update && java 11 install 4 | RUN apt-get update && \ 5 | apt-get upgrade -y && \ 6 | apt-get install -y software-properties-common && \ 7 | add-apt-repository ppa:linuxuprising/java -y && \ 8 | apt-get update && \ 9 | echo oracle-java11-installer shared/accepted-oracle-license-v1-2 select true | /usr/bin/debconf-set-selections && \ 10 | apt-get install -y oracle-java11-installer && \ 11 | apt-get install oracle-java11-set-default && \ 12 | apt-get clean 13 | # setup worker dir 14 | WORKDIR /credits 15 | # copy all files from current dir to ./credits 16 | COPY /build /credits 17 | # ports 18 | EXPOSE 6000 19 | EXPOSE 9090 20 | # run 21 | CMD ["./runner", "--db-path main_db/ --public-key-file main_keys/public.txt --private-key-file main_keys/private.txt"] 22 | -------------------------------------------------------------------------------- /Docker/credits_docker_mainnet/Readme.md: -------------------------------------------------------------------------------- 1 | # credits_docker_mainnet 2 | 3 | Using Credits (version 4_2_410) in Docker 4 | https://developers.credits.com/en/Articles/a_Using_Credits_blockchain_software_in_Docker 5 | 6 | ## How to build 7 | 8 | #### You can run build.sh or run step by step commands below: 9 | ```shell 10 | wget https://credits.com/Content/file_users/Credits_Network_for_Linux_x64_4_2_410.tar.gz -P build Credits_Network_for_Linux_x64_4_2_410.tar.gz 11 | tar -xvzf build/Credits_Network_for_Linux_x64_4_2_410.tar.gz --strip-components 1 -C build 12 | rm build/Credits_Network_for_Linux_x64_4_2_410.tar.gz 13 | 14 | g++ -pthread source/runner.cpp -o build/runner 15 | cp common/* build/ 16 | 17 | sudo docker build -t credits_mainnet:4.2.410 . 18 | sudo docker volume create main_db 19 | sudo docker volume create main_keys 20 | ``` 21 | 22 | ### some helpers 23 | ```shell 24 | sudo docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer 25 | ``` 26 | 27 | ### run bash 28 | ```shell 29 | sudo docker run -it -p 6000:6000 -p 9090:9090 --mount source=main_db,target=/credits/main_db --mount source=main_keys,target=/credits/main_keys credits_mainnet:4.2.410 bash 30 | ``` 31 | 32 | ### run local repo node 33 | ```shell 34 | sudo docker run -it -p 6000:6000 -p 9090:9090 --mount source=main_db,target=/credits/main_db --mount source=main_keys,target=/credits/main_keys credits_mainnet:4.2.410 35 | ``` 36 | 37 | ### run node docker repo 38 | ```shell 39 | sudo docker run -it -p 6000:6000 -p 9090:9090 --mount source=main_db,target=/credits/main_db --mount source=main_keys,target=/credits/main_keys pvl1175/credits_mainnet:4.2.410 40 | ``` 41 | 42 | ### additional example 43 | ```shell 44 | ./client --db-path main_db/ --public-key-file main_keys/public.txt --private-key-file main_keys/private.txt 45 | ``` 46 | 47 | ## How to run 48 | ### You can run run.sh or run step by step commands below: 49 | 50 | ### run bash 51 | ```shell 52 | sudo docker run -it -p 6000:6000 -p 9090:9090 --mount source=main_db,target=/credits/main_db --mount source=main_keys,target=/credits/main_keys credits_mainnet:latest bash 53 | ``` 54 | 55 | ### run node 56 | ```shell 57 | sudo docker run -it -p 6000:6000 -p 9090:9090 --mount source=main_db,target=/credits/main_db --mount source=main_keys,target=/credits/main_keys credits_mainnet:latest 58 | ``` 59 | -------------------------------------------------------------------------------- /Docker/credits_docker_mainnet/build.sh: -------------------------------------------------------------------------------- 1 | wget https://credits.com/Content/file_users/Credits_Network_for_Linux_x64_4_2_410.tar.gz -P build Credits_Network_for_Linux_x64_4_2_410.tar.gz 2 | tar -xvzf build/Credits_Network_for_Linux_x64_4_2_410.tar.gz --strip-components 1 -C build 3 | rm build/Credits_Network_for_Linux_x64_4_2_410.tar.gz 4 | 5 | g++ -pthread source/runner.cpp -o build/runner 6 | cp common/* build/ 7 | 8 | sudo docker build -t credits_mainnet:4.2.410 . 9 | sudo docker volume create main_db 10 | sudo docker volume create main_keys 11 | 12 | # some helpers 13 | #sudo docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer 14 | 15 | # run bash 16 | #sudo docker run -it -p 6000:6000 -p 9090:9090 --mount source=main_db,target=/credits/main_db --mount source=main_keys,target=/credits/main_keys credits_mainnet:4.2.410 bash 17 | 18 | # run local repo node 19 | #sudo docker run -it -p 6000:6000 -p 9090:9090 --mount source=main_db,target=/credits/main_db --mount source=main_keys,target=/credits/main_keys credits_mainnet:4.2.410 20 | 21 | # run node docker repo 22 | #sudo docker run -it -p 6000:6000 -p 9090:9090 --mount source=main_db,target=/credits/main_db --mount source=main_keys,target=/credits/main_keys pvl1175/credits_mainnet:4.2.410 23 | 24 | # additional example 25 | #./client --db-path main_db/ --public-key-file main_keys/public.txt --private-key-file main_keys/private.txt 26 | -------------------------------------------------------------------------------- /Docker/credits_docker_mainnet/clean.sh: -------------------------------------------------------------------------------- 1 | rm -r -f build -------------------------------------------------------------------------------- /Docker/credits_docker_mainnet/common/clean_main_db.sh: -------------------------------------------------------------------------------- 1 | rm main_db/* -------------------------------------------------------------------------------- /Docker/credits_docker_mainnet/common/clean_main_keys.sh: -------------------------------------------------------------------------------- 1 | rm main_keys/* -------------------------------------------------------------------------------- /Docker/credits_docker_mainnet/common/run.sh: -------------------------------------------------------------------------------- 1 | ./runner "--db-path main_db/ --public-key-file main_keys/public.txt --private-key-file main_keys/private.txt" -------------------------------------------------------------------------------- /Docker/credits_docker_mainnet/run.sh: -------------------------------------------------------------------------------- 1 | # run bash 2 | #sudo docker run -it -p 6000:6000 -p 9090:9090 --mount source=main_db,target=/credits/main_db --mount source=main_keys,target=/credits/main_keys credits_mainnet:latest bash 3 | 4 | # run node 5 | sudo docker run -it -p 6000:6000 -p 9090:9090 --mount source=main_db,target=/credits/main_db --mount source=main_keys,target=/credits/main_keys credits_mainnet:latest 6 | -------------------------------------------------------------------------------- /Docker/credits_docker_mainnet/source/runner.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | void run_contract_executor() 8 | { 9 | system("java -jar contract-executor.jar"); 10 | } 11 | 12 | void run_node(char* params) 13 | { 14 | ostringstream ss; 15 | ss << "./client " << params; 16 | system(ss.str().c_str()); 17 | } 18 | 19 | int main(int argc, char* argv[]) 20 | { 21 | if(argc != 2) 22 | { 23 | cout << "Usage: ./runner \"parameters\"" << endl; 24 | cout << "For example: ./runner \"--db-path main_db/ --public-key-file main_keys/public.txt --private-key-file main_keys/private.txt\"" << endl; 25 | return 1; 26 | } 27 | 28 | thread th1(run_contract_executor); 29 | thread th2(run_node, ref(argv[1])); 30 | 31 | th1.join(); 32 | th2.join(); 33 | } 34 | 35 | 36 | -------------------------------------------------------------------------------- /Docker/credits_docker_testnet/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ubuntu:18.04 2 | 3 | # update && java 11 install 4 | RUN apt-get update && \ 5 | apt-get upgrade -y && \ 6 | apt-get install -y software-properties-common && \ 7 | add-apt-repository ppa:linuxuprising/java -y && \ 8 | apt-get update && \ 9 | echo oracle-java11-installer shared/accepted-oracle-license-v1-2 select true | /usr/bin/debconf-set-selections && \ 10 | apt-get install -y oracle-java11-installer && \ 11 | apt-get install oracle-java11-set-default && \ 12 | apt-get clean 13 | # setup worker dir 14 | WORKDIR /credits 15 | # copy all files from current dir to ./credits 16 | COPY /build /credits 17 | # ports 18 | EXPOSE 6000 19 | EXPOSE 9090 20 | # run 21 | CMD ["./runner", "--db-path test_db/ --public-key-file test_keys/public.txt --private-key-file test_keys/private.txt"] 22 | -------------------------------------------------------------------------------- /Docker/credits_docker_testnet/Readme.md: -------------------------------------------------------------------------------- 1 | # credits_docker_testnet 2 | Using Credits (version 4.2.417) in Docker 3 | https://developers.credits.com/en/Articles/a_Using_Credits_blockchain_software_in_Docker 4 | 5 | ## How to build 6 | ### You can run build.sh or run step by step commands below: 7 | ```shell 8 | wget https://credits.com/Content/file_users/Credits_Node_linux_x64_ver_4.2.417_testnet.tar.gz -P build Credits_Node_linux_x64_ver_4.2.417_testnet.tar.gz 9 | tar -xvzf build/Credits_Node_linux_x64_ver_4.2.417_testnet.tar.gz --strip-components 1 -C build 10 | rm build/Credits_Node_linux_x64_ver_4.2.417_testnet.tar.gz 11 | 12 | g++ -pthread source/runner.cpp -o build/runner 13 | cp common/* build/ 14 | 15 | sudo docker build -t credits_testnet:4.2.417 . 16 | sudo docker volume create test_db 17 | sudo docker volume create test_keys 18 | ``` 19 | ### some helpers 20 | ```shell 21 | sudo docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer 22 | ``` 23 | ### run bash 24 | ```shell 25 | sudo docker run -it -p 6000:6000 -p 9090:9090 --mount source=test_db,target=/credits/test_db --mount source=test_keys,target=/credits/test_keys credits_testnet:4.2.417 bash 26 | ``` 27 | ### run local repo node 28 | ```shell 29 | sudo docker run -it -p 6000:6000 -p 9090:9090 --mount source=test_db,target=/credits/test_db --mount source=test_keys,target=/credits/test_keys credits_testnet:4.2.417 30 | ``` 31 | ### run node docker repo 32 | ```shell 33 | sudo docker run -it -p 6000:6000 -p 9090:9090 --mount source=test_db,target=/credits/test_db --mount source=test_keys,target=/credits/test_keys pvl1175/credits_testnet:4.2.417 34 | ``` 35 | ### additional example 36 | ```shell 37 | ./client --db-path test_db/ --public-key-file test_keys/public.txt --private-key-file test_keys/private.txt 38 | ``` 39 | 40 | ## How to run 41 | ### You can run run.sh or run step by step commands below: 42 | ### run bash 43 | ```shell 44 | sudo docker run -it -p 6000:6000 -p 9090:9090 --mount source=test_db,target=/credits/test_db --mount source=test_keys,target=/credits/test_keys credits_testnet:latest bash 45 | ``` 46 | ### run node 47 | ```shell 48 | sudo docker run -it -p 6000:6000 -p 9090:9090 --mount source=test_db,target=/credits/test_db --mount source=test_keys,target=/credits/test_keys credits_testnet:latest 49 | ``` 50 | -------------------------------------------------------------------------------- /Docker/credits_docker_testnet/build.sh: -------------------------------------------------------------------------------- 1 | wget https://credits.com/Content/file_users/Credits_Node_linux_x64_ver_4.2.417_testnet.tar.gz -P build Credits_Node_linux_x64_ver_4.2.417_testnet.tar.gz 2 | tar -xvzf build/Credits_Node_linux_x64_ver_4.2.417_testnet.tar.gz --strip-components 1 -C build 3 | rm build/Credits_Node_linux_x64_ver_4.2.417_testnet.tar.gz 4 | 5 | g++ -pthread source/runner.cpp -o build/runner 6 | cp common/* build/ 7 | 8 | sudo docker build -t credits_testnet:4.2.417 . 9 | sudo docker volume create test_db 10 | sudo docker volume create test_keys 11 | 12 | # some helpers 13 | #sudo docker run -d -p 9000:9000 -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer 14 | 15 | # run bash 16 | #sudo docker run -it -p 6000:6000 -p 9090:9090 --mount source=test_db,target=/credits/test_db --mount source=test_keys,target=/credits/test_keys credits_testnet:4.2.417 bash 17 | 18 | # run local repo node 19 | #sudo docker run -it -p 6000:6000 -p 9090:9090 --mount source=test_db,target=/credits/test_db --mount source=test_keys,target=/credits/test_keys credits_testnet:4.2.417 20 | 21 | # run node docker repo 22 | #sudo docker run -it -p 6000:6000 -p 9090:9090 --mount source=test_db,target=/credits/test_db --mount source=test_keys,target=/credits/test_keys pvl1175/credits_testnet:4.2.417 23 | # additional example 24 | #./client --db-path test_db/ --public-key-file test_keys/public.txt --private-key-file test_keys/private.txt 25 | -------------------------------------------------------------------------------- /Docker/credits_docker_testnet/clean.sh: -------------------------------------------------------------------------------- 1 | rm -r -f build -------------------------------------------------------------------------------- /Docker/credits_docker_testnet/common/clean_test_db.sh: -------------------------------------------------------------------------------- 1 | rm test_db/* -------------------------------------------------------------------------------- /Docker/credits_docker_testnet/common/clean_test_keys.sh: -------------------------------------------------------------------------------- 1 | rm test_keys/* -------------------------------------------------------------------------------- /Docker/credits_docker_testnet/common/run.sh: -------------------------------------------------------------------------------- 1 | ./runner "--db-path test_db/ --public-key-file test_keys/public.txt --private-key-file test_keys/private.txt" -------------------------------------------------------------------------------- /Docker/credits_docker_testnet/run.sh: -------------------------------------------------------------------------------- 1 | # run bash 2 | #sudo docker run -it -p 6000:6000 -p 9090:9090 --mount source=test_db,target=/credits/test_db --mount source=test_keys,target=/credits/test_keys credits_testnet:latest bash 3 | 4 | # run node 5 | sudo docker run -it -p 6000:6000 -p 9090:9090 --mount source=test_db,target=/credits/test_db --mount source=test_keys,target=/credits/test_keys credits_testnet:latest 6 | -------------------------------------------------------------------------------- /Docker/credits_docker_testnet/source/runner.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | using namespace std; 6 | 7 | void run_contract_executor() 8 | { 9 | system("java -jar contract-executor.jar"); 10 | } 11 | 12 | void run_node(char* params) 13 | { 14 | ostringstream ss; 15 | ss << "./client " << params; 16 | system(ss.str().c_str()); 17 | } 18 | 19 | int main(int argc, char* argv[]) 20 | { 21 | if(argc != 2) 22 | { 23 | cout << "Usage: ./runner \"parameters\"" << endl; 24 | cout << "For example: ./runner \"--db-path test_db/ --public-key-file test_keys/public.txt --private-key-file test_keys/private.txt\"" << endl; 25 | return 1; 26 | } 27 | 28 | thread th1(run_contract_executor); 29 | thread th2(run_node, ref(argv[1])); 30 | 31 | th1.join(); 32 | th2.join(); 33 | } 34 | 35 | 36 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # API (Linux/Windows) 2 | 3 | ## CreditsCPlusPlusDemoCMake 4 | 5 | A simple console C++ (CMake) application 6 | Using the public key of the wallet displays the balance. 7 | 8 | ## CreditsCSharpDemo 9 | A simple console C# (.NET Core) application.
10 | Using the public key of the wallet displays the balance.
11 | Allows to create a transaction (transfer coins from the current wallet to the specified one) and execute it. 12 | 13 | ## CreditsJSDemo 14 | A simple console JS application
15 | Using the public key of the wallet displays the balance. 16 | 17 | ## CreditsPythonApiDemo 18 | A simple console Python application
19 | Using the public key of the wallet displays the balance. 20 | 21 | 22 | # Docker (Linux/Windows) 23 | 24 | ## credits_docker_mainnet 25 | Using Credits (version 4_2_410) in Docker 26 | 27 | ## credits_docker_testnet 28 | Using Credits (version 4.2.412.3) in Docker 29 | 30 | 31 | # Utils (Linux/Windows) 32 | 33 | ## cr-dev-book-windows 34 | A simple Electron application, showing the contents of the Credits Developer Portal https://developers.credits.com/ 35 | 36 | ## cr-monitor-windows 37 | A simple Electron application, showing the contents of the Credits Monitor 38 | 39 | ## cr-web-wallet-windows 40 | A simple Electron application, showing the contents of the Credits Web Wallet 41 | -------------------------------------------------------------------------------- /SmartContracts/Readme.md: -------------------------------------------------------------------------------- 1 | # CS smart-contracts (examples) 2 | -------------------------------------------------------------------------------- /SmartContracts/sm_tracking the movement/Readme.md: -------------------------------------------------------------------------------- 1 | # Tracking the movement of ordered goods 2 | 3 | ## Our user class 4 | ### The user class must inherit from Serializable 5 | ```shell 6 | public static class Geo implements Serializable { 7 | private final int productId; 8 | private final String latitude; 9 | private final String longitude; 10 | public Geo(int productId, String latitude, String longitude) { 11 | this.productId = productId; 12 | this.latitude = latitude; 13 | this.longitude = longitude; 14 | } 15 | } 16 | ``` 17 | 18 | ### The custom list declaration 19 | ```shell 20 | private final ArrayList geoList; 21 | ``` 22 | 23 | ### Creating the list in the constructor 24 | ```shell 25 | public Contract() { 26 | geoList = new ArrayList<>(); 27 | } 28 | ``` 29 | 30 | ### Adding the geo position of our product 31 | ```shell 32 | public void saveGeo(int productId, String latitude, String longitude){ 33 | geoList.add(new Geo(productId, latitude, longitude)); 34 | } 35 | ``` 36 | 37 | ### Getting our user list 38 | ```shell 39 | public ArrayList loadGeo(){ 40 | return geoList; 41 | } 42 | ``` 43 | 44 | ### Getting the count of our user list 45 | ```shell 46 | public int geoListSize(){ 47 | return geoList.size(); 48 | } 49 | ``` 50 | -------------------------------------------------------------------------------- /SmartContracts/sm_tracking the movement/sm_tracking the movement.java: -------------------------------------------------------------------------------- 1 | import com.credits.scapi.v0.SmartContract; 2 | import java.io.Serializable; 3 | import java.util.ArrayList; 4 | 5 | public class Contract extends SmartContract { 6 | private final ArrayList geoList; 7 | 8 | public Contract() { 9 | geoList = new ArrayList<>(); 10 | } 11 | 12 | public void saveGeo(int productId, String latitude, String longitude){ 13 | geoList.add(new Geo(productId, latitude, longitude)); 14 | } 15 | 16 | public ArrayList loadGeo(){ 17 | return geoList; 18 | } 19 | 20 | public int geoListSize(){ 21 | return geoList.size(); 22 | } 23 | 24 | public static class Geo implements Serializable { 25 | private final int productId; 26 | private final String latitude; 27 | private final String longitude; 28 | 29 | public Geo(int productId, String latitude, String longitude) { 30 | this.productId = productId; 31 | this.latitude = latitude; 32 | this.longitude = longitude; 33 | } 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Utils/Readme.md: -------------------------------------------------------------------------------- 1 | # Utils (Linux/Windows) 2 | 3 | ## cr-dev-book-windows 4 | A simple Electron application, showing the contents of the Credits Developer Portal https://developers.credits.com/ 5 | 6 | ## cr-monitor-windows 7 | A simple Electron application, showing the contents of the Credits Monitor 8 | 9 | ## cr-web-wallet-windows 10 | A simple Electron application, showing the contents of the Credits Web Wallet 11 | -------------------------------------------------------------------------------- /Utils/cr-dev-book-windows/Readme.md: -------------------------------------------------------------------------------- 1 | # cr-dev-book-windows 2 | A simple Electron application, showing the contents of the Credits Developer Portal
3 | https://developers.credits.com/ -------------------------------------------------------------------------------- /Utils/cr-dev-book-windows/index.js: -------------------------------------------------------------------------------- 1 | const { app, BrowserWindow } = require('electron'); 2 | 3 | let win = null; 4 | 5 | const appUrl = `https://developers.credits.com/`; 6 | 7 | function createElectronShell() { 8 | win = new BrowserWindow( 9 | { 10 | width: 1200, 11 | height: 900, 12 | webPreferences: { 13 | plugins: true, 14 | nodeIntegration: false, 15 | webSecurity: false, 16 | allowDisplayingInsecureContent: true, 17 | allowRunningInsecureContent: true 18 | } 19 | } 20 | ); 21 | 22 | win.setMenu(null); 23 | win.loadURL(appUrl); 24 | win.on('closed', () => { 25 | win = null 26 | }); 27 | } 28 | 29 | app.commandLine.appendSwitch('ignore-certificate-errors', 'true'); 30 | 31 | app.on('ready', createElectronShell); 32 | 33 | app.on('browser-window-created',function(e,window) { 34 | window.setMenu(null); 35 | }); 36 | 37 | app.on('window-all-closed', () => { 38 | if (process.platform !== 'darwin') app.quit(); 39 | }); 40 | 41 | app.on('activate', () => { 42 | if (win == null) createElectronShell(); 43 | }); -------------------------------------------------------------------------------- /Utils/cr-dev-book-windows/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cr-dev-book", 3 | "version": "1.0.0", 4 | "description": "CREDITS Dev Book", 5 | "main": "index.js", 6 | "homepage": "credits.com", 7 | "author": "pvl1175 ", 8 | "license": "ISC", 9 | "build": { 10 | "appId": "com.credits.dev-book", 11 | "productName": "CREDITS Dev Book", 12 | "win": { 13 | "target": [ 14 | "nsis" 15 | ] 16 | }, 17 | "nsis": { 18 | "runAfterFinish": true 19 | } 20 | }, 21 | "scripts": { 22 | "pack": "build --dir", 23 | "dist": "build", 24 | "postinstall": "install-app-deps", 25 | "start": "electron ." 26 | }, 27 | "devDependencies": { 28 | "electron": "^1.8.8", 29 | "electron-builder": "^20.38.3" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Utils/cr-monitor-windows/Readme.md: -------------------------------------------------------------------------------- 1 | # cr-monitor-windows 2 | A simple Electron application, showing the contents of the Credits Monitor 3 | -------------------------------------------------------------------------------- /Utils/cr-monitor-windows/index.js: -------------------------------------------------------------------------------- 1 | const { app, BrowserWindow } = require('electron'); 2 | 3 | let win = null; 4 | 5 | const appUrl = `http://monitor.credits.com/`; 6 | 7 | function createElectronShell() { 8 | win = new BrowserWindow( 9 | { 10 | width: 1000, 11 | height: 900, 12 | webPreferences: { 13 | plugins: true, 14 | nodeIntegration: false, 15 | webSecurity: false, 16 | allowDisplayingInsecureContent: true, 17 | allowRunningInsecureContent: true 18 | } 19 | } 20 | ); 21 | 22 | win.setMenu(null); 23 | win.loadURL(appUrl); 24 | win.on('closed', () => { 25 | win = null 26 | }); 27 | } 28 | 29 | app.commandLine.appendSwitch('ignore-certificate-errors', 'true'); 30 | 31 | app.on('ready', createElectronShell); 32 | 33 | app.on('browser-window-created',function(e,window) { 34 | window.setMenu(null); 35 | }); 36 | 37 | app.on('window-all-closed', () => { 38 | if (process.platform !== 'darwin') app.quit(); 39 | }); 40 | 41 | app.on('activate', () => { 42 | if (win == null) createElectronShell(); 43 | }); -------------------------------------------------------------------------------- /Utils/cr-monitor-windows/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cr-web-monitor", 3 | "version": "1.0.0", 4 | "description": "CREDITS Monitor", 5 | "main": "index.js", 6 | "homepage": "credits.com", 7 | "author": "pvl1175 ", 8 | "license": "ISC", 9 | "build": { 10 | "appId": "com.credits.monitor", 11 | "productName": "CREDITS Monitor", 12 | "win": { 13 | "target": [ 14 | "nsis" 15 | ] 16 | }, 17 | "nsis": { 18 | "runAfterFinish": true 19 | } 20 | }, 21 | "scripts": { 22 | "pack": "build --dir", 23 | "dist": "build", 24 | "postinstall": "install-app-deps", 25 | "start": "electron ." 26 | }, 27 | "devDependencies": { 28 | "electron": "^1.8.8", 29 | "electron-builder": "18.0.1" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Utils/cr-web-wallet-windows/Readme.md: -------------------------------------------------------------------------------- 1 | # cr-web-wallet-windows 2 | A simple Electron application, showing the contents of the Credits Web Wallet 3 | -------------------------------------------------------------------------------- /Utils/cr-web-wallet-windows/index.js: -------------------------------------------------------------------------------- 1 | const { app, BrowserWindow } = require('electron'); 2 | 3 | let win = null; 4 | 5 | const appUrl = `http://wallet.credits.com/`; 6 | 7 | function createElectronShell() { 8 | win = new BrowserWindow( 9 | { 10 | width: 1000, 11 | height: 900, 12 | webPreferences: { 13 | plugins: true, 14 | nodeIntegration: false, 15 | webSecurity: false, 16 | allowDisplayingInsecureContent: true, 17 | allowRunningInsecureContent: true 18 | } 19 | } 20 | ); 21 | 22 | win.setMenu(null); 23 | win.loadURL(appUrl); 24 | win.on('closed', () => { 25 | win = null 26 | }); 27 | } 28 | 29 | app.commandLine.appendSwitch('ignore-certificate-errors', 'true'); 30 | 31 | app.on('ready', createElectronShell); 32 | 33 | app.on('browser-window-created',function(e,window) { 34 | window.setMenu(null); 35 | }); 36 | 37 | app.on('window-all-closed', () => { 38 | if (process.platform !== 'darwin') app.quit(); 39 | }); 40 | 41 | app.on('activate', () => { 42 | if (win == null) createElectronShell(); 43 | }); -------------------------------------------------------------------------------- /Utils/cr-web-wallet-windows/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cr-web-wallet", 3 | "version": "1.0.0", 4 | "description": "CREDITS Web Wallet", 5 | "main": "index.js", 6 | "homepage": "credits.com", 7 | "author": "pvl1175 ", 8 | "license": "ISC", 9 | "build": { 10 | "appId": "com.credits.web-wallet", 11 | "productName": "CREDITS Web Wallet", 12 | "win": { 13 | "target": [ 14 | "nsis" 15 | ] 16 | }, 17 | "nsis": { 18 | "runAfterFinish": true 19 | } 20 | }, 21 | "scripts": { 22 | "pack": "build --dir", 23 | "dist": "build", 24 | "postinstall": "install-app-deps", 25 | "start": "electron ." 26 | }, 27 | "devDependencies": { 28 | "electron": "^1.8.8", 29 | "electron-builder": "18.0.1" 30 | }, 31 | "dependencies": { 32 | "dist": "^0.1.2", 33 | "run": "^1.4.0" 34 | } 35 | } 36 | --------------------------------------------------------------------------------