diff --git a/.clang-format b/.clang-format
index 659c31276..7d430d401 100644
--- a/.clang-format
+++ b/.clang-format
@@ -2,6 +2,9 @@ BasedOnStyle: LLVM
AlignConsecutiveAssignments: true
AlignConsecutiveDeclarations: true
AlignTrailingComments: true
+AlignAfterOpenBracket: Align
+AlignEscapedNewlines: Right
+AlignOperands: true
AllowShortBlocksOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: true
AllowShortFunctionsOnASingleLine: All
diff --git a/.gitignore b/.gitignore
index b8cdc8e9c..8084eda55 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,6 +9,7 @@ _build
**/.vscode/ipch/
**/.DS_Store
/.metadata/
+/build.gradle
.DS_Store
/RemoteSystemsTempFiles/
cmake-build-debug/
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 34a630246..6c2353311 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -78,7 +78,7 @@ clang50:
clang10:
image: docker.slock.it/build-images/cmake:clang10
extends: .conanbuild
-
+
mac_os:
stage: build
script:
@@ -86,17 +86,21 @@ mac_os:
- cd mac_build
- cmake -DTEST=true -DTAG_VERSION=$CI_COMMIT_TAG -DEVM_GAS=true -DCMAKE_BUILD_TYPE=Debug -DLIBCURL_TYPE=shared ..
- make
- - CTEST_OUTPUT_ON_FAILURE=1 make test
+ - ctest -V | tee ../mac_test_c.log | test/junit > ../mac_test_c.xml
- rm -rf *
- cmake -DTAG_VERSION=$CI_COMMIT_TAG -DCMAKE_BUILD_TYPE=MINSIZEREL -DJAVA=true ..
- make
artifacts:
+ reports:
+ junit: mac_test_c.xml
paths:
- mac_build/c/docs
- mac_build/java/docs
- mac_build/lib
- mac_build/bin
+ - mac_test_c.xml
+ - mac_test_c.log
tags:
- mac-mini-runner
@@ -170,6 +174,8 @@ coverage:
image: silkeh/clang:dev
tags:
- short-jobs
+ dependencies:
+ - java_linux
script:
- mkdir cov_build; cd cov_build
- cmake -DIN3API=true -DIN3_LIB=false -DCMD=false -DUSE_CURL=false -DTEST=true -DCODE_COVERAGE=true -DUSE_SEGGER_RTT=false -DTRANSPORTS=false -DCMAKE_BUILD_TYPE=Debug ..
@@ -177,7 +183,8 @@ coverage:
- ../scripts/lcov_report.sh | xargs llvm-cov report
- ../scripts/lcov_report.sh | xargs llvm-cov show -show-line-counts-or-regions -output-dir=ccov/all-merged -format=html
- ../scripts/lcov_report.sh | xargs llvm-cov export -format=lcov > ccov/all-merged/lcov.info
-
+ - mkdir jcov
+ - cp -r ../java/build/reports/jacoco/test cov_build
artifacts:
paths:
- cov_build/ccov/all-merged
@@ -236,7 +243,7 @@ test_c:
- cd testbuild
- cmake -DTEST=true -DEVM_GAS=true -DCMAKE_BUILD_TYPE=Debug ..
- make
- - CTEST_OUTPUT_ON_FAILURE=1 make test
+ - make test
artifacts:
paths:
- testbuild/test
@@ -257,6 +264,26 @@ test_c:
# - cd ../vmTests
# - ../../../../testbuild/test/vmrunner */*.json || echo "\n ignoring failure .."
+
+test_android:
+ image: cangol/android-gradle
+ stage: test
+ tags:
+ - short-jobs
+ script:
+ - git clone https://github.com/slockit/in3-example-android.git
+ - cd in3-example-android/app
+ - cp -r ../../java/src/in3 src/main/java/
+ - mv ../../c ../../java in3-c/
+ - mkdir c
+ - cp in3-c/c/compiler.cmake c/
+ - cd ..
+ - ./gradlew build
+ artifacts:
+ paths:
+ - in3-example-android/app/build/outputs/apk
+
+
test_wasm:
image: docker.slock.it/build-images/node:10-alpine
dependencies:
@@ -269,7 +296,10 @@ test_wasm:
- cd wasm/test
- sh /prepare.sh
- npm install
- - npm test
+ - npm run test_report
+ artifacts:
+ reports:
+ junit: wasm/test/mocha.xml
test_asmjs:
image: docker.slock.it/build-images/node:10-alpine
@@ -306,6 +336,11 @@ java_linux:
- ./gradlew test
tags:
- short-jobs
+ artifacts:
+ paths:
+ - java/build/reports/jacoco/test
+ reports:
+ junit: java/build/test-results/test/TEST-*.xml
examples_linux:
image: docker.slock.it/build-images/cmake:gcc8
@@ -363,17 +398,24 @@ java_arm:
- ./gradlew test
tags:
- arm
+ artifacts:
+ reports:
+ junit: java/build/test-results/test/TEST-*.xml
java_macos:
stage: test
+ allow_failure: true
dependencies:
- java
script:
- mv java_build build
- - cd java
+ - cd java; cp test/build_test.gradle build.gradle
- ./gradlew test
tags:
- mac-mini-runner
+# artifacts:
+# reports:
+# junit: java/build/test-results/test/TEST-*.xml
##### local_docker_deploy_and_vulnerability_analysis #####
@@ -418,7 +460,7 @@ format:
tags:
- short-jobs
script:
- - find c/src/core/ c/src/cmd/ c/src/api/ c/src/verifier/ c/src/transport/ \( -name "*.c" -o -name "*.h" \) | xargs clang-format-10 -i
+ - find c/src/core/ c/src/cmd/ c/src/api/ c/src/verifier/ c/src/transport/ java \( -name "*.c" -o -name "*.h" -o -name "*.java" \) | xargs clang-format-10 -i
- git diff --patch --exit-code
cpd:
@@ -457,11 +499,13 @@ metrics:
- gcc8
- wasm
- asmjs
+ - java
script:
- echo "mac_cmd_size `stat -c %s mac_build/bin/in3` " > metrics.txt
- echo "wasm_min_size `stat -c %s wasm_build/bin/in3w_min.wasm` " >> metrics.txt
- echo "wasm_js_size `stat -c %s wasm_build/bin/in3.js` " >> metrics.txt
- echo "asmjs_js_size `stat -c %s asmjs_build/bin/in3.js` " >> metrics.txt
+ - echo "java_size `stat -c %s java_build/lib/in3.jar` " > metrics.txt
- echo "gcc8_size `stat -c %s x64_build/bin/in3` " >> metrics.txt
- echo "reported metrics"; cat metrics.txt
artifacts:
@@ -572,13 +616,22 @@ readthedocs:
dependencies:
- gcc8
script:
+ - cd scripts
+ - ./update_examples.sh
+ - cd ..
+ - export PRE_DOC=`cat wasm/docs/*.md`
- git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@git.slock.it/in3/doc.git
- git clone https://gitlab-ci-token:${CI_JOB_TOKEN}@git.slock.it/tools/generator.git
- cd generator
- npm i && npm run build
- bin/slockit-doxygen ../x64_build/c/docs/doc_doxygen/xml "# API Reference C\n\n" > ../doc/docs/api-c.md
- bin/slockit-doxygen ../x64_build/java/docs/doc_doxygen/xml "# API Reference Java\n\n" java > ../doc/docs/api-java.md
- - cd ../doc/docs && make html && make latexpdf && make text
+ - chmod 777 bin/*
+ - cd ../wasm/src
+ - npm i typedoc
+ - node_modules/.bin/typedoc --includeDeclarations --ignoreCompilerErrors --readme none --target ES6 --mode 'modules' --excludeExternals --json doc.json in3.d.ts
+ - cat doc.json | ../../generator/bin/slockit-docu in3.d slockit/in3-c/blob/master/wasm/src "$PRE_DOC" > ../../doc/docs/api-wasm.md
+ - cd ../../doc/docs && make html && make latexpdf && make text
artifacts:
paths:
- doc/build
@@ -599,6 +652,7 @@ release_mac_and_wasm:
- readthedocs
- wasm
- asmjs
+ - java
script:
- export IMAGE_VERSION=$(echo ${CI_COMMIT_TAG} | grep -E '\d+.*' -o)
- mkdir in3-mac-wasm
@@ -607,14 +661,17 @@ release_mac_and_wasm:
- cp -r ../mac_build/lib .
- cp -r ../c ../java ../CMakeLists.txt ../python ../wasm ../README.md ../LICENSE ../LICENSE.AGPL .
- cp -r ../doc/build doc
- - cp -r ../wasm_build/module js-wasm
- - cp -r ../wasm_build/module js-asmjs
+ - cp -r ../wasm_build/module wasm/release-wasm
+ - cp -r ../asmjs_build/module wasm/release-asmjs
+ - cp ../java_build/lib/in3.jar lib/in3.jar
- cd ..
- - tar -zcv --exclude=in3-mac-wasm/src --exclude=in3-mac-wasm/c/include --exclude=in3-mac-wasm/js-wasm --exclude=in3-mac-wasm/js-asmjs --exclude=*cmake* -f in3_${CI_COMMIT_TAG}_mac.tar.gz in3-mac-wasm/
+ - tar -zcv --exclude=*cmake* -f in3_${CI_COMMIT_TAG}_mac.tar.gz in3-mac-wasm/
- IPFS_RESPONSE=$(curl -X POST https://api.pinata.cloud/pinning/pinFileToIPFS -H 'Content-Type:multipart/form-data' -H 'pinata_api_key:'"$PINATA_API_KEY" -H 'pinata_secret_api_key:'"$PINATA_SECRET_API_KEY" -F file=@in3_${CI_COMMIT_TAG}_mac.tar.gz -F 'pinataMetadata={"name":"in3_'${CI_COMMIT_TAG}'_mac.tar.gz","keyValues":{"version":"${CI_COMMIT_TAG}"}}' -F 'pinataOptions={"cidVersion":0}')
- "IPFS_HASH=$(echo $IPFS_RESPONSE | sed -e 's/[{}]/''/g' | awk -v RS=',' -F: '/IpfsHash/ {print $2}')"
- ghr -u slockIt -r in3-c $CI_COMMIT_TAG in3_${CI_COMMIT_TAG}_mac.tar.gz
- - tar -zcv --exclude=in3-mac-wasm/src --exclude=in3-mac-wasm/c/include --exclude=in3-mac-wasm/bin --exclude=in3-mac-wasm/lib --exclude=*cmake* -f in3_${CI_COMMIT_TAG}_wasm.tar.gz in3-mac-wasm/
+ - mv wasm/release-wasm .
+ - mv wasm/release-asmjs .
+ - tar -zcv --exclude=in3-mac-wasm/python --exclude=in3-mac-wasm/java --exclude=in3-mac-wasm/bin --exclude=in3-mac-wasm/lib --exclude=*cmake* -f in3_${CI_COMMIT_TAG}_wasm.tar.gz in3-mac-wasm/
- IPFS_RESPONSE=$(curl -X POST https://api.pinata.cloud/pinning/pinFileToIPFS -H 'Content-Type:multipart/form-data' -H 'pinata_api_key:'"$PINATA_API_KEY" -H 'pinata_secret_api_key:'"$PINATA_SECRET_API_KEY" -F file=@in3_${CI_COMMIT_TAG}_wasm.tar.gz -F 'pinataMetadata={"name":"in3_'${CI_COMMIT_TAG}'_wasm.tar.gz","keyValues":{"version":"${CI_COMMIT_TAG}"}}' -F 'pinataOptions={"cidVersion":0}')
- "IPFS_HASH=$(echo $IPFS_RESPONSE | sed -e 's/[{}]/''/g' | awk -v RS=',' -F: '/IpfsHash/ {print $2}')"
- echo "Mac release:" $IPFS_HASH >> in3-mac-wasm/mac_release_ipfs_hash.txt
@@ -634,6 +691,7 @@ release_x64:
- readthedocs
- wasm
- asmjs
+ - java
only:
- /^v[0-9]+.[0-9]+.[0-9]+(\-RC[0-9]+)?$/
except:
@@ -647,10 +705,11 @@ release_x64:
- cp -r ../x64_build/lib .
- cp -r ../c ../java ../CMakeLists.txt ../python ../wasm ../README.md ../LICENSE ../LICENSE.AGPL .
- cp -r ../doc/build doc
- - cp -r ../wasm_build/module js-wasm
- - cp -r ../asmjs_build/module js-asmjs
+ - cp -r ../wasm_build/module wasm/release-wasm
+ - cp -r ../asmjs_build/module wasm/release-asmjs
+ - cp ../java_build/lib/in3.jar lib/in3.jar
- cd ..
- - tar -zcv --exclude=in3-x64/src --exclude=in3-x64/c/include --exclude=in3-x64/js-asmjs --exclude=in3-x64/js-wasm --exclude=*cmake* -f in3_${CI_COMMIT_TAG}_x64.tar.gz in3-x64/
+ - tar -zcv --exclude=*cmake* -f in3_${CI_COMMIT_TAG}_x64.tar.gz in3-x64/
- IPFS_RESPONSE=$(curl -X POST https://api.pinata.cloud/pinning/pinFileToIPFS -H 'Content-Type:multipart/form-data' -H 'pinata_api_key:'"$PINATA_API_KEY" -H 'pinata_secret_api_key:'"$PINATA_SECRET_API_KEY" -F file=@in3_${CI_COMMIT_TAG}_x64.tar.gz -F 'pinataMetadata={"name":"in3_'${CI_COMMIT_TAG}'_mac.tar.gz","keyValues":{"version":"${CI_COMMIT_TAG}"}}' -F 'pinataOptions={"cidVersion":0}')
- "IPFS_HASH=$(echo $IPFS_RESPONSE | sed -e 's/[{}]/''/g' | awk -v RS=',' -F: '/IpfsHash/ {print $2}')"
- echo "x64 release:" $IPFS_HASH >> in3-x64/x64_release_ipfs_hash.txt
@@ -676,6 +735,7 @@ release_x86:
- readthedocs
- wasm
- asmjs
+ - java
script:
- export IMAGE_VERSION=$(echo ${CI_COMMIT_TAG} | grep -E '\d+.*' -o)
- mkdir in3-x86
@@ -684,10 +744,11 @@ release_x86:
- cp -r ../x86_build/lib .
- cp -r ../c ../java ../CMakeLists.txt ../python ../wasm ../README.md ../LICENSE ../LICENSE.AGPL .
- cp -r ../doc/build doc
- - cp -r ../wasm_build/module js-wasm
- - cp -r ../wasm_build/module js-asmjs
+ - cp -r ../wasm_build/module wasm/release-wasm
+ - cp -r ../asmjs_build/module wasm/release-asmjs
+ - cp ../java_build/lib/in3.jar lib/in3.jar
- cd ..
- - tar -zcv --exclude=in3-x86/src --exclude=in3-x86/c/include --exclude=in3-x86/js-asmjs --exclude=in3-x86/js-wasm --exclude=*cmake* -f in3_${CI_COMMIT_TAG}_x86.tar.gz in3-x86/
+ - tar -zcv --exclude=*cmake* -f in3_${CI_COMMIT_TAG}_x86.tar.gz in3-x86/
- IPFS_RESPONSE=$(curl -X POST https://api.pinata.cloud/pinning/pinFileToIPFS -H 'Content-Type:multipart/form-data' -H 'pinata_api_key:'"$PINATA_API_KEY" -H 'pinata_secret_api_key:'"$PINATA_SECRET_API_KEY" -F file=@in3_${CI_COMMIT_TAG}_x86.tar.gz -F 'pinataMetadata={"name":"in3_'${CI_COMMIT_TAG}'_x86.tar.gz","keyValues":{"version":"${CI_COMMIT_TAG}"}}' -F 'pinataOptions={"cidVersion":0}')
- "IPFS_HASH=$(echo $IPFS_RESPONSE | sed -e 's/[{}]/''/g' | awk -v RS=',' -F: '/IpfsHash/ {print $2}')"
- echo "x86 release:" $IPFS_HASH >> in3-x86/x86_release_ipfs_hash.txt
@@ -713,19 +774,20 @@ release_arm7:
- readthedocs
- wasm
- asmjs
+ - java
script:
- export IMAGE_VERSION=$(echo ${CI_COMMIT_TAG} | grep -E '\d+.*' -o)
- mkdir in3-arm7
- cd in3-arm7
- - mkdir doc
- cp -r ../arm7_build/bin .
- cp -r ../arm7_build/lib .
- cp -r ../c ../java ../CMakeLists.txt ../python ../wasm ../README.md ../LICENSE ../LICENSE.AGPL .
- cp -r ../doc/build doc
- - cp -r ../wasm_build/module js-wasm
- - cp -r ../wasm_build/module js-asmjs
+ - cp -r ../wasm_build/module wasm/release-wasm
+ - cp -r ../asmjs_build/module wasm/release-asmjs
+ - cp ../java_build/lib/in3.jar lib/in3.jar
- cd ..
- - tar -zcv --exclude=in3-arm7/src --exclude=in3-arm7/c/include --exclude=in3-arm7/js-asmjs --exclude=in3-arm7/js-wasm --exclude=*cmake* -f in3_${CI_COMMIT_TAG}_arm7.tar.gz in3-arm7/
+ - tar -zcv --exclude=*cmake* -f in3_${CI_COMMIT_TAG}_arm7.tar.gz in3-arm7/
- IPFS_RESPONSE=$(curl -X POST https://api.pinata.cloud/pinning/pinFileToIPFS -H 'Content-Type:multipart/form-data' -H 'pinata_api_key:'"$PINATA_API_KEY" -H 'pinata_secret_api_key:'"$PINATA_SECRET_API_KEY" -F file=@in3_${CI_COMMIT_TAG}_arm7.tar.gz -F 'pinataMetadata={"name":"in3_'${CI_COMMIT_TAG}'_arm7.tar.gz","keyValues":{"version":"${CI_COMMIT_TAG}"}}' -F 'pinataOptions={"cidVersion":0}')
- "IPFS_HASH=$(echo $IPFS_RESPONSE | sed -e 's/[{}]/''/g' | awk -v RS=',' -F: '/IpfsHash/ {print $2}')"
- echo "arm7 release:" $IPFS_HASH >> in3-arm7/arm7_release_ipfs_hash.txt
@@ -751,11 +813,11 @@ release_win:
- readthedocs
- wasm
- asmjs
+ - java
script:
- export IMAGE_VERSION=$(echo ${CI_COMMIT_TAG} | grep -E '\d+.*' -o)
- mkdir in3-win
- cd in3-win
- - mkdir doc
- cp -r ../win_build/bin .
- cp -r ../win_build/lib .
- mv bin/in3 bin/in3.exe
@@ -764,10 +826,11 @@ release_win:
- mv lib/libin3.so lib/in3.dll
- cp -r ../c ../java ../CMakeLists.txt ../python ../wasm ../README.md ../LICENSE ../LICENSE.AGPL .
- cp -r ../doc/build doc
- - cp -r ../wasm_build/module js-wasm
- - cp -r ../wasm_build/module js-asmjs
+ - cp -r ../wasm_build/module wasm/release-wasm
+ - cp -r ../asmjs_build/module wasm/release-asmjs
+ - cp ../java_build/lib/in3.jar lib/in3.jar
- cd ..
- - tar -zcv --exclude=in3-win/src --exclude=in3-win/c/include --exclude=in3-win/js-asmjs --exclude=in3-win/js-wasm --exclude=*cmake* -f in3_${CI_COMMIT_TAG}_windows.tar.gz in3-win/
+ - tar -zcv --exclude=*cmake* -f in3_${CI_COMMIT_TAG}_windows.tar.gz in3-win/
- IPFS_RESPONSE=$(curl -X POST https://api.pinata.cloud/pinning/pinFileToIPFS -H 'Content-Type:multipart/form-data' -H 'pinata_api_key:'"$PINATA_API_KEY" -H 'pinata_secret_api_key:'"$PINATA_SECRET_API_KEY" -F file=@in3_${CI_COMMIT_TAG}_windows.tar.gz -F 'pinataMetadata={"name":"in3_'${CI_COMMIT_TAG}'_windows.tar.gz","keyValues":{"version":"${CI_COMMIT_TAG}"}}' -F 'pinataOptions={"cidVersion":0}')
- "IPFS_HASH=$(echo $IPFS_RESPONSE | sed -e 's/[{}]/''/g' | awk -v RS=',' -F: '/IpfsHash/ {print $2}')"
- echo "windows release:" $IPFS_HASH >> in3-win/win_release_ipfs_hash.txt
@@ -820,17 +883,18 @@ release_pip:
pages:
stage: deploy
+ tags:
+ - arm
only:
refs:
- develop
- tags:
- - arm
dependencies:
- arm7
- readthedocs
- coverage
- clangcheck
- vulnerabilities
+ - java_linux
script:
- mkdir -p public/lib
- tar -zcvf libFiles_$CI_COMMIT_SHORT_SHA.tar.gz arm7_build/lib
@@ -840,7 +904,8 @@ pages:
- cp -r report/* public/code_analysis
- cp -r doc/build public/rtd
- cp -r vulnerability_analysis.json public/vulnerability_analysis.json
- - echo "
Incubed report for last build
" > public/index.html
+ - cp -r java/build/reports/jacoco/test/html public/coverage_java
+ - echo "Incubed report for last build
" > public/index.html
artifacts:
paths:
- public
diff --git a/.vscode/launch.json b/.vscode/launch.json
index 350db8d47..6e29ead5e 100644
--- a/.vscode/launch.json
+++ b/.vscode/launch.json
@@ -4,6 +4,13 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
+ {
+ "type": "java",
+ "name": "Debug (Attach)",
+ "request": "attach",
+ "hostName": "localhost",
+ "port": "5005"
+ },
{
"type": "lldb",
"request": "launch",
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 2091f7301..f0389e788 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -2,7 +2,7 @@
# This file is part of the Incubed project.
# Sources: https://github.com/slockit/in3-c
#
-# Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+# Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
#
#
# COMMERCIAL LICENSE USAGE
@@ -45,6 +45,7 @@ option(ETH_NANO "build minimal eth verification.(eth_getTransactionReceipt)" ON)
option(ETH_BASIC "build basic eth verification.(all rpc-calls except eth_call)" ON)
option(ETH_FULL "build full eth verification.(including eth_call)" ON)
option(IPFS "build IPFS verification" ON)
+option(COLOR "Enable color codes for debug" ON)
option(BTC "if true, the bitcoin verifiers will be build" OFF)
option(IN3API "build the USN-API which offer better interfaces and additional functions on top of the pure verification" ON)
option(USE_PRECOMPUTED_EC "if true the secp256k1 curve uses precompiled tables to boost performance. turning this off makes ecrecover slower, but saves about 37kb." ON)
@@ -99,6 +100,11 @@ if(IPFS)
set(IN3_VERIFIER ${IN3_VERIFIER} ipfs)
endif()
+if(COLOR AND NOT (MSVC OR MSYS OR MINGW))
+ ADD_DEFINITIONS(-DLOG_USE_COLOR)
+endif()
+
+
if(CMAKE_BUILD_TYPE MATCHES Debug)
ADD_DEFINITIONS(-DDEBUG)
endif(CMAKE_BUILD_TYPE MATCHES Debug)
@@ -150,7 +156,6 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
if(TEST)
MESSAGE(STATUS "Build Tests and add debug infos")
ADD_DEFINITIONS(-DTEST)
- ADD_DEFINITIONS(-DLOG_USE_COLOR)
ADD_DEFINITIONS(-DIN3_DONT_HASH_KEYS)
ADD_DEFINITIONS(-DIN3_EXPORT_TEST=)
ADD_DEFINITIONS(-DIN3_IMPORT_TEST=extern)
@@ -159,6 +164,7 @@ if(TEST)
enable_testing()
add_subdirectory(c/test)
add_custom_target(ptest COMMAND ${CMAKE_CTEST_COMMAND} -j 8)
+ add_custom_target(rtest COMMAND ${CMAKE_CTEST_COMMAND} -V )
endif(TEST)
diff --git a/Dockerfile b/Dockerfile
index 7b8996999..b1d83cf6f 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -2,7 +2,7 @@
# This file is part of the Incubed project.
# Sources: https://github.com/slockit/in3-c
#
-# Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+# Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
#
#
# COMMERCIAL LICENSE USAGE
diff --git a/c/CMakeLists.txt b/c/CMakeLists.txt
index 907052c56..c261eb242 100644
--- a/c/CMakeLists.txt
+++ b/c/CMakeLists.txt
@@ -2,7 +2,7 @@
# This file is part of the Incubed project.
# Sources: https://github.com/slockit/in3-c
#
-# Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+# Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
#
#
# COMMERCIAL LICENSE USAGE
@@ -41,10 +41,13 @@ add_subdirectory(src/core)
add_subdirectory(src/transport)
add_subdirectory(src/verifier)
add_subdirectory(src/api)
-add_subdirectory(src/cmd)
+IF (ETH_FULL)
+ add_subdirectory(src/cmd)
+endif()
add_subdirectory(docs)
+
# create the library
if (IN3_LIB)
set(IN3_LIBS
diff --git a/c/compiler.cmake b/c/compiler.cmake
index 56310a9d6..53235f1fe 100644
--- a/c/compiler.cmake
+++ b/c/compiler.cmake
@@ -3,7 +3,11 @@ if(MSVC)
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall -funsigned-char -std=c99 -D__FILENAME__=none")
else(MSVC)
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fPIC -Wall -funsigned-char -Wextra -std=c99")
- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall -funsigned-char -Wextra -std=c99 -D__FILENAME__='\"$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<))\"'")
+ if (NOT DEFINED ANDROID_ABI)
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall -funsigned-char -Wextra -std=c99 -D__FILENAME__='\"$(subst ${CMAKE_SOURCE_DIR}/,,$(abspath $<))\"'")
+ else()
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -Wall -funsigned-char -Wextra -std=c99 -D__FILENAME__=none")
+ endif()
endif(MSVC)
if (WASM)
set (CMAKE_C_FLAGS "-Wall -funsigned-char -Wextra -std=c99")
diff --git a/c/include/in3/api_utils.h b/c/include/in3/api_utils.h
index 888e7c66a..e4b8754f1 100644
--- a/c/include/in3/api_utils.h
+++ b/c/include/in3/api_utils.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/include/in3/bytes.h b/c/include/in3/bytes.h
index e2ab5b7cc..66d74b956 100644
--- a/c/include/in3/bytes.h
+++ b/c/include/in3/bytes.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/include/in3/chainspec.h b/c/include/in3/chainspec.h
index acf0808dc..11acd9968 100644
--- a/c/include/in3/chainspec.h
+++ b/c/include/in3/chainspec.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/include/in3/client.h b/c/include/in3/client.h
index 59c3d2014..ad1244f35 100644
--- a/c/include/in3/client.h
+++ b/c/include/in3/client.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/include/in3/context.h b/c/include/in3/context.h
index 208a5e9ec..1b7caf1bf 100644
--- a/c/include/in3/context.h
+++ b/c/include/in3/context.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -38,11 +38,11 @@
* This is used for each request holding request and response-pointers but also controls the execution process.
* */
+#include "client.h"
#include "data.h"
#include "scache.h"
#include "stringbuilder.h"
#include "utils.h"
-#include "client.h"
#include
#include
#ifndef CONTEXT_H
diff --git a/c/include/in3/data.h b/c/include/in3/data.h
index dd416abba..99cd01a58 100644
--- a/c/include/in3/data.h
+++ b/c/include/in3/data.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/include/in3/error.h b/c/include/in3/error.h
index 3c7e8a64c..fdb58ee4f 100644
--- a/c/include/in3/error.h
+++ b/c/include/in3/error.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/include/in3/eth_api.h b/c/include/in3/eth_api.h
index 0ba99d206..09e0b6cfc 100644
--- a/c/include/in3/eth_api.h
+++ b/c/include/in3/eth_api.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -42,8 +42,8 @@
#ifndef ETH_API_H
#define ETH_API_H
-#include "client.h"
#include "api_utils.h"
+#include "client.h"
#include
/** Initializer macros for eth_blknum_t */
diff --git a/c/include/in3/eth_basic.h b/c/include/in3/eth_basic.h
index 5b40f50c7..988dcb075 100644
--- a/c/include/in3/eth_basic.h
+++ b/c/include/in3/eth_basic.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/include/in3/eth_full.h b/c/include/in3/eth_full.h
index 025bad414..787a9bb53 100644
--- a/c/include/in3/eth_full.h
+++ b/c/include/in3/eth_full.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/include/in3/eth_nano.h b/c/include/in3/eth_nano.h
index 64b926903..837b1bee9 100644
--- a/c/include/in3/eth_nano.h
+++ b/c/include/in3/eth_nano.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/include/in3/in3_curl.h b/c/include/in3/in3_curl.h
index 4d69349df..5b0a3e42a 100644
--- a/c/include/in3/in3_curl.h
+++ b/c/include/in3/in3_curl.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/include/in3/in3_http.h b/c/include/in3/in3_http.h
index 9dc67b898..ce11ef9ec 100644
--- a/c/include/in3/in3_http.h
+++ b/c/include/in3/in3_http.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/include/in3/ipfs.h b/c/include/in3/ipfs.h
index 0671e4e39..2dd561588 100644
--- a/c/include/in3/ipfs.h
+++ b/c/include/in3/ipfs.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/include/in3/ipfs_api.h b/c/include/in3/ipfs_api.h
index 215643929..ae3e458dc 100644
--- a/c/include/in3/ipfs_api.h
+++ b/c/include/in3/ipfs_api.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -42,8 +42,8 @@
#ifndef IN3_IPFS_API_H
#define IN3_IPFS_API_H
-#include "client.h"
#include "bytes.h"
+#include "client.h"
char* ipfs_put(in3_t* in3, const bytes_t* content); /**< Returns the IPFS multihash of stored content on success OR NULL on error (check api_last_error()). Result must be freed by caller. */
bytes_t* ipfs_get(in3_t* in3, const char* multihash); /**< Returns the content associated with specified multihash on success OR NULL on error (check api_last_error()). Result must be freed by caller. */
diff --git a/c/include/in3/rpc.h b/c/include/in3/rpc.h
index 450cf0633..e79ff21ec 100644
--- a/c/include/in3/rpc.h
+++ b/c/include/in3/rpc.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/include/in3/scache.h b/c/include/in3/scache.h
index 934b45912..5bffd7fe6 100644
--- a/c/include/in3/scache.h
+++ b/c/include/in3/scache.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/include/in3/signer.h b/c/include/in3/signer.h
index 118f30bda..1a3a4c68d 100644
--- a/c/include/in3/signer.h
+++ b/c/include/in3/signer.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/include/in3/stringbuilder.h b/c/include/in3/stringbuilder.h
index 96c18a410..94014900c 100644
--- a/c/include/in3/stringbuilder.h
+++ b/c/include/in3/stringbuilder.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/include/in3/usn_api.h b/c/include/in3/usn_api.h
index 91f93ae0a..22a8a8f3b 100644
--- a/c/include/in3/usn_api.h
+++ b/c/include/in3/usn_api.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/include/in3/utils.h b/c/include/in3/utils.h
index 442115942..6dd2ca963 100644
--- a/c/include/in3/utils.h
+++ b/c/include/in3/utils.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/include/in3/verifier.h b/c/include/in3/verifier.h
index 0675c2fc0..b0535dbc0 100644
--- a/c/include/in3/verifier.h
+++ b/c/include/in3/verifier.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -38,11 +38,11 @@
* This context is passed to the verifier.
* */
+#include "client.h"
+#include "context.h"
#include "data.h"
#include "stringbuilder.h"
#include "utils.h"
-#include "client.h"
-#include "context.h"
#include
#include
diff --git a/c/src/api/CMakeLists.txt b/c/src/api/CMakeLists.txt
index 13e53e433..9add16dff 100644
--- a/c/src/api/CMakeLists.txt
+++ b/c/src/api/CMakeLists.txt
@@ -2,7 +2,7 @@
# This file is part of the Incubed project.
# Sources: https://github.com/slockit/in3-c
#
-# Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+# Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
#
#
# COMMERCIAL LICENSE USAGE
diff --git a/c/src/api/eth1/CMakeLists.txt b/c/src/api/eth1/CMakeLists.txt
index f355d93d3..2a815d620 100644
--- a/c/src/api/eth1/CMakeLists.txt
+++ b/c/src/api/eth1/CMakeLists.txt
@@ -2,7 +2,7 @@
# This file is part of the Incubed project.
# Sources: https://github.com/slockit/in3-c
#
-# Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+# Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
#
#
# COMMERCIAL LICENSE USAGE
diff --git a/c/src/api/eth1/abi.c b/c/src/api/eth1/abi.c
index 33e88cc88..2c7ed7ef3 100644
--- a/c/src/api/eth1/abi.c
+++ b/c/src/api/eth1/abi.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/api/eth1/abi.h b/c/src/api/eth1/abi.h
index d8faa2151..339fdb7de 100644
--- a/c/src/api/eth1/abi.h
+++ b/c/src/api/eth1/abi.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/api/eth1/ens.h b/c/src/api/eth1/ens.h
index 238c46ead..157b501b3 100644
--- a/c/src/api/eth1/ens.h
+++ b/c/src/api/eth1/ens.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/api/eth1/eth_api.c b/c/src/api/eth1/eth_api.c
index 78e6b1348..acf88dae4 100644
--- a/c/src/api/eth1/eth_api.c
+++ b/c/src/api/eth1/eth_api.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/api/eth1/eth_api.h b/c/src/api/eth1/eth_api.h
index 3a90b520f..23d55a211 100644
--- a/c/src/api/eth1/eth_api.h
+++ b/c/src/api/eth1/eth_api.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/api/eth1/key.c b/c/src/api/eth1/key.c
index f8a5efdad..e570a4c61 100644
--- a/c/src/api/eth1/key.c
+++ b/c/src/api/eth1/key.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/api/eth1/rpc_api.c b/c/src/api/eth1/rpc_api.c
index ed3bdc893..3e3de841a 100644
--- a/c/src/api/eth1/rpc_api.c
+++ b/c/src/api/eth1/rpc_api.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/api/ipfs/CMakeLists.txt b/c/src/api/ipfs/CMakeLists.txt
index a28e01ce3..c9c6c3111 100644
--- a/c/src/api/ipfs/CMakeLists.txt
+++ b/c/src/api/ipfs/CMakeLists.txt
@@ -2,7 +2,7 @@
# This file is part of the Incubed project.
# Sources: https://github.com/slockit/in3-c
#
-# Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+# Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
#
#
# COMMERCIAL LICENSE USAGE
diff --git a/c/src/api/ipfs/ipfs_api.c b/c/src/api/ipfs/ipfs_api.c
index ca4e3e364..081d85271 100644
--- a/c/src/api/ipfs/ipfs_api.c
+++ b/c/src/api/ipfs/ipfs_api.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/api/ipfs/ipfs_api.h b/c/src/api/ipfs/ipfs_api.h
index 9365bbf38..001a31b3c 100644
--- a/c/src/api/ipfs/ipfs_api.h
+++ b/c/src/api/ipfs/ipfs_api.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/api/usn/CMakeLists.txt b/c/src/api/usn/CMakeLists.txt
index ef91f0fe6..4a2ba1717 100644
--- a/c/src/api/usn/CMakeLists.txt
+++ b/c/src/api/usn/CMakeLists.txt
@@ -2,7 +2,7 @@
# This file is part of the Incubed project.
# Sources: https://github.com/slockit/in3-c
#
-# Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+# Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
#
#
# COMMERCIAL LICENSE USAGE
diff --git a/c/src/api/usn/usn_api.c b/c/src/api/usn/usn_api.c
index 547ad5ed6..4fedf462b 100644
--- a/c/src/api/usn/usn_api.c
+++ b/c/src/api/usn/usn_api.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/api/usn/usn_api.h b/c/src/api/usn/usn_api.h
index 4c09df1f3..12ca2e9ab 100644
--- a/c/src/api/usn/usn_api.h
+++ b/c/src/api/usn/usn_api.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/api/utils/api_utils.h b/c/src/api/utils/api_utils.h
index 888e7c66a..e4b8754f1 100644
--- a/c/src/api/utils/api_utils.h
+++ b/c/src/api/utils/api_utils.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/api/utils/api_utils_priv.c b/c/src/api/utils/api_utils_priv.c
index 7c1e0a55b..29bbbeb7e 100644
--- a/c/src/api/utils/api_utils_priv.c
+++ b/c/src/api/utils/api_utils_priv.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/api/utils/api_utils_priv.h b/c/src/api/utils/api_utils_priv.h
index 175943377..876b523f6 100644
--- a/c/src/api/utils/api_utils_priv.h
+++ b/c/src/api/utils/api_utils_priv.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/cmd/CMakeLists.txt b/c/src/cmd/CMakeLists.txt
index df8d4c80b..02452f1af 100644
--- a/c/src/cmd/CMakeLists.txt
+++ b/c/src/cmd/CMakeLists.txt
@@ -2,7 +2,7 @@
# This file is part of the Incubed project.
# Sources: https://github.com/slockit/in3-c
#
-# Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+# Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
#
#
# COMMERCIAL LICENSE USAGE
diff --git a/c/src/cmd/http-server/CMakeLists.txt b/c/src/cmd/http-server/CMakeLists.txt
index 7cfcf0181..8a75d5923 100644
--- a/c/src/cmd/http-server/CMakeLists.txt
+++ b/c/src/cmd/http-server/CMakeLists.txt
@@ -2,7 +2,7 @@
# This file is part of the Incubed project.
# Sources: https://github.com/slockit/in3-c
#
-# Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+# Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
#
#
# COMMERCIAL LICENSE USAGE
diff --git a/c/src/cmd/http-server/http_server.c b/c/src/cmd/http-server/http_server.c
index e6a040f70..8a34d284d 100644
--- a/c/src/cmd/http-server/http_server.c
+++ b/c/src/cmd/http-server/http_server.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -34,6 +34,7 @@
#include "http_server.h"
#include "../../core/client/context.h"
+#include "../../core/util/colors.h"
#include "../../core/util/mem.h"
#include
#include
@@ -132,7 +133,7 @@ void http_run_server(const char* port, in3_t* in3) {
printf(
"Server started %shttp://127.0.0.1:%s%s\n",
- "\033[92m", port, "\033[0m");
+ COLORT_LIGHTGREEN, port, COLORT_RESET);
for (int i = 0; i < MAX_CON; i++) clients[i] = -1;
diff --git a/c/src/cmd/http-server/http_server.h b/c/src/cmd/http-server/http_server.h
index 60a13beb8..b0e6e7f9c 100644
--- a/c/src/cmd/http-server/http_server.h
+++ b/c/src/cmd/http-server/http_server.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/cmd/in3/CMakeLists.txt b/c/src/cmd/in3/CMakeLists.txt
index 9ddd3bab9..ba40ab30b 100644
--- a/c/src/cmd/in3/CMakeLists.txt
+++ b/c/src/cmd/in3/CMakeLists.txt
@@ -2,7 +2,7 @@
# This file is part of the Incubed project.
# Sources: https://github.com/slockit/in3-c
#
-# Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+# Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
#
#
# COMMERCIAL LICENSE USAGE
diff --git a/c/src/cmd/in3/in3_storage.c b/c/src/cmd/in3/in3_storage.c
index 2d5c46991..a43ec165d 100644
--- a/c/src/cmd/in3/in3_storage.c
+++ b/c/src/cmd/in3/in3_storage.c
@@ -3,7 +3,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/cmd/in3/in3_storage.h b/c/src/cmd/in3/in3_storage.h
index ecabc6f64..aee393ddd 100644
--- a/c/src/cmd/in3/in3_storage.h
+++ b/c/src/cmd/in3/in3_storage.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/cmd/in3/main.c b/c/src/cmd/in3/main.c
index 76e644442..b0b31012c 100644
--- a/c/src/cmd/in3/main.c
+++ b/c/src/cmd/in3/main.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -38,6 +38,7 @@
#include "../../api/eth1/abi.h"
#include "../../api/eth1/eth_api.h"
+#include "../../core/util/bitset.h"
#include "../../core/util/data.h"
#include "../../core/util/debug.h"
#include "../../core/util/log.h"
@@ -58,6 +59,7 @@
#include "../../core/client/keys.h"
#include "../../core/client/nodelist.h"
#include "../../core/client/version.h"
+#include "../../core/util/colors.h"
#include "../../verifier/eth1/basic/signer.h"
#include "../../verifier/eth1/evm/evm.h"
#include "../../verifier/eth1/full/eth_full.h"
@@ -166,7 +168,7 @@ in3_ens \n\
}
static void die(char* msg) {
- fprintf(stderr, "\033[31mError: %s\033[0m\n", msg);
+ fprintf(stderr, COLORT_RED "Error: %s" COLORT_RESET "\n", msg);
exit(EXIT_FAILURE);
}
@@ -179,7 +181,7 @@ static void print_hex(uint8_t* data, int len) {
// helper to read the password from tty
void read_pass(char* pw, int pwsize) {
int i = 0, ch = 0;
- fprintf(stderr, "\033[8m"); //conceal typing and save position
+ fprintf(stderr, COLORT_HIDDEN); //conceal typing and save position
while (true) {
ch = getchar();
if (ch == '\r' || ch == '\n' || ch == EOF) break; //get characters until CR or NL
@@ -189,7 +191,7 @@ void read_pass(char* pw, int pwsize) {
}
i++;
}
- fprintf(stderr, "\033[28m"); //reveal typing
+ fprintf(stderr, COLORT_RESETHIDDEN); //reveal typing
}
// accepts a value as
@@ -525,7 +527,7 @@ static bytes_t in_response = {.data = NULL, .len = 0};
static in3_ret_t debug_transport(in3_request_t* req) {
#ifndef DEBUG
if (debug_mode)
- fprintf(stderr, "send request to %s: \n\033[0;33m%s\033[0m\n", req->urls_len ? req->urls[0] : "none", req->payload);
+ fprintf(stderr, "send request to %s: \n" COLORT_RYELLOW "%s" COLORT_RESET "\n", req->urls_len ? req->urls[0] : "none", req->payload);
#endif
if (in_response.len) {
for (int i = 0; i < req->urls_len; i++)
@@ -541,9 +543,9 @@ static in3_ret_t debug_transport(in3_request_t* req) {
#ifndef DEBUG
if (debug_mode) {
if (req->results[0].result.len)
- fprintf(stderr, "success response \n\033[0;32m%s\033[0m\n", req->results[0].result.data);
+ fprintf(stderr, "success response \n" COLORT_RGREEN "%s" COLORT_RESET "\n", req->results[0].result.data);
else
- fprintf(stderr, "error response \n\033[0;31m%s\033[0m\n", req->results[0].error.data);
+ fprintf(stderr, "error response \n" COLORT_RRED "%s" COLORT_RESET "\n", req->results[0].error.data);
}
#endif
return r;
@@ -648,7 +650,9 @@ int main(int argc, char* argv[]) {
#ifdef __MINGW32__
c->flags |= FLAGS_HTTP;
#endif
-
+#ifndef USE_CURL
+ c->flags |= FLAGS_HTTP;
+#endif
// handle clear cache opt before initializing cache
for (i = 1; i < argc; i++)
if (strcmp(argv[i], "-ccache") == 0)
@@ -846,7 +850,9 @@ int main(int argc, char* argv[]) {
return 0;
} else if (strcmp(method, "in3_weights") == 0) {
- c->max_attempts = 1;
+ c->max_attempts = 1;
+ uint32_t block = 0, b = 0;
+ BIT_CLEAR(c->flags, FLAGS_AUTO_UPDATE_LIST);
uint64_t now = in3_time(NULL);
in3_chain_t* chain = in3_find_chain(c, c->chain_id);
printf(" : %45s : %7s : %5s : %5s: %s\n----------------------------------------------------------------------------------------\n", "URL", "BL", "CNT", "AVG", run_test_request ? "WEIGHT : LAST_BLOCK" : "WEIGHT");
@@ -864,26 +870,38 @@ int main(int argc, char* argv[]) {
in3_node_weight_t* weight = chain->weights + i;
uint64_t blacklisted = weight->blacklisted_until > now ? weight->blacklisted_until : 0;
uint32_t calc_weight = in3_node_calculate_weight(weight, node->capacity);
- if (blacklisted) printf("\033[31m");
- char* tr = NULL;
+ char * tr = NULL, *warning = NULL;
if (ctx) {
- tr = _malloc(100);
+ tr = _malloc(300);
if (!ctx->error) {
- sprintf(tr, "#%i", d_get_intk(ctx->responses[0], K_RESULT));
- }
+ b = d_get_intk(ctx->responses[0], K_RESULT);
+ if (block < b) block = b;
+ if (b < block - 1)
+ sprintf((warning = tr), "#%i ( out of sync : %i blocks behind latest )", b, block - b);
+ else if (strncmp(node->url, "https://", 8))
+ sprintf((warning = tr), "#%i (missing https, which is required in a browser )", b);
+ else
+ sprintf(tr, "#%i", b);
+ } else if (!strlen(node->url) || !node->props)
+ sprintf((warning = tr), "No URL spcified anymore props = %i ", (int) (node->props & 0xFFFFFF));
else if ((node->props & NODE_PROP_DATA) == 0)
- sprintf(tr, "The node is marked as not supporting Data-Providing");
+ sprintf((warning = tr), "The node is marked as not supporting Data-Providing");
else if (c->proof != PROOF_NONE && (node->props & NODE_PROP_PROOF) == 0)
- sprintf(tr, "The node is marked as able to provide proof");
+ sprintf((warning = tr), "The node is marked as able to provide proof");
else if ((c->flags & FLAGS_HTTP) && (node->props & NODE_PROP_HTTP) == 0)
- sprintf(tr, "The node is marked as able to support http-requests");
+ sprintf((warning = tr), "The node is marked as able to support http-requests");
else
tr = ctx->error;
}
+ if (blacklisted)
+ printf(COLORT_RED);
+ else if (warning)
+ printf(COLORT_YELLOW);
+ else
+ printf(COLORT_GREEN);
printf("%2i %45s %7i %5i %5i %5i %s", i, node->url, (int) (blacklisted ? blacklisted - now : 0), weight->response_count, weight->response_count ? (weight->total_response_time / weight->response_count) : 0, calc_weight, tr ? tr : "");
- if (blacklisted) printf("\033[0m");
- printf("\n");
+ printf(COLORT_RESET "\n");
if (tr && tr != ctx->error) _free(tr);
if (ctx) ctx_free(ctx);
}
diff --git a/c/src/cmd/tools/CMakeLists.txt b/c/src/cmd/tools/CMakeLists.txt
index fd14b7ce6..ce18b80a3 100644
--- a/c/src/cmd/tools/CMakeLists.txt
+++ b/c/src/cmd/tools/CMakeLists.txt
@@ -2,7 +2,7 @@
# This file is part of the Incubed project.
# Sources: https://github.com/slockit/in3-c
#
-# Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+# Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
#
#
# COMMERCIAL LICENSE USAGE
diff --git a/c/src/cmd/tools/data.c b/c/src/cmd/tools/data.c
index a7d7b0715..3a799bae7 100644
--- a/c/src/cmd/tools/data.c
+++ b/c/src/cmd/tools/data.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -37,6 +37,7 @@
* */
#include "../../core/util/data.h"
+#include "../../core/util/colors.h"
#include "../../core/util/mem.h"
#include "../../core/util/utils.h"
#include "used_keys.h"
@@ -100,15 +101,15 @@ static void init_keys() {
}
static void print_hex(uint8_t* d, uint32_t l, char* color) {
- if (color) printf("\033[%sm", color);
+ if (color) printf(COLORT_SELECT, color);
for (uint32_t i = 0; i < l; i++)
printf("%02x", d[i]);
printf(" ");
- if (color) printf("\033[0m");
+ if (color) printf(COLORT_RESET);
}
static int read_token(uint8_t* d, size_t* p, int level, int* index, int keyval) {
- printf("%03i: \033[0;31m", *index);
+ printf("%03i: " COLORT_RRED, *index);
d_type_t type = d[*p] >> 5;
uint32_t len = d[*p] & 0x1F, i; // the other 5 bits (0-31) the length
// first 3 bits define the type
@@ -143,11 +144,11 @@ static int read_token(uint8_t* d, size_t* p, int level, int* index, int keyval)
}
printf(" ");
- for (int i = 0; i < level; i++) printf("\033[1;30m.\033[0m ");
+ for (int i = 0; i < level; i++) printf(COLORT_BBLACK "." COLORT_RESET);
if (keyval >= 0) {
char* keyname = d_get_keystr((d_key_t) keyval);
if (keyname)
- printf("\033[0;35m%s\033[0m ", keyname);
+ printf(COLORT_RMAGENTA "%s" COLORT_RESET, keyname);
else {
uint8_t tmp[2];
tmp[0] = (keyval >> 8) & 0xFF;
diff --git a/c/src/cmd/tools/rlp.c b/c/src/cmd/tools/rlp.c
index 654207da9..3c8caa41f 100644
--- a/c/src/cmd/tools/rlp.c
+++ b/c/src/cmd/tools/rlp.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/core/CMakeLists.txt b/c/src/core/CMakeLists.txt
index 6bc3f4451..b6210214c 100644
--- a/c/src/core/CMakeLists.txt
+++ b/c/src/core/CMakeLists.txt
@@ -2,7 +2,7 @@
# This file is part of the Incubed project.
# Sources: https://github.com/slockit/in3-c
#
-# Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+# Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
#
#
# COMMERCIAL LICENSE USAGE
diff --git a/c/src/core/client/cache.c b/c/src/core/client/cache.c
index 3a1e4080f..4b0af2054 100644
--- a/c/src/core/client/cache.c
+++ b/c/src/core/client/cache.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/core/client/cache.h b/c/src/core/client/cache.h
index 6a38a008f..e76d05beb 100644
--- a/c/src/core/client/cache.h
+++ b/c/src/core/client/cache.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/core/client/client.c b/c/src/core/client/client.c
index 150f9310e..133ef5dd4 100644
--- a/c/src/core/client/client.c
+++ b/c/src/core/client/client.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/core/client/client.h b/c/src/core/client/client.h
index 1a10fd070..e9a69545f 100644
--- a/c/src/core/client/client.h
+++ b/c/src/core/client/client.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/core/client/client_init.c b/c/src/core/client/client_init.c
index c358f2228..cebfa19ed 100644
--- a/c/src/core/client/client_init.c
+++ b/c/src/core/client/client_init.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -410,6 +410,7 @@ in3_ret_t in3_client_clear_nodes(in3_t* c, chain_id_t chain_id) {
/* frees the data */
void in3_free(in3_t* a) {
+ if (!a) return;
int i;
for (i = 0; i < a->chains_length; i++) {
if (a->chains[i].verified_hashes) _free(a->chains[i].verified_hashes);
@@ -419,9 +420,9 @@ void in3_free(in3_t* a) {
_free(a->chains[i].nodelist_upd8_params);
}
if (a->signer) _free(a->signer);
- _free(a->chains);
+ if (a->chains) _free(a->chains);
- if (a->filters != NULL) {
+ if (a->filters) {
in3_filter_t* f = NULL;
for (size_t j = 0; j < a->filters->count; j++) {
f = a->filters->array[j];
diff --git a/c/src/core/client/context.c b/c/src/core/client/context.c
index 1ad30ebc7..40934a9d2 100644
--- a/c/src/core/client/context.c
+++ b/c/src/core/client/context.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/core/client/context.h b/c/src/core/client/context.h
index 1712c3ca0..d8e8d0cf9 100644
--- a/c/src/core/client/context.h
+++ b/c/src/core/client/context.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/core/client/execute.c b/c/src/core/client/execute.c
index bc94728c5..460dfee38 100644
--- a/c/src/core/client/execute.c
+++ b/c/src/core/client/execute.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -590,9 +590,13 @@ in3_ret_t in3_send_ctx(in3_ctx_t* ctx) {
in3_request_t* request = in3_create_request(ctx);
if (request == NULL)
return IN3_ENOMEM;
- in3_log_trace("... request to \x1B[35m%s\x1B[33m\n... %s\x1B[0m\n", request->urls[0], request->payload);
+ in3_log_trace("... request to " COLOR_YELLOW_STR "\n... " COLOR_MAGENTA_STR "\n", request->urls[0], request->payload);
ctx->client->transport(request);
- in3_log_trace("... response: \n... \x1B[%sm%s\x1B[0m\n", request->results[0].error.len ? "31" : "32", request->results[0].error.len ? request->results[0].error.data : request->results[0].result.data);
+ if (request->results[0].error.len) {
+ in3_log_trace("... response: \n... " COLOR_RED_STR "\n", request->results[0].error.len ? request->results[0].error.data : request->results[0].result.data);
+ } else {
+ in3_log_trace("... response: \n... " COLOR_GREEN_STR "\n", request->results[0].error.len ? request->results[0].error.data : request->results[0].result.data);
+ }
request_free(request, ctx, false);
break;
} else
diff --git a/c/src/core/client/keys.h b/c/src/core/client/keys.h
index 0a604bb5a..400d543f6 100644
--- a/c/src/core/client/keys.h
+++ b/c/src/core/client/keys.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/core/client/nodelist.c b/c/src/core/client/nodelist.c
index 11ddb7b35..c5836cfda 100644
--- a/c/src/core/client/nodelist.c
+++ b/c/src/core/client/nodelist.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/core/client/nodelist.h b/c/src/core/client/nodelist.h
index 1dfe02cf6..ae4ea5fed 100644
--- a/c/src/core/client/nodelist.h
+++ b/c/src/core/client/nodelist.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/core/client/verifier.c b/c/src/core/client/verifier.c
index 662967213..60a76afe9 100644
--- a/c/src/core/client/verifier.c
+++ b/c/src/core/client/verifier.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/core/client/verifier.h b/c/src/core/client/verifier.h
index ac4ce4787..1020093f9 100644
--- a/c/src/core/client/verifier.h
+++ b/c/src/core/client/verifier.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/core/client/version.h b/c/src/core/client/version.h
index 0905ef6f6..d393e7b67 100644
--- a/c/src/core/client/version.h
+++ b/c/src/core/client/version.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -35,7 +35,7 @@
#ifndef IN3_VERSION_H
#define IN3_VERSION_H
-#define IN3_COPYRIGHT "2018 - 2018-2019 slock.it, ."
+#define IN3_COPYRIGHT "2018 - 2018-2020 slock.it, ."
#define IN3_VERSION_BITS(x, y, z) ((x) << 16 | (y) << 8 | (z))
#define IN3_AT_LEAST_VERSION(x, y, z) (IN3_VERSION_NUM >= IN3_VERSION_BITS(x, y, z))
diff --git a/c/src/core/util/bitset.c b/c/src/core/util/bitset.c
index b123dfc90..a753169cf 100644
--- a/c/src/core/util/bitset.c
+++ b/c/src/core/util/bitset.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/core/util/bitset.h b/c/src/core/util/bitset.h
index 86c88d110..7763fb0cb 100644
--- a/c/src/core/util/bitset.h
+++ b/c/src/core/util/bitset.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/core/util/bytes.c b/c/src/core/util/bytes.c
index 20379ef93..fe5658fa6 100644
--- a/c/src/core/util/bytes.c
+++ b/c/src/core/util/bytes.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/core/util/bytes.h b/c/src/core/util/bytes.h
index e2ab5b7cc..66d74b956 100644
--- a/c/src/core/util/bytes.h
+++ b/c/src/core/util/bytes.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/core/util/colors.h b/c/src/core/util/colors.h
new file mode 100644
index 000000000..edbc8a538
--- /dev/null
+++ b/c/src/core/util/colors.h
@@ -0,0 +1,180 @@
+/*******************************************************************************
+ * This file is part of the Incubed project.
+ * Sources: https://github.com/slockit/in3-c
+ *
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
+ *
+ *
+ * COMMERCIAL LICENSE USAGE
+ *
+ * Licensees holding a valid commercial license may use this file in accordance
+ * with the commercial license agreement provided with the Software or, alternatively,
+ * in accordance with the terms contained in a written agreement between you and
+ * slock.it GmbH/Blockchains LLC. For licensing terms and conditions or further
+ * information please contact slock.it at in3@slock.it.
+ *
+ * Alternatively, this file may be used under the AGPL license as follows:
+ *
+ * AGPL LICENSE USAGE
+ *
+ * This program is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Affero General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+ * [Permissions of this strong copyleft license are conditioned on making available
+ * complete source code of licensed works and modifications, which include larger
+ * works using a licensed work, under the same license. Copyright and license notices
+ * must be preserved. Contributors provide an express grant of patent rights.]
+ * You should have received a copy of the GNU Affero General Public License along
+ * with this program. If not, see .
+ *******************************************************************************/
+
+/*Term colors*/
+
+#ifdef LOG_USE_COLOR
+#define COLORT_RESET "\033[0m"
+#define COLORT_BOLD "\033[1m"
+#define COLORT_DIM "\033[2m"
+#define COLORT_UNDERLINED "\033[4m"
+#define COLORT_BLINK "\033[5m"
+#define COLORT_REVERSE "\033[7m"
+#define COLORT_HIDDEN "\033[8m"
+#define COLORT_RESETBOLD "\033[21m"
+#define COLORT_RESETDIM "\033[22m"
+#define COLORT_RESETUNDERLINED "\033[24m"
+#define COLORT_RESETBLINK "\033[25m"
+#define COLORT_RESETREVERSE "\033[27m"
+#define COLORT_RESETHIDDEN "\033[28m"
+#define COLORT_DEFAULT "\033[39m"
+#define COLORT_BLACK "\033[30m"
+#define COLORT_BBLACK "\033[1;30m"
+#define COLORT_RRED "\033[0;31m"
+#define COLORT_RED "\033[31m"
+#define COLORT_SELECT "\033[%sm"
+#define COLORT_GREEN "\033[32m"
+#define COLORT_RGREEN "\033[0;32m"
+#define COLORT_YELLOW "\033[33m"
+#define COLORT_RYELLOW "\033[0;33m"
+#define COLORT_BLUE "\033[34m"
+#define COLORT_MAGENTA "\033[35m"
+#define COLORT_RMAGENTA "\033[0;35m"
+#define COLORT_CYAN "\033[36m"
+#define COLORT_LIGHTGRAY "\033[37m"
+#define COLORT_DARKGRAY "\033[90m"
+#define COLORT_LIGHTRED "\033[91m"
+#define COLORT_LIGHTGREEN "\033[92m"
+#define COLORT_LIGHTYELLOW "\033[93m"
+#define COLORT_LIGHTBLUE "\033[94m"
+#define COLORT_LIGHTMAGENTA "\033[95m"
+#define COLORT_LIGHTCYAN "\033[96m"
+#define COLORT_WHITE "\033[97m"
+#else
+#define COLORT_RESET " "
+#define COLORT_BOLD ""
+#define COLORT_DIM ""
+#define COLORT_UNDERLINED ""
+#define COLORT_BLINK ""
+#define COLORT_REVERSE ""
+#define COLORT_HIDDEN " "
+#define COLORT_RESETBOLD ""
+#define COLORT_RESETDIM ""
+#define COLORT_RESETUNDERLINED ""
+#define COLORT_RESETBLINK ""
+#define COLORT_RESETREVERSE ""
+#define COLORT_RESETHIDDEN " "
+#define COLORT_DEFAULT ""
+#define COLORT_BLACK ""
+#define COLORT_BBLACK ""
+#define COLORT_RRED " "
+#define COLORT_RED " "
+#define COLORT_SELECT "%s"
+#define COLORT_GREEN ""
+#define COLORT_RGREEN ""
+#define COLORT_YELLOW " "
+#define COLORT_RYELLOW ""
+#define COLORT_BLUE ""
+#define COLORT_MAGENTA ""
+#define COLORT_RMAGENTA ""
+#define COLORT_CYAN ""
+#define COLORT_LIGHTGRAY ""
+#define COLORT_DARKGRAY ""
+#define COLORT_LIGHTRED ""
+#define COLORT_LIGHTGREEN ""
+#define COLORT_LIGHTYELLOW ""
+#define COLORT_LIGHTBLUE ""
+#define COLORT_LIGHTMAGENTA ""
+#define COLORT_LIGHTCYAN ""
+#define COLORT_WHITE ""
+#endif
+
+/* Control sequences, based on ANSI.
+Can be used to control color, and
+clear the screen
+*/
+
+#ifdef LOG_USE_COLOR
+#define COLOR_RESET "\x1B[0m" // Reset to default colors
+#define COLOR_CLEAR "\x1B[2J" // Clear screen, reposition cursor to top left
+#define COLOR_BLACK "\x1B[30m"
+#define COLOR_RED "\x1B[31m"
+#define COLOR_GREEN "\x1B[32m"
+#define COLOR_YELLOW "\x1B[33m"
+#define COLOR_BLUE "\x1B[34m"
+#define COLOR_MAGENTA "\x1B[35m"
+#define COLOR_CYAN "\x1B[36m"
+#define COLOR_WHITE "\x1B[37m"
+#define COLOR_DEFAULT "\x1B[39m"
+#else
+#define COLOR_RESET " " // Reset to default colors
+#define COLOR_CLEAR " " // Clear screen, reposition cursor to top left
+#define COLOR_BLACK " "
+#define COLOR_RED " "
+#define COLOR_GREEN " "
+#define COLOR_YELLOW " "
+#define COLOR_BLUE " "
+#define COLOR_MAGENTA " "
+#define COLOR_CYAN " "
+#define COLOR_WHITE " "
+#define COLOR_DEFAULT " "
+#endif
+
+#define COLOR_RED_STR COLOR_RED "%s" COLOR_RESET
+#define COLOR_GREEN_STR COLOR_GREEN "%s" COLOR_RESET
+#define COLOR_GREEN_S2 COLOR_GREEN "%-10s" COLOR_RESET
+#define COLOR_GREEN_X1 COLOR_GREEN "%01x" COLOR_RESET
+#define COLOR_GREEN_STR_INT COLOR_GREEN "%s%i" COLOR_RESET
+#define COLOR_YELLOW_STR COLOR_YELLOW "%s" COLOR_RESET
+#define COLOR_YELLOW_STR COLOR_YELLOW "%s" COLOR_RESET
+#define COLOR_MAGENTA_STR COLOR_MAGENTA "%s" COLOR_RESET
+#define COLOR_YELLOW_PRIu64 COLOR_YELLOW "%5" PRIu64 "" COLOR_RESET
+#define COLOR_YELLOW_PRIu64plus COLOR_YELLOW "%5" PRIu64 "" COLOR_RESET
+#define COLOR_BRIGHT_BLACK "\x1B[90m"
+#define COLOR_BRIGHT_RED "\x1B[91m"
+#define COLOR_BRIGHT_GREEN "\x1B[92m"
+#define COLOR_BRIGHT_YELLOW "\x1B[93m"
+#define COLOR_BRIGHT_BLUE "\x1B[94m"
+#define COLOR_BRIGHT_MAGENTA "\x1B[95m"
+#define COLOR_BRIGHT_CYAN "\x1B[96m"
+#define COLOR_BRIGHT_WHITE "\x1B[97m"
+
+#define COLOR_BG_DEFAULT "\x1B[24;49m"
+#define COLOR_BG_BLACK "\x1B[24;40m"
+#define COLOR_BG_RED "\x1B[24;41m"
+#define COLOR_BG_GREEN "\x1B[24;42m"
+#define COLOR_BG_YELLOW "\x1B[24;43m"
+#define COLOR_BG_BLUE "\x1B[24;44m"
+#define COLOR_BG_MAGENTA "\x1B[24;45m"
+#define COLOR_BG_CYAN "\x1B[24;46m"
+#define COLOR_BG_WHITE "\x1B[24;47m"
+
+#define COLOR_BG_BRIGHT_BLACK "\x1B[4;100m"
+#define COLOR_BG_BRIGHT_RED "\x1B[4;101m"
+#define COLOR_BG_BRIGHT_GREEN "\x1B[4;102m"
+#define COLOR_BG_BRIGHT_YELLOW "\x1B[4;103m"
+#define COLOR_BG_BRIGHT_BLUE "\x1B[4;104m"
+#define COLOR_BG_BRIGHT_MAGENTA "\x1B[4;105m"
+#define COLOR_BG_BRIGHT_CYAN "\x1B[4;106m"
+#define COLOR_BG_BRIGHT_WHITE "\x1B[4;107m"
diff --git a/c/src/core/util/data.c b/c/src/core/util/data.c
index 5971f8ee0..e530c6cd0 100644
--- a/c/src/core/util/data.c
+++ b/c/src/core/util/data.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/core/util/data.h b/c/src/core/util/data.h
index c6e06286e..aaf253f67 100644
--- a/c/src/core/util/data.h
+++ b/c/src/core/util/data.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/core/util/debug.c b/c/src/core/util/debug.c
index d975ed037..ca9299870 100644
--- a/c/src/core/util/debug.c
+++ b/c/src/core/util/debug.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/core/util/debug.h b/c/src/core/util/debug.h
index ce269fab2..ba40693a2 100644
--- a/c/src/core/util/debug.h
+++ b/c/src/core/util/debug.h
@@ -3,7 +3,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/core/util/error.h b/c/src/core/util/error.h
index 3c7e8a64c..fdb58ee4f 100644
--- a/c/src/core/util/error.h
+++ b/c/src/core/util/error.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/core/util/log.h b/c/src/core/util/log.h
old mode 100755
new mode 100644
index e60421e3e..29e680e6a
--- a/c/src/core/util/log.h
+++ b/c/src/core/util/log.h
@@ -9,10 +9,10 @@
#ifndef LOG_H
#define LOG_H
+#include "colors.h"
#include "utils.h"
#include
#include
-
#define LOG_VERSION "0.1.0"
typedef void (*in3_log_LockFn)(void* udata, int lock);
diff --git a/c/src/core/util/mem.c b/c/src/core/util/mem.c
index a14620115..54adc61c0 100644
--- a/c/src/core/util/mem.c
+++ b/c/src/core/util/mem.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -168,12 +168,13 @@ int mem_stack_size() {
}
void memstack() {
- printf("\n M:");
+ printf("\n M-Stack ");
mem_p_t* t = mem_tracker;
while (t) {
printf("[%p %zu ] ", t->ptr, t->size);
t = t->next;
}
+ printf("\n");
}
void t_free(void* ptr, char* file, const char* func, int line) {
@@ -222,7 +223,7 @@ void* t_realloc(void* ptr, size_t size, size_t oldsize, char* file, const char*
}
t = t->next;
}
- printf("realloc a pointer which was not allocated anymore %s : %s : %i\n", file, func, line);
+ //printf("realloc a pointer which was not allocated anymore %s : %s : %i\n", file, func, line);
return _realloc_(ptr, size, oldsize, file, func, line);
}
diff --git a/c/src/core/util/mem.h b/c/src/core/util/mem.h
index 334b81314..3c65509c6 100644
--- a/c/src/core/util/mem.h
+++ b/c/src/core/util/mem.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/core/util/scache.c b/c/src/core/util/scache.c
index 130dba61e..8180cb5fd 100644
--- a/c/src/core/util/scache.c
+++ b/c/src/core/util/scache.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/core/util/scache.h b/c/src/core/util/scache.h
index 934b45912..5bffd7fe6 100644
--- a/c/src/core/util/scache.h
+++ b/c/src/core/util/scache.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/core/util/stringbuilder.c b/c/src/core/util/stringbuilder.c
index ff7774c2f..34f2ac129 100644
--- a/c/src/core/util/stringbuilder.c
+++ b/c/src/core/util/stringbuilder.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/core/util/stringbuilder.h b/c/src/core/util/stringbuilder.h
index 96c18a410..94014900c 100644
--- a/c/src/core/util/stringbuilder.h
+++ b/c/src/core/util/stringbuilder.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/core/util/utils.c b/c/src/core/util/utils.c
index d496b6a9a..e9b019036 100644
--- a/c/src/core/util/utils.c
+++ b/c/src/core/util/utils.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/core/util/utils.h b/c/src/core/util/utils.h
index 442115942..6dd2ca963 100644
--- a/c/src/core/util/utils.h
+++ b/c/src/core/util/utils.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/third-party/CMakeLists.txt b/c/src/third-party/CMakeLists.txt
index 5b09ab947..201b28e26 100644
--- a/c/src/third-party/CMakeLists.txt
+++ b/c/src/third-party/CMakeLists.txt
@@ -2,7 +2,7 @@
# This file is part of the Incubed project.
# Sources: https://github.com/slockit/in3-c
#
-# Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+# Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
#
#
# COMMERCIAL LICENSE USAGE
diff --git a/c/src/third-party/crypto/CMakeLists.txt b/c/src/third-party/crypto/CMakeLists.txt
index 2d202fd67..019cfc3aa 100644
--- a/c/src/third-party/crypto/CMakeLists.txt
+++ b/c/src/third-party/crypto/CMakeLists.txt
@@ -2,7 +2,7 @@
# This file is part of the Incubed project.
# Sources: https://github.com/slockit/in3-c
#
-# Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+# Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
#
#
# COMMERCIAL LICENSE USAGE
diff --git a/c/src/third-party/libb64/CMakeLists.txt b/c/src/third-party/libb64/CMakeLists.txt
index 597a09644..9bc2e5c11 100644
--- a/c/src/third-party/libb64/CMakeLists.txt
+++ b/c/src/third-party/libb64/CMakeLists.txt
@@ -2,7 +2,7 @@
# This file is part of the Incubed project.
# Sources: https://github.com/slockit/in3-c
#
-# Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+# Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
#
#
# COMMERCIAL LICENSE USAGE
diff --git a/c/src/third-party/segger_rtt/CMakeLists.txt b/c/src/third-party/segger_rtt/CMakeLists.txt
index 36d6d3777..5f5d77aff 100644
--- a/c/src/third-party/segger_rtt/CMakeLists.txt
+++ b/c/src/third-party/segger_rtt/CMakeLists.txt
@@ -2,7 +2,7 @@
# This file is part of the Incubed project.
# Sources: https://github.com/slockit/in3-c
#
-# Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+# Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
#
#
# COMMERCIAL LICENSE USAGE
diff --git a/c/src/third-party/tommath/CMakeLists.txt b/c/src/third-party/tommath/CMakeLists.txt
index fd9e2df74..277b9a0f5 100644
--- a/c/src/third-party/tommath/CMakeLists.txt
+++ b/c/src/third-party/tommath/CMakeLists.txt
@@ -2,7 +2,7 @@
# This file is part of the Incubed project.
# Sources: https://github.com/slockit/in3-c
#
-# Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+# Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
#
#
# COMMERCIAL LICENSE USAGE
diff --git a/c/src/transport/CMakeLists.txt b/c/src/transport/CMakeLists.txt
index a3a02b645..64d415b74 100644
--- a/c/src/transport/CMakeLists.txt
+++ b/c/src/transport/CMakeLists.txt
@@ -2,7 +2,7 @@
# This file is part of the Incubed project.
# Sources: https://github.com/slockit/in3-c
#
-# Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+# Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
#
#
# COMMERCIAL LICENSE USAGE
diff --git a/c/src/transport/curl/CMakeLists.txt b/c/src/transport/curl/CMakeLists.txt
index d79a32532..d110d833d 100644
--- a/c/src/transport/curl/CMakeLists.txt
+++ b/c/src/transport/curl/CMakeLists.txt
@@ -2,7 +2,7 @@
# This file is part of the Incubed project.
# Sources: https://github.com/slockit/in3-c
#
-# Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+# Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
#
#
# COMMERCIAL LICENSE USAGE
@@ -118,6 +118,6 @@ endif()
if (MSVC OR MSYS OR MINGW)
# for detecting Windows compilers
- target_link_libraries(transport_curl_o ws2_32 wsock32 -static gcc stdc++ winpthread -dynamic)
- target_link_libraries(transport_curl ws2_32 wsock32 -static gcc stdc++ winpthread -dynamic)
+ target_link_libraries(transport_curl_o ws2_32 wsock32 -static gcc -Lcrypto stdc++ winpthread -L/home/conan/xc/mingw64/ssl/lib/libcrypto.a -L/home/conan/xc/mingw64/ssl/lib/libssl.a -dynamic)
+ target_link_libraries(transport_curl ws2_32 wsock32 -static gcc stdc++ winpthread -L/home/conan/xc/mingw64/ssl/lib/libcrypto.a -L/home/conan/xc/mingw64/ssl/lib/libssl.a -dynamic)
endif ()
diff --git a/c/src/transport/curl/in3_curl.c b/c/src/transport/curl/in3_curl.c
index f2ec41e7c..a832bdd8d 100644
--- a/c/src/transport/curl/in3_curl.c
+++ b/c/src/transport/curl/in3_curl.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/transport/curl/in3_curl.h b/c/src/transport/curl/in3_curl.h
index 36991fc53..ecd497058 100644
--- a/c/src/transport/curl/in3_curl.h
+++ b/c/src/transport/curl/in3_curl.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/transport/http/CMakeLists.txt b/c/src/transport/http/CMakeLists.txt
index 68d519e24..90919b6a1 100644
--- a/c/src/transport/http/CMakeLists.txt
+++ b/c/src/transport/http/CMakeLists.txt
@@ -2,7 +2,7 @@
# This file is part of the Incubed project.
# Sources: https://github.com/slockit/in3-c
#
-# Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+# Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
#
#
# COMMERCIAL LICENSE USAGE
diff --git a/c/src/transport/http/in3_http.c b/c/src/transport/http/in3_http.c
index 2cc1f6865..1e12058ca 100644
--- a/c/src/transport/http/in3_http.c
+++ b/c/src/transport/http/in3_http.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/transport/http/in3_http.h b/c/src/transport/http/in3_http.h
index bd7c3ef58..45edbbe29 100644
--- a/c/src/transport/http/in3_http.h
+++ b/c/src/transport/http/in3_http.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/CMakeLists.txt b/c/src/verifier/CMakeLists.txt
index a4b807ac7..5a3f346bf 100644
--- a/c/src/verifier/CMakeLists.txt
+++ b/c/src/verifier/CMakeLists.txt
@@ -2,7 +2,7 @@
# This file is part of the Incubed project.
# Sources: https://github.com/slockit/in3-c
#
-# Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+# Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
#
#
# COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/basic/CMakeLists.txt b/c/src/verifier/eth1/basic/CMakeLists.txt
index 43f11fa93..3967961c1 100644
--- a/c/src/verifier/eth1/basic/CMakeLists.txt
+++ b/c/src/verifier/eth1/basic/CMakeLists.txt
@@ -2,7 +2,7 @@
# This file is part of the Incubed project.
# Sources: https://github.com/slockit/in3-c
#
-# Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+# Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
#
#
# COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/basic/eth_account.c b/c/src/verifier/eth1/basic/eth_account.c
index 74298b11a..c9a9c4b43 100644
--- a/c/src/verifier/eth1/basic/eth_account.c
+++ b/c/src/verifier/eth1/basic/eth_account.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/basic/eth_basic.c b/c/src/verifier/eth1/basic/eth_basic.c
index c9027cd93..ee5f75a91 100644
--- a/c/src/verifier/eth1/basic/eth_basic.c
+++ b/c/src/verifier/eth1/basic/eth_basic.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -82,18 +82,18 @@ in3_ret_t in3_verify_eth_basic(in3_vctx_t* vc) {
if (!method) return vc_err(vc, "No Method in request defined!");
if (strcmp(method, "eth_getTransactionByHash") == 0)
- // for txReceipt, we need the txhash
return eth_verify_eth_getTransaction(vc, d_get_bytes_at(d_get(vc->request, K_PARAMS), 0));
else if (!strcmp(method, "eth_getTransactionByBlockHashAndIndex") || !strcmp(method, "eth_getTransactionByBlockNumberAndIndex")) {
return eth_verify_eth_getTransactionByBlock(vc, d_get_at(d_get(vc->request, K_PARAMS), 0), d_get_int_at(d_get(vc->request, K_PARAMS), 1));
} else if (strcmp(method, "eth_getBlockByNumber") == 0)
- // for txReceipt, we need the txhash
return eth_verify_eth_getBlock(vc, NULL, d_get_long_at(d_get(vc->request, K_PARAMS), 0));
+ else if (strcmp(method, "eth_getBlockTransactionCountByHash") == 0)
+ return eth_verify_eth_getBlockTransactionCount(vc, d_get_bytes_at(d_get(vc->request, K_PARAMS), 0), 0);
+ else if (strcmp(method, "eth_getBlockTransactionCountByNumber") == 0)
+ return eth_verify_eth_getBlockTransactionCount(vc, NULL, d_get_long_at(d_get(vc->request, K_PARAMS), 0));
else if (strcmp(method, "eth_getBlockByHash") == 0)
- // for txReceipt, we need the txhash
return eth_verify_eth_getBlock(vc, d_get_bytes_at(d_get(vc->request, K_PARAMS), 0), 0);
else if (strcmp(method, "eth_getBalance") == 0 || strcmp(method, "eth_getCode") == 0 || strcmp(method, "eth_getStorageAt") == 0 || strcmp(method, "eth_getTransactionCount") == 0)
- // for txReceipt, we need the txhash
return eth_verify_account_proof(vc);
else if (strcmp(method, "eth_gasPrice") == 0)
return IN3_OK;
diff --git a/c/src/verifier/eth1/basic/eth_basic.h b/c/src/verifier/eth1/basic/eth_basic.h
index 5497f4b35..2ef299d3b 100644
--- a/c/src/verifier/eth1/basic/eth_basic.h
+++ b/c/src/verifier/eth1/basic/eth_basic.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -69,6 +69,11 @@ in3_ret_t eth_verify_account_proof(in3_vctx_t* vc);
*/
in3_ret_t eth_verify_eth_getBlock(in3_vctx_t* vc, bytes_t* block_hash, uint64_t blockNumber);
+/**
+ * verifies block transaction count by number or hash
+ */
+in3_ret_t eth_verify_eth_getBlockTransactionCount(in3_vctx_t* vc, bytes_t* block_hash, uint64_t blockNumber);
+
/**
* this function should only be called once and will register the eth-nano verifier.
*/
diff --git a/c/src/verifier/eth1/basic/eth_getBlock.c b/c/src/verifier/eth1/basic/eth_getBlock.c
index e5d0fa0e9..4783be861 100644
--- a/c/src/verifier/eth1/basic/eth_getBlock.c
+++ b/c/src/verifier/eth1/basic/eth_getBlock.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -67,6 +67,64 @@ static in3_ret_t eth_verify_uncles(in3_vctx_t* vc, bytes32_t uncle_hash, d_token
return memcmp(hash2, uncle_hash, 32) ? vc_err(vc, "invalid uncles root") : IN3_OK;
}
+in3_ret_t eth_verify_eth_getBlockTransactionCount(in3_vctx_t* vc, bytes_t* block_hash, uint64_t blockNumber) {
+
+ in3_ret_t res = IN3_OK;
+ int i;
+ d_token_t *transactions, *t = NULL;
+ bytes_t t_root, tmp;
+ if (d_type(vc->result) != T_INTEGER)
+ return vc_err(vc, "Invalid transaction count");
+
+ //transactions count
+ int32_t count = d_int(vc->result);
+
+ // this means result: null, which is ok, since we can not verify a transaction that does not exists
+ if (!vc->proof)
+ return vc_err(vc, "Proof is missing!");
+
+ // verify the blockdata
+ bytes_t* header = d_get_bytesk(vc->proof, K_BLOCK);
+ if (!header)
+ return vc_err(vc, "no blockheader");
+ if (eth_verify_blockheader(vc, header, block_hash) != IN3_OK)
+ return vc_err(vc, "invalid blockheader");
+
+ // check blocknumber
+ if (!block_hash && (rlp_decode_in_list(header, BLOCKHEADER_NUMBER, &tmp) != 1 || bytes_to_long(tmp.data, tmp.len) != blockNumber))
+ return vc_err(vc, "Invalid blocknumber");
+
+ // extract transaction root
+ if (rlp_decode_in_list(header, BLOCKHEADER_TRANSACTIONS_ROOT, &t_root) != 1)
+ return vc_err(vc, "invalid transaction root");
+
+ // if we have transaction, we need to verify them as well
+ if (!(transactions = d_get(vc->proof, K_TRANSACTIONS)))
+ vc_err(vc, "Missing transaction-properties");
+
+ // verify transaction count
+ if (d_len(transactions) != count)
+ return vc_err(vc, "Transaction count mismatch");
+
+ trie_t* trie = trie_new();
+ for (i = 0, t = transactions + 1; i < d_len(transactions); i++, t = d_next(t)) {
+ bool is_raw_tx = d_type(t) == T_BYTES;
+ bytes_t* path = create_tx_path(i);
+ bytes_t* tx = is_raw_tx ? d_bytes(t) : serialize_tx(t);
+ trie_set_value(trie, path, tx);
+ if (!is_raw_tx) b_free(tx);
+ b_free(path);
+ }
+
+ // check tx root
+ if (t_root.len != 32 || memcmp(t_root.data, trie->root, 32))
+ res = vc_err(vc, "Wrong Transaction root");
+
+ trie_free(trie);
+
+ return res;
+}
+
in3_ret_t eth_verify_eth_getBlock(in3_vctx_t* vc, bytes_t* block_hash, uint64_t blockNumber) {
in3_ret_t res = IN3_OK;
diff --git a/c/src/verifier/eth1/basic/eth_getLog.c b/c/src/verifier/eth1/basic/eth_getLog.c
index 9bf0b40ee..392d56059 100644
--- a/c/src/verifier/eth1/basic/eth_getLog.c
+++ b/c/src/verifier/eth1/basic/eth_getLog.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/basic/eth_getTransaction.c b/c/src/verifier/eth1/basic/eth_getTransaction.c
index 41140f526..96e6a0dd5 100644
--- a/c/src/verifier/eth1/basic/eth_getTransaction.c
+++ b/c/src/verifier/eth1/basic/eth_getTransaction.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/basic/filter.c b/c/src/verifier/eth1/basic/filter.c
index 06b3564ba..ba8eb594d 100644
--- a/c/src/verifier/eth1/basic/filter.c
+++ b/c/src/verifier/eth1/basic/filter.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/basic/filter.h b/c/src/verifier/eth1/basic/filter.h
index 8126a3c4b..507ab86ab 100644
--- a/c/src/verifier/eth1/basic/filter.h
+++ b/c/src/verifier/eth1/basic/filter.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/basic/signer-priv.h b/c/src/verifier/eth1/basic/signer-priv.h
index 1f72443bf..a4d7185b0 100644
--- a/c/src/verifier/eth1/basic/signer-priv.h
+++ b/c/src/verifier/eth1/basic/signer-priv.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/basic/signer.c b/c/src/verifier/eth1/basic/signer.c
index 637d1795d..ee2263679 100644
--- a/c/src/verifier/eth1/basic/signer.c
+++ b/c/src/verifier/eth1/basic/signer.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/basic/signer.h b/c/src/verifier/eth1/basic/signer.h
index 11d6f5705..4854f8eb4 100644
--- a/c/src/verifier/eth1/basic/signer.h
+++ b/c/src/verifier/eth1/basic/signer.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/basic/trie.c b/c/src/verifier/eth1/basic/trie.c
index cc8f94aa8..d726f3d5e 100644
--- a/c/src/verifier/eth1/basic/trie.c
+++ b/c/src/verifier/eth1/basic/trie.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -421,12 +421,12 @@ static void hexprint(uint8_t* a, int l) {
}
static void print_nibbles(bytes_t* path) {
uint8_t *nibbles = trie_path_to_nibbles(*path, true), *p = nibbles;
- in3_log_trace("\x1B[32m");
+ in3_log_trace(COLOR_GREEN);
while (*p != 0xFF) {
in3_log_trace("%01x", *p);
p++;
}
- in3_log_trace("\x1B[0m");
+ in3_log_trace(COLOR_RESET);
_free(nibbles);
}
@@ -444,7 +444,7 @@ static void dump_handle(trie_t* trie, trie_node_t* n, uint8_t with_hash, int lev
if (with_hash) in3_log_trace("<%02x%02x%02x>", n->hash[0], n->hash[1], n->hash[2]);
switch (n->type) {
case NODE_BRANCH:
- in3_log_trace("\x1B[33m\x1B[0m ");
+ in3_log_trace("" COLOR_YELLOW " ", "");
tmp = trie_node_get_item(n, 16);
if (tmp.len) {
in3_log_trace(" = ");
@@ -452,19 +452,19 @@ static void dump_handle(trie_t* trie, trie_node_t* n, uint8_t with_hash, int lev
}
for (i = 0; i < 16; i++) {
if (rlp_decode(&n->items, i, &tmp) == 2) {
- sprintf(_prefix, "\x1B[32m%01x\x1B[0m : (EMBED) ", i);
+ sprintf(_prefix, "" COLOR_GREEN_X1 " : (EMBED) ", i);
// b_print(&tmp);
trie_node_t* t = get_node_target(trie, n, i);
dump_handle(trie, t, with_hash, level + 1, _prefix);
_free(t);
} else if (tmp.len) {
- sprintf(_prefix, "\x1B[32m%01x\x1B[0m : ", i);
+ sprintf(_prefix, "" COLOR_GREEN_X1 " : ", i);
dump_handle(trie, get_node(trie, hash_key(tmp.data)), with_hash, level + 1, _prefix);
}
}
break;
case NODE_LEAF:
- in3_log_trace("\x1B[33m");
@@ -473,7 +473,7 @@ static void dump_handle(trie_t* trie, trie_node_t* n, uint8_t with_hash, int lev
hexprint(tmp.data, tmp.len);
break;
case NODE_EXT:
- in3_log_trace("\x1B[33m");
diff --git a/c/src/verifier/eth1/basic/trie.h b/c/src/verifier/eth1/basic/trie.h
index 16af88684..5f59e6c5a 100644
--- a/c/src/verifier/eth1/basic/trie.h
+++ b/c/src/verifier/eth1/basic/trie.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/evm/CMakeLists.txt b/c/src/verifier/eth1/evm/CMakeLists.txt
index db1664344..06db87680 100644
--- a/c/src/verifier/eth1/evm/CMakeLists.txt
+++ b/c/src/verifier/eth1/evm/CMakeLists.txt
@@ -2,7 +2,7 @@
# This file is part of the Incubed project.
# Sources: https://github.com/slockit/in3-c
#
-# Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+# Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
#
#
# COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/evm/accounts.c b/c/src/verifier/eth1/evm/accounts.c
index caf5d1df0..f1c00535a 100644
--- a/c/src/verifier/eth1/evm/accounts.c
+++ b/c/src/verifier/eth1/evm/accounts.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/evm/accounts.h b/c/src/verifier/eth1/evm/accounts.h
index 94c717a12..ee77190eb 100644
--- a/c/src/verifier/eth1/evm/accounts.h
+++ b/c/src/verifier/eth1/evm/accounts.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/evm/big.c b/c/src/verifier/eth1/evm/big.c
index 3206b7a47..f17b40458 100644
--- a/c/src/verifier/eth1/evm/big.c
+++ b/c/src/verifier/eth1/evm/big.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/evm/big.h b/c/src/verifier/eth1/evm/big.h
index 8e2fcc669..00aaab3b6 100644
--- a/c/src/verifier/eth1/evm/big.h
+++ b/c/src/verifier/eth1/evm/big.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/evm/call.c b/c/src/verifier/eth1/evm/call.c
index edd06908a..9ba1c4ae7 100644
--- a/c/src/verifier/eth1/evm/call.c
+++ b/c/src/verifier/eth1/evm/call.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -169,6 +169,9 @@ int evm_sub_call(evm_t* parent,
uint32_t out_offset, uint32_t out_len
) {
+
+ UNUSED_VAR(gas);
+
// create a new evm
evm_t evm;
int res = evm_prepare_evm(&evm, address, code_address, origin, caller, parent->env, parent->env_ptr, mode), success = 0;
@@ -184,6 +187,7 @@ int evm_sub_call(evm_t* parent,
if (mode == EVM_CALL_MODE_STATIC) evm.properties |= EVM_PROP_STATIC;
account_t* new_account = NULL;
+ UNUSED_VAR(new_account);
UPDATE_SUBCALL_GAS(evm, parent, address, code_address, caller, gas, mode, value, l_value);
// execute the internal call
diff --git a/c/src/verifier/eth1/evm/code.c b/c/src/verifier/eth1/evm/code.c
index 3e9c28d3c..863b6a12c 100644
--- a/c/src/verifier/eth1/evm/code.c
+++ b/c/src/verifier/eth1/evm/code.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/evm/code.h b/c/src/verifier/eth1/evm/code.h
index 75a254844..4e802421f 100644
--- a/c/src/verifier/eth1/evm/code.h
+++ b/c/src/verifier/eth1/evm/code.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/evm/env.c b/c/src/verifier/eth1/evm/env.c
index d26f3fbc0..28ee63efe 100644
--- a/c/src/verifier/eth1/evm/env.c
+++ b/c/src/verifier/eth1/evm/env.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/evm/evm.c b/c/src/verifier/eth1/evm/evm.c
index 965f88213..3ff11897a 100644
--- a/c/src/verifier/eth1/evm/evm.c
+++ b/c/src/verifier/eth1/evm/evm.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -202,10 +202,10 @@ I:79338654 267 3 63 : PUSH4 [ 364087e | 1 | 945304eb96065b2a98b57a48a06
P:79338654 267 3 63 : PUSH4 [ 364087e | 1 | 945304eb96065b2a98b57a48a06ae28d285a71b5 | ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff | ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff | ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff |
*/
-#define __code(n) \
- { \
- in3_log_trace("\x1B[32m%-10s\x1B[0m", n); \
- return; \
+#define __code(n) \
+ { \
+ in3_log_trace(COLOR_GREEN_S2, n); \
+ return; \
}
void evm_print_op(evm_t* evm, uint64_t last_gas, uint32_t pos) {
uint8_t op = evm->code.data[pos];
@@ -218,29 +218,29 @@ void evm_print_op(evm_t* evm, uint64_t last_gas, uint32_t pos) {
}
if (last_gas > evm->gas) {
- in3_log_trace("%" PRIu64 " %03i \x1B[33m%5" PRIu64 "\x1B[0m %02x : ", evm->gas, pos, last_gas - evm->gas, op);
+ in3_log_trace("%" PRIu64 " %03i " COLOR_YELLOW_PRIu64 " %02x : ", evm->gas, pos, last_gas - evm->gas, op);
} else {
- in3_log_trace("%" PRIu64 " %03i \x1B[33m+%5" PRIu64 "\x1B[0m %02x : ", evm->gas, pos, evm->gas - last_gas, op);
+ in3_log_trace("%" PRIu64 " %03i " COLOR_YELLOW_PRIu64plus " %02x : ", evm->gas, pos, evm->gas - last_gas, op);
}
#else
UNUSED_VAR(last_gas);
in3_log_trace("\n%03i %02x : ", pos, op);
#endif
if (op >= 0x60 && op <= 0x7F) {
- in3_log_trace("\x1B[32mPUSH%i\x1B[0m %s", op - 0x5F, (op - 0x05F) < 10 ? " " : "");
+ in3_log_trace(COLOR_GREEN_STR_INT " %s", "PUSH", op - 0x5F, (op - 0x05F) < 10 ? " " : "");
// for (int j = 0; j < op - 0x5F; j++) printf("%02x", evm->code.data[evm->pos + j + 1]);
return;
}
if (op >= 0x80 && op <= 0x8F) {
- in3_log_trace("\x1B[32mDUP%i\x1B[0m %s", op - 0x7F, (op - 0x7F) < 10 ? " " : "");
+ in3_log_trace(COLOR_GREEN_STR_INT " %s", "DUP", op - 0x7F, (op - 0x7F) < 10 ? " " : "");
return;
}
if (op >= 0x90 && op <= 0x9F) {
- in3_log_trace("\x1B[32mSWAP%i\x1B[0m %s", op - 0x8F, (op - 0x8F) < 10 ? " " : "");
+ in3_log_trace(COLOR_GREEN_STR_INT " %s", "SWAP", op - 0x8F, (op - 0x8F) < 10 ? " " : "");
return;
}
if (op >= 0xA0 && op <= 0xA4) {
- in3_log_trace("\x1B[32mLOG%i\x1B[0m ", op - 0xA0);
+ in3_log_trace(COLOR_GREEN_STR_INT " ", "LOG", op - 0xA0);
return;
}
diff --git a/c/src/verifier/eth1/evm/evm.h b/c/src/verifier/eth1/evm/evm.h
index d46d72632..bf629d63a 100644
--- a/c/src/verifier/eth1/evm/evm.h
+++ b/c/src/verifier/eth1/evm/evm.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/evm/evm_mem.c b/c/src/verifier/eth1/evm/evm_mem.c
index aa5018aeb..51b08dc75 100644
--- a/c/src/verifier/eth1/evm/evm_mem.c
+++ b/c/src/verifier/eth1/evm/evm_mem.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/evm/evm_mem.h b/c/src/verifier/eth1/evm/evm_mem.h
index a8833689d..7dcf53929 100644
--- a/c/src/verifier/eth1/evm/evm_mem.h
+++ b/c/src/verifier/eth1/evm/evm_mem.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/evm/gas.c b/c/src/verifier/eth1/evm/gas.c
index 026961bfe..ccd3358c9 100644
--- a/c/src/verifier/eth1/evm/gas.c
+++ b/c/src/verifier/eth1/evm/gas.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/evm/gas.h b/c/src/verifier/eth1/evm/gas.h
index 663a79e1a..4c6896873 100644
--- a/c/src/verifier/eth1/evm/gas.h
+++ b/c/src/verifier/eth1/evm/gas.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/evm/opcodes.c b/c/src/verifier/eth1/evm/opcodes.c
index cba7884bf..9dc7ed685 100644
--- a/c/src/verifier/eth1/evm/opcodes.c
+++ b/c/src/verifier/eth1/evm/opcodes.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/evm/opcodes.h b/c/src/verifier/eth1/evm/opcodes.h
index 5b29f0939..a9a80119f 100644
--- a/c/src/verifier/eth1/evm/opcodes.h
+++ b/c/src/verifier/eth1/evm/opcodes.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/evm/pre_blake2.c b/c/src/verifier/eth1/evm/pre_blake2.c
index a87beef28..916fbafd7 100644
--- a/c/src/verifier/eth1/evm/pre_blake2.c
+++ b/c/src/verifier/eth1/evm/pre_blake2.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/evm/pre_ec.c b/c/src/verifier/eth1/evm/pre_ec.c
index 7f5d8e67d..8e3daebce 100644
--- a/c/src/verifier/eth1/evm/pre_ec.c
+++ b/c/src/verifier/eth1/evm/pre_ec.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/evm/precompiled.c b/c/src/verifier/eth1/evm/precompiled.c
index ebd172599..908f58a18 100644
--- a/c/src/verifier/eth1/evm/precompiled.c
+++ b/c/src/verifier/eth1/evm/precompiled.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -149,6 +149,9 @@ int pre_modexp(evm_t* evm) {
subgas(lm * MAX(1, ael) / G_PRE_MODEXP_GQUAD_DIVISOR);
+#else
+ UNUSED_VAR(hp);
+
#endif
// we use gmp for now
mp_int m_base, m_exp, m_mod, m_res;
diff --git a/c/src/verifier/eth1/evm/precompiled.h b/c/src/verifier/eth1/evm/precompiled.h
index 7bf8585f3..2db20328d 100644
--- a/c/src/verifier/eth1/evm/precompiled.h
+++ b/c/src/verifier/eth1/evm/precompiled.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/full/CMakeLists.txt b/c/src/verifier/eth1/full/CMakeLists.txt
index 45af78498..fcbb65617 100644
--- a/c/src/verifier/eth1/full/CMakeLists.txt
+++ b/c/src/verifier/eth1/full/CMakeLists.txt
@@ -2,7 +2,7 @@
# This file is part of the Incubed project.
# Sources: https://github.com/slockit/in3-c
#
-# Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+# Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
#
#
# COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/full/eth_full.c b/c/src/verifier/eth1/full/eth_full.c
index cd3c2a1f5..acd50c348 100644
--- a/c/src/verifier/eth1/full/eth_full.c
+++ b/c/src/verifier/eth1/full/eth_full.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/full/eth_full.h b/c/src/verifier/eth1/full/eth_full.h
index ca4332437..f22960368 100644
--- a/c/src/verifier/eth1/full/eth_full.h
+++ b/c/src/verifier/eth1/full/eth_full.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/nano/CMakeLists.txt b/c/src/verifier/eth1/nano/CMakeLists.txt
index 19b68948a..bb4da2625 100644
--- a/c/src/verifier/eth1/nano/CMakeLists.txt
+++ b/c/src/verifier/eth1/nano/CMakeLists.txt
@@ -2,7 +2,7 @@
# This file is part of the Incubed project.
# Sources: https://github.com/slockit/in3-c
#
-# Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+# Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
#
#
# COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/nano/blockheader.c b/c/src/verifier/eth1/nano/blockheader.c
index c8dc55d61..5b3a36482 100644
--- a/c/src/verifier/eth1/nano/blockheader.c
+++ b/c/src/verifier/eth1/nano/blockheader.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/nano/chains.h b/c/src/verifier/eth1/nano/chains.h
index d0d98790c..ca97b31cf 100644
--- a/c/src/verifier/eth1/nano/chains.h
+++ b/c/src/verifier/eth1/nano/chains.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/nano/chainspec.c b/c/src/verifier/eth1/nano/chainspec.c
index 6b64a726b..5d0f7d11c 100644
--- a/c/src/verifier/eth1/nano/chainspec.c
+++ b/c/src/verifier/eth1/nano/chainspec.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/nano/chainspec.h b/c/src/verifier/eth1/nano/chainspec.h
index 45dbf3bb4..09f34ff26 100644
--- a/c/src/verifier/eth1/nano/chainspec.h
+++ b/c/src/verifier/eth1/nano/chainspec.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/nano/eth_nano.c b/c/src/verifier/eth1/nano/eth_nano.c
index 590589952..7213ed4d0 100644
--- a/c/src/verifier/eth1/nano/eth_nano.c
+++ b/c/src/verifier/eth1/nano/eth_nano.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/nano/eth_nano.h b/c/src/verifier/eth1/nano/eth_nano.h
index 50b444e99..6504f3eed 100644
--- a/c/src/verifier/eth1/nano/eth_nano.h
+++ b/c/src/verifier/eth1/nano/eth_nano.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/nano/merkle.c b/c/src/verifier/eth1/nano/merkle.c
index 4b041c095..bf3cb39b9 100644
--- a/c/src/verifier/eth1/nano/merkle.c
+++ b/c/src/verifier/eth1/nano/merkle.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/nano/merkle.h b/c/src/verifier/eth1/nano/merkle.h
index 595988a2c..51d6688aa 100644
--- a/c/src/verifier/eth1/nano/merkle.h
+++ b/c/src/verifier/eth1/nano/merkle.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/nano/registry.c b/c/src/verifier/eth1/nano/registry.c
index 072254996..7f76b4f36 100644
--- a/c/src/verifier/eth1/nano/registry.c
+++ b/c/src/verifier/eth1/nano/registry.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/nano/rlp.c b/c/src/verifier/eth1/nano/rlp.c
index da8355046..53efd1ef3 100644
--- a/c/src/verifier/eth1/nano/rlp.c
+++ b/c/src/verifier/eth1/nano/rlp.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/nano/rlp.h b/c/src/verifier/eth1/nano/rlp.h
index d04bf2e43..f842e9ba2 100644
--- a/c/src/verifier/eth1/nano/rlp.h
+++ b/c/src/verifier/eth1/nano/rlp.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/nano/serialize.c b/c/src/verifier/eth1/nano/serialize.c
index 578096fc2..81a6944b8 100644
--- a/c/src/verifier/eth1/nano/serialize.c
+++ b/c/src/verifier/eth1/nano/serialize.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/nano/serialize.h b/c/src/verifier/eth1/nano/serialize.h
index 80bd16aeb..410a0198f 100644
--- a/c/src/verifier/eth1/nano/serialize.h
+++ b/c/src/verifier/eth1/nano/serialize.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/nano/signature.c b/c/src/verifier/eth1/nano/signature.c
index 851a0c91b..82b32023e 100644
--- a/c/src/verifier/eth1/nano/signature.c
+++ b/c/src/verifier/eth1/nano/signature.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/nano/txreceipt.c b/c/src/verifier/eth1/nano/txreceipt.c
index 865b68918..bfe92e8ca 100644
--- a/c/src/verifier/eth1/nano/txreceipt.c
+++ b/c/src/verifier/eth1/nano/txreceipt.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/nano/vhist.c b/c/src/verifier/eth1/nano/vhist.c
index c84cbdbdc..db2cf3f25 100644
--- a/c/src/verifier/eth1/nano/vhist.c
+++ b/c/src/verifier/eth1/nano/vhist.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/nano/vhist.h b/c/src/verifier/eth1/nano/vhist.h
index 017629f63..4e77bdfee 100644
--- a/c/src/verifier/eth1/nano/vhist.h
+++ b/c/src/verifier/eth1/nano/vhist.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/rpc/CMakeLists.txt b/c/src/verifier/eth1/rpc/CMakeLists.txt
index 9d828c26e..77bba63cf 100644
--- a/c/src/verifier/eth1/rpc/CMakeLists.txt
+++ b/c/src/verifier/eth1/rpc/CMakeLists.txt
@@ -2,7 +2,7 @@
# This file is part of the Incubed project.
# Sources: https://github.com/slockit/in3-c
#
-# Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+# Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
#
#
# COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/eth1/rpc/rpc.h b/c/src/verifier/eth1/rpc/rpc.h
index 9dabae2c8..e9050f0e9 100644
--- a/c/src/verifier/eth1/rpc/rpc.h
+++ b/c/src/verifier/eth1/rpc/rpc.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/ipfs/CMakeLists.txt b/c/src/verifier/ipfs/CMakeLists.txt
index 9543daae8..46e063e28 100644
--- a/c/src/verifier/ipfs/CMakeLists.txt
+++ b/c/src/verifier/ipfs/CMakeLists.txt
@@ -2,7 +2,7 @@
# This file is part of the Incubed project.
# Sources: https://github.com/slockit/in3-c
#
-# Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+# Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
#
#
# COMMERCIAL LICENSE USAGE
diff --git a/c/src/verifier/ipfs/ipfs.h b/c/src/verifier/ipfs/ipfs.h
index 06b5d8c47..b59d1c719 100644
--- a/c/src/verifier/ipfs/ipfs.h
+++ b/c/src/verifier/ipfs/ipfs.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/test/CMakeLists.txt b/c/test/CMakeLists.txt
index d06784a8b..5d3367656 100644
--- a/c/test/CMakeLists.txt
+++ b/c/test/CMakeLists.txt
@@ -2,7 +2,7 @@
# This file is part of the Incubed project.
# Sources: https://github.com/slockit/in3-c
#
-# Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+# Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
#
#
# COMMERCIAL LICENSE USAGE
@@ -56,6 +56,9 @@ endif()
add_executable(runner runner.c)
target_link_libraries(runner eth_full eth_api ipfs)
+add_executable(junit util/junit.c)
+target_link_libraries(junit eth_full)
+
add_executable(vmrunner vm_runner.c test_evm.c test_trie.c test_rlp.c)
target_link_libraries(vmrunner eth_full)
diff --git a/c/test/qemu/src/main.c b/c/test/qemu/src/main.c
index b6549311a..a5c9a079e 100644
--- a/c/test/qemu/src/main.c
+++ b/c/test/qemu/src/main.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/test/runner.c b/c/test/runner.c
index c27cd8f2a..74c553fe2 100644
--- a/c/test/runner.c
+++ b/c/test/runner.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -209,7 +209,7 @@ static int send_mock(in3_request_t* req) {
return 0;
}
-int execRequest(in3_t* c, d_token_t* test, int must_fail) {
+int execRequest(in3_t* c, d_token_t* test, int must_fail, int counter, char* descr) {
d_token_t* request = d_get(test, key("request"));
d_token_t* response = d_get(test, key("response"));
d_token_t* config = d_get(request, key("config"));
@@ -242,6 +242,9 @@ int execRequest(in3_t* c, d_token_t* test, int must_fail) {
int is_bin = d_get_int(test, "binaryFormat");
in3_client_rpc(c, method, params, is_bin ? NULL : &res, &err);
+ fflush(stdout);
+ fflush(stderr);
+ printf("\n%2i : %-60s ", counter, descr);
if (res && intern) {
json_ctx_t* actual_json = parse_json(res);
@@ -307,7 +310,6 @@ int run_test(d_token_t* test, int counter, char* fuzz_prop, in3_proof_t proof) {
strcpy(temp, descr);
} else
sprintf(temp, "Request #%i", counter);
- printf("\n%2i : %-60s ", counter, temp);
in3_t* c = in3_for_chain(d_get_intkd(test, key("chainId"), 1));
int j;
@@ -344,7 +346,7 @@ int run_test(d_token_t* test, int counter, char* fuzz_prop, in3_proof_t proof) {
}
}
}
- int fail = execRequest(c, test, fuzz_prop != NULL);
+ int fail = execRequest(c, test, fuzz_prop != NULL, counter, temp);
in3_free(c);
if (mem_get_memleak_cnt()) {
diff --git a/c/test/test_evm.c b/c/test/test_evm.c
index 496160d57..669390a1c 100644
--- a/c/test/test_evm.c
+++ b/c/test/test_evm.c
@@ -4,7 +4,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/test/test_libcurl.c b/c/test/test_libcurl.c
index f5a350cc8..82a352f7e 100644
--- a/c/test/test_libcurl.c
+++ b/c/test/test_libcurl.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/test/test_rlp.c b/c/test/test_rlp.c
index 40a24e95a..d7dab5a5b 100644
--- a/c/test/test_rlp.c
+++ b/c/test/test_rlp.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/test/test_trie.c b/c/test/test_trie.c
index deeaa0c12..2c8052b01 100644
--- a/c/test/test_trie.c
+++ b/c/test/test_trie.c
@@ -3,7 +3,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -105,7 +105,7 @@ int test_trie(d_token_t* test, uint32_t props, uint64_t* ms) {
});
#ifdef TRIETEST
- trie_dump(trie, 0);
+ trie_dump(trie, 0);
#endif
}
} else {
@@ -134,7 +134,7 @@ int test_trie(d_token_t* test, uint32_t props, uint64_t* ms) {
ba_print(value_bytes.data, value_bytes.len);
});
#ifdef TRIETEST
- trie_dump(trie, 0);
+ trie_dump(trie, 0);
#endif
}
}
diff --git a/c/test/test_utils.h b/c/test/test_utils.h
index 0d3b8e3a5..94ba522e5 100644
--- a/c/test/test_utils.h
+++ b/c/test/test_utils.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/test/testdata/requests/eth_getblockTransactionCount.json b/c/test/testdata/requests/eth_getblockTransactionCount.json
new file mode 100644
index 000000000..c27f54d80
--- /dev/null
+++ b/c/test/testdata/requests/eth_getblockTransactionCount.json
@@ -0,0 +1,56 @@
+[{
+ "descr": "eth_getBlockTransactionCountByNumber",
+ "success": true,
+ "fuzzer": true,
+ "verification": "proof",
+ "chainId": "0x5",
+ "request": {
+ "id":1,
+ "jsonrpc":"2.0",
+ "method":"eth_getBlockTransactionCountByNumber",
+ "params":["0x23129e"]
+ },
+ "response": [{
+ "jsonrpc":"2.0",
+ "result":"0x0",
+ "id":1,
+ "in3":{
+ "proof":{
+ "type":"blockProof",
+ "signatures":[],
+ "transactions":[],
+ "block":"0xf90259a0b3143c0324971ee0d75c42dd529ee6b8ab20700290bf1edf949295e9ed57916fa01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a0533d16be15f4f1ea5505a58dd953e7ef8d47f82b0a57c4fecac7de90ed08f832a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421b9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000028323129e837a120080845e626f0cb861d88301090a846765746888676f312e31332e36856c696e757800000000000000e394b70415d69dae3ce3771c8a0de99f379ca5d4d7031bab3c3814670bb13aa6304ab6d6452d2964b44a4d6f1fcd3ad08376fc9ad74fe16ed06b262f1f9967af01a00000000000000000000000000000000000000000000000000000000000000000880000000000000000"},
+ "version":"2.1.0"
+ }
+ }]
+ },
+ {
+ "descr": "eth_getBlockTransactionCountByHash",
+ "success": true,
+ "fuzzer": true,
+ "verification": "proof",
+ "chainId": "0x5",
+ "request": {
+ "id":1,
+ "jsonrpc":"2.0",
+ "method":"eth_getBlockTransactionCountByHash",
+ "params":["0x51aaed52540c997eb92c17e184beee6b1207e1b071543fca8169e2864a7ca1d8"]
+ },
+ "response": [{
+ "jsonrpc":"2.0",
+ "result":"0x1",
+ "id":1,
+ "in3":{
+ "proof":{
+ "type":"blockProof",
+ "signatures":[],
+ "transactions":[
+ "0xf902ed822c01850165a0bc008312ce609460b6b593c381e5d31ec9a7b74a4cc1f2c5235eeb80b902844f32195df643f3f630666b69721831bc7141e6f2fc3abea0ef399cadcd022f5955251506000000000000000000000000000000000000000000000000000000000000024022cd19d1c8640bbec397fe9f55bc65056abbd8e932ad4b25dbb478b59b336e620b3f2f37299292fd6e4d5ecdb253f4d6f53094ce036afb8202c39c71549fb32b2177117ad654e456db57934171b312d824ab6216f40c33026829d4fd2d3e1b1109a9c8bad12531f2cb2da800b90bd8b7f26bdc3f9283d712895baa62c4a03954173214c888a42f0c1b85d6f721031b6bf7c9c41d79fd787e85da994cf415ec7d2b47f56a4beb9d47b3e4214d35c77038de5b11eda4ec0c06fb67f6716b260a2a1690a722b65b0861d97701f343dd6837c5441405aa742019d7ede4d4e557c4a6046ccfc1d3596c396953bbce2ba42c77fe6d1fda2aa9ca90a4ff753039591a9c2c7ff5b8f8ed69989f2d921d85367e2826e31e25c55777c15e9c0997c9fa4bc800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000256fb9c4796b15a7ec4b0d5319e9e493ca4cffda658310420bdfd31e1c59da7900000000000000000000000000000000000000000000000000000000000000002c7ff5b8f8ed69989f2d921d85367e2826e31e25c55777c15e9c0997c9fa4bc800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000002ea0e0920067b78fe73e0b2680a090861de042a520c27d756f2f50e5abb7e8477371a04473d1a1eb225d8fe31a7cf5cb70b443e03f4ea29f114b8fdeead6e7112e54d8"
+ ],
+ "block":"0xf9025ca041810e25dc42c6f6725e8acf7b5bcff7e47b928f6ad0e767d5e042aaf0dd98c4a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347940000000000000000000000000000000000000000a087642deda78efb39728a929e9386ed992d9d5e82af99d73ddea5581ffc219301a01b14c80324071f73560a2f32c79368a89ec775e280a55faed2fddbeeed356736a0ae2952e41f5dbd682c92e4abbf3e4ad46685dcc830b9cd24d3ab2026cd21594cb9010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000020000000000000000002000000000040000040000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000120000000000000000000000020010000000000000000000000000000018323129a837a12008306acd1845e626ed0b861726f6e696e6b61697a656e00000000000000000000000000000000000000000085f82e1be066bf26ca91ce5aac66cf533c71bb1dfe522a92a68cfe00e5fa28284e1e7d39e829504dfd75c70989f05cd6ed0c977d730c25bddad5e739236cb81b01a00000000000000000000000000000000000000000000000000000000000000000880000000000000000"
+ },
+ "version":"2.1.0"
+ }
+ }]
+ }
+]
\ No newline at end of file
diff --git a/c/test/unit_tests/test_abi.c b/c/test/unit_tests/test_abi.c
index 25f86e98b..ffe58a9cb 100644
--- a/c/test/unit_tests/test_abi.c
+++ b/c/test/unit_tests/test_abi.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/test/unit_tests/test_binary_encoding.c b/c/test/unit_tests/test_binary_encoding.c
index 7b566aeba..0656ceaca 100644
--- a/c/test/unit_tests/test_binary_encoding.c
+++ b/c/test/unit_tests/test_binary_encoding.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -50,7 +50,6 @@
#include
#include
-
d_key_t key_(const char* c) {
uint16_t val = 0;
size_t l = strlen(c);
@@ -64,25 +63,24 @@ const char* account_proof_array[] = {
"f90211a0e857fc28938ccaace8c403128bf9848fef722f25f8d55c9dfcddd980b0b85c7ea0329d29fce8ca4e4807205751e9f4376926e3d56dc3bb639345e410dc20bc2c7ba0075edfc7246e4719a2c09c397c4cea41d448254820f1974a70841b9d58e3bcdda08f48b35a917b095ed73971faf013879b77a2838de736651b48a6aaa10ab15e8fa0c5983fe9441f72cc6cb8b579f7071224280661a45a14408401bb1f759dbf0128a03b8cbc5ed56781199fb4fb9768c2ddcc2bdf00816097ec10291b30ac8964bd76a0d3a8e19461710aee36c32068722261863b86c7eacb50188e8f30deaffae024d2a0f1b377bcc8de17636d7f51dbb5377fdc8b9b98da3ea32edbafd10ff557e65f67a01756aebd26a37a6dfa2ebab54206ec14a4ed1c0771316a93b2302d029dc9fb77a016cc5db286c0a3694dd0a5dfbf17ae7e6e71ee86345f5b447c47703d216e8a49a0985de3d814a4a420fb4aa29cea550447ff26700e6f8201979853e2ab58ffb881a05c37520f1f9b351efb77546b89ba562cab7e3ff846f660d2924a327149fda54aa007b0f783eeecba8d2e1b19cd27bc32962d21c78589fb2469918c27fa1fb9f3f5a07aadde6f5a16f1bc14deae2cfdc59a3b12fa4334c8ab3ca938a0ad1f165171d7a08553712a5b419ad8742e02c1b2826f9d6f226ec29205f317460e3543c4432cfaa0989cbf17578dc31a7048bb6f7951bbcb4390a4dc34548749ddec5808ff70179080",
"f901d1a0e58784367fe398679d1e6bf78a3dde3fa10c258a65eea417848eaa9c1365c52880a02c563764c450274db1cb7ed88cb682e357593263c87f03702e61f27038e6e922a07922b0a621b87690b1d9c3ac5d65453e8986f7119310aaa2382ce97790c970f6a03b791f9b5ea7b53ccc84bab05c1ab7fc182e5bd509489443e243a52834f12c4da02f3649d1bacefd45f4b86a92519e11fefde52bf9c033de305ab01e52da1e48e1a0a5b9e0f7516da5fc7363da0173758cf09a9d5e690871de79cb679c4fc58461a3a01b364c944363705f8ece380cff7c2e97f02ec60bf1dfab7fb05416650e521e07a0d4fc2dbc2c9cda95844bd354e7b15d597129986c08d647936566cdc6e6706703a0c0e749ab6f93f5e2d8c3ddce4069b14209bc1af57ae92495a2aab329c05cec4680a02ce6842baa2cf1f1ae3ca83d14671d0542a68d56ee6e5988fcf3bebe350871fba08b653c5eec87175195fbc9f2d4ea4812f247e8750c82a898da213754dd432740a067fd774407561e7a0a58dab51f060e6aae9f328b5b0da61eabb9c3fbdc7d0885a0fd684711826b61ca2db1c759aa1fa7358076077d6b39eebb634372acaf24d513a0f6a420560467e2f0373f048d29563653021b07d9e6bec69b0b441a2aba5c184680",
"f8718080a05962e5c16b55955a1b3e61772a6e724d3a1781d01560a451af4863fd8e9fa93a808080a01f98d45e3935f95ab00d8719a0fc6622c7b94f222ac5a8646cddda41c9d2a05f80808080a0fa04c9c955cb58796e3c31163dfc2a7eabe844afa89b2fa56e41e374498b3d788080808080",
- "f8679e3f79d03bccd3d5515f1e14b1abc5eefe027e5a7252bcfd9f428823d3593db846f8440180a0821e2556a290c86405f8160a2d662042a431ba456b9db265c79bb837c04be5f0a08bfc1c7c7464660a68ba241ea78b6a1d36cd85b5cb4fba521d4270bd0c7d7bb7"
-};
+ "f8679e3f79d03bccd3d5515f1e14b1abc5eefe027e5a7252bcfd9f428823d3593db846f8440180a0821e2556a290c86405f8160a2d662042a431ba456b9db265c79bb837c04be5f0a08bfc1c7c7464660a68ba241ea78b6a1d36cd85b5cb4fba521d4270bd0c7d7bb7"};
-static json_ctx_t * init() {
+static json_ctx_t* init() {
bytes_t b = {.data = (uint8_t*) mock_eth_call_response, .len = mock_eth_call_response_len};
//print_debug(&b);
return parse_binary(&b);
}
static void test_binary_primitives() {
- json_ctx_t* ctx = init();
- int k_result = key_("result");
- int k_id = key_("id");
- int k_jsonrpc = key_("jsonrpc");
- bytes_t *d = d_bytes(d_get(ctx->result, k_result));
- char *str_result = malloc(d->len * 2 + 2);
- bytes_to_hex(d->data, d->len, str_result);
- char* jsonrpc = d_get_stringk(ctx->result, k_jsonrpc);
- int32_t id_ = d_get_intk(ctx->result, k_id);
+ json_ctx_t* ctx = init();
+ int k_result = key_("result");
+ int k_id = key_("id");
+ int k_jsonrpc = key_("jsonrpc");
+ bytes_t* d = d_bytes(d_get(ctx->result, k_result));
+ char* str_result = malloc(d->len * 2 + 2);
+ bytes_to_hex(d->data, d->len, str_result);
+ char* jsonrpc = d_get_stringk(ctx->result, k_jsonrpc);
+ int32_t id_ = d_get_intk(ctx->result, k_id);
TEST_ASSERT_EQUAL_STRING(str_result, "0000000000000000000000000000000000000000000000000000000000000001");
TEST_ASSERT_EQUAL_STRING(jsonrpc, "2.0");
TEST_ASSERT_EQUAL_INT32(id_, 1);
@@ -98,16 +96,16 @@ static void test_binary_object() {
int k_proof = key_("proof");
int k_value = key_("value");
//test object
- d_token_t* accounts = d_get(d_get(d_get(ctx->result, k_in3), k_proof), k_accounts);
- char *str_proof = NULL;
+ d_token_t* accounts = d_get(d_get(d_get(ctx->result, k_in3), k_proof), k_accounts);
+ char* str_proof = NULL;
for (d_iterator_t iter = d_iter(accounts); iter.left; d_iter_next(&iter)) {
d_token_t* storage_object = d_get_at(d_get(iter.token, k_storageProof), 0);
bytes_t* proof_s = d_get_bytes_at(d_get(storage_object, k_proof), 0);
- int32_t key = d_int(d_get(storage_object, k_key));
- int32_t value = d_int(d_get(storage_object, k_value));
- str_proof = malloc(proof_s->len * 2 + 10);
- bytes_to_hex(proof_s->data, proof_s->len, str_proof);
- TEST_ASSERT_EQUAL_STRING(str_proof,"e3a120290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e56301");
+ int32_t key = d_int(d_get(storage_object, k_key));
+ int32_t value = d_int(d_get(storage_object, k_value));
+ str_proof = malloc(proof_s->len * 2 + 10);
+ bytes_to_hex(proof_s->data, proof_s->len, str_proof);
+ TEST_ASSERT_EQUAL_STRING(str_proof, "e3a120290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e56301");
TEST_ASSERT_EQUAL_INT32(key, 0);
TEST_ASSERT_EQUAL_INT32(value, 1);
}
@@ -123,17 +121,16 @@ static void test_binary_array() {
d_token_t* accounts = d_get(d_get(d_get(ctx->result, k_in3), k_proof), k_accounts);
for (d_iterator_t iter = d_iter(accounts); iter.left; d_iter_next(&iter)) {
d_token_t* accounts_array = d_get(iter.token, k_accountProof);
- int index =0;
- char *str_proof= NULL;
+ int index = 0;
+ char* str_proof = NULL;
for (d_iterator_t iter_arr = d_iter(accounts_array); iter_arr.left; d_iter_next(&iter_arr)) {
bytes_t* proof_data = d_bytes(iter_arr.token);
- str_proof = malloc(proof_data->len * 2 + 10);
- bytes_to_hex(proof_data->data, proof_data->len, str_proof);
+ str_proof = malloc(proof_data->len * 2 + 10);
+ bytes_to_hex(proof_data->data, proof_data->len, str_proof);
TEST_ASSERT_EQUAL_STRING(str_proof, account_proof_array[index]);
index++;
free(str_proof);
}
-
}
}
diff --git a/c/test/unit_tests/test_bitset.c b/c/test/unit_tests/test_bitset.c
index fcdab100a..b49773c8b 100644
--- a/c/test/unit_tests/test_bitset.c
+++ b/c/test/unit_tests/test_bitset.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/test/unit_tests/test_cache.c b/c/test/unit_tests/test_cache.c
index 3cae0d945..dabb279f6 100644
--- a/c/test/unit_tests/test_cache.c
+++ b/c/test/unit_tests/test_cache.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/test/unit_tests/test_core.c b/c/test/unit_tests/test_core.c
index 146271c08..8b9449b3e 100644
--- a/c/test/unit_tests/test_core.c
+++ b/c/test/unit_tests/test_core.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/test/unit_tests/test_ethapi.c b/c/test/unit_tests/test_ethapi.c
index f17d88bb2..217c6a85f 100644
--- a/c/test/unit_tests/test_ethapi.c
+++ b/c/test/unit_tests/test_ethapi.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -363,7 +363,7 @@ static void test_eth_getblock_txcount_number(void) {
// we expect this to fail as we dont have verification for this
char* error = eth_last_error();
in3_log_debug("error found: %s", error);
- TEST_ASSERT_TRUE(!tx_count);
+ TEST_ASSERT_EQUAL_INT64(tx_count,6ll);
in3_free(in3);
}
@@ -375,7 +375,7 @@ static void test_eth_getblock_txcount_hash(void) {
uint64_t tx_count = eth_getBlockTransactionCountByHash(in3, blk_hash);
char* error = eth_last_error();
in3_log_debug("error found: %s", error);
- TEST_ASSERT_TRUE(!tx_count);
+ TEST_ASSERT_EQUAL_INT64(tx_count,2ll);
in3_free(in3);
}
diff --git a/c/test/unit_tests/test_filter.c b/c/test/unit_tests/test_filter.c
index e2ee5f32f..9c50c1cd3 100644
--- a/c/test/unit_tests/test_filter.c
+++ b/c/test/unit_tests/test_filter.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/test/unit_tests/test_ipfs_api.c b/c/test/unit_tests/test_ipfs_api.c
index 183eb017e..3b00553a1 100644
--- a/c/test/unit_tests/test_ipfs_api.c
+++ b/c/test/unit_tests/test_ipfs_api.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/test/unit_tests/test_key_hash.c b/c/test/unit_tests/test_key_hash.c
index 66dd5a2cf..700a5a6d2 100644
--- a/c/test/unit_tests/test_key_hash.c
+++ b/c/test/unit_tests/test_key_hash.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -100,7 +100,7 @@ static char* filetostr(const char* filename) {
fseek(f, 0, SEEK_END);
length = ftell(f);
fseek(f, 0, SEEK_SET);
- buffer = _malloc(length + 1);
+ buffer = _malloc(length + 1);
buffer[length] = 0;
if (buffer) {
fread(buffer, 1, length, f);
@@ -129,15 +129,14 @@ void test_key_hash_collisions() {
hashes = _realloc(hashes, cap * 2 * sizeof(*hashes), cap);
cap *= 2;
}
- char* kstr= substr(tok, "key(\"", "\")");
+ char* kstr = substr(tok, "key(\"", "\")");
if (kstr) {
hashes[i] = key_(kstr);
#ifdef DEBUG
printf("\"%s\" => [%u]\n", kstr, hashes[i]);
#endif
- }
- else{
- hashes[i]= 0;
+ } else {
+ hashes[i] = 0;
}
}
uint16_t nc = -1;
diff --git a/c/test/unit_tests/test_logging.c b/c/test/unit_tests/test_logging.c
index 7c360923b..3fbb11674 100644
--- a/c/test/unit_tests/test_logging.c
+++ b/c/test/unit_tests/test_logging.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -38,8 +38,8 @@
#endif
#include "../../src/core/util/log.h"
-#include "../test_utils.h"
#include "../../src/core/util/mem.h"
+#include "../test_utils.h"
#include
static char* read_file(FILE* file) {
@@ -59,8 +59,8 @@ static char* read_file(FILE* file) {
len += r;
if (feof(file)) break;
size_t new_alloc = allocated * 2 + 1;
- buffer = _realloc(buffer, new_alloc, allocated);
- allocated = new_alloc;
+ buffer = _realloc(buffer, new_alloc, allocated);
+ allocated = new_alloc;
}
if (len && buffer[len - 1] == '\n') buffer[len - 1] = 0;
@@ -100,8 +100,8 @@ static void test_prefix(void) {
fseek(fp, 0, SEEK_SET);
fclose(fp);
- fp = fopen("test.log", "rb");
- log = _malloc(size + 1);
+ fp = fopen("test.log", "rb");
+ log = _malloc(size + 1);
log[size] = 0;
fread(log, sizeof(char), size, fp);
TEST_ASSERT_EQUAL_STRING_LEN(log, prefix, strlen(prefix));
diff --git a/c/test/unit_tests/test_nodelist.c b/c/test/unit_tests/test_nodelist.c
index fd95612ed..cfbeb264e 100644
--- a/c/test/unit_tests/test_nodelist.c
+++ b/c/test/unit_tests/test_nodelist.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/test/unit_tests/test_request.c b/c/test/unit_tests/test_request.c
index ee5ba834d..b17dc3dcb 100644
--- a/c/test/unit_tests/test_request.c
+++ b/c/test/unit_tests/test_request.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/test/unit_tests/test_rpc_api.c b/c/test/unit_tests/test_rpc_api.c
index 92bf64d73..576316a22 100644
--- a/c/test/unit_tests/test_rpc_api.c
+++ b/c/test/unit_tests/test_rpc_api.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/test/unit_tests/test_sign.c b/c/test/unit_tests/test_sign.c
index f3738628b..fcb5e1fcb 100644
--- a/c/test/unit_tests/test_sign.c
+++ b/c/test/unit_tests/test_sign.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/test/unit_tests/test_verify_eth_getLog.c b/c/test/unit_tests/test_verify_eth_getLog.c
index 1e5694b6b..ab09306c9 100644
--- a/c/test/unit_tests/test_verify_eth_getLog.c
+++ b/c/test/unit_tests/test_verify_eth_getLog.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/test/util/junit.c b/c/test/util/junit.c
new file mode 100644
index 000000000..a803df8b5
--- /dev/null
+++ b/c/test/util/junit.c
@@ -0,0 +1,218 @@
+#include "../../src/core/util/stringbuilder.h"
+#include
+#include
+#include
+
+static char* trim(char* data) {
+ char *s = NULL, *e = NULL;
+ for (; *data; data++) {
+ switch (*data) {
+ case ' ':
+ case '\n':
+ case '\r':
+ case '\t':
+ break;
+
+ default:
+ if (!s) s = data;
+ e = data;
+ break;
+ }
+ }
+ if (e) e[1] = 0;
+ return s ? s : data;
+}
+#define TYPE_JSON 0
+#define TYPE_EVM 1
+#define TYPE_UNIT 2
+
+typedef struct suite {
+ int type;
+ bool success;
+ int index;
+ int fails;
+ int total;
+ char* name;
+ float time;
+ sb_t out;
+ sb_t testcases;
+ sb_t props;
+ struct suite* next;
+} suite_t;
+
+static void escape(sb_t* sb, char* c) {
+ for (; *c; c++) {
+ switch (*c) {
+ case '<':
+ sb_add_chars(sb, "<");
+ break;
+ case '>':
+ sb_add_chars(sb, ">");
+ break;
+ case '&':
+ sb_add_chars(sb, "&");
+ break;
+ case '"':
+ sb_add_chars(sb, """);
+ break;
+ case '\'':
+ sb_add_chars(sb, "'");
+ break;
+ case 27:
+ break;
+ default:
+ sb_add_char(sb, *c);
+ break;
+ }
+ }
+}
+
+static void add_testcase(suite_t* suite, char* name, char* file, char* error) {
+ if (error && !*error) error = NULL;
+ // if (file) file = trim(file);
+ suite->total++;
+ if (error) suite->fails++;
+ sb_t* sb = &suite->testcases;
+ sb_add_chars(sb, " ");
+ if (error) {
+ sb_add_chars(sb, "\n name);
+ sb_add_chars(sb, "\" message=\"");
+ escape(sb, error);
+ sb_add_chars(sb, "\"/>\n ");
+ }
+ sb_add_chars(sb, "\n");
+}
+
+static bool start_with_number(char* c) {
+ int count = 0;
+ for (; *c; c++, count++) {
+ if ((*c >= '0' && *c <= '9') || *c == ' ') continue;
+ if (*c == ':' && count) return true;
+ return false;
+ }
+ return false;
+}
+
+int main(int argc, char* argv[]) {
+ char* full_line = NULL;
+ size_t line_n = 0;
+ char current[10];
+ char start_string[100];
+ int total = 0, failed = 0;
+ current[0] = 0;
+ strcpy(start_string, "Start ");
+ suite_t suite;
+ memset(&suite, 0, sizeof(suite_t));
+ suite_t* last_suite = &suite;
+ printf("\n\n");
+ int n = 0;
+ char last_json_test[300], tmp[500];
+ last_json_test[0] = 0;
+
+ while ((n = getline(&full_line, &line_n, stdin)) > 0) {
+ // printf("%i:%i|%s", n, (int) line_n, full_line);
+ char* line = trim(full_line);
+ if (strncmp(line, "test ", 5) == 0) {
+
+ if (suite.out.data) free(suite.out.data);
+ if (suite.props.data) free(suite.props.data);
+ if (suite.testcases.data) free(suite.testcases.data);
+ if (suite.name) free(suite.name);
+
+ memset(&suite, 0, sizeof(suite_t));
+
+ // new test
+ sb_init(&suite.out);
+ sb_init(&suite.props);
+ sb_init(&suite.testcases);
+ strcpy(current, line + 5);
+ suite.index = atoi(current);
+ total++;
+ sprintf(start_string, "Start %5i", suite.index);
+ } else if (strncmp(line, start_string, 6) == 0) {
+ last_suite->name = strdup(strstr(line, ":") ? strstr(line, ":") + 2 : (line + strlen(start_string) + 2));
+ } else if (*line >= '0' && *line <= '9' && line[strlen(current)] == ':') {
+ char* out = line + strlen(current) + 2;
+ if (strncmp(out, "Test command:", 13) == 0) {
+ if (strstr(out, "/vmrunner"))
+ last_suite->type = TYPE_EVM;
+ else if (strstr(out, "/runner"))
+ last_suite->type = TYPE_JSON;
+ else
+ last_suite->type = TYPE_UNIT;
+ sb_add_chars(&last_suite->props, " props, out + 14);
+ sb_add_chars(&last_suite->props, "\"/>\n");
+ } else {
+
+ if (last_suite->out.len) sb_add_char(&last_suite->out, '\n');
+ escape(&last_suite->out, out);
+ char* pp = strstr(out, ":");
+ int p = pp ? pp - out : 0;
+ if (p > 5) p = 0;
+
+ if (last_suite->type == TYPE_UNIT && (strstr(out, ":PASS") || strstr(out, ":FAIL"))) {
+ char* file = strtok(out, ":");
+ while (file && strstr(file, "/")) file = strstr(file, "/") + 1;
+ char* line = strtok(NULL, ":");
+ char* name = strtok(NULL, ":");
+ char* pass = strtok(NULL, ":");
+ char* error = (pass && strcmp(pass, "FAIL") == 0) ? pass + 6 : NULL;
+ add_testcase(last_suite, name, file, error);
+ } else if (last_suite->type == TYPE_JSON && out[p] == ':' && start_with_number(out)) {
+ char* error = strstr(out + 66, "OK") == NULL ? "Failed" : NULL;
+ out[65] = 0;
+ char* name = trim(out + p + 1);
+ if (*name == '.') {
+ sprintf(tmp, "%s%s", last_json_test, name);
+ add_testcase(last_suite, tmp, "runner", error);
+ } else {
+ strcpy(last_json_test, name);
+ add_testcase(last_suite, name, "runner", error);
+ }
+ } else if (last_suite->type == TYPE_EVM && out[p] == ':' && start_with_number(out)) {
+ char* error = strstr(out + 66, "OK") == NULL ? "Failed" : NULL;
+ out[65] = 0;
+ char* name = trim(out + p + 1);
+ if (!strstr(name, ":"))
+ name = last_suite->name;
+ // name = strstr(name, ":") + 2;
+ // else
+ add_testcase(last_suite, name, "runner", error);
+ }
+ }
+ } else if (*line >= '0' && *line <= '9' && line[strlen(current)] == '/') {
+ if (strstr(line, "***Failed"))
+ failed++;
+ else
+ last_suite->success = true;
+
+ char* ptr = strtok(line, " \t");
+ while (ptr) {
+ if (strstr(ptr, ".") && *ptr >= '0' && *ptr <= '9')
+ last_suite->time = atof(ptr);
+ ptr = strtok(NULL, " \t");
+ }
+
+ if (!last_suite->testcases.len) add_testcase(last_suite, "default", last_suite->name, last_suite->success ? NULL : "Failed");
+
+ printf(" \n",
+ last_suite->type == TYPE_EVM ? "evm" : (last_suite->type == TYPE_JSON ? "json" : "unit"),
+ last_suite->name, last_suite->total, last_suite->fails, last_suite->index - 1, last_suite->time);
+ if (last_suite->testcases.len) printf("%s", last_suite->testcases.data);
+ if (last_suite->props.len) printf(" \n%s \n", last_suite->props.data);
+ if (last_suite->out.len) printf(" \n%s \n", last_suite->out.data);
+ printf(" \n");
+
+ // printf("%i : %-100s %8s %02f\n", total, last_suite->name, last_suite->error ? last_suite->error : "PASSED", last_suite->time);
+ }
+ }
+ printf("");
+
+ return failed ? -1 : 0;
+}
\ No newline at end of file
diff --git a/c/test/util/platform.h b/c/test/util/platform.h
index 392b5a342..02b5c564e 100644
--- a/c/test/util/platform.h
+++ b/c/test/util/platform.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/test/util/stack_diag.c b/c/test/util/stack_diag.c
index 64e2f2a1f..0558da23e 100644
--- a/c/test/util/stack_diag.c
+++ b/c/test/util/stack_diag.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/test/util/stack_diag.h b/c/test/util/stack_diag.h
index c60ed6368..d365809df 100644
--- a/c/test/util/stack_diag.h
+++ b/c/test/util/stack_diag.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/c/test/util/transport.h b/c/test/util/transport.h
index a8d7431ee..a96ca37fd 100644
--- a/c/test/util/transport.h
+++ b/c/test/util/transport.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -40,8 +40,8 @@ extern "C" {
#endif
#include "../../src/core/client/client.h"
-void add_response(char* request_method, char* request_params, char* result, char* error, char* in3);
-void add_response_test(char* test);
+void add_response(char* request_method, char* request_params, char* result, char* error, char* in3);
+void add_response_test(char* test);
in3_ret_t test_transport(in3_request_t* req);
in3_ret_t mock_transport(in3_request_t* req);
diff --git a/c/test/vm_runner.c b/c/test/vm_runner.c
index 2701b9228..557e0a305 100644
--- a/c/test/vm_runner.c
+++ b/c/test/vm_runner.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -79,8 +79,8 @@ char* readContent(char* name) {
len += r;
if (feof(file)) break;
size_t new_alloc = allocated * 2;
- buffer = _realloc(buffer, new_alloc, allocated);
- allocated = new_alloc;
+ buffer = _realloc(buffer, new_alloc, allocated);
+ allocated = new_alloc;
}
buffer[len] = 0;
@@ -95,6 +95,8 @@ int run_test(d_token_t* test, int counter, char* name, uint32_t props) {
char* descr = NULL;
int i;
+ char* sname = strstr(name, "/testdata/");
+ if (sname) name = sname + 10;
int l = strlen(name), fail = 0;
if (name[l - 5] == '.') name[l - 5] = 0;
char* tname = d_get_keystr(test->key);
diff --git a/c/test/vm_runner.h b/c/test/vm_runner.h
index e39e5edf8..e1823fc61 100644
--- a/c/test/vm_runner.h
+++ b/c/test/vm_runner.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/java/CMakeLists.txt b/java/CMakeLists.txt
index b4f51b944..e295b4bc1 100644
--- a/java/CMakeLists.txt
+++ b/java/CMakeLists.txt
@@ -2,7 +2,7 @@
# This file is part of the Incubed project.
# Sources: https://github.com/slockit/in3-c
#
-# Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+# Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
#
#
# COMMERCIAL LICENSE USAGE
diff --git a/java/build.gradle b/java/build.gradle
index 008f53157..0d88ff5e8 100644
--- a/java/build.gradle
+++ b/java/build.gradle
@@ -10,20 +10,21 @@
Need to change this because its generating garbage in the build directory... consider on using a custom nonjava pipeline
it is also kind of schizophrenic to have a standalone build system for running tests
*/
-apply plugin: 'java'
-apply plugin: "eclipse"
+plugins {
+ id 'java'
+ id 'jacoco'
+ id 'com.github.ksoichiro.console.reporter' version '0.6.2'
+}
def jarSourceFolder = "../build/lib/in3.jar"
def jarOutputFolder = "./target"
-test.dependsOn 'copyJarToBindings'
-
+// Custom tasks for testing the .jar
task createLibDir {
mkdir jarOutputFolder
}
task copyJarToBindings(type: Copy) {
- dependsOn 'createLibDir'
from jarSourceFolder
into jarOutputFolder
}
@@ -39,19 +40,16 @@ sourceSets {
}
test {
java {
- srcDirs = ['./test']
+ srcDirs = ['test']
}
resources {
- srcDirs = ['./resources']
+ srcDirs = ['resources']
}
}
}
test {
- testLogging {
- outputs.upToDateWhen { false }
- showStandardStreams = true
- }
+// systemProperty "java.library.path", "../build/lib"
useJUnitPlatform()
}
@@ -69,3 +67,37 @@ dependencies {
testImplementation 'org.json:json:20190722'
testImplementation 'commons-io:commons-io:2.6'
}
+
+jacocoTestReport {
+ sourceSets {
+ main {
+ java {
+ srcDirs = ['./src']
+ }
+ resources {
+ srcDirs = ['./src']
+ }
+ }
+ }
+}
+
+/*
+ * Custom sourceSets definition for running the tasks. Since building the .jar has a point of failure (aka the CMakeLists.txt) its desirable to test the .jar
+ * For the actual coverage report to work, jacoco plugin must know the source code hence the specific sourceMaps.
+*/
+consoleReporter {
+ jacoco {
+ onlyWhenCoverageTaskExecuted true
+ reportAfterBuildFinished false
+ }
+}
+
+/*
+ * Testing tasks pipeline. Since the key task is testing, this sequence was built arround it.
+ * Also note that the coverage report plugin has a bug on it so we had to disable the attachment of the report after the build
+ * and do it manually here (see: https://github.com/ksoichiro/gradle-console-reporter/issues/7).
+*/
+test.dependsOn 'createLibDir'
+test.dependsOn 'copyJarToBindings'
+test.finalizedBy jacocoTestReport
+jacocoTestReport.finalizedBy reportCoverage
\ No newline at end of file
diff --git a/java/examples/Configure.java b/java/examples/Configure.java
index 610df0762..5401f7c03 100644
--- a/java/examples/Configure.java
+++ b/java/examples/Configure.java
@@ -21,11 +21,11 @@ public static void main(String[] args) {
clientConfig.setMaxAttempts(1); // sets max attempts to 1 before giving up
clientConfig.setProof(Proof.none); // does not require proof (not recommended)
- // Setup the NodeConfiguration object for the nodes on a certain chain
- NodeConfiguration nodeConfiguration = new NodeConfiguration(Chain.GOERLI, clientConfig);
- nodeConfiguration.setNeedsUpdate(false);
- nodeConfiguration.setContract("0xac1b824795e1eb1f6e609fe0da9b9af8beaab60f");
- nodeConfiguration.setRegistryId("0x23d5345c5c13180a8080bd5ddbe7cde64683755dcce6e734d95b7b573845facb");
+ // Setup the ChainConfiguration object for the nodes on a certain chain
+ ChainConfiguration chainConfiguration = new ChainConfiguration(Chain.GOERLI, clientConfig);
+ chainConfiguration.setNeedsUpdate(false);
+ chainConfiguration.setContract("0xac1b824795e1eb1f6e609fe0da9b9af8beaab60f");
+ chainConfiguration.setRegistryId("0x23d5345c5c13180a8080bd5ddbe7cde64683755dcce6e734d95b7b573845facb");
in3.setConfig(clientConfig);
diff --git a/java/examples/GetBalance.java b/java/examples/GetBalance.java
index 3424178a4..6ed22ed23 100644
--- a/java/examples/GetBalance.java
+++ b/java/examples/GetBalance.java
@@ -13,16 +13,16 @@ public static void main(String[] args) throws Exception {
// create incubed
IN3 in3 = IN3.forChain(Chain.MAINNET); // set it to mainnet (which is also dthe default)
- System.out.println("Balance API" + GetBalanceAPI(in3).longValue());
+ System.out.println("Balance API" + getBalanceAPI(in3).longValue());
- System.out.println("Balance RPC " + GetBalanceRPC(in3));
+ System.out.println("Balance RPC " + getBalanceRPC(in3));
}
- static BigInteger GetBalanceAPI(IN3 in3) {
+ static BigInteger getBalanceAPI(IN3 in3) {
return in3.getEth1API().getBalance(AC_ADDR, Block.LATEST);
}
- static String GetBalanceRPC(IN3 in3) {
+ static String getBalanceRPC(IN3 in3) {
return in3.sendRPC("eth_getBalance", new Object[] {AC_ADDR, "latest"});
}
}
diff --git a/java/examples/GetTransaction.java b/java/examples/GetTransaction.java
index 94d5b44c1..256ff77bb 100644
--- a/java/examples/GetTransaction.java
+++ b/java/examples/GetTransaction.java
@@ -13,17 +13,17 @@ public static void main(String[] args) throws Exception {
// create incubed
IN3 in3 = IN3.forChain(Chain.MAINNET); // set it to mainnet (which is also dthe default)
- Transaction txn = GetTransactionAPI(in3);
+ Transaction txn = getTransactionAPI(in3);
System.out.println("Transaction API #blockNumber: " + txn.getBlockNumber());
- System.out.println("Transaction RPC :" + GetTransactionRPC(in3));
+ System.out.println("Transaction RPC :" + getTransactionRPC(in3));
}
- static Transaction GetTransactionAPI(IN3 in3) {
+ static Transaction getTransactionAPI(IN3 in3) {
return in3.getEth1API().getTransactionByHash(TXN_HASH);
}
- static String GetTransactionRPC(IN3 in3) {
+ static String getTransactionRPC(IN3 in3) {
return in3.sendRPC("eth_getTransactionByHash", new Object[] {TXN_HASH});
}
}
\ No newline at end of file
diff --git a/java/examples/GetTransactionReceipt.java b/java/examples/GetTransactionReceipt.java
index b1afecbbe..015dd6fe3 100644
--- a/java/examples/GetTransactionReceipt.java
+++ b/java/examples/GetTransactionReceipt.java
@@ -13,17 +13,17 @@ public static void main(String[] args) throws Exception {
// create incubed
IN3 in3 = IN3.forChain(Chain.MAINNET); // set it to mainnet (which is also the default)
- TransactionReceipt txn = GetTransactionReceiptAPI(in3);
+ TransactionReceipt txn = getTransactionReceiptAPI(in3);
System.out.println("TransactionRerceipt API : for txIndex " + txn.getTransactionIndex() + " Block num " + txn.getBlockNumber() + " Gas used " + txn.getGasUsed() + " status " + txn.getStatus());
- System.out.println("TransactionReceipt RPC : " + GetTransactionReceiptRPC(in3));
+ System.out.println("TransactionReceipt RPC : " + getTransactionReceiptRPC(in3));
}
- static TransactionReceipt GetTransactionReceiptAPI(IN3 in3) {
+ static TransactionReceipt getTransactionReceiptAPI(IN3 in3) {
return in3.getEth1API().getTransactionReceipt(TRANSACTION_HASH);
}
- static String GetTransactionReceiptRPC(IN3 in3) {
+ static String getTransactionReceiptRPC(IN3 in3) {
return in3.sendRPC("eth_getTransactionReceipt", new Object[] {TRANSACTION_HASH});
}
}
diff --git a/java/resources/responses/eth_call.json b/java/resources/responses/eth_call_1.json
similarity index 100%
rename from java/resources/responses/eth_call.json
rename to java/resources/responses/eth_call_1.json
diff --git a/java/resources/responses/eth_call_2.json b/java/resources/responses/eth_call_2.json
new file mode 100644
index 000000000..d422b256d
--- /dev/null
+++ b/java/resources/responses/eth_call_2.json
@@ -0,0 +1,53 @@
+[
+ {
+ "jsonrpc": "2.0",
+ "result": "0x00000000000000000000000006012c8cf97bead5deae237070f9587f8e7a266d",
+ "id": 1,
+ "in3": {
+ "proof": {
+ "type": "callProof",
+ "block": "0xf9021aa00d4eaa6808c43eeb79b789b4134d87bd406fb8dc52f5f0d0ac54e12bbce66b28a01dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347945a0b54d5dc17e0aadc383d2db43b0a0d3e029c4ca03c98eea5b355fb0c78ee640a044dad450976e8dd91b99e2f54715f9fb480d5d2a0f3dba66e046da028e9b8c0e5a10cafd32af7aa0188f2cf7c367765a31b064a29a0f21cbc82667c6d4b44bb4237ac4efc9addd2795f97b17ca7f196f71f96f5f24ab90100ea8140021c33a889016d222158111b4730e04a90c1112ece198029409201ae61f40812f760384e06806081060b0047040fa904885b113889200b50d060faaa801508804882038212481c001dd0c01866a684a6280660f14cb640e0a5a240a29a1808150606c150a52411525c3aa538232208150078409c993808d036700030e42c20f1826301c413d02d8c15cb2685b3e4248d6d4f83503ce1d100c1741240c862d80501803607411aa068d505c48444302e8580d5804032286008061e253e075284064b6832447044c640321900d22548653603838082b1412252cac0906045b2907404008910a0e46a689dc51403018884002092a7525012640c8c98b121128707e3debd89ed3c83910c8c839896808398668c845e4b9ba1995050594520737061726b706f6f6c2d6574682d636e2d687a33a00678985580d2d23a46b06f737237ce0d1fe5858d9c21211ac33e7ebe2e41b9ba88885cf9e819a5e5b4",
+ "signatures": [],
+ "accounts": {
+ "0x1da022710df5002339274aadee8d58218e9d6ab5": {
+ "accountProof": [
+ "0xf90211a09c03df5c89a0e9395b562160851aba29135d62803bd66aed2bad92412569e24fa0bda2632214d8048a5d4c45c8d32fff36d8746aae3caf6fe1d0f1a5629b12951fa06ba04d3584e2c05a0957f683e2d5e5a121c1fdb005812a14aff3def670ff5ebda0d49464cdf2a4d4a1a0ba39b0d94df1d5c8be7321360f5b5a45e7d694ab609521a04526138afbb8fd8a39f70b3d177d63b36dd6f4ac0e070f64f35be80c993bac8ea0c1af85dfc243cdf8720ea926cc89c6918ca74357d1fdda8668dac8aeff4621aea076b7501be573cc64ad2334320754806c10b5fee2585fa897f3c261a9a64afdd3a0cf8a6027d1b375c597d1d6615b36b1145df8d325f93c38f49575d6e59a613860a06fd030173a8414b3cced39156003a52dc28ef3092ecd9a7eb8d8d71bcdda87f3a00a8c1bc19ac9adc3feb00469d50d35301b4a7a4e50a5aa59c577f7d6e027ab28a05da84b9cc88bfc8a7693fb563a8e347e5d8baa104a151e7e7f34b98feb6d0be7a085073e0d549219f34847f7b98e6e038dcf14bb3a1f3214efcf580d6d82a35d5ba080b3d97bf23497c32abf0f3e4b060b6fb8bcb26ae61acea4094c8afde18ae7aaa0fa844ff2e77f44f74a949da1616b671f70af7a5b4f503a1223e4af94530f102ba0e488a45d433be7a536c4e35cd1c05ce96cf2be1c7cab9603e320592c1b159efaa0c2085955a09d0d3e87088259d220b586b735f97c5eef2b05dd575d035415424180",
+ "0xf90211a04749a4c101bbb6dd01fb691a0ce6bf852ebfb90b077876bd0e37b2b5dcae2488a0f59a0b4206c45226304a2230bbb45833b505f816a8bc6012bed188bca541134fa061e000493a2aa696debef6e67bd0267ef3a1bcac04b2993902a7bc032f756ddea0c98ab4cbdca8060b60151369be7ef6350b0105ef7823f8fa27d1f913814d73eba036d76f4bebccf0e56a603caeb2200a90d7d49d6186c4288dd7a6a4ab24dde8c9a02aefe5b95f3388dcc22f4ce475c7045ee24e2d2c0caa5e66b61f65c03e8d5576a062c439e1b407ef94b8bc7e6239b9e9743b91e4bd5e78d151c9a119d4f5110d94a01c84b7ca510e5fdaeb5268fd8f7c999110f5e6b54e8480ae336849687fd813cba0e9acba582def1382482ccb45fda3469cc494422a92054a9c5106c29204b7c680a0ee2d20a8d7f3300f9982bb3bf97bf8001598a80087c98e40b764e3798f3ac2dfa04bfaf6aacbcb47c93b93322c2e7a7d2f670ed4bc62035973a1ecd338c626e0d6a0d4f72511e88cb4020006ba6c0741c7ed4b78441f5e3ca27116dcc867281412d5a0465dac8345b7217b8696e06cb2eec8e258783b478c401272f05182bf3629e5b8a0c986ea622dc5f2d7a90c57e481cf999df06e6365671fbf8a01144b8c3f17fedaa0cc0c11adfe0b9b7574b32710b5aec91389b8023bfcef6e98d0da48ff1353a528a0c9c4f47d0a85762de16483edbcbf75482bdbb2e25f58ffa2a8905abb21cfb1a880",
+ "0xf90211a0421d47805960c9324c9c65cfaa2757cdef8d385d2d88aeaa918e0d629f7bee06a0bac3958ab28d8b3a47e3f74172bf276b0ca0ee061eb03e0799cf0982c5914ee6a02a7f71c1489c6ab83e4e5f637a016b67a2b439cd2098e9550feeadb1cc06b7b1a09ebccb005760d1e961c05222facc9edbd65279b09c9808dba610f9c93ee0162da03347dbb5ffc7953775b5c01025b00f6c475e9e91b2f333789d213c9eede988d1a0db1d1de6ea6a5abdfdca819f514799791e5901d27378bd7f5d24293be1f40f4fa001f094e4f1357189decdeca91c585f31373eb07cf3fd800e1ffac402b2422baba01a5a0fc0ae73e7eba87343c945baf0a39b78206e16b3110f6d4bca2bebe7956ca0d5138810079832b59c79ea1b1053862f77c9054b054ce26b88247da193d76751a029e6f99e90ddfd5bd3c0878d53d3d3863adfdb767fbd613be88f89926fc14149a049d9e1ac7b6ebd0921259c7f1762ee8bfeaa13920aff5b17cd8f9411a1404280a0294fcd70b9130d3fed293a5cb11f7cde367610531385fbef125242f801690fdda0f17e2d6c7ffdc496f1a0296f8f2879a77193e27882ba9db3f4bb10e1ce3f0fa1a0057b934f2cbbf29c5d19cbc450c1a620885c1cffe92a9790e349a9345a1ae5c0a04a8f7e0f98c6089ba4ae1f8f45d20effd66a1da08c31b94613eb4f285a0bc638a0d09b8c4f9920d6e7190bd3da780ea4ff91e47408703dc726c193b45b999c0a7580",
+ "0xf90211a0dd51143a61d6ea570b7bd5d0e5c9b7f12bac69808ade380be07167ef3d3ad70da0d540d6812bc7c09e6b6db29f1fc8d7751b2e3422fe002f410fb9ee382597fc10a0bd66c03133addce1cba3c8b9cc25c6144b510bd8ddd22b8880129a31417d0f77a019f8621ed8e0522b09db2f60294828fefebb07afb12f93156b66b6e4d39f10cba0da576600e4bfa9adebbd7bc039474e73178d00472caad4f5b94d28f263adce15a0b0a506bebb06ceab88d00df98204c3b01f1a5e0ddd6da1d00785bf197e56dcfea091f4ba55a9f7e78075a0e40a081e56021953109a3dc18169a1b889496ea5ead4a0c00e14ffbe2adcef450f3d68bf3c742981af27de1e7afd303bd8c002b307dcaca04235436790dba10839f6b92dc0e9d9a7d8dc56ed16b565fc9628d98f99318063a076c019b378b1d7a75b1f0d5bef8dfe5d37578ba017b4be2691810d4108b97abaa0ba85578eca7cf82f89d89cd13fa9fd4c3dbdae1d337a8bddc76cffe6c235f6cfa0fc83aa4c3b5d32f565137173691efa74aed1054aec6a2a23d0f007cde3528183a0fc893b0b296ae92da4edfa3ecc59610871bc84cce95bb71f185614e1e70af859a09980836c7b1d74b244335d2f5039882fb0cfbcc7c19cd82e5277ef6c0a76367fa0a079297c4f6e850a5f3bdfcefb3553141ed41b66fab93fb3210af673ede2d248a00e3098f23c3a91de30039eae480bb8bdab723a49a9cab8cb50817f391a97dcc680",
+ "0xf90211a0c1b92c857da0340b0ce443833b66e5d0314ffd1cf92f2d695734456724e375eba00edd53ca526fd6f0ec43ea34ac4615f6997f5b1c0816f43794359b73f1ffc1c4a03e3c016f181362c3061a2f10b7d4aa4bc33c8d843a0ae464f3f2a96c153c437aa075c74847eee27cbf4f2031f76ad5f81d15646dd166f92e014529fd588e55ecaea06e2d4692022e8518a3017e4ce614264d592a2e5bc9ab4eafd274550dd962a63ea005d2e402784d5d1ccd4f63effb9d6f3fc955607532976656b344fbc2f6254d61a050d0b371e5324fe1753f81c8b0099b4426cc71e61025b9dc4acbf97ee91269cca04a733100cb3ff46ca6801d8ef5c4a5c17ef841efeeb0145cf49090c40e5d1580a09f5d83f3f0d0f697ca29c1b2d73800f19e195965215d4def53615435c73b4229a0013dffcd30a1233cf6dea6f8890557f925f303a89999faf2229ee6e1b51fb928a0f9e4d06cab2e49c9a2c8b88e5e4e2ca1266284cfa30a75a257ee1dd6994824ffa0f7f003ea25289eccff8b34fc78f3e821d557e6e0b93260b7eebb14a8ca069b06a037c82c23d927730ca6d4eaec8e3f2c188dceba6b99db4fc1bdb5b97fcc642af1a0804b978d2965c4913aeb43ac4eb2e8eb7136b6f275c37977203522cf1fa0ed34a04bd08b3b746253d0e5dfced158ccc7babccc8f3f862a033aa0efadae7775e070a0ca301518f7fcfdd10e24ae77d03f57ba1362bccf9d91f4ea3eeb54cd8588ee1080",
+ "0xf90211a094ff7643ea6a0875424d4bc0e7da632ee374cf92b23331dd200af20ab5108cdba02fdde91dfe1c91fcad765379bd602c17c488f0d0e65ec1cfddc45f89ce202213a0581479dd203d8a5d727c9eab7c3f95ed8dfd22c901c79d171dfb3f62a65cab55a06bafdd88fd4ca1d1019e0ae925fd55e93a12b8e90e395d4ff8f98584ae852c33a06d855744c75ccfdd9fbf5c6936d5382d1d31d8fce311e2d2d4c60c402b34c0a1a08b79b80a00b9b028748bd6b7d7bb0ab27502c7f6546705f8e67505a808fc6ba5a0fbb00de89d433d33dfad3a0cb5ffede3dfc41a97901a2b4730df6e82b04e575ea07f11477d71bc9ef74a721d3b94f46459ffb7bb16b1bdf420515dce624ebcc78da0a095d4c285e725c5e7ff550ebd4816b5cc89690f69ec9482a5bb65445bc685eca03958da0619d48a296def1741501057ca9383644839ca6dbb8e1089b3ee26b240a0cd32aa41e090d9c1eb92d6cf897ae1d0726d90525840044569d1c26ee00543cfa0a23d881cb739ec54c5428a212699c76649a64f46652252cc423935688e0b02a2a04749a577db36c04163e0bce5dfe0c7ffd76c6611c6c107379d57a45cbefc1ef9a0d3f2980a7f16010f56dab3b27234d5bb313ff34e86e56af270beb6b57dfa8c20a002a477a48013182250b9dd2ff85f508603920b13cef7b493e7282ae238e2bf11a0ac2d7c401dc1439cd0d1cfe8cf1c218144e261f35bda1c66d23cb36dc3ef71ac80",
+ "0xf8d180a08a5f70d31b16fcc2c06b558972d8c8cfebb63ecc7b45565eef21e8ed2191a51f808080a0674b12ef5b6b2104a014ceccba26c17b0ced72334b64aaeb53085ab4ab799188a0fb66681fdfb84951238da74372bfa7ca780cb48ee1d2b3dec484b5074fddd46f8080808080a01e1480859e14558b1a689d138a5e931e3270fdc7065b584a7fab17ed77f29926a0ea1989c7493a30d5a9a2dea74c5526e3922a94e3a8f33e2d335244a7dd43e8c0a00b08a289e59e8e38f42b21291a3c91861e0e94266000a8099f6302d9460015f88080",
+ "0xf8669d37ecef1dd7ed16827708f440d9beccf60a5ac8af5646f28db424c8ae7cb846f8440180a0cab2b579fa27d8d21dfa82076a7782c03745a97da929ede1b2a31eacd855e874a0ca1658c2e5516c4bc959e682d9a4cf235e8c28b5eef98aaf7ded27142689853a"
+ ],
+ "address": "0x1da022710df5002339274aadee8d58218e9d6ab5",
+ "balance": "0x0",
+ "codeHash": "0xca1658c2e5516c4bc959e682d9a4cf235e8c28b5eef98aaf7ded27142689853a",
+ "nonce": "0x1",
+ "storageHash": "0xcab2b579fa27d8d21dfa82076a7782c03745a97da929ede1b2a31eacd855e874",
+ "storageProof": [
+ {
+ "key": "0xc848fdf77cc0f2f355981619cea0e9d55c2399f1f5afdd4494a1e62363e47c0d",
+ "proof": [
+ "0xf90211a0467c60cdf034065efdfd22ceb8458ffab017343c2444558d6d97605fc0702f68a05796d8d7d3967ad64900143a234199008e96efc6c2d3adcdf34d1689a2b1531ba040a1c802995378db6ed34e824d31df278e83d5b0718718743770975ef42b2bcda0680f0ed73a4544acb3fc39f63610eef68e0b99d58cbfb8cbe932451d7d2dc082a07986f67b7a0c2afe4ad55d2b52db859265ee1bc023fb73334ee508064155c997a02af0b5ea3c0acad20667243eeab67828a2faeccd964ac8921244fe73b180c068a02b1f850aecf2caff1fdf9bed8e2170408d8566ba9c0ad906a09bdab057568a9fa0134bcb4c9747c128c8ac698fa13023eccf8df06b15a6567019b63774117a28bfa0a1f95734cbb2ebc4690b580b80c7d775c1de50ca04e209a2b9e4ab193c9d425ba0dadf861a4b28231a3a7557128a0b256e32ae2d99b5040bb60fc794f9f86fc564a09d3f3d5924ab998736b246bd7dc848e170542ec00a1ee3a606057ac7a002ba29a0259b4bb16b712ceeba9e8b6153a91e33b65bbd177a704c4973d965eaa34cbb64a03cdc6113f74aee3e5e258ec7237ee5115a092ed701d10e913df8c3924e01eb76a0a593663dd92a2241ec7e8f692e92b418509dc623f38520b91e67b68396bdec11a0e1e260bf2757d472839cb4ebfc646e0ff4b8b7041a1a324c7fd355d3d7559bbda052e26ad2527bedda7414214992cdd25ffb9cea2e027c49712b9f007b8fc2272f80",
+ "0xf90211a011437e06aad067b401c100ef508fd2111a02b630b8e5a4c52c88dfc41c48ee27a03e729e2eb56f2b0630243f520765460cfe633c395aa64bed450b089be4ebed1ea043d9aade3132c903c4aa299673dd05909cf0b78834543be0eb9319a9e756a57da060963ddadddc3852d910ecb676992517f4442d0d2e3052b4fa05e01c85b99edba0649b73780dab5ef7384951a31f8ecf10e8add8aaff21f64d810deda754c5b926a018747924feba26ef7196e7eb54b900a98e23cc1ef7acc156234b902fd1e8d086a0fa5ccd5d57adf588f9ca86a6b73ab17632d983c9927225c2853730a6fdf84c3aa03faea24e91769ba46e2a201959f4f4ae350203721eac31e8d0ef3915aacf1982a0a43e7600ac427d7910305b04946ebd6d15fb9a90f3b1cd891cc66b3f12bed34aa04cd3ab22240af89561b7063301fe4a3caba69c303784a0cbe7c3fbafdb14085aa02a207f51a5479db4a461c0c564e87822cf70d0e7eef6338961a6936bc1bdfaa1a05ed1731052dafbbda71dfdebc534f17c07bd95882430356ff276e0c1465607dfa07b68c0e1d39b467c0000b917a954f800c945329dda403e72cf6427a9e09d6aaaa0df5a7dd22ac55108e0d9f87cb022d334360f9471472090993cfef9156adf7dc8a0017d74f963cb610f8448c68fab87c45450f0b47d30094760a8b7d47014b2419aa07caaa80bff6d5fc7895e69d8573f784758dbf3da2f6bb4f2cd9459c01afffa2180",
+ "0xf90211a0950ace6b297c31ad3477c5bde5f156e2b639f5f1460ff6c8f643789b751b9da6a009c0cafe2f8e796bb8d23598732fab880710ff30dcc60a14c6ce3f872bfd1033a0f37814e343f287b5ae49f8d60a7f084be328ab3ad9b934bf4b8a192ca8828d5aa0624b3440eac4ba121953009bb6c6a70eed748bd17d3734b19b7b90d7f3b2b2dfa075ca7a41bf2f4e44cc09f0fefb275c17755f67c5d887f64e0bda048739f6eeb1a0db8a3e8eb8672fefcfcecd32ff86449e923ce5b7b62a3a50a88a365835eee90da028f5fc4d8ffafd78828e7ba6440f4ebcc917019a7b5fe1874c1374c89a7ff9b9a0fc4a0836a34b7f0ee1c3309a33b7228f533be2edd8a578eab2c875cf3f90c546a02c9fbba1878abc494c671ce475ea32fe237092d68eb93ba8a6d33f7aa76efbe4a0d0f1d867d11509fd1e9388ba3a293b3369a32d4fab841b53d141d971a6725438a0e05ffc695903166cb488f6f96e1b989cd16c4c03c1a3629f18a14c68143aa226a0975837d2f5dec549a1c5250e524de4113604ca53f9f65c9d51b9192c9fbecca4a0f672d7e3ddb6de3b2d81af90363c4bb30bee173b2d8e806b43f652871dc9f31fa065ac71a82f8d0464641c812bcadcd5d959124e740c33856893dad9a7f819c195a0dd6b9e04f7dbbf5b33fba2df751b07db33342d70e8b630e05fb48ecb03b6cfefa0df17ec6efa3ced8a815626baf8d9660af9cdf9f71eb45d8f6665d8e0c28b461680",
+ "0xf87180808080a0b0307376726efdec4f3f654675216698e2ce7ccfa717bdcd37be56f4080762f0808080a064c62ea1a1cfdeb8c6312c988d30ceca56274e86e1a14603c8cc1dd9951bf52f80a066d6d805d6ece8f57e7b7efedd9a8afb46c6bc88c510d360b57133caa86d4a39808080808080",
+ "0xf69f20418c51730f6a5ce35c0dbc36fb093e8f537e867199f58ce93429fab67575959406012c8cf97bead5deae237070f9587f8e7a266d"
+ ],
+ "value": "0x6012c8cf97bead5deae237070f9587f8e7a266d"
+ }
+ ]
+ }
+ }
+ },
+ "version": "2.1.0",
+ "currentBlock": 9505932,
+ "lastValidatorChange": 0,
+ "lastNodeList": 9491715,
+ "execTime": 21,
+ "rpcTime": 18,
+ "rpcCount": 2
+ }
+ }
+]
\ No newline at end of file
diff --git a/java/resources/responses/in3_sign.json b/java/resources/responses/in3_sign.json
new file mode 100644
index 000000000..7201f919e
--- /dev/null
+++ b/java/resources/responses/in3_sign.json
@@ -0,0 +1,25 @@
+[
+ {
+ "id": 1,
+ "jsonrpc": "2.0",
+ "result": [
+ {
+ "blockHash": "0x2a8bf38abe3fec478a2029e74ac95ecdbef95ff2fb832786ba4c5231c8cea480",
+ "block": 9551793,
+ "r": "0x16cf7b94a7276532ceff4bf6fd50fd01f2c2962a5f0887c70c75943ce9e08b77",
+ "s": "0x01f51c90e7f3493acf3c5b4efbed63534711f6209b2c47c34074f4882b92feaa",
+ "v": 27,
+ "msgHash": "0x0284928ef6fd270bacbfdba3087d0c50ad2db74af54c8bda8209b8ac9e41cfe1"
+ }
+ ],
+ "in3": {
+ "lastValidatorChange": 0,
+ "lastNodeList": 9422326,
+ "execTime": 60,
+ "rpcTime": 58,
+ "rpcCount": 1,
+ "currentBlock": 9552071,
+ "version": "2.1.0"
+ }
+ }
+]
\ No newline at end of file
diff --git a/java/src/CMakeLists.txt b/java/src/CMakeLists.txt
index 056450dd0..f9c0464d9 100644
--- a/java/src/CMakeLists.txt
+++ b/java/src/CMakeLists.txt
@@ -2,7 +2,7 @@
# This file is part of the Incubed project.
# Sources: https://github.com/slockit/in3-c
#
-# Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+# Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
#
#
# COMMERCIAL LICENSE USAGE
@@ -49,44 +49,54 @@ IF (NOT DEFINED ANDROID_ABI)
set(CMAKE_JAVA_COMPILE_FLAGS "-source" "1.7" "-target" "1.7")
set(SOURCES
- in3/Chain.java
- in3/IN3.java
- in3/IN3DefaultTransport.java
- in3/IN3Transport.java
- in3/JSON.java
- in3/StorageProvider.java
- in3/TempStorageProvider.java
- in3/Proof.java
+ in3/BlockID.java
+ in3/Chain.java
+ in3/IN3.java
+ in3/IN3DefaultTransport.java
+ in3/IN3Node.java
+ in3/IN3Transport.java
in3/Loader.java
- in3/Signer.java
- in3/config/Configuration.java
+ in3/NodeList.java
+ in3/NodeProps.java
+ in3/Proof.java
+ in3/SignedBlockHash.java
in3/config/ClientConfiguration.java
+ in3/config/ChainConfiguration.java
+ in3/config/Configuration.java
in3/config/NodeConfiguration.java
- in3/config/NodeListConfiguration.java
+ in3/eth1/ENSMethod.java
in3/eth1/API.java
in3/eth1/Block.java
- in3/eth1/Transaction.java
- in3/eth1/TransactionRequest.java
- in3/eth1/TransactionReceipt.java
in3/eth1/Log.java
in3/eth1/LogFilter.java
in3/eth1/SimpleWallet.java
+ in3/eth1/Transaction.java
+ in3/eth1/TransactionReceipt.java
+ in3/eth1/TransactionRequest.java
+ in3/utils/Account.java
+ in3/utils/Crypto.java
+ in3/utils/JSON.java
+ in3/utils/Signature.java
+ in3/utils/SignatureType.java
+ in3/utils/Signer.java
+ in3/utils/StorageProvider.java
+ in3/utils/TempStorageProvider.java
)
if(JAVA_MULTI_LIBS)
set(SOURCES
${SOURCES}
- in3/native/libin3_jni.dylib
- in3/native/libin3_jni.so
+ in3/native/libin3_jni.dylib
+ in3/native/libin3_jni.so
in3/native/libin3_jni_arm.so
in3/native/in3_jni.dll
)
endif()
- add_jar(in3j
+ add_jar(in3j
${SOURCES}
- OUTPUT_DIR ${CMAKE_BINARY_DIR}/lib
+ OUTPUT_DIR ${CMAKE_BINARY_DIR}/lib
OUTPUT_NAME in3
)
diff --git a/java/src/in3/BlockID.java b/java/src/in3/BlockID.java
new file mode 100644
index 000000000..0b31e2f83
--- /dev/null
+++ b/java/src/in3/BlockID.java
@@ -0,0 +1,85 @@
+package in3;
+
+import in3.utils.JSON;
+
+/*
+ * Class that represents a Block
+ */
+public class BlockID {
+ private Long number;
+ private String hash;
+
+ private BlockID() {}
+
+ /*
+ * creates an instance from a hashString
+ */
+ public static BlockID fromHash(String hash) {
+ BlockID blockId = new BlockID();
+ blockId.setHash(hash);
+
+ return blockId;
+ }
+
+ /*
+ * creates an instance from a block number.
+ */
+ public static BlockID fromNumber(long number) {
+ BlockID blockId = new BlockID();
+ blockId.setNumber(number);
+
+ return blockId;
+ }
+
+ /*
+ * returns the number of the BlockId
+ */
+ public Long getNumber() {
+ return number;
+ }
+
+ /*
+ * sets the number of the BlockId
+ */
+ public void setNumber(long block) {
+ this.number = block;
+ }
+
+ /*
+ * returns the hash of the BlockId
+ */
+ public String getHash() {
+ return hash;
+ }
+
+ /*
+ * sets the hash of the BlockId
+ */
+ public void setHash(String hash) {
+ this.hash = hash;
+ }
+
+ /*
+ * returns the json representation of the BlockID
+ */
+ public String toJSON() {
+ return JSON.toJson(this);
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder("{");
+
+ if (getNumber() != null) {
+ JSON.appendKey(sb, "blockNumber", getNumber());
+ }
+
+ if (getHash() != null) {
+ JSON.appendKey(sb, "hash", getHash());
+ }
+
+ sb.setCharAt(sb.length() - 1, '}');
+
+ return sb.toString();
+ }
+}
diff --git a/java/src/in3/Chain.java b/java/src/in3/Chain.java
index 42134adc1..b28ef285d 100644
--- a/java/src/in3/Chain.java
+++ b/java/src/in3/Chain.java
@@ -4,41 +4,41 @@
* Constants for Chain-specs
*/
public final class Chain {
- /**
+ /**
* support for multiple chains, a client can then switch between different chains (but consumes more memory)
*/
- public static final long MULTICHAIN = 0x0;
+ public static final long MULTICHAIN = 0x0;
- /**
+ /**
* use mainnet
*/
- public static final long MAINNET = 0x01;
- /**
+ public static final long MAINNET = 0x01;
+ /**
* use kovan testnet
*/
- public static final long KOVAN = 0x2a;
- /**
+ public static final long KOVAN = 0x2a;
+ /**
* use tobalaba testnet
*/
- public static final long TOBALABA = 0x44d;
- /**
+ public static final long TOBALABA = 0x44d;
+ /**
* use goerli testnet
*/
- public static final long GOERLI = 0x5;
- /**
+ public static final long GOERLI = 0x5;
+ /**
* use evan testnet
*/
- public static final long EVAN = 0x4b1;
- /**
+ public static final long EVAN = 0x4b1;
+ /**
* use ipfs
*/
- public static final long IPFS = 0x7d0;
- /**
+ public static final long IPFS = 0x7d0;
+ /**
* use volta test net
*/
- public static final long VOLTA = 0x12046;
- /**
+ public static final long VOLTA = 0x12046;
+ /**
* use local client
*/
- public static final long LOCAL = 0xFFFF;
+ public static final long LOCAL = 0xFFFF;
}
diff --git a/java/src/in3/IN3.java b/java/src/in3/IN3.java
index fa60164aa..3cf7e2bab 100644
--- a/java/src/in3/IN3.java
+++ b/java/src/in3/IN3.java
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -34,11 +34,13 @@
package in3;
-import in3.Proof;
-import in3.StorageProvider;
import in3.config.ClientConfiguration;
-import in3.config.Configuration;
import in3.eth1.API;
+import in3.utils.Crypto;
+import in3.utils.JSON;
+import in3.utils.Signature;
+import in3.utils.Signer;
+import in3.utils.StorageProvider;
/**
* This is the main class creating the incubed client. The client can then be
@@ -46,6 +48,12 @@
*
*/
public class IN3 {
+ private static final String CONFIG = "in3_config";
+ private static final String NODE_LIST = "in3_nodeList";
+ private static final String SIGN = "in3_sign";
+ private static final String CACHE_CLEAR = "in3_cacheClear";
+
+ private static final String ENS_SUFFIX = ".ETH";
static {
Loader.loadLibrary();
@@ -135,10 +143,17 @@ public Signer getSigner() {
/**
* gets the ethereum-api
*/
- public in3.eth1.API getEth1API() {
+ public API getEth1API() {
return new API(this);
}
+ /**
+ * gets the utils/crypto-api
+ */
+ public Crypto getCrypto() {
+ return new Crypto(this);
+ }
+
/**
* provides the ability to cache content like nodelists, contract codes and
* validatorlists
@@ -177,13 +192,26 @@ public IN3Transport getTransport() {
/**
* send a request. The request must a valid json-string with method and params
*/
- public native String send(String request);
+ public String send(String request) {
+ if (!config.isSynced()) {
+ this.applyConfig();
+ }
+ return sendinternal(request);
+ }
+
+ private native String sendinternal(String request);
/**
* send a request but returns a object like array or map with the parsed
* response. The request must a valid json-string with method and params
*/
- public native Object sendobject(String request);
+ public Object sendobject(String request) {
+ if (!config.isSynced()) {
+ this.applyConfig();
+ }
+ return sendobjectinternal(request);
+ }
+ private native Object sendobjectinternal(String request);
private String toRPC(String method, Object[] params) {
String p = "";
@@ -199,31 +227,54 @@ else if (params[i] instanceof String) {
else
p += "\"" + s + "\"";
} else
- p += params[i].toString();
+ p += JSON.toJson(params[i]);
}
return "{\"method\":\"" + method + "\", \"params\":[" + p + "]}";
}
+ private String toRPC(String method, Object[] params, Object[] address) {
+ String p = "";
+ for (int i = 0; i < params.length; i++) {
+ if (p.length() > 0)
+ p += ",";
+ if (params[i] == null)
+ p += "null";
+ else if (params[i] instanceof String) {
+ String s = (String) params[i];
+ if (s.charAt(0) == '{' || s.equals("true") || s.equals("false"))
+ p += s;
+ else
+ p += "\"" + s + "\"";
+ } else
+ p += JSON.toJson(params[i]);
+ }
+
+ return "{\"in3\":{\"data_nodes\":" + JSON.toJson(address) + "}, \"method\":\"" + method + "\", \"params\":[" + p + "]}";
+ }
+
/**
* send a RPC request by only passing the method and params. It will create the
* raw request from it and return the result.
*/
public String sendRPC(String method, Object[] params) {
- if (!config.isSynced()) {
- this.applyConfig();
- }
return this.send(toRPC(method, params));
}
+ private Object sendObjectRPC(String method, Object[] params, String[] address) {
+ return this.sendobject(toRPC(method, params, address));
+ }
+
+ public Object sendRPCasObject(String method, Object[] params, boolean useEnsResolver) {
+ Object[] resolvedParams = useEnsResolver ? handleEns(params) : params;
+ return this.sendobject(toRPC(method, resolvedParams));
+ }
+
/**
* send a RPC request by only passing the method and params. It will create the
* raw request from it and return the result.
*/
public Object sendRPCasObject(String method, Object[] params) {
- if (!config.isSynced()) {
- this.applyConfig();
- }
- return this.sendobject(toRPC(method, params));
+ return sendRPCasObject(method, params, true);
}
/** internal function to handle the internal requests */
@@ -231,14 +282,50 @@ static byte[][] sendRequest(String[] urls, byte[] payload) {
return IN3.transport.handle(urls, payload);
}
- private native void free();
+ protected native void free();
private native long init(long chainId);
private native void initcache();
+ /**
+ * returns the current incubed version.
+ */
public static native String getVersion();
+ /**
+ * clears the cache.
+ */
+ public boolean cacheClear() {
+ return (boolean) sendRPCasObject(CACHE_CLEAR, new Object[] {});
+ }
+
+ /**
+ * restrieves the node list
+ */
+ public IN3Node[] nodeList() {
+ NodeList nl = NodeList.asNodeList(sendRPCasObject(NODE_LIST, new Object[] {}));
+ return nl.getNodes();
+ }
+
+ /**
+ * request for a signature of an already verified hash.
+ */
+ public SignedBlockHash[] sign(BlockID[] blocks, String[] address) {
+ return SignedBlockHash.asSignedBlockHashs(sendObjectRPC(SIGN, blocks, address));
+ }
+
+ protected Object[] handleEns(Object[] params) {
+ Object[] result = params.clone();
+ for (int i = 0; i < result.length; i++) {
+ if (result[i] != null && result[i].toString().toUpperCase().endsWith(ENS_SUFFIX)) {
+ result[i] = (Object) getEth1API().ens(result[i].toString());
+ }
+ }
+
+ return result;
+ }
+
// Test it
public static void main(String[] args) {
Object[] params = new Object[args.length - 1];
@@ -247,9 +334,8 @@ public static void main(String[] args) {
// create client
IN3 in3 = IN3.forChain(Chain.MAINNET);
-
// set cache in tempfolder
- in3.setStorageProvider(new in3.TempStorageProvider());
+ in3.setStorageProvider(new in3.utils.TempStorageProvider());
// execute the command
System.out.println(in3.sendRPC(args[0], params));
diff --git a/java/src/in3/IN3DefaultTransport.java b/java/src/in3/IN3DefaultTransport.java
index 5cdf732f8..fe4d37110 100644
--- a/java/src/in3/IN3DefaultTransport.java
+++ b/java/src/in3/IN3DefaultTransport.java
@@ -3,6 +3,9 @@
import java.io.*;
import java.net.*;
+/*
+ * Default implementation for HTTP transport in the java using java.net.HttpURLConnection
+ */
class IN3DefaultTransport implements IN3Transport {
@Override
diff --git a/java/src/in3/IN3Node.java b/java/src/in3/IN3Node.java
new file mode 100644
index 000000000..cc2c129d9
--- /dev/null
+++ b/java/src/in3/IN3Node.java
@@ -0,0 +1,90 @@
+package in3;
+
+/*
+ * Class that represents an IN3 node.
+ */
+import in3.eth1.Log;
+import in3.utils.JSON;
+
+public class IN3Node {
+ private JSON data;
+
+ private IN3Node(JSON data) {
+ this.data = data;
+ }
+
+ protected static IN3Node[] asIN3Nodes(Object o) {
+ if (o == null)
+ return null;
+ if (o instanceof Object[]) {
+ Object[] a = (Object[]) o;
+ IN3Node[] s = new IN3Node[a.length];
+ for (int i = 0; i < s.length; i++)
+ s[i] = a[i] == null ? null : new IN3Node((JSON) a[i]);
+ return s;
+ }
+ return null;
+ }
+
+ protected static IN3Node asNode(Object o) {
+ if (o == null)
+ return null;
+ return new IN3Node((JSON) o);
+ }
+
+ /*
+ * returns the url of the node
+ */
+ public String getUrl() {
+ return JSON.asString(data.get("url"));
+ }
+
+ /*
+ * returns the address of the node
+ */
+ public String getAddress() {
+ return JSON.asString(data.get("address"));
+ }
+
+ /*
+ * returns the index of the node
+ */
+ public int getIndex() {
+ return JSON.asInt(data.get("index"));
+ }
+
+ /*
+ * returns the deposit for the the node
+ */
+ public String getDeposit() {
+ return JSON.asString(data.get("deposit"));
+ }
+
+ /*
+ * returns the props of the the node
+ */
+ public long getProps() {
+ return JSON.asLong(data.get("props"));
+ }
+
+ /*
+ * returns the timeout for the the node
+ */
+ public int getTimeout() {
+ return JSON.asInt(data.get("timeout"));
+ }
+
+ /*
+ * returns the register time of the the node
+ */
+ public int getRegisterTime() {
+ return JSON.asInt(data.get("registerTime"));
+ }
+
+ /*
+ * returns the weight of the node
+ */
+ public int getWeight() {
+ return JSON.asInt(data.get("weight"));
+ }
+}
diff --git a/java/src/in3/IN3Transport.java b/java/src/in3/IN3Transport.java
index d097b2395..2d4a1ecfc 100644
--- a/java/src/in3/IN3Transport.java
+++ b/java/src/in3/IN3Transport.java
@@ -1,5 +1,8 @@
package in3;
+/*
+ * Interface for the IN3 transport.
+ */
interface IN3Transport {
- byte[][] handle(String[] urls, byte[] payload);
+ byte[][] handle(String[] urls, byte[] payload);
}
\ No newline at end of file
diff --git a/java/src/in3/JSON.java b/java/src/in3/JSON.java
deleted file mode 100644
index 0c17360dd..000000000
--- a/java/src/in3/JSON.java
+++ /dev/null
@@ -1,244 +0,0 @@
-/*******************************************************************************
- * This file is part of the Incubed project.
- * Sources: https://github.com/slockit/in3-c
- *
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
- *
- *
- * COMMERCIAL LICENSE USAGE
- *
- * Licensees holding a valid commercial license may use this file in accordance
- * with the commercial license agreement provided with the Software or, alternatively,
- * in accordance with the terms contained in a written agreement between you and
- * slock.it GmbH/Blockchains LLC. For licensing terms and conditions or further
- * information please contact slock.it at in3@slock.it.
- *
- * Alternatively, this file may be used under the AGPL license as follows:
- *
- * AGPL LICENSE USAGE
- *
- * This program is free software: you can redistribute it and/or modify it under the
- * terms of the GNU Affero General Public License as published by the Free Software
- * Foundation, either version 3 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but WITHOUT ANY
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
- * [Permissions of this strong copyleft license are conditioned on making available
- * complete source code of licensed works and modifications, which include larger
- * works using a licensed work, under the same license. Copyright and license notices
- * must be preserved. Contributors provide an express grant of patent rights.]
- * You should have received a copy of the GNU Affero General Public License along
- * with this program. If not, see .
- *******************************************************************************/
-
-package in3;
-
-import java.util.*;
-
-import in3.eth1.Log;
-
-import java.math.*;
-
-/**
- * internal helper tool to represent a JSON-Object.
- *
- * Since the internal representation of JSON in incubed uses hashes instead of
- * name, the getter will creates these hashes.
- */
-public class JSON {
- static {
- Loader.loadLibrary();
- }
-
- private HashMap map = new HashMap();
-
- private static native int key(String name);
-
- JSON() {
- }
-
- /**
- * gets the property
- *
- * @return the raw object.
- */
- public Object get(String prop /** the name of the property. */
- ) {
- return map.get(key(prop));
- }
-
- /**
- * adds values. This function will be called from the JNI-Iterface.
- *
- * Internal use only!
- */
- public void put(int key/** the hash of the key */
- ,Object val /** the value object */
- ) {
- map.put(key, val);
- }
-
- /**
- * returns the property as long
- *
- * @return the long value
- */
- public long getLong(String key /** the propertyName */
- ) {
- return asLong(get(key));
- }
-
- /**
- * returns the property as BigInteger
- *
- * @return the BigInteger value
- */
- public BigInteger getBigInteger(String key/** the propertyName */
- ) {
- return asBigInteger(get(key));
- }
-
- /**
- * returns the property as StringArray
- *
- * @return the array or null
- */
- public String[] getStringArray(String key/** the propertyName */
- ) {
- return asStringArray(get(key));
- }
-
- /**
- * returns the property as String or in case of a number as hexstring.
- *
- * @return the hexstring
- */
- public String getString(String key/** the propertyName */
- ) {
- return asString(get(key));
- }
-
- /**
- * casts the object to a String[]
- */
- public static String[] asStringArray(Object o) {
- if (o == null)
- return null;
- if (o instanceof Object[]) {
- Object[] a = (Object[]) o;
- String[] s = new String[a.length];
- for (int i = 0; i < s.length; i++)
- s[i] = a[i] == null ? null : a[i].toString();
- return s;
- }
- return null;
- }
-
- public static BigInteger asBigInteger(Object o) {
- if (o == null)
- return BigInteger.valueOf(0);
- if (o instanceof String)
- return (((String) o).length() > 2 && o.toString().charAt(1) == 'x')
- ? new BigInteger(o.toString().substring(2), 16)
- : new BigInteger(o.toString(), 10);
- if (o instanceof Integer)
- return BigInteger.valueOf(((Integer) o).longValue());
- return BigInteger.valueOf(0);
-
- }
-
- public static long asLong(Object o) {
- if (o == null)
- return 0;
- if (o instanceof String)
- return (((String) o).length() > 2 && o.toString().charAt(1) == 'x')
- ? Long.parseLong(o.toString().substring(2), 16)
- : Long.parseLong(o.toString(), 10);
- if (o instanceof Integer)
- return ((Integer) o).longValue();
- return 0;
- }
-
- public static int asInt(Object o) {
- if (o == null)
- return 0;
- if (o instanceof String)
- return (((String) o).length() > 2 && o.toString().charAt(1) == 'x')
- ? Integer.parseInt(o.toString().substring(2), 16)
- : Integer.parseInt(o.toString(), 10);
- if (o instanceof Number)
- return ((Number) o).intValue();
- return 0;
- }
-
- public static String asString(Object o) {
- if (o == null)
- return null;
- if (o instanceof Integer)
- return "0x" + Integer.toHexString((Integer) o);
- if (o instanceof Long)
- return "0x" + Long.toHexString((Long) o);
- if (o instanceof BigInteger)
- return "0x" + ((BigInteger) o).toString(16);
- return o.toString();
- }
-
- public String toString() {
- return "";
- }
-
- public static String toJson(Object ob) {
- if (ob == null)
- return "null";
- if (ob instanceof String)
- return "\"" + ob + "\"";
- if (ob instanceof BigInteger)
- return "\"0x" + ((BigInteger) ob).toString(16) + "\"";
- if (ob instanceof Number)
- return ob.toString();
- if (ob instanceof Boolean)
- return ob.toString();
- if (ob instanceof Object[]) {
- Object[] a = (Object[]) ob;
- StringBuilder sb = new StringBuilder();
- sb.append("[");
- for (int i = 0; i < a.length; i++) {
- if (i > 0)
- sb.append(",");
- sb.append(toJson(a[i]));
- }
- return sb.append("]").toString();
- }
- return ob.toString();
- }
-
- public static void appendKey(StringBuilder sb, String key, Object value) {
- sb.append("\"").append(key).append("\":").append(toJson(value)).append(",");
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((map == null) ? 0 : map.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- JSON other = (JSON) obj;
- if (map == null) {
- if (other.map != null)
- return false;
- } else if (!map.equals(other.map))
- return false;
- return true;
- }
-}
diff --git a/java/src/in3/Loader.java b/java/src/in3/Loader.java
index 6526c4597..aa39dc578 100644
--- a/java/src/in3/Loader.java
+++ b/java/src/in3/Loader.java
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -46,97 +46,95 @@
public class Loader {
- private static boolean loaded = false;
- /*
+ private static boolean loaded = false;
+ /*
Based on the assumptions of: https://developer.android.com/ndk/guides/abis.html
The name has to be the same of the target library of CMakeLists.txt
*/
- private static final String TARGET_LINK_LIBRARY = "in3_jni";
-
- private static String getLibName() {
- final String os = System.getProperty("os.name").toLowerCase();
- final String arch = System.getProperty("os.arch").toLowerCase();
- final String model = System.getProperty("sun.arch.data.model");
- if (os.indexOf("linux") >= 0 && arch.indexOf("arm") >= 0) {
- return "in3_jni_arm";
- }
- if ("32".equals(model)) return "in3_jni_32";
-
- return TARGET_LINK_LIBRARY;
+ private static final String TARGET_LINK_LIBRARY = "in3_jni";
+
+ private static String getLibName() {
+ final String os = System.getProperty("os.name").toLowerCase();
+ final String arch = System.getProperty("os.arch").toLowerCase();
+ final String model = System.getProperty("sun.arch.data.model");
+ if (os.indexOf("linux") >= 0 && arch.indexOf("arm") >= 0) {
+ return "in3_jni_arm";
}
-
- private static byte[] md5(InputStream is) throws IOException {
- try {
- MessageDigest md = MessageDigest.getInstance("MD5");
- md.reset();
- byte[] bytes = new byte[2048];
- int numBytes;
- while ((numBytes = is.read(bytes)) != -1)
- md.update(bytes, 0, numBytes);
- return md.digest();
-
- } catch (Exception ex) {
- throw new IOException(ex);
- } finally {
- is.close();
- }
+ if ("32".equals(model)) return "in3_jni_32";
+
+ return TARGET_LINK_LIBRARY;
+ }
+
+ private static byte[] md5(InputStream is) throws IOException {
+ try {
+ MessageDigest md = MessageDigest.getInstance("MD5");
+ md.reset();
+ byte[] bytes = new byte[2048];
+ int numBytes;
+ while ((numBytes = is.read(bytes)) != -1)
+ md.update(bytes, 0, numBytes);
+ return md.digest();
+
+ } catch (Exception ex) {
+ throw new IOException(ex);
+ } finally {
+ is.close();
}
+ }
- public static void loadLibrary() {
- if (loaded)
- return;
- loaded = true;
+ public static void loadLibrary() {
+ if (loaded)
+ return;
+ loaded = true;
- try {
- // try to load it from the path
- System.loadLibrary(TARGET_LINK_LIBRARY);
- return;
- } catch (java.lang.UnsatisfiedLinkError ignored) {}
+ try {
+ // try to load it from the path
+ System.loadLibrary(TARGET_LINK_LIBRARY);
+ return;
+ } catch (java.lang.UnsatisfiedLinkError ignored) {}
+
+ // ok, not found, so we use the one in the package.
- // ok, not found, so we use the one in the package.
+ String libFileName = System.mapLibraryName(getLibName());
+ String jarPath = "/in3/native/" + libFileName;
- String libFileName = System.mapLibraryName(getLibName());
- String jarPath = "/in3/native/" + libFileName;
+ URL src = Loader.class.getResource(jarPath);
+ if (src == null)
+ throw new RuntimeException("Could not load the library for " + jarPath);
- URL src = Loader.class.getResource(jarPath);
- if (src == null)
- throw new RuntimeException("Could not load the library for " + jarPath);
+ try {
+ File lib = new File(new File(System.getProperty("java.io.tmpdir")), libFileName);
+ if (lib.exists() && !Arrays.equals(md5(src.openStream()), md5(new FileInputStream(lib))) && !lib.delete())
+ throw new IOException(
+ "Could not delete the library from temp-file! Maybe some other proccess is still using it ");
+ if (!lib.exists()) {
+ InputStream is = null;
+ OutputStream os = null;
try {
- File lib = new File(new File(System.getProperty("java.io.tmpdir")), libFileName);
- if (lib.exists() && !Arrays.equals(md5(src.openStream()), md5(new FileInputStream(lib))) && !lib.delete())
- throw new IOException(
- "Could not delete the library from temp-file! Maybe some other proccess is still using it ");
-
- if (!lib.exists()) {
- InputStream is = null;
- OutputStream os = null;
- try {
- is = src.openStream();
- os = new FileOutputStream(lib);
- byte[] buffer = new byte[4096];
- int read = 0;
- while ((read = is.read(buffer)) >= 0)
- os.write(buffer, 0, read);
- } finally {
- if (is != null)
- is.close();
- if (os != null)
- os.close();
- }
- if (!System.getProperty("os.name").contains("Windows")) {
- try {
- Runtime.getRuntime().exec(new String[] { "chmod", "755", lib.getAbsolutePath() }).waitFor();
- } catch (Throwable e) {
- }
- }
-
- }
- System.load(lib.getAbsolutePath());
-
- } catch (Exception ex) {
- throw new RuntimeException("Could not load the native library ", ex);
+ is = src.openStream();
+ os = new FileOutputStream(lib);
+ byte[] buffer = new byte[4096];
+ int read = 0;
+ while ((read = is.read(buffer)) >= 0)
+ os.write(buffer, 0, read);
+ } finally {
+ if (is != null)
+ is.close();
+ if (os != null)
+ os.close();
}
- }
+ if (!System.getProperty("os.name").contains("Windows")) {
+ try {
+ Runtime.getRuntime().exec(new String[] {"chmod", "755", lib.getAbsolutePath()}).waitFor();
+ } catch (Throwable e) {
+ }
+ }
+ }
+ System.load(lib.getAbsolutePath());
+ } catch (Exception ex) {
+ throw new RuntimeException("Could not load the native library ", ex);
+ }
+ }
}
diff --git a/java/src/in3/NodeList.java b/java/src/in3/NodeList.java
new file mode 100644
index 000000000..2da7fff13
--- /dev/null
+++ b/java/src/in3/NodeList.java
@@ -0,0 +1,43 @@
+package in3;
+
+import in3.utils.JSON;
+
+/*
+ * Class that represents an aggregation of IN3 nodes.
+ */
+class NodeList {
+ private JSON data;
+
+ private NodeList(JSON data) {
+ this.data = data;
+ }
+
+ protected static NodeList[] asNodeLists(Object o) {
+ if (o == null)
+ return null;
+ if (o instanceof Object[]) {
+ Object[] a = (Object[]) o;
+ NodeList[] s = new NodeList[a.length];
+ for (int i = 0; i < s.length; i++)
+ s[i] = a[i] == null ? null : new NodeList((JSON) a[i]);
+ return s;
+ }
+ return null;
+ }
+
+ protected static NodeList asNodeList(Object o) {
+ if (o == null)
+ return null;
+ return new NodeList((JSON) o);
+ }
+
+ /** returns an array of IN3Node */
+ public IN3Node[] getNodes() {
+ Object obj = data.get("nodes");
+ if (obj != null) {
+ return IN3Node.asIN3Nodes(obj);
+ } else {
+ return new IN3Node[] {};
+ }
+ }
+}
diff --git a/java/src/in3/NodeProps.java b/java/src/in3/NodeProps.java
index 9db3d621e..4dba44151 100644
--- a/java/src/in3/NodeProps.java
+++ b/java/src/in3/NodeProps.java
@@ -1,18 +1,21 @@
package in3;
+/*
+ * Constants for props of an IN3 node.
+ */
public final class NodeProps {
- /* filter out nodes which are providing no proof */
- public static final long NODE_PROP_PROOF = 0x1;
- /* filter out nodes other then which have capability of the same RPC endpoint may also accept requests for different chains */
- public static final long NODE_PROP_MULTICHAIN = 0x2;
- /* filter out non-archive supporting nodes */
- public static final long NODE_PROP_ARCHIVE = 0x4;
- /* filter out non-http nodes */
- public static final long NODE_PROP_HTTP = 0x8;
- /* filter out nodes that don't support binary encoding */
- public static final long NODE_PROP_BINARY = 0x10;
- /* filter out non-onion nodes */
- public static final long NODE_PROP_ONION = 0x20;
- /* filter out nodes that do not provide stats */
- public static final long NODE_PROP_STATS = 0x100;
+ /* filter out nodes which are providing no proof */
+ public static final long NODE_PROP_PROOF = 0x1;
+ /* filter out nodes other then which have capability of the same RPC endpoint may also accept requests for different chains */
+ public static final long NODE_PROP_MULTICHAIN = 0x2;
+ /* filter out non-archive supporting nodes */
+ public static final long NODE_PROP_ARCHIVE = 0x4;
+ /* filter out non-http nodes */
+ public static final long NODE_PROP_HTTP = 0x8;
+ /* filter out nodes that don't support binary encoding */
+ public static final long NODE_PROP_BINARY = 0x10;
+ /* filter out non-onion nodes */
+ public static final long NODE_PROP_ONION = 0x20;
+ /* filter out nodes that do not provide stats */
+ public static final long NODE_PROP_STATS = 0x100;
}
diff --git a/java/src/in3/Proof.java b/java/src/in3/Proof.java
index ab20d158d..00e218d22 100644
--- a/java/src/in3/Proof.java
+++ b/java/src/in3/Proof.java
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -39,10 +39,10 @@
*/
public enum Proof {
- /** No Verification */
- none,
- /** Standard Verification of the important properties */
- standard,
- /** Full Verification including even uncles wich leads to higher payload */
- full
+ /** No Verification */
+ none,
+ /** Standard Verification of the important properties */
+ standard,
+ /** Full Verification including even uncles wich leads to higher payload */
+ full
}
diff --git a/java/src/in3/SignedBlockHash.java b/java/src/in3/SignedBlockHash.java
new file mode 100644
index 000000000..06bf2dc9c
--- /dev/null
+++ b/java/src/in3/SignedBlockHash.java
@@ -0,0 +1,54 @@
+package in3;
+
+import in3.utils.JSON;
+
+public class SignedBlockHash {
+ private JSON data;
+
+ private SignedBlockHash(JSON data) {
+ this.data = data;
+ }
+
+ protected static SignedBlockHash[] asSignedBlockHashs(Object o) {
+ if (o == null)
+ return null;
+ if (o instanceof Object[]) {
+ Object[] a = (Object[]) o;
+ SignedBlockHash[] s = new SignedBlockHash[a.length];
+ for (int i = 0; i < s.length; i++)
+ s[i] = a[i] == null ? null : new SignedBlockHash((JSON) a[i]);
+ return s;
+ }
+ return null;
+ }
+
+ protected SignedBlockHash asSignedBlockHash(Object o) {
+ if (o == null)
+ return null;
+ return new SignedBlockHash((JSON) o);
+ }
+
+ public String getBlockHash() {
+ return data.getString("blockHash");
+ }
+
+ public long getBlock() {
+ return data.getLong("block");
+ }
+
+ public String getR() {
+ return data.getString("r");
+ }
+
+ public String getS() {
+ return data.getString("s");
+ }
+
+ public long getV() {
+ return data.getLong("v");
+ }
+
+ public String getMsgHash() {
+ return data.getString("msgHash");
+ }
+}
diff --git a/java/src/in3/config/ChainConfiguration.java b/java/src/in3/config/ChainConfiguration.java
new file mode 100644
index 000000000..fbd590147
--- /dev/null
+++ b/java/src/in3/config/ChainConfiguration.java
@@ -0,0 +1,117 @@
+package in3.config;
+
+import in3.utils.JSON;
+import java.util.ArrayList;
+
+/**
+ * Part of the configuration hierarchy for IN3 Client. Holds the configuration
+ * a node group in a particular Chain.
+ */
+public class ChainConfiguration implements Configuration {
+
+ private long chain;
+ private Boolean needsUpdate;
+ private String contract;
+ private String registryId;
+ private String whiteListContract;
+ private String[] whiteList = new String[] {};
+ public ArrayList nodesConfig = new ArrayList();
+
+ public ChainConfiguration(long chain, ClientConfiguration config) {
+ this.chain = chain;
+ config.addChainConfiguration(this);
+ }
+
+ public long getChain() {
+ return chain;
+ }
+
+ public Boolean isNeedsUpdate() {
+ return needsUpdate;
+ }
+
+ /* preemptively update the nodelist */
+ public void setNeedsUpdate(boolean needsUpdate) {
+ this.needsUpdate = needsUpdate;
+ }
+
+ public String getContract() {
+ return contract;
+ }
+
+ /* the address of the registry contract */
+ public void setContract(String contract) {
+ this.contract = contract;
+ }
+
+ public String getRegistryId() {
+ return registryId;
+ }
+
+ /* the identifier of the registry */
+ public void setRegistryId(String registryId) {
+ this.registryId = registryId;
+ }
+
+ public String getWhiteListContract() {
+ return whiteListContract;
+ }
+
+ /* address of whiteList contract. If specified, whiteList is always auto-updated and manual whiteList is overridden */
+ public void setWhiteListContract(String whiteListContract) {
+ this.whiteListContract = whiteListContract;
+ }
+
+ public String[] getWhiteList() {
+ return whiteList;
+ }
+
+ /* array of node addresses that constitute the whiteList */
+ public void setWhiteList(String[] whiteList) {
+ this.whiteList = whiteList;
+ }
+
+ protected void addNodeConfig(NodeConfiguration config) {
+ nodesConfig.add(config);
+ }
+
+ private ArrayList getNodesConfig() {
+ return nodesConfig;
+ }
+
+ public String toJSON() {
+ return JSON.toJson(this);
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder("{");
+
+ if (isNeedsUpdate() != null) {
+ JSON.appendKey(sb, "needsUpdate", isNeedsUpdate());
+ }
+ if (getContract() != null) {
+ JSON.appendKey(sb, "contract", getContract());
+ }
+
+ if (getContract() != null) {
+ JSON.appendKey(sb, "registryId", getRegistryId());
+ }
+
+ if (getNodesConfig().size() > 0) {
+ JSON.appendKey(sb, "nodeList", getNodesConfig());
+ }
+
+ if (getWhiteList().length > 0) {
+ JSON.appendKey(sb, "whiteList", getWhiteList());
+ }
+
+ if (getWhiteListContract() != null) {
+ JSON.appendKey(sb, "whiteListContract", getWhiteListContract());
+ }
+
+ sb.setCharAt(sb.length() - 1, '}');
+
+ return sb.toString();
+ }
+}
diff --git a/java/src/in3/config/ClientConfiguration.java b/java/src/in3/config/ClientConfiguration.java
index ff9db229e..91e3daab2 100644
--- a/java/src/in3/config/ClientConfiguration.java
+++ b/java/src/in3/config/ClientConfiguration.java
@@ -1,313 +1,325 @@
package in3.config;
+import in3.Proof;
+import in3.utils.JSON;
import java.util.ArrayList;
import java.util.HashMap;
-import in3.JSON;
-import in3.Proof;
-
/**
* Configuration Object for Incubed Client. It holds the state for the root
* of the configuration tree. Should be retrieved from the client instance as IN3#getConfig()
*/
public class ClientConfiguration implements Configuration {
- // Based on core/client/client_init.c
- private Integer requestCount;
- private Boolean autoUpdateList;
- private Proof proof = Proof.standard;
- private Integer maxAttempts;
- private Integer signatureCount;
- private Integer finality;
- private Boolean includeCode;
- private Boolean keepIn3;
- private Boolean useBinary;
- private Boolean useHttp;
- private Long maxCodeCache;
- private Long timeout;
- private Long minDeposit;
- private Long nodeProps;
- private Long nodeLimit;
- private Integer replaceLatestBlock;
- private String rpc;
- private Long maxBlockCache;
-
- private String serialzedState;
-
- private HashMap nodesConfig = new HashMap();
-
- // Make the constructor private in order to ensure people use client.getConfig()
- private ClientConfiguration() {}
-
- public Integer getRequestCount() {
- return requestCount;
- }
-
- /** sets the number of requests send when getting a first answer */
- public void setRequestCount(int requestCount) {
- this.requestCount = requestCount;
- }
-
- public Boolean isAutoUpdateList() {
- return autoUpdateList;
- }
-
- /**
+ // Based on core/client/client_init.c
+ private Integer requestCount;
+ private Boolean autoUpdateList;
+ private Proof proof = Proof.standard;
+ private Integer maxAttempts;
+ private Integer signatureCount;
+ private Integer finality;
+ private Boolean includeCode;
+ private Boolean keepIn3;
+ private Boolean useBinary;
+ private Boolean useHttp;
+ private Long maxCodeCache;
+ private Long timeout;
+ private Long minDeposit;
+ private Long nodeProps;
+ private Long nodeLimit;
+ private Integer replaceLatestBlock;
+ private String rpc;
+ private Long maxBlockCache;
+ private Boolean stats;
+
+ private String serialzedState;
+
+ private HashMap chainsConfig = new HashMap();
+
+ // Make the constructor private in order to ensure people use client.getConfig()
+ private ClientConfiguration() {}
+
+ public Integer getRequestCount() {
+ return requestCount;
+ }
+
+ /** sets the number of requests send when getting a first answer */
+ public void setRequestCount(int requestCount) {
+ this.requestCount = requestCount;
+ }
+
+ public Boolean isAutoUpdateList() {
+ return autoUpdateList;
+ }
+
+ /**
* activates the auto update.if true the nodelist will be automaticly updated if
* the lastBlock is newer
*/
- public void setAutoUpdateList(boolean autoUpdateList) {
- this.autoUpdateList = autoUpdateList;
- }
-
- public Proof getProof() {
- return proof;
- }
-
- /** sets the type of proof used */
- public void setProof(Proof proof) {
- this.proof = proof;
- }
-
- public Integer getMaxAttempts() {
- return maxAttempts;
- }
-
- /** sets the max number of attempts before giving up */
- public void setMaxAttempts(int maxAttempts) {
- this.maxAttempts = maxAttempts;
- }
-
- public Integer getSignatureCount() {
- return signatureCount;
- }
-
- /** sets the number of signatures used to proof the blockhash. */
- public void setSignatureCount(int signatureCount) {
- this.signatureCount = signatureCount;
- }
-
- public Integer getFinality() {
- return finality;
- }
-
- /** sets the number of signatures in percent required for the request */
- public void setFinality(int finality) {
- this.finality = finality;
- }
-
- public Boolean isIncludeCode() {
- return includeCode;
- }
-
- /* TODO ask what is this to Simon */
- public void setIncludeCode(boolean includeCode) {
- this.includeCode = includeCode;
- }
-
- public Boolean isKeepIn3() {
- return keepIn3;
- }
+ public void setAutoUpdateList(boolean autoUpdateList) {
+ this.autoUpdateList = autoUpdateList;
+ }
+
+ public Proof getProof() {
+ return proof;
+ }
+
+ /** sets the type of proof used */
+ public void setProof(Proof proof) {
+ this.proof = proof;
+ }
+
+ public Integer getMaxAttempts() {
+ return maxAttempts;
+ }
+
+ /** sets the max number of attempts before giving up */
+ public void setMaxAttempts(int maxAttempts) {
+ this.maxAttempts = maxAttempts;
+ }
+
+ public Integer getSignatureCount() {
+ return signatureCount;
+ }
+
+ /** sets the number of signatures used to proof the blockhash. */
+ public void setSignatureCount(int signatureCount) {
+ this.signatureCount = signatureCount;
+ }
+
+ public Boolean isStats() {
+ return stats;
+ }
+
+ /** if true (default) the request will be counted as part of the regular stats, if not they are not shown as part of the dashboard. */
+ public void setStats(boolean stats) {
+ this.stats = stats;
+ }
+
+ public Integer getFinality() {
+ return finality;
+ }
+
+ /** sets the number of signatures in percent required for the request */
+ public void setFinality(int finality) {
+ this.finality = finality;
+ }
+
+ public Boolean isIncludeCode() {
+ return includeCode;
+ }
+
+ /* TODO ask what is this to Simon */
+ public void setIncludeCode(boolean includeCode) {
+ this.includeCode = includeCode;
+ }
+
+ public Boolean isKeepIn3() {
+ return keepIn3;
+ }
+
+ /* preserve in3 section of the rpc call response intact */
+ public void setKeepIn3(boolean keepIn3) {
+ this.keepIn3 = keepIn3;
+ }
+
+ public Boolean isUseBinary() {
+ return useBinary;
+ }
+
+ /* use binary payload instead of json */
+ public void setUseBinary(boolean useBinary) {
+ this.useBinary = useBinary;
+ }
+
+ public Boolean isUseHttp() {
+ return useHttp;
+ }
+
+ /* allow transport to use non-ssl */
+ public void setUseHttp(boolean useHttp) {
+ this.useHttp = useHttp;
+ }
+
+ public Long getMaxCodeCache() {
+ return maxCodeCache;
+ }
+
+ /** sets number of max bytes used to cache the code in memory */
+ public void setMaxCodeCache(long maxCodeCache) {
+ this.maxCodeCache = maxCodeCache;
+ }
+
+ public Long getTimeout() {
+ return timeout;
+ }
+
+ /**
+ * specifies the number of milliseconds before the request times out. increasing
+ * may be helpful if the device uses a slow connection.
+ */
+ public void setTimeout(long timeout) {
+ this.timeout = timeout;
+ }
- /* preserve in3 section of the rpc call response intact */
- public void setKeepIn3(boolean keepIn3) {
- this.keepIn3 = keepIn3;
- }
+ public Long getMinDeposit() {
+ return minDeposit;
+ }
- public Boolean isUseBinary() {
- return useBinary;
- }
+ /**
+ * sets min stake of the server. Only nodes owning at least this amount will be
+ * chosen.
+ */
+ public void setMinDeposit(long minDeposit) {
+ this.minDeposit = minDeposit;
+ }
+
+ public Long getNodeProps() {
+ return nodeProps;
+ }
+
+ /* used to filter nodes according to its capabilities */
+ public void setNodeProps(long nodeProps) {
+ this.nodeProps = nodeProps;
+ }
+
+ public Long getNodeLimit() {
+ return nodeLimit;
+ }
+
+ /** sets the limit of nodes to store in the client. */
+ public void setNodeLimit(long nodeLimit) {
+ this.nodeLimit = nodeLimit;
+ }
+
+ public Integer getReplaceLatestBlock() {
+ return replaceLatestBlock;
+ }
+
+ /** replaces the *latest* with blockNumber- specified value */
+ public void setReplaceLatestBlock(int replaceLatestBlock) {
+ this.replaceLatestBlock = replaceLatestBlock;
+ }
+
+ public String getRpc() {
+ return rpc;
+ }
+
+ /** setup an custom rpc source for requests by setting Chain to local and proof to none */
+ public void setRpc(String rpc) {
+ this.rpc = rpc;
+ }
+
+ public Long getMaxBlockCache() {
+ return maxBlockCache;
+ }
+
+ /** sets the number of blocks cached in memory */
+ public void setMaxBlockCache(long maxBlockCache) {
+ this.maxBlockCache = maxBlockCache;
+ }
+
+ public HashMap getNodesConfig() {
+ return chainsConfig;
+ }
+
+ public void setChainsConfig(HashMap chainsConfig) {
+ this.chainsConfig = chainsConfig;
+ }
+
+ protected void addChainConfiguration(ChainConfiguration configuration) {
+ /*
+ * This is stored in a HashMap to ensure uniqueness between chains without changing NodeConfiguration equals or toHash methods
+ */
+ chainsConfig.put(configuration.getChain(), configuration);
+ }
- /* use binary payload instead of json */
- public void setUseBinary(boolean useBinary) {
- this.useBinary = useBinary;
- }
+ public void markAsSynced() {
+ serialzedState = toJSON();
+ }
- public Boolean isUseHttp() {
- return useHttp;
- }
+ public boolean isSynced() {
+ return toJSON().equals(serialzedState);
+ }
- /* allow transport to use non-ssl */
- public void setUseHttp(boolean useHttp) {
- this.useHttp = useHttp;
- }
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder("{");
- public Long getMaxCodeCache() {
- return maxCodeCache;
+ if (getRequestCount() != null) {
+ JSON.appendKey(sb, "requestCount", getRequestCount());
}
-
- /** sets number of max bytes used to cache the code in memory */
- public void setMaxCodeCache(long maxCodeCache) {
- this.maxCodeCache = maxCodeCache;
+ if (isAutoUpdateList() != null) {
+ JSON.appendKey(sb, "autoUpdateList", isAutoUpdateList());
}
-
- public Long getTimeout() {
- return timeout;
+ if (getProof() != null) {
+ JSON.appendKey(sb, "proof", JSON.asString(getProof()));
}
-
- /**
- * specifies the number of milliseconds before the request times out. increasing
- * may be helpful if the device uses a slow connection.
- */
- public void setTimeout(long timeout) {
- this.timeout = timeout;
+ if (getMaxAttempts() != null) {
+ JSON.appendKey(sb, "maxAttempts", getMaxAttempts());
}
-
- public Long getMinDeposit() {
- return minDeposit;
+ if (getSignatureCount() != null) {
+ JSON.appendKey(sb, "signatureCount", getSignatureCount());
}
-
- /**
- * sets min stake of the server. Only nodes owning at least this amount will be
- * chosen.
- */
- public void setMinDeposit(long minDeposit) {
- this.minDeposit = minDeposit;
+ if (getFinality() != null) {
+ JSON.appendKey(sb, "finality", getFinality());
}
-
- public Long getNodeProps() {
- return nodeProps;
+ if (isIncludeCode() != null) {
+ JSON.appendKey(sb, "includeCode", isIncludeCode());
}
-
- /* used to filter nodes according to its capabilities */
- public void setNodeProps(long nodeProps) {
- this.nodeProps = nodeProps;
+ if (isKeepIn3() != null) {
+ JSON.appendKey(sb, "keepIn3", isKeepIn3());
}
-
- public Long getNodeLimit() {
- return nodeLimit;
+ if (isStats() != null) {
+ JSON.appendKey(sb, "stats", isStats());
}
-
- /** sets the limit of nodes to store in the client. */
- public void setNodeLimit(long nodeLimit) {
- this.nodeLimit = nodeLimit;
+ if (isUseBinary() != null) {
+ JSON.appendKey(sb, "useBinary", isUseBinary());
}
-
- public Integer getReplaceLatestBlock() {
- return replaceLatestBlock;
+ if (isUseHttp() != null) {
+ JSON.appendKey(sb, "useHttp", isUseHttp());
}
-
- /** replaces the *latest* with blockNumber- specified value */
- public void setReplaceLatestBlock(int replaceLatestBlock) {
- this.replaceLatestBlock = replaceLatestBlock;
+ if (getMaxCodeCache() != null) {
+ JSON.appendKey(sb, "maxCodeCache", getMaxCodeCache());
}
-
- public String getRpc() {
- return rpc;
+ if (getTimeout() != null) {
+ JSON.appendKey(sb, "timeout", getTimeout());
}
-
- /** setup an custom rpc source for requests by setting Chain to local and proof to none */
- public void setRpc(String rpc) {
- this.rpc = rpc;
+ if (getMinDeposit() != null) {
+ JSON.appendKey(sb, "minDeposit", getMinDeposit());
}
-
- public Long getMaxBlockCache() {
- return maxBlockCache;
+ if (getNodeProps() != null) {
+ JSON.appendKey(sb, "nodeProps", getNodeProps());
}
-
- /** sets the number of blocks cached in memory */
- public void setMaxBlockCache(long maxBlockCache) {
- this.maxBlockCache = maxBlockCache;
+ if (getNodeLimit() != null) {
+ JSON.appendKey(sb, "nodeLimit", getNodeLimit());
}
-
- public HashMap getNodesConfig() {
- return nodesConfig;
+ if (getReplaceLatestBlock() != null) {
+ JSON.appendKey(sb, "replaceLatestBlock", getReplaceLatestBlock());
}
-
- public void setNodesConfig(HashMap nodesConfig) {
- this.nodesConfig = nodesConfig;
+ if (getRpc() != null) {
+ JSON.appendKey(sb, "rpc", getRpc());
}
-
- protected void addNodeConfiguration(NodeConfiguration configuration) {
- /*
- * This is stored in a HashMap to ensure uniqueness between chains without changing NodeConfiguration equals or toHash methods
- */
- nodesConfig.put(configuration.getChain(), configuration);
+ if (getMaxBlockCache() != null) {
+ JSON.appendKey(sb, "maxBlockCache", getMaxBlockCache());
}
- public void markAsSynced() {
- serialzedState = toJSON();
- }
+ if (!chainsConfig.isEmpty()) {
+ StringBuilder sb2 = new StringBuilder("{");
+ for (ChainConfiguration chainConfig : chainsConfig.values()) {
+ JSON.appendKey(sb2, JSON.asString(chainConfig.getChain()), chainConfig);
+ }
- public boolean isSynced() {
- return toJSON().equals(serialzedState);
+ sb2.setCharAt(sb2.length() - 1, '}');
+ JSON.appendKey(sb, "nodes", sb2);
}
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder("{");
-
- if (getRequestCount() != null) {
- JSON.appendKey(sb, "requestCount", getRequestCount());
- }
- if (isAutoUpdateList() != null) {
- JSON.appendKey(sb, "autoUpdateList", isAutoUpdateList());
- }
- if (getProof() != null) {
- JSON.appendKey(sb, "proof", JSON.asString(getProof()));
- }
- if (getMaxAttempts() != null) {
- JSON.appendKey(sb, "maxAttempts", getMaxAttempts());
- }
- if (getSignatureCount() != null) {
- JSON.appendKey(sb, "signatureCount", getSignatureCount());
- }
- if (getFinality() != null) {
- JSON.appendKey(sb, "finality", getFinality());
- }
- if (isIncludeCode() != null) {
- JSON.appendKey(sb, "includeCode", isIncludeCode());
- }
- if (isKeepIn3() != null) {
- JSON.appendKey(sb, "keepIn3", isKeepIn3());
- }
- if (isUseBinary() != null) {
- JSON.appendKey(sb, "useBinary", isUseBinary());
- }
- if (isUseHttp() != null) {
- JSON.appendKey(sb, "useHttp", isUseHttp());
- }
- if (getMaxCodeCache() != null) {
- JSON.appendKey(sb, "maxCodeCache", getMaxCodeCache());
- }
- if (getTimeout() != null) {
- JSON.appendKey(sb, "timeout", getTimeout());
- }
- if (getMinDeposit() != null) {
- JSON.appendKey(sb, "minDeposit", getMinDeposit());
- }
- if (getNodeProps() != null) {
- JSON.appendKey(sb, "nodeProps", getNodeProps());
- }
- if (getNodeLimit() != null) {
- JSON.appendKey(sb, "nodeLimit", getNodeLimit());
- }
- if (getReplaceLatestBlock() != null) {
- JSON.appendKey(sb, "replaceLatestBlock", getReplaceLatestBlock());
- }
- if (getRpc() != null) {
- JSON.appendKey(sb, "rpc", getRpc());
- }
- if (getMaxBlockCache() != null) {
- JSON.appendKey(sb, "maxBlockCache", getMaxBlockCache());
- }
-
- if (!nodesConfig.isEmpty()) {
- StringBuilder sb2 = new StringBuilder("{");
- for (NodeConfiguration nodeConfig: nodesConfig.values()) {
- JSON.appendKey(sb2, JSON.asString(nodeConfig.getChain()), nodeConfig);
- }
-
- sb2.setCharAt(sb2.length() - 1, '}');
- JSON.appendKey(sb, "nodes", sb2);
- }
-
- sb.setCharAt(sb.length() - 1, '}');
- return sb.toString();
- }
+ sb.setCharAt(sb.length() - 1, '}');
+ return sb.toString();
+ }
- @Override
- public String toJSON() {
- return JSON.toJson(this);
- }
+ @Override
+ public String toJSON() {
+ return JSON.toJson(this);
+ }
}
diff --git a/java/src/in3/config/Configuration.java b/java/src/in3/config/Configuration.java
index 13935ed8a..4bac1c7ed 100644
--- a/java/src/in3/config/Configuration.java
+++ b/java/src/in3/config/Configuration.java
@@ -1,11 +1,11 @@
package in3.config;
/**
- * a INterface class, which is able to generate a JSON-String.
+ * an Interface class, which is able to generate a JSON-String.
*/
public interface Configuration {
- /**
+ /**
* generates a json-string based on the internal data.
*/
- public String toJSON();
+ public String toJSON();
}
diff --git a/java/src/in3/config/NodeConfiguration.java b/java/src/in3/config/NodeConfiguration.java
index dc7c3d56a..6816be555 100644
--- a/java/src/in3/config/NodeConfiguration.java
+++ b/java/src/in3/config/NodeConfiguration.java
@@ -1,116 +1,63 @@
package in3.config;
-import java.util.ArrayList;
-
-import in3.JSON;
+import in3.utils.JSON;
/**
- * Part of the configuration hierarchy for IN3 Client. Holds the configuration
- * a node group in a particular Chain.
+ * Configuration Object for Incubed Client. It represents the node of a nodelist.
*/
-public class NodeConfiguration implements Configuration {
+public class NodeConfiguration {
+ private String url;
+ private Long props;
+ private String address;
- private long chain;
- private Boolean needsUpdate;
- private String contract;
- private String registryId;
- private String whiteListContract;
- private String[] whiteList = new String[] {};
- public ArrayList nodeList = new ArrayList();
+ public NodeConfiguration(ChainConfiguration config) {
+ config.addNodeConfig(this);
+ }
- public NodeConfiguration(long chain, ClientConfiguration config) {
- this.chain = chain;
- config.addNodeConfiguration(this);
- }
+ public String getUrl() {
+ return url;
+ }
- public long getChain() {
- return chain;
- }
+ // TODO Use an actual URL object to enforce semantic validation on java side
+ /* the url of the node */
+ public void setUrl(String url) {
+ this.url = url;
+ }
- public Boolean isNeedsUpdate() {
- return needsUpdate;
- }
+ public long getProps() {
+ return props;
+ }
- /* preemptively update the nodelist */
- public void setNeedsUpdate(boolean needsUpdate) {
- this.needsUpdate = needsUpdate;
- }
+ /* used to identify the capabilities of the node */
+ public void setProps(long props) {
+ this.props = props;
+ }
- public String getContract() {
- return contract;
- }
+ public String getAddress() {
+ return address;
+ }
- /* the address of the registry contract */
- public void setContract(String contract) {
- this.contract = contract;
- }
-
- public String getRegistryId() {
- return registryId;
- }
-
- /* the identifier of the registry */
- public void setRegistryId(String registryId) {
- this.registryId = registryId;
- }
-
- public String getWhiteListContract() {
- return whiteListContract;
- }
+ /* address of the server */
+ public void setAddress(String address) {
+ this.address = address;
+ }
- /* address of whiteList contract. If specified, whiteList is always auto-updated and manual whiteList is overridden */
- public void setWhiteListContract(String whiteListContract) {
- this.whiteListContract = whiteListContract;
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder("{");
+ if (url != null) {
+ JSON.appendKey(sb, "url", getUrl());
}
- public String[] getWhiteList() {
- return whiteList;
+ if (props != null) {
+ JSON.appendKey(sb, "props", getProps());
}
- /* array of node addresses that constitute the whiteList */
- public void setWhiteList(String[] whiteList) {
- this.whiteList = whiteList;
+ if (address != null) {
+ JSON.appendKey(sb, "address", getAddress());
}
- protected void addNodeListConfiguration(NodeListConfiguration configuration) {
- nodeList.add(configuration);
- }
-
- private ArrayList getNodeList() {
- return nodeList;
- }
-
- public String toJSON() {
- return JSON.toJson(this);
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder("{");
- if (isNeedsUpdate() != null) {
- JSON.appendKey(sb, "needsUpdate", isNeedsUpdate());
- }
- if (getContract() != null) {
- JSON.appendKey(sb, "contract", getContract());
- }
-
- if (getContract() != null) {
- JSON.appendKey(sb, "registryId", getRegistryId());
- }
-
- if (getNodeList().size() > 0) {
- JSON.appendKey(sb, "nodeList", getNodeList());
- }
-
- if (getWhiteList().length > 0) {
- JSON.appendKey(sb, "whiteList", getWhiteList());
- }
-
- if (getWhiteListContract() != null) {
- JSON.appendKey(sb, "whiteListContract", getWhiteListContract());
- }
- sb.setCharAt(sb.length() - 1, '}');
-
- return sb.toString();
- }
+ sb.setCharAt(sb.length() - 1, '}');
+ return sb.toString();
+ }
}
diff --git a/java/src/in3/config/NodeListConfiguration.java b/java/src/in3/config/NodeListConfiguration.java
deleted file mode 100644
index 7ce955eca..000000000
--- a/java/src/in3/config/NodeListConfiguration.java
+++ /dev/null
@@ -1,63 +0,0 @@
-package in3.config;
-
-import in3.JSON;
-
-/**
- * Configuration Object for Incubed Client. It represents the nodes of a nodelist.
- */
-public class NodeListConfiguration {
- private String url;
- private Long props;
- private String address;
-
- public NodeListConfiguration(NodeConfiguration config) {
- config.addNodeListConfiguration(this);
- }
-
- public String getUrl() {
- return url;
- }
-
- // TODO Use an actual URL object to enforce semantic validation on java side
- /* the url of the node */
- public void setUrl(String url) {
- this.url = url;
- }
-
- public long getProps() {
- return props;
- }
-
- /* used to identify the capabilities of the node */
- public void setProps(long props) {
- this.props = props;
- }
-
- public String getAddress() {
- return address;
- }
-
- /* address of the server */
- public void setAddress(String address) {
- this.address = address;
- }
-
- @Override
- public String toString() {
- StringBuilder sb = new StringBuilder("{");
- if (url != null) {
- JSON.appendKey(sb, "url", getUrl());
- }
-
- if (props != null) {
- JSON.appendKey(sb, "props", getProps());
- }
-
- if (address != null) {
- JSON.appendKey(sb, "address", getAddress());
- }
-
- sb.setCharAt(sb.length() - 1, '}');
- return sb.toString();
- }
-}
diff --git a/java/src/in3/eth1/API.java b/java/src/in3/eth1/API.java
index f3a4c318e..838e9a35d 100644
--- a/java/src/in3/eth1/API.java
+++ b/java/src/in3/eth1/API.java
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -36,7 +36,8 @@
import in3.*;
import in3.eth1.*;
-
+import in3.utils.JSON;
+import in3.utils.Signer;
import java.math.BigInteger;
/**
@@ -45,239 +46,273 @@
*/
public class API {
- private IN3 in3;
-
- /**
+ // Methods
+ private static final String GET_BLOCK_BY_NUMBER = "eth_getBlockByNumber";
+ private static final String BLOCK_BY_HASH = "eth_getBlockByHash";
+ private static final String BLOCK_NUMBER = "eth_blockNumber";
+ private static final String GAS_PRICE = "eth_gasPrice";
+ private static final String CHAIN_ID = "eth_chainId";
+ private static final String CALL = "eth_call";
+ private static final String ESTIMATE_GAS = "eth_estimateGas";
+ private static final String GET_BALANCE = "eth_getBalance";
+ private static final String GET_CODE = "eth_getCode";
+ private static final String GET_STORAGE_AT = "eth_getStorageAt";
+ private static final String GET_BLOCK_TRANSACTION_COUNT_BY_HASH = "eth_getBlockTransactionCountByHash";
+ private static final String GET_BLOCK_TRANSACTION_COUNT_BY_NUMBER = "eth_getBlockTransactionCountByNumber";
+ private static final String GET_FILTER_CHANGES = "eth_getFilterChanges";
+ private static final String GET_FILTER_LOGS = "eth_getFilterLogs";
+ private static final String GET_LOGS = "eth_getLogs";
+ private static final String GET_TRANSACTION_BY_BLOCK_HASH_AND_INDEX = "eth_getTransactionByBlockHashAndIndex";
+ private static final String GET_TRANSACTION_BY_BLOCK_NUMBER_AND_INDEX = "eth_getTransactionByBlockNumberAndIndex";
+ private static final String GET_TRANSACTION_BY_HASH = "eth_getTransactionByHash";
+ private static final String GET_TRANSACTION_COUNT = "eth_getTransactionCount";
+ private static final String GET_TRANSACTION_RECEIPT = "eth_getTransactionReceipt";
+ private static final String GET_UNCLE_BY_BLOCK_NUMBER_AND_INDEX = "eth_getUncleByBlockNumberAndIndex";
+ private static final String GET_UNCLE_COUNT_BY_BLOCK_HASH = "eth_getUncleCountByBlockHash";
+ private static final String GET_UNCLE_COUNT_BY_BLOCK_NUMBER = "eth_getUncleCountByBlockNumber";
+ private static final String NEW_BLOCK_FILTER = "eth_newBlockFilter";
+ private static final String NEW_FILTER = "eth_newFilter";
+ private static final String UNINSTALL_FILTER = "eth_uninstallFilter";
+ private static final String SEND_RAW_TRANSACTION = "eth_sendRawTransaction";
+ private static final String SEND_TRANSACTION = "eth_sendTransaction";
+ private static final String ABI_ENCODE = "in3_abiEncode";
+ private static final String ABI_DECODE = "in3_abiDecode";
+ private static final String CHECKSUM_ADDRESS = "in3_checksumAddress";
+ private static final String ENS = "in3_ens";
+
+ private IN3 in3;
+
+ /**
* creates a API using the given incubed instance.
*/
- public API(IN3 in3) {
- this.in3 = in3;
- }
+ public API(IN3 in3) {
+ this.in3 = in3;
+ }
- /**
+ /**
* finds the Block as specified by the number. use `Block.LATEST` for getting
* the lastest block.
*/
- public Block getBlockByNumber(long block, /** < the Blocknumber */
- boolean includeTransactions /**
+ public Block getBlockByNumber(long block, /** < the Blocknumber */
+ boolean includeTransactions /**
* < if true all Transactions will be includes, if not only the
* transactionhashes
*/
- ) {
- return Block.asBlock(in3.sendRPCasObject("eth_getBlockByNumber",
- new Object[] { getBlockString(block), includeTransactions }));
- }
+ ) {
+ return Block.asBlock(in3.sendRPCasObject(GET_BLOCK_BY_NUMBER,
+ new Object[] {getBlockString(block), includeTransactions}));
+ }
- /**
+ /**
* Returns information about a block by hash.
*/
- public Block getBlockByHash(String blockHash, /** < the Blocknumber */
- boolean includeTransactions /**
+ public Block getBlockByHash(String blockHash, /** < the Blocknumber */
+ boolean includeTransactions /**
* < if true all Transactions will be includes, if not only the
* transactionhashes
*/
- ) {
- return Block
- .asBlock(in3.sendRPCasObject("eth_getBlockByHash", new Object[] { blockHash, includeTransactions }));
- }
+ ) {
+ return Block
+ .asBlock(in3.sendRPCasObject(BLOCK_BY_HASH, new Object[] {blockHash, includeTransactions}));
+ }
- /**
+ /**
* the current BlockNumber.
*/
- public long getBlockNumber() {
- return JSON.asLong(in3.sendRPCasObject("eth_blockNumber", new Object[] {}));
- }
+ public long getBlockNumber() {
+ return JSON.asLong(in3.sendRPCasObject(BLOCK_NUMBER, new Object[] {}));
+ }
- /**
+ /**
* the current Gas Price.
*/
- public long getGasPrice() {
- return JSON.asLong(in3.sendRPCasObject("eth_gasPrice", new Object[] {}));
- }
+ public long getGasPrice() {
+ return JSON.asLong(in3.sendRPCasObject(GAS_PRICE, new Object[] {}));
+ }
- /**
+ /**
* Returns the EIP155 chain ID used for transaction signing at the current best
* block. Null is returned if not available.
*/
- public String getChainId() {
- return JSON.asString(in3.sendRPCasObject("eth_chainId", new Object[] {}));
- }
+ public String getChainId() {
+ return JSON.asString(in3.sendRPCasObject(CHAIN_ID, new Object[] {}));
+ }
- /**
+ /**
* calls a function of a smart contract and returns the result.
*
* @return the decoded result. if only one return value is expected the Object
* will be returned, if not an array of objects will be the result.
*/
- public Object call(TransactionRequest request, /** < the transaction to call. */
- long block /** < the Block used to for the state. */
- ) {
- return request.getResult((String) in3.sendRPCasObject("eth_call",
- new Object[] { request.getTransactionJson(), getBlockString(block) }));
- }
-
- /**
+ public Object call(TransactionRequest request, /** < the transaction to call. */
+ long block /** < the Block used to for the state. */
+ ) {
+ return request.getResult((String) in3.sendRPCasObject(CALL,
+ new Object[] {request.getTransactionJson(), getBlockString(block)}));
+ }
+
+ /**
* Makes a call or transaction, which won't be added to the blockchain and
* returns the used gas, which can be used for estimating the used gas.
*
* @return the gas required to call the function.
*/
- public long estimateGas(TransactionRequest request, /** < the transaction to call. */
- long block /** < the Block used to for the state. */
- ) {
- return JSON.asLong(in3.sendRPCasObject("eth_estimateGas",
- new Object[] { request.getTransactionJson(), getBlockString(block) }));
- }
-
- /**
+ public long estimateGas(TransactionRequest request, /** < the transaction to call. */
+ long block /** < the Block used to for the state. */
+ ) {
+ return JSON.asLong(in3.sendRPCasObject(ESTIMATE_GAS,
+ new Object[] {request.getTransactionJson(), getBlockString(block)}));
+ }
+
+ /**
* Returns the balance of the account of given address in wei.
*/
- public BigInteger getBalance(String address, long block) {
- return JSON
- .asBigInteger(in3.sendRPCasObject("eth_getBalance", new Object[] { address, getBlockString(block) }));
- }
+ public BigInteger getBalance(String address, long block) {
+ return JSON
+ .asBigInteger(in3.sendRPCasObject(GET_BALANCE, new Object[] {address, getBlockString(block)}));
+ }
- /**
+ /**
* Returns code at a given address.
*/
- public String getCode(String address, long block) {
- return JSON.asString(in3.sendRPCasObject("eth_getCode", new Object[] { address, getBlockString(block) }));
- }
+ public String getCode(String address, long block) {
+ return JSON.asString(in3.sendRPCasObject(GET_CODE, new Object[] {address, getBlockString(block)}));
+ }
- /**
+ /**
* Returns the value from a storage position at a given address.
*/
- public String getStorageAt(String address, BigInteger position, long block) {
- return JSON.asString(in3.sendRPCasObject("eth_getStorageAt",
- new Object[] { address, JSON.asString(position), getBlockString(block) }));
- }
+ public String getStorageAt(String address, BigInteger position, long block) {
+ return JSON.asString(in3.sendRPCasObject(GET_STORAGE_AT,
+ new Object[] {address, JSON.asString(position), getBlockString(block)}));
+ }
- /**
+ /**
* Returns the number of transactions in a block from a block matching the given
* block hash.
*/
- public long getBlockTransactionCountByHash(String blockHash) {
- return JSON.asLong(in3.sendRPCasObject("eth_getBlockTransactionCountByHash", new Object[] { blockHash }));
- }
+ public long getBlockTransactionCountByHash(String blockHash) {
+ return JSON.asLong(in3.sendRPCasObject(GET_BLOCK_TRANSACTION_COUNT_BY_HASH, new Object[] {blockHash}));
+ }
- /**
+ /**
* Returns the number of transactions in a block from a block matching the given
* block number.
*/
- public long getBlockTransactionCountByNumber(long block) {
- return JSON.asLong(
- in3.sendRPCasObject("eth_getBlockTransactionCountByNumber", new Object[] { getBlockString(block) }));
- }
+ public long getBlockTransactionCountByNumber(long block) {
+ return JSON.asLong(
+ in3.sendRPCasObject(GET_BLOCK_TRANSACTION_COUNT_BY_NUMBER, new Object[] {getBlockString(block)}));
+ }
- /**
+ /**
* Polling method for a filter, which returns an array of logs which occurred
* since last poll.
*/
- public Log[] getFilterChangesFromLogs(long id) {
- return Log.asLogs(in3.sendRPCasObject("eth_getFilterChanges", new Object[] { JSON.asString(id) }));
- }
+ public Log[] getFilterChangesFromLogs(long id) {
+ return Log.asLogs(in3.sendRPCasObject(GET_FILTER_CHANGES, new Object[] {JSON.asString(id)}));
+ }
- /**
+ /**
* Polling method for a filter, which returns an array of logs which occurred
* since last poll.
*/
- public String[] getFilterChangesFromBlocks(long id) {
- return JSON.asStringArray(in3.sendRPCasObject("eth_getFilterChanges", new Object[] { JSON.asString(id) }));
- }
+ public String[] getFilterChangesFromBlocks(long id) {
+ return JSON.asStringArray(in3.sendRPCasObject(GET_FILTER_CHANGES, new Object[] {JSON.asString(id)}));
+ }
- /**
+ /**
* Polling method for a filter, which returns an array of logs which occurred
* since last poll.
*/
- public Log[] getFilterLogs(long id) {
- return Log.asLogs(in3.sendRPCasObject("eth_getFilterLogs", new Object[] { JSON.asString(id) }));
- }
+ public Log[] getFilterLogs(long id) {
+ return Log.asLogs(in3.sendRPCasObject(GET_FILTER_LOGS, new Object[] {JSON.asString(id)}));
+ }
- /**
+ /**
* Polling method for a filter, which returns an array of logs which occurred
* since last poll.
*/
- public Log[] getLogs(LogFilter filter) {
- return Log.asLogs(in3.sendRPCasObject("eth_getLogs", new Object[] { filter.toString() }));
- }
+ public Log[] getLogs(LogFilter filter) {
+ return Log.asLogs(in3.sendRPCasObject(GET_LOGS, new Object[] {filter.toString()}));
+ }
- /**
+ /**
* Returns information about a transaction by block hash and transaction index
* position.
*/
- public Transaction getTransactionByBlockHashAndIndex(String blockHash, int index) {
- return Transaction.asTransaction(in3.sendRPCasObject("eth_getTransactionByBlockHashAndIndex",
- new Object[] { blockHash, JSON.asString(index) }));
- }
+ public Transaction getTransactionByBlockHashAndIndex(String blockHash, int index) {
+ return Transaction.asTransaction(in3.sendRPCasObject(GET_TRANSACTION_BY_BLOCK_HASH_AND_INDEX,
+ new Object[] {blockHash, JSON.asString(index)}));
+ }
- /**
+ /**
* Returns information about a transaction by block number and transaction index
* position.
*/
- public Transaction getTransactionByBlockNumberAndIndex(long block, int index) {
- return Transaction.asTransaction(in3.sendRPCasObject("eth_getTransactionByBlockNumberAndIndex",
- new Object[] { JSON.asString(block), JSON.asString(index) }));
- }
+ public Transaction getTransactionByBlockNumberAndIndex(long block, int index) {
+ return Transaction.asTransaction(in3.sendRPCasObject(GET_TRANSACTION_BY_BLOCK_NUMBER_AND_INDEX,
+ new Object[] {JSON.asString(block), JSON.asString(index)}));
+ }
- /**
+ /**
* Returns the information about a transaction requested by transaction hash.
*/
- public Transaction getTransactionByHash(String transactionHash) {
- return Transaction
- .asTransaction(in3.sendRPCasObject("eth_getTransactionByHash", new Object[] { transactionHash }));
- }
+ public Transaction getTransactionByHash(String transactionHash) {
+ return Transaction
+ .asTransaction(in3.sendRPCasObject(GET_TRANSACTION_BY_HASH, new Object[] {transactionHash}));
+ }
- /**
+ /**
* Returns the number of transactions sent from an address.
*/
- public BigInteger getTransactionCount(String address, long block) {
- return JSON.asBigInteger(
- in3.sendRPCasObject("eth_getTransactionCount", new Object[] { address, getBlockString(block) }));
- }
+ public BigInteger getTransactionCount(String address, long block) {
+ return JSON.asBigInteger(
+ in3.sendRPCasObject(GET_TRANSACTION_COUNT, new Object[] {address, getBlockString(block)}));
+ }
- /**
+ /**
* Returns the number of transactions sent from an address.
*/
- public TransactionReceipt getTransactionReceipt(String transactionHash) {
- return TransactionReceipt.asTransactionReceipt(
- in3.sendRPCasObject("eth_getTransactionReceipt", new Object[] { transactionHash }));
- }
+ public TransactionReceipt getTransactionReceipt(String transactionHash) {
+ return TransactionReceipt.asTransactionReceipt(
+ in3.sendRPCasObject(GET_TRANSACTION_RECEIPT, new Object[] {transactionHash}));
+ }
- /**
+ /**
* Returns information about a uncle of a block number and uncle index position.
* Note: An uncle doesn't contain individual transactions.
*/
- public Block getUncleByBlockNumberAndIndex(long block, int pos) {
- return Block.asBlock(in3.sendRPCasObject("eth_getUncleByBlockNumberAndIndex",
- new Object[] { getBlockString(block), JSON.asString(pos) }));
- }
+ public Block getUncleByBlockNumberAndIndex(long block, int pos) {
+ return Block.asBlock(in3.sendRPCasObject(GET_UNCLE_BY_BLOCK_NUMBER_AND_INDEX,
+ new Object[] {getBlockString(block), JSON.asString(pos)}));
+ }
- /**
+ /**
* Returns the number of uncles in a block from a block matching the given block
* hash.
*/
- public long getUncleCountByBlockHash(String block) {
- return JSON.asLong(in3.sendRPCasObject("eth_getUncleCountByBlockHash", new Object[] { block }));
- }
+ public long getUncleCountByBlockHash(String block) {
+ return JSON.asLong(in3.sendRPCasObject(GET_UNCLE_COUNT_BY_BLOCK_HASH, new Object[] {block}));
+ }
- /**
+ /**
* Returns the number of uncles in a block from a block matching the given block
* hash.
*/
- public long getUncleCountByBlockNumber(long block) {
- return JSON
- .asLong(in3.sendRPCasObject("eth_getUncleCountByBlockNumber", new Object[] { getBlockString(block) }));
- }
+ public long getUncleCountByBlockNumber(long block) {
+ return JSON
+ .asLong(in3.sendRPCasObject(GET_UNCLE_COUNT_BY_BLOCK_NUMBER, new Object[] {getBlockString(block)}));
+ }
- /**
+ /**
* Creates a filter in the node, to notify when a new block arrives. To check if
* the state has changed, call eth_getFilterChanges.
*/
- public long newBlockFilter() {
- return JSON.asLong(in3.sendRPCasObject("eth_newBlockFilter", new Object[] {}));
- }
+ public long newBlockFilter() {
+ return JSON.asLong(in3.sendRPCasObject(NEW_BLOCK_FILTER, new Object[] {}));
+ }
- /**
+ /**
* Creates a filter object, based on filter options, to notify when the state
* changes (logs). To check if the state has changed, call eth_getFilterChanges.
*
@@ -291,60 +326,105 @@ public long newBlockFilter() {
* (and anything after)"
*
*/
- public long newLogFilter(LogFilter filter) {
- return JSON.asLong(in3.sendRPCasObject("eth_newFilter", new Object[] { filter.toString() }));
- }
+ public long newLogFilter(LogFilter filter) {
+ return JSON.asLong(in3.sendRPCasObject(NEW_FILTER, new Object[] {filter.toString()}));
+ }
- /**
+ /**
* uninstall filter.
*/
- public boolean uninstallFilter(long filter) {
- return (boolean) in3.sendRPCasObject("eth_uninstallFilter", new Object[] { JSON.asString(filter) });
- }
+ public boolean uninstallFilter(long filter) {
+ return (boolean) in3.sendRPCasObject(UNINSTALL_FILTER, new Object[] {JSON.asString(filter)});
+ }
- /**
+ /**
* Creates new message call transaction or a contract creation for signed
* transactions.
*
* @return transactionHash
*/
- public String sendRawTransaction(String data) {
- return JSON.asString(in3.sendRPCasObject("eth_sendRawTransaction", new Object[] { data }));
- }
-
- /**
- * sends a Transaction as desribed by the TransactionRequest. This will require
+ public String sendRawTransaction(String data) {
+ return JSON.asString(in3.sendRPCasObject(SEND_RAW_TRANSACTION, new Object[] {data}));
+ }
+
+ /**
+ * encodes the arguments as described in the method signature using ABI-Encoding.
+ */
+ public String abiEncode(String signature, String[] params) {
+ Object rawResult = in3.sendRPCasObject(ABI_ENCODE, new Object[] {
+ signature,
+ params});
+ return JSON.asString(rawResult);
+ }
+
+ /**
+ * decodes the data based on the signature.
+ */
+ public String[] abiDecode(String signature, String encoded) {
+ Object rawResult = in3.sendRPCasObject(ABI_DECODE, new Object[] {signature, encoded});
+ return JSON.asStringArray(rawResult);
+ }
+
+ /**
+ * converts the given address to a checksum address.
+ */
+ public String checksumAddress(String address) {
+ return checksumAddress(address, null);
+ }
+
+ /**
+ * converts the given address to a checksum address. Second parameter includes the chainId.
+ */
+ public String checksumAddress(String address, Boolean useChainId) {
+ return JSON.asString(in3.sendRPCasObject(CHECKSUM_ADDRESS, new Object[] {address, useChainId}));
+ }
+
+ /**
+ * resolve ens-name.
+ */
+ public String ens(String name) {
+ return ens(name, null);
+ }
+
+ /**
+ * resolve ens-name. Second parameter especifies if it is an address, owner, resolver or hash.
+ */
+ public String ens(String name, ENSMethod type) {
+ return JSON.asString(in3.sendRPCasObject(ENS, new Object[] {name, type}, false));
+ }
+
+ /**
+ * sends a Transaction as described by the TransactionRequest. This will require
* a signer to be set in order to sign the transaction.
*/
- public String sendTransaction(TransactionRequest tx) {
- Signer signer = in3.getSigner();
- if (signer == null)
- throw new RuntimeException("No Signer set. This is needed in order to sign transaction.");
- if (tx.getFrom() == null)
- throw new RuntimeException("No from address set");
- if (!signer.hasAccount(tx.getFrom()))
- throw new RuntimeException("The from address is not supported by the signer");
- tx = signer.prepareTransaction(in3, tx);
-
- return JSON.asString(in3.sendRPCasObject("eth_sendTransaction", new Object[] { tx.getTransactionJson() }));
- }
-
- /**
+ public String sendTransaction(TransactionRequest tx) {
+ Signer signer = in3.getSigner();
+ if (signer == null)
+ throw new RuntimeException("No Signer set. This is needed in order to sign transaction.");
+ if (tx.getFrom() == null)
+ throw new RuntimeException("No from address set");
+ if (!signer.canSign(tx.getFrom()))
+ throw new RuntimeException("The from address is not supported by the signer");
+ tx = signer.prepareTransaction(in3, tx);
+
+ return JSON.asString(in3.sendRPCasObject(SEND_TRANSACTION, new Object[] {tx.getTransactionJson()}));
+ }
+
+ /**
* the current Gas Price.
*
* @return the decoded result. if only one return value is expected the Object
* will be returned, if not an array of objects will be the result.
*/
- public Object call(String to, String function, Object... params) {
- TransactionRequest req = new TransactionRequest();
- req.setTo(to);
- req.setFunction(function);
- req.setParams(params);
- return call(req, Block.LATEST);
- }
-
- private static String getBlockString(long l) {
- return l == Block.LATEST ? "latest" : "0x" + Long.toHexString(l);
- }
-
+ public Object call(String to, String function, Object... params) {
+ TransactionRequest req = new TransactionRequest();
+ req.setTo(to);
+ req.setFunction(function);
+ req.setParams(params);
+ return call(req, Block.LATEST);
+ }
+
+ private static String getBlockString(long l) {
+ return l == Block.LATEST ? "latest" : "0x" + Long.toHexString(l);
+ }
}
diff --git a/java/src/in3/eth1/Block.java b/java/src/in3/eth1/Block.java
index a40c8bf92..542a3baae 100644
--- a/java/src/in3/eth1/Block.java
+++ b/java/src/in3/eth1/Block.java
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -35,6 +35,7 @@
package in3.eth1;
import in3.*;
+import in3.utils.JSON;
import java.math.*;
/**
@@ -44,229 +45,229 @@
public class Block {
- /**
+ /**
* The latest Block Number.
*/
- public static long LATEST = -1;
+ public static long LATEST = -1;
- /**
+ /**
* The Genesis Block.
*/
- public static long EARLIEST = 0;
-
- private JSON data;
-
- private Block(JSON data) {
- this.data = data;
- }
-
- protected static Block asBlock(Object o) {
- if (o == null)
- return null;
- return new Block((JSON) o);
- }
-
- protected static Block[] asBlocks(Object o) {
- if (o == null)
- return null;
- Object[] a = (Object[]) o;
- Block[] b = new Block[a.length];
- for (int i = 0; i < a.length; i++)
- b[i] = Block.asBlock(a[i]);
- return b;
- }
-
- /**
+ public static long EARLIEST = 0;
+
+ private JSON data;
+
+ private Block(JSON data) {
+ this.data = data;
+ }
+
+ protected static Block asBlock(Object o) {
+ if (o == null)
+ return null;
+ return new Block((JSON) o);
+ }
+
+ protected static Block[] asBlocks(Object o) {
+ if (o == null)
+ return null;
+ Object[] a = (Object[]) o;
+ Block[] b = new Block[a.length];
+ for (int i = 0; i < a.length; i++)
+ b[i] = Block.asBlock(a[i]);
+ return b;
+ }
+
+ /**
* returns the total Difficulty as a sum of all difficulties starting from
* genesis.
*/
- public BigInteger getTotalDifficulty() {
- return data.getBigInteger("totalDifficulty");
- }
+ public BigInteger getTotalDifficulty() {
+ return data.getBigInteger("totalDifficulty");
+ }
- /**
+ /**
* the gas limit of the block.
*/
- public BigInteger getGasLimit() {
- return data.getBigInteger("gasLimit");
- }
+ public BigInteger getGasLimit() {
+ return data.getBigInteger("gasLimit");
+ }
- /**
+ /**
* the extra data of the block.
*/
- public String getExtraData() {
- return data.getString("extraData");
- }
+ public String getExtraData() {
+ return data.getString("extraData");
+ }
- /**
+ /**
* the difficulty of the block.
*/
- public BigInteger getDifficulty() {
- return data.getBigInteger("difficulty");
- }
+ public BigInteger getDifficulty() {
+ return data.getBigInteger("difficulty");
+ }
- /**
+ /**
* the author or miner of the block.
*/
- public String getAuthor() {
- return data.getString("author");
- }
+ public String getAuthor() {
+ return data.getString("author");
+ }
- /**
+ /**
* the roothash of the merkletree containing all transaction of the block.
*/
- public String getTransactionsRoot() {
- return data.getString("transactionsRoot");
- }
+ public String getTransactionsRoot() {
+ return data.getString("transactionsRoot");
+ }
- /**
+ /**
* the roothash of the merkletree containing all transaction receipts of the
* block.
*/
- public String getTransactionReceiptsRoot() {
- return data.getString("receiptsRoot");
- }
+ public String getTransactionReceiptsRoot() {
+ return data.getString("receiptsRoot");
+ }
- /**
+ /**
* the roothash of the merkletree containing the complete state.
*/
- public String getStateRoot() {
- return data.getString("stateRoot");
- }
+ public String getStateRoot() {
+ return data.getString("stateRoot");
+ }
- /**
+ /**
* the transaction hashes of the transactions in the block.
*/
- public String[] getTransactionHashes() {
- Object[] tx = (Object[]) data.get("transactions");
- if (tx == null || tx.length == 0)
- return new String[0];
- if (tx[0] instanceof String)
- return data.getStringArray("transactions");
- String[] res = new String[tx.length];
- for (int i = 0; i < tx.length; i++)
- res[i] = ((JSON) tx[i]).getString("hash");
- return res;
- }
-
- /**
+ public String[] getTransactionHashes() {
+ Object[] tx = (Object[]) data.get("transactions");
+ if (tx == null || tx.length == 0)
+ return new String[0];
+ if (tx[0] instanceof String)
+ return data.getStringArray("transactions");
+ String[] res = new String[tx.length];
+ for (int i = 0; i < tx.length; i++)
+ res[i] = ((JSON) tx[i]).getString("hash");
+ return res;
+ }
+
+ /**
* the transactions of the block.
*
* @throws if the Transactions are noot available
*/
- public Transaction[] getTransactions() throws Exception {
- Object[] tx = (Object[]) data.get("transactions");
- if (tx == null || tx.length == 0)
- return new Transaction[0];
+ public Transaction[] getTransactions() throws Exception {
+ Object[] tx = (Object[]) data.get("transactions");
+ if (tx == null || tx.length == 0)
+ return new Transaction[0];
- if (tx[0] instanceof String)
- throw new Exception("The Block only contains the transaction hashes!");
+ if (tx[0] instanceof String)
+ throw new Exception("The Block only contains the transaction hashes!");
- Transaction[] res = new Transaction[tx.length];
- for (int i = 0; i < tx.length; i++)
- res[i] = Transaction.asTransaction(tx[i]);
- return res;
- }
+ Transaction[] res = new Transaction[tx.length];
+ for (int i = 0; i < tx.length; i++)
+ res[i] = Transaction.asTransaction(tx[i]);
+ return res;
+ }
- /**
+ /**
* the unix timestamp in seconds since 1970.
*/
- public long getTimeStamp() {
- return data.getLong("timestamp");
- }
+ public long getTimeStamp() {
+ return data.getLong("timestamp");
+ }
- /**
+ /**
* the roothash of the merkletree containing all uncles of the block.
*/
- public String getSha3Uncles() {
- return data.getString("sha3Uncles");
- }
+ public String getSha3Uncles() {
+ return data.getString("sha3Uncles");
+ }
- /**
+ /**
* the size of the block.
*/
- public long getSize() {
- return data.getLong("size");
- }
+ public long getSize() {
+ return data.getLong("size");
+ }
- /**
+ /**
* the seal fields used for proof of authority.
*/
- public String[] getSealFields() {
- return data.getStringArray("sealFields");
- }
+ public String[] getSealFields() {
+ return data.getStringArray("sealFields");
+ }
- /**
+ /**
* the block hash of the of the header.
*/
- public String getHash() {
- return data.getString("hash");
- }
+ public String getHash() {
+ return data.getString("hash");
+ }
- /**
+ /**
* the bloom filter of the block.
*/
- public String getLogsBloom() {
- return data.getString("logsBloom");
- }
+ public String getLogsBloom() {
+ return data.getString("logsBloom");
+ }
- /**
+ /**
* the mix hash of the block. (only valid of proof of work)
*/
- public String getMixHash() {
- return data.getString("mixHash");
- }
+ public String getMixHash() {
+ return data.getString("mixHash");
+ }
- /**
+ /**
* the mix hash of the block. (only valid of proof of work)
*/
- public String getNonce() {
- return data.getString("nonce");
- }
+ public String getNonce() {
+ return data.getString("nonce");
+ }
- /**
+ /**
* the block number
*/
- public long getNumber() {
- return data.getLong("number");
- }
+ public long getNumber() {
+ return data.getLong("number");
+ }
- /**
+ /**
* the hash of the parent-block.
*/
- public String getParentHash() {
- return data.getString("parentHash");
- }
+ public String getParentHash() {
+ return data.getString("parentHash");
+ }
- /**
+ /**
* returns the blockhashes of all uncles-blocks.
*/
- public String[] getUncles() {
- return data.getStringArray("uncles");
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((data == null) ? 0 : data.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- Block other = (Block) obj;
- if (data == null) {
- if (other.data != null)
- return false;
- } else if (!data.equals(other.data))
- return false;
- return true;
- }
+ public String[] getUncles() {
+ return data.getStringArray("uncles");
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((data == null) ? 0 : data.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Block other = (Block) obj;
+ if (data == null) {
+ if (other.data != null)
+ return false;
+ } else if (!data.equals(other.data))
+ return false;
+ return true;
+ }
}
diff --git a/java/src/in3/eth1/ENSMethod.java b/java/src/in3/eth1/ENSMethod.java
new file mode 100644
index 000000000..6f153fcb8
--- /dev/null
+++ b/java/src/in3/eth1/ENSMethod.java
@@ -0,0 +1,11 @@
+package in3.eth1;
+
+/*
+ * Constants for the ens resolver
+ */
+public enum ENSMethod {
+ addr,
+ resolver,
+ hash,
+ owner
+}
diff --git a/java/src/in3/eth1/Log.java b/java/src/in3/eth1/Log.java
index 7b679e695..feb1a1082 100644
--- a/java/src/in3/eth1/Log.java
+++ b/java/src/in3/eth1/Log.java
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -35,6 +35,7 @@
package in3.eth1;
import in3.*;
+import in3.utils.JSON;
/**
* a log entry of a transaction receipt.
@@ -43,93 +44,92 @@
public class Log {
- private JSON data;
-
- private Log(JSON data) {
- this.data = data;
- }
-
- protected static Log[] asLogs(Object o) {
- if (o == null)
- return null;
- if (o instanceof Object[]) {
- Object[] a = (Object[]) o;
- Log[] s = new Log[a.length];
- for (int i = 0; i < s.length; i++)
- s[i] = a[i] == null ? null : new Log((JSON) a[i]);
- return s;
- }
- return null;
+ private JSON data;
+
+ private Log(JSON data) {
+ this.data = data;
+ }
+
+ protected static Log[] asLogs(Object o) {
+ if (o == null)
+ return null;
+ if (o instanceof Object[]) {
+ Object[] a = (Object[]) o;
+ Log[] s = new Log[a.length];
+ for (int i = 0; i < s.length; i++)
+ s[i] = a[i] == null ? null : new Log((JSON) a[i]);
+ return s;
}
+ return null;
+ }
- protected static Log asLog(Object o) {
- if (o == null)
- return null;
- return new Log((JSON) o);
- }
+ protected static Log asLog(Object o) {
+ if (o == null)
+ return null;
+ return new Log((JSON) o);
+ }
- /**
+ /**
* true when the log was removed, due to a chain reorganization. false if its a
* valid log.
*/
- public boolean isRemoved() {
- return (Boolean) data.get("removed");
- }
+ public boolean isRemoved() {
+ return (Boolean) data.get("removed");
+ }
- /**
+ /**
* integer of the log index position in the block. null when its pending log.
*/
- public int getLogIndex() {
- return JSON.asInt(data.get("logIndex"));
- }
+ public int getLogIndex() {
+ return JSON.asInt(data.get("logIndex"));
+ }
- /**
+ /**
* integer of the transactions index position log was created from. null when
* its pending log.
*/
- public int gettTansactionIndex() {
- return JSON.asInt(data.get("transactionIndex"));
- }
+ public int gettTansactionIndex() {
+ return JSON.asInt(data.get("transactionIndex"));
+ }
- /**
+ /**
* Hash, 32 Bytes - hash of the transactions this log was created from. null
* when its pending log.
*/
- public String getTransactionHash() {
- return data.getString("transactionHash");
- }
+ public String getTransactionHash() {
+ return data.getString("transactionHash");
+ }
- /**
+ /**
* Hash, 32 Bytes - hash of the block where this log was in. null when its
* pending. null when its pending log.
*/
- public String getBlockHash() {
- return data.getString("blockHash");
- }
+ public String getBlockHash() {
+ return data.getString("blockHash");
+ }
- /**
+ /**
* the block number where this log was in. null when its pending. null when its
* pending log.
*/
- public long getBlockNumber() {
- return data.getLong("blockNumber");
- }
+ public long getBlockNumber() {
+ return data.getLong("blockNumber");
+ }
- /**
+ /**
* 20 Bytes - address from which this log originated.
*/
- public String getAddress() {
- return data.getString("address");
- }
+ public String getAddress() {
+ return data.getString("address");
+ }
- /**
+ /**
* Array of 0 to 4 32 Bytes DATA of indexed log arguments. (In solidity: The
* first topic is the hash of the signature of the event (e.g.
* Deposit(address,bytes32,uint256)), except you declared the event with the
* anonymous specifier.)
*/
- public String[] getTopics() {
- return data.getStringArray("topics");
- }
-
+ public String[] getTopics() {
+ return data.getStringArray("topics");
+ }
}
diff --git a/java/src/in3/eth1/LogFilter.java b/java/src/in3/eth1/LogFilter.java
index 5a0daeb73..61cb099fa 100644
--- a/java/src/in3/eth1/LogFilter.java
+++ b/java/src/in3/eth1/LogFilter.java
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -34,98 +34,97 @@
package in3.eth1;
-import in3.JSON;
+import in3.utils.JSON;
/**
* Log configuration for search logs.
*/
public class LogFilter {
- /**
+ /**
* Quantity or Tag - (optional) (default: latest) Integer block number, or
* 'latest' for the last mined block or 'pending', 'earliest' for not yet mined
* transactions.
*/
- private long fromBlock = Block.LATEST;
- /**
+ private long fromBlock = Block.LATEST;
+ /**
* Quantity or Tag - (optional) (default: latest) Integer block number, or
* 'latest' for the last mined block or 'pending', 'earliest' for not yet mined
* transactions.
*/
- private long toBlock = Block.LATEST;
- /**
+ private long toBlock = Block.LATEST;
+ /**
* (optional) 20 Bytes - Contract address or a list of addresses from which logs
* should originate.
*/
- private String address;
- /**
+ private String address;
+ /**
* (optional) Array of 32 Bytes Data topics. Topics are order-dependent. It's
* possible to pass in null to match any topic, or a subarray of multiple topics
* of which one should be matching.
*/
- private Object[] topics;
+ private Object[] topics;
- /** a(optional) The maximum number of entries to retrieve (latest first). */
- private int limit;
+ /** a(optional) The maximum number of entries to retrieve (latest first). */
+ private int limit;
- public long getFromBlock() {
- return fromBlock;
- }
+ public long getFromBlock() {
+ return fromBlock;
+ }
- public void setFromBlock(long fromBlock) {
- this.fromBlock = fromBlock;
- }
+ public void setFromBlock(long fromBlock) {
+ this.fromBlock = fromBlock;
+ }
- public long getToBlock() {
- return toBlock;
- }
+ public long getToBlock() {
+ return toBlock;
+ }
- public void setToBlock(long toBlock) {
- this.toBlock = toBlock;
- }
+ public void setToBlock(long toBlock) {
+ this.toBlock = toBlock;
+ }
- public String getAddress() {
- return address;
- }
+ public String getAddress() {
+ return address;
+ }
- public void setAddress(String address) {
- this.address = address;
- }
+ public void setAddress(String address) {
+ this.address = address;
+ }
- public Object[] getTopics() {
- return topics;
- }
+ public Object[] getTopics() {
+ return topics;
+ }
- public void setTopics(Object[] topics) {
- this.topics = topics;
- }
+ public void setTopics(Object[] topics) {
+ this.topics = topics;
+ }
- public int getLimit() {
- return limit;
- }
+ public int getLimit() {
+ return limit;
+ }
- public void setLimit(int limit) {
- this.limit = limit;
- }
+ public void setLimit(int limit) {
+ this.limit = limit;
+ }
- /**
+ /**
* creates a JSON-String.
*/
- public String toString() {
- StringBuilder sb = new StringBuilder("{");
- if (fromBlock >= 0)
- JSON.appendKey(sb, "fromBlock", "0x" + Long.toHexString(fromBlock));
- if (toBlock >= 0)
- JSON.appendKey(sb, "toBlock", "0x" + Long.toHexString(toBlock));
- if (topics != null)
- JSON.appendKey(sb, "topics", JSON.toJson(topics));
- if (limit > 0)
- JSON.appendKey(sb, "limit", JSON.asString(limit));
- if (address != null)
- JSON.appendKey(sb, "address", JSON.asString(address));
- sb.setCharAt(sb.length() - 1, '}');
-
- return sb.toString();
- }
-
+ public String toString() {
+ StringBuilder sb = new StringBuilder("{");
+ if (fromBlock >= 0)
+ JSON.appendKey(sb, "fromBlock", "0x" + Long.toHexString(fromBlock));
+ if (toBlock >= 0)
+ JSON.appendKey(sb, "toBlock", "0x" + Long.toHexString(toBlock));
+ if (topics != null)
+ JSON.appendKey(sb, "topics", JSON.toJson(topics));
+ if (limit > 0)
+ JSON.appendKey(sb, "limit", JSON.asString(limit));
+ if (address != null)
+ JSON.appendKey(sb, "address", JSON.asString(address));
+ sb.setCharAt(sb.length() - 1, '}');
+
+ return sb.toString();
+ }
}
\ No newline at end of file
diff --git a/java/src/in3/eth1/SimpleWallet.java b/java/src/in3/eth1/SimpleWallet.java
index 62d8f90a3..f8045490c 100644
--- a/java/src/in3/eth1/SimpleWallet.java
+++ b/java/src/in3/eth1/SimpleWallet.java
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -34,12 +34,10 @@
package in3.eth1;
-import java.util.HashMap;
-import java.util.Map;
-
import in3.IN3;
import in3.Loader;
-import in3.Signer;
+import in3.utils.Signer;
+import java.util.*;
/**
* a simple Implementation for holding private keys to sing data or
@@ -47,59 +45,58 @@
*/
public class SimpleWallet implements Signer {
- static {
- Loader.loadLibrary();
- }
+ static {
+ Loader.loadLibrary();
+ }
- // ke for holding the map
- Map privateKeys = new HashMap();
+ // ke for holding the map
+ Map privateKeys = new HashMap();
- /**
+ /**
* adds a key to the wallet and returns its public address.
*/
- public String addRawKey(String data) {
- String address = getAddressFromKey(data);
- // create address
- privateKeys.put(address.toLowerCase(), data);
- return address;
- }
+ public String addRawKey(String data) {
+ String address = getAddressFromKey(data);
+ // create address
+ privateKeys.put(address.toLowerCase(), data);
+ return address;
+ }
- /**
+ /**
* adds a key to the wallet and returns its public address.
*/
- public String addKeyStore(String jsonData, String passphrase) {
- String data = decodeKeystore(jsonData, passphrase);
- if (data == null)
- throw new RuntimeException("Invalid password");
- // create address
- return addRawKey(data);
- }
+ public String addKeyStore(String jsonData, String passphrase) {
+ String data = decodeKeystore(jsonData, passphrase);
+ if (data == null)
+ throw new RuntimeException("Invalid password");
+ // create address
+ return addRawKey(data);
+ }
- /**
+ /**
* optiional method which allows to change the transaction-data before sending
* it. This can be used for redirecting it through a multisig.
*/
- public TransactionRequest prepareTransaction(IN3 in3, TransactionRequest tx) {
- // TODO here you could transform the data in order to support multisigs.
- // for now we don't manipulate the data.
- return tx;
- }
-
- /** returns true if the account is supported (or unlocked) */
- public boolean hasAccount(String address) {
- return privateKeys.containsKey(address.toLowerCase());
- }
+ public TransactionRequest prepareTransaction(IN3 in3, TransactionRequest tx) {
+ // TODO here you could transform the data in order to support multisigs.
+ // for now we don't manipulate the data.
+ return tx;
+ }
- /** signing of the raw data. */
- public String sign(String data, String address) {
- String key = privateKeys.get(address.toLowerCase());
- return signData(key, data);
- }
+ /** returns true if the account is supported (or unlocked) */
+ public boolean canSign(String address) {
+ return privateKeys.containsKey(address.toLowerCase());
+ }
- private static native String getAddressFromKey(String key);
+ /** signing of the raw data. */
+ public String sign(String data, String address) {
+ String key = privateKeys.get(address.toLowerCase());
+ return signData(key, data);
+ }
- private static native String signData(String key, String data);
+ private static native String getAddressFromKey(String key);
- private static native String decodeKeystore(String keystore, String passwd);
+ private static native String signData(String key, String data);
+ private static native String decodeKeystore(String keystore, String passwd);
}
diff --git a/java/src/in3/eth1/Transaction.java b/java/src/in3/eth1/Transaction.java
index 04e8823c0..4e573c18a 100644
--- a/java/src/in3/eth1/Transaction.java
+++ b/java/src/in3/eth1/Transaction.java
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -35,6 +35,7 @@
package in3.eth1;
import in3.*;
+import in3.utils.JSON;
import java.math.*;
/**
@@ -44,118 +45,118 @@
public class Transaction {
- private JSON data;
+ private JSON data;
- private Transaction(JSON data) {
- this.data = data;
- }
+ private Transaction(JSON data) {
+ this.data = data;
+ }
- protected static Transaction asTransaction(Object o) {
- return o == null ? null : new Transaction((JSON) o);
- }
+ protected static Transaction asTransaction(Object o) {
+ return o == null ? null : new Transaction((JSON) o);
+ }
- /**
+ /**
* the blockhash of the block containing this transaction.
*/
- public String getBlockHash() {
- return data.getString("blockHash");
- }
+ public String getBlockHash() {
+ return data.getString("blockHash");
+ }
- /**
+ /**
* the block number of the block containing this transaction.
*/
- public long getBlockNumber() {
- return data.getLong("blockNumber");
- }
+ public long getBlockNumber() {
+ return data.getLong("blockNumber");
+ }
- /**
+ /**
* the chainId of this transaction.
*/
- public String getChainId() {
- return data.getString("chainId");
- }
+ public String getChainId() {
+ return data.getString("chainId");
+ }
- /**
+ /**
* the address of the deployed contract (if successfull)
*/
- public String getCreatedContractAddress() {
- return data.getString("creates");
- }
+ public String getCreatedContractAddress() {
+ return data.getString("creates");
+ }
- /**
+ /**
* the address of the sender.
*/
- public String getFrom() {
- return data.getString("from");
- }
+ public String getFrom() {
+ return data.getString("from");
+ }
- /**
+ /**
* the Transaction hash.
*/
- public String getHash() {
- return data.getString("hash");
- }
+ public String getHash() {
+ return data.getString("hash");
+ }
- /**
+ /**
* the Transaction data or input data.
*/
- public String getData() {
- return data.getString("input");
- }
+ public String getData() {
+ return data.getString("input");
+ }
- /**
+ /**
* the nonce used in the transaction.
*/
- public long getNonce() {
- return data.getLong("nonce");
- }
+ public long getNonce() {
+ return data.getLong("nonce");
+ }
- /**
+ /**
* the public key of the sender.
*/
- public String getPublicKey() {
- return data.getString("publicKey");
- }
+ public String getPublicKey() {
+ return data.getString("publicKey");
+ }
- /**
+ /**
* the value send in wei.
*/
- public BigInteger getValue() {
- return data.getBigInteger("value");
- }
+ public BigInteger getValue() {
+ return data.getBigInteger("value");
+ }
- /**
+ /**
* the raw transaction as rlp encoded data.
*/
- public String getRaw() {
- return data.getString("raw");
- }
+ public String getRaw() {
+ return data.getString("raw");
+ }
- /**
+ /**
* the address of the receipient or contract.
*/
- public String getTo() {
- return data.getString("to");
- }
+ public String getTo() {
+ return data.getString("to");
+ }
- /**
+ /**
* the signature of the sender - a array of the [ r, s, v]
*/
- public String[] getSignature() {
- return new String[] { data.getString("r"), data.getString("s"), data.getString("v") };
- }
+ public String[] getSignature() {
+ return new String[] {data.getString("r"), data.getString("s"), data.getString("v")};
+ }
- /**
+ /**
* the gas price provided by the sender.
*/
- public long getGasPrice() {
- return data.getLong("gasPrice");
- }
+ public long getGasPrice() {
+ return data.getLong("gasPrice");
+ }
- /**
+ /**
* the gas provided by the sender.
*/
- public long getGas() {
- return data.getLong("gas");
- }
+ public long getGas() {
+ return data.getLong("gas");
+ }
}
diff --git a/java/src/in3/eth1/TransactionReceipt.java b/java/src/in3/eth1/TransactionReceipt.java
index d3ca07d5f..f58e389f0 100644
--- a/java/src/in3/eth1/TransactionReceipt.java
+++ b/java/src/in3/eth1/TransactionReceipt.java
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -35,6 +35,7 @@
package in3.eth1;
import in3.*;
+import in3.utils.JSON;
/**
* represents a Transaction receipt in ethereum.
@@ -43,105 +44,104 @@
public class TransactionReceipt {
- private JSON data;
+ private JSON data;
- private TransactionReceipt(JSON data) {
- this.data = data;
- }
+ private TransactionReceipt(JSON data) {
+ this.data = data;
+ }
- protected static TransactionReceipt asTransactionReceipt(Object o) {
- return o == null ? null : new TransactionReceipt((JSON) o);
- }
+ protected static TransactionReceipt asTransactionReceipt(Object o) {
+ return o == null ? null : new TransactionReceipt((JSON) o);
+ }
- /**
+ /**
* the blockhash of the block containing this transaction.
*/
- public String getBlockHash() {
- return data.getString("blockHash");
- }
+ public String getBlockHash() {
+ return data.getString("blockHash");
+ }
- /**
+ /**
* the block number of the block containing this transaction.
*/
- public long getBlockNumber() {
- return data.getLong("blockNumber");
- }
+ public long getBlockNumber() {
+ return data.getLong("blockNumber");
+ }
- /**
+ /**
* the address of the deployed contract (if successfull)
*/
- public String getCreatedContractAddress() {
- return data.getString("contractAddress");
- }
+ public String getCreatedContractAddress() {
+ return data.getString("contractAddress");
+ }
- /**
+ /**
* the address of the sender.
*/
- public String getFrom() {
- return data.getString("from");
- }
+ public String getFrom() {
+ return data.getString("from");
+ }
- /**
+ /**
* the Transaction hash.
*/
- public String getTransactionHash() {
- return data.getString("transactionHash");
- }
+ public String getTransactionHash() {
+ return data.getString("transactionHash");
+ }
- /**
+ /**
* the Transaction index.
*/
- public int getTransactionIndex() {
- return JSON.asInt(data.get("transactionIndex"));
- }
+ public int getTransactionIndex() {
+ return JSON.asInt(data.get("transactionIndex"));
+ }
- /**
+ /**
* 20 Bytes - The address of the receiver. null when it's a contract creation
* transaction.
*/
- public String getTo() {
- return data.getString("to");
- }
+ public String getTo() {
+ return data.getString("to");
+ }
- /**
+ /**
* The amount of gas used by this specific transaction alone.
*/
- public long getGasUsed() {
- return data.getLong("gasUsed");
- }
+ public long getGasUsed() {
+ return data.getLong("gasUsed");
+ }
- /**
+ /**
* Array of log objects, which this transaction generated.
*/
- public Log[] getLogs() {
- return Log.asLogs(data.get("logs"));
- }
+ public Log[] getLogs() {
+ return Log.asLogs(data.get("logs"));
+ }
- /**
+ /**
* 256 Bytes - A bloom filter of logs/events generated by contracts during
* transaction execution. Used to efficiently rule out transactions without
* expected logs
*/
- public String getLogsBloom() {
- return data.getString("logsBloom");
- }
+ public String getLogsBloom() {
+ return data.getString("logsBloom");
+ }
- /**
+ /**
* 32 Bytes - Merkle root of the state trie after the transaction has been
* executed (optional after Byzantium hard fork EIP609).
*/
- public String getRoot() {
- return data.getString("root");
- }
+ public String getRoot() {
+ return data.getString("root");
+ }
- /**
+ /**
* success of a Transaction.
*
* true indicates transaction failure , false indicates transaction success. Set
* for blocks mined after Byzantium hard fork EIP609, null before.
*/
- public boolean getStatus() {
- return data.getLong("status") == 1;
- }
-
+ public boolean getStatus() {
+ return data.getLong("status") == 1;
+ }
}
diff --git a/java/src/in3/eth1/TransactionRequest.java b/java/src/in3/eth1/TransactionRequest.java
index 0d5b7ceb3..c196b2d46 100644
--- a/java/src/in3/eth1/TransactionRequest.java
+++ b/java/src/in3/eth1/TransactionRequest.java
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -35,6 +35,7 @@
package in3.eth1;
import in3.*;
+import in3.utils.JSON;
import java.math.*;
/**
@@ -42,147 +43,146 @@
*/
public class TransactionRequest {
- /** the from address */
- private String from;
+ /** the from address */
+ private String from;
- /** the recipients address */
- private String to;
+ /** the recipients address */
+ private String to;
- /** the data */
- private String data;
+ /** the data */
+ private String data;
- /** the value of the transaction */
- private BigInteger value;
+ /** the value of the transaction */
+ private BigInteger value;
- /** the nonce (transactionCount of the sender) */
- private long nonce = -1;
+ /** the nonce (transactionCount of the sender) */
+ private long nonce = -1;
- /** the gas to use */
- private long gas;
+ /** the gas to use */
+ private long gas;
- /** the gas price to use */
- private long gasPrice;
+ /** the gas price to use */
+ private long gasPrice;
- /** the signature for the function to call */
- private String function;
+ /** the signature for the function to call */
+ private String function;
- /** the params to use for encoding in the data */
- private Object[] params;
+ /** the params to use for encoding in the data */
+ private Object[] params;
- public String getFrom() {
- return from;
- }
+ public String getFrom() {
+ return from;
+ }
- public void setFrom(String from) {
- this.from = from;
- }
+ public void setFrom(String from) {
+ this.from = from;
+ }
- public String getTo() {
- return to;
- }
+ public String getTo() {
+ return to;
+ }
- public void setTo(String to) {
- this.to = to;
- }
+ public void setTo(String to) {
+ this.to = to;
+ }
- public BigInteger getValue() {
- return value;
- }
+ public BigInteger getValue() {
+ return value;
+ }
- public void setValue(BigInteger value) {
- this.value = value;
- }
+ public void setValue(BigInteger value) {
+ this.value = value;
+ }
- public long getNonce() {
- return nonce;
- }
+ public long getNonce() {
+ return nonce;
+ }
- public void setNonce(long nonce) {
- this.nonce = nonce;
- }
+ public void setNonce(long nonce) {
+ this.nonce = nonce;
+ }
- public long getGas() {
- return gas;
- }
+ public long getGas() {
+ return gas;
+ }
- public void setGas(long gas) {
- this.gas = gas;
- }
+ public void setGas(long gas) {
+ this.gas = gas;
+ }
- public long getGasPrice() {
- return gasPrice;
- }
+ public long getGasPrice() {
+ return gasPrice;
+ }
- public void setGasPrice(long gasPrice) {
- this.gasPrice = gasPrice;
- }
+ public void setGasPrice(long gasPrice) {
+ this.gasPrice = gasPrice;
+ }
- public String getFunction() {
- return function;
- }
+ public String getFunction() {
+ return function;
+ }
- public void setFunction(String function) {
- this.function = function;
- }
+ public void setFunction(String function) {
+ this.function = function;
+ }
- public Object[] getParams() {
- return params;
- }
+ public Object[] getParams() {
+ return params;
+ }
- public void setParams(Object[] params) {
- this.params = params;
- }
+ public void setParams(Object[] params) {
+ this.params = params;
+ }
- public void setData(String data) {
- this.data = data;
- }
+ public void setData(String data) {
+ this.data = data;
+ }
- /**
+ /**
* creates the data based on the function/params values.
*/
- public String getData() {
- String result = data == null || data.length() < 2 ? "0x" : data;
- if (function != null) {
- String fnData = abiEncode(function, JSON.toJson(params));
- if (fnData != null && fnData.length() > 2 && fnData.startsWith("0x"))
- result += fnData.substring(2 + (result.length() > 2 ? 8 : 0));
- }
- return result;
- }
-
- public String getTransactionJson() {
- StringBuilder sb = new StringBuilder();
- sb.append("{");
- if (to != null)
- JSON.appendKey(sb, "to", to);
- if (from != null)
- JSON.appendKey(sb, "from", from);
- if (gas > 0)
- JSON.appendKey(sb, "gasLimit", JSON.asString(gas));
- if (gasPrice > 0)
- JSON.appendKey(sb, "gasPrice", JSON.asString(gasPrice));
- if (value != null)
- JSON.appendKey(sb, "value", JSON.asString(value));
- if (nonce >= 0)
- JSON.appendKey(sb, "nonce", JSON.asString(nonce));
- JSON.appendKey(sb, "data", getData());
- sb.setCharAt(sb.length() - 1, '}');
- return sb.toString();
- }
-
- public Object getResult(String data) {
- if (function == null)
- return data;
- Object[] res = (Object[]) abiDecode(function, data);
- return res.length == 1 ? res[0] : res;
- }
-
- static {
- Loader.loadLibrary();
- }
-
- private static native String abiEncode(String function, String jsonParams);
-
- private static native Object abiDecode(String function, String data);
-
+ public String getData() {
+ String result = data == null || data.length() < 2 ? "0x" : data;
+ if (function != null) {
+ String fnData = abiEncode(function, JSON.toJson(params));
+ if (fnData != null && fnData.length() > 2 && fnData.startsWith("0x"))
+ result += fnData.substring(2 + (result.length() > 2 ? 8 : 0));
+ }
+ return result;
+ }
+
+ public String getTransactionJson() {
+ StringBuilder sb = new StringBuilder();
+ sb.append("{");
+ if (to != null)
+ JSON.appendKey(sb, "to", to);
+ if (from != null)
+ JSON.appendKey(sb, "from", from);
+ if (gas > 0)
+ JSON.appendKey(sb, "gasLimit", JSON.asString(gas));
+ if (gasPrice > 0)
+ JSON.appendKey(sb, "gasPrice", JSON.asString(gasPrice));
+ if (value != null)
+ JSON.appendKey(sb, "value", JSON.asString(value));
+ if (nonce >= 0)
+ JSON.appendKey(sb, "nonce", JSON.asString(nonce));
+ JSON.appendKey(sb, "data", getData());
+ sb.setCharAt(sb.length() - 1, '}');
+ return sb.toString();
+ }
+
+ public Object getResult(String data) {
+ if (function == null)
+ return data;
+ Object[] res = (Object[]) abiDecode(function, data);
+ return res.length == 1 ? res[0] : res;
+ }
+
+ static {
+ Loader.loadLibrary();
+ }
+
+ private static native String abiEncode(String function, String jsonParams);
+
+ private static native Object abiDecode(String function, String data);
}
\ No newline at end of file
diff --git a/java/src/in3/utils/Account.java b/java/src/in3/utils/Account.java
new file mode 100644
index 000000000..6db7a3fb3
--- /dev/null
+++ b/java/src/in3/utils/Account.java
@@ -0,0 +1,32 @@
+package in3.utils;
+
+/**
+ * Pojo that represents the result of an ecrecover operation (see: Crypto class).
+ */
+public class Account {
+ private JSON data;
+
+ private Account(JSON data) {
+ this.data = data;
+ }
+
+ protected static Account asAccount(Object o) {
+ if (o == null)
+ return null;
+ return new Account((JSON) o);
+ }
+
+ /**
+ * address from ecrecover operation.
+ */
+ public String getAddress() {
+ return data.getString("address");
+ }
+
+ /**
+ * public key from ecrecover operation.
+ */
+ public String getPublicKey() {
+ return data.getString("publicKey");
+ }
+}
diff --git a/java/src/in3/utils/Crypto.java b/java/src/in3/utils/Crypto.java
new file mode 100644
index 000000000..a126f041c
--- /dev/null
+++ b/java/src/in3/utils/Crypto.java
@@ -0,0 +1,73 @@
+package in3.utils;
+
+import in3.IN3;
+import in3.Loader;
+
+/**
+ * a Wrapper for crypto-related helper functions.
+ */
+public class Crypto {
+
+ static {
+ Loader.loadLibrary();
+ }
+
+ private static final String PK2ADDRESS = "in3_pk2address";
+ private static final String PK2PUBLIC = "in3_pk2public";
+ private static final String ECRECOVER = "in3_ecrecover";
+ private static final String DECRYPT_KEY = "in3_decryptKey";
+ private static final String SHA3 = "web3_sha3";
+ private static final String SIGN_DATA = "in3_signData";
+
+ private IN3 in3;
+
+ public Crypto(IN3 in3) {
+ this.in3 = in3;
+ }
+
+ /**
+ * returns a signature given a message and a key.
+ */
+ public Signature signData(String msg, String key, SignatureType sigType) {
+ return Signature.asSignature(in3.sendRPCasObject(SIGN_DATA, new Object[] {msg, key, JSON.asString(sigType)}));
+ }
+
+ public String decryptKey(String key, String passphrase) {
+ return JSON.asString(in3.sendRPCasObject(DECRYPT_KEY, new Object[] {key, passphrase}));
+ }
+
+ /**
+ * extracts the public address from a private key.
+ */
+ public String pk2address(String key) {
+ return JSON.asString(in3.sendRPCasObject(PK2ADDRESS, new Object[] {key}));
+ }
+
+ /**
+ * extracts the public key from a private key.
+ */
+ public String pk2public(String key) {
+ return JSON.asString(in3.sendRPCasObject(PK2PUBLIC, new Object[] {key}));
+ }
+
+ /**
+ * extracts the address and public key from a signature.
+ */
+ public Account ecrecover(String msg, String sig) {
+ return ecrecover(msg, sig, null);
+ }
+
+ /**
+ * extracts the address and public key from a signature.
+ */
+ public Account ecrecover(String msg, String sig, SignatureType sigType) {
+ return Account.asAccount(in3.sendRPCasObject(ECRECOVER, new Object[] {msg, sig, JSON.asString(sigType)}));
+ }
+
+ /**
+ * returns a signature given a message and a key.
+ */
+ public Signature signData(String msg, String key) {
+ return Signature.asSignature(signData(msg, key, null));
+ }
+}
diff --git a/java/src/in3/utils/JSON.java b/java/src/in3/utils/JSON.java
new file mode 100644
index 000000000..9f1bd96e2
--- /dev/null
+++ b/java/src/in3/utils/JSON.java
@@ -0,0 +1,241 @@
+/*******************************************************************************
+ * This file is part of the Incubed project.
+ * Sources: https://github.com/slockit/in3-c
+ *
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
+ *
+ *
+ * COMMERCIAL LICENSE USAGE
+ *
+ * Licensees holding a valid commercial license may use this file in accordance
+ * with the commercial license agreement provided with the Software or, alternatively,
+ * in accordance with the terms contained in a written agreement between you and
+ * slock.it GmbH/Blockchains LLC. For licensing terms and conditions or further
+ * information please contact slock.it at in3@slock.it.
+ *
+ * Alternatively, this file may be used under the AGPL license as follows:
+ *
+ * AGPL LICENSE USAGE
+ *
+ * This program is free software: you can redistribute it and/or modify it under the
+ * terms of the GNU Affero General Public License as published by the Free Software
+ * Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Affero General Public License for more details.
+ * [Permissions of this strong copyleft license are conditioned on making available
+ * complete source code of licensed works and modifications, which include larger
+ * works using a licensed work, under the same license. Copyright and license notices
+ * must be preserved. Contributors provide an express grant of patent rights.]
+ * You should have received a copy of the GNU Affero General Public License along
+ * with this program. If not, see .
+ *******************************************************************************/
+
+package in3.utils;
+
+import in3.Loader;
+import java.math.*;
+import java.util.*;
+
+/**
+ * internal helper tool to represent a JSON-Object.
+ *
+ * Since the internal representation of JSON in incubed uses hashes instead of
+ * name, the getter will creates these hashes.
+ */
+public class JSON {
+ static {
+ Loader.loadLibrary();
+ }
+
+ private HashMap map = new HashMap();
+
+ private static native int key(String name);
+
+ JSON() {}
+
+ /**
+ * gets the property
+ *
+ * @return the raw object.
+ */
+ public Object get(String prop /** the name of the property. */
+ ) {
+ return map.get(key(prop));
+ }
+
+ /**
+ * adds values. This function will be called from the JNI-Iterface.
+ *
+ * Internal use only!
+ */
+ public void put(int key /** the hash of the key */
+ ,
+ Object val /** the value object */
+ ) {
+ map.put(key, val);
+ }
+
+ /**
+ * returns the property as long
+ *
+ * @return the long value
+ */
+ public long getLong(String key /** the propertyName */
+ ) {
+ return asLong(get(key));
+ }
+
+ /**
+ * returns the property as BigInteger
+ *
+ * @return the BigInteger value
+ */
+ public BigInteger getBigInteger(String key /** the propertyName */
+ ) {
+ return asBigInteger(get(key));
+ }
+
+ /**
+ * returns the property as StringArray
+ *
+ * @return the array or null
+ */
+ public String[] getStringArray(String key /** the propertyName */
+ ) {
+ return asStringArray(get(key));
+ }
+
+ /**
+ * returns the property as String or in case of a number as hexstring.
+ *
+ * @return the hexstring
+ */
+ public String getString(String key /** the propertyName */
+ ) {
+ return asString(get(key));
+ }
+
+ /**
+ * casts the object to a String[]
+ */
+ public static String[] asStringArray(Object o) {
+ if (o == null)
+ return null;
+ if (o instanceof Object[]) {
+ Object[] a = (Object[]) o;
+ String[] s = new String[a.length];
+ for (int i = 0; i < s.length; i++)
+ s[i] = a[i] == null ? null : asString(a[i]);
+ return s;
+ }
+ return null;
+ }
+
+ public static BigInteger asBigInteger(Object o) {
+ if (o == null)
+ return BigInteger.valueOf(0);
+ if (o instanceof String)
+ return (((String) o).length() > 2 && o.toString().charAt(1) == 'x')
+ ? new BigInteger(o.toString().substring(2), 16)
+ : new BigInteger(o.toString(), 10);
+ if (o instanceof Integer)
+ return BigInteger.valueOf(((Integer) o).longValue());
+ return BigInteger.valueOf(0);
+ }
+
+ public static long asLong(Object o) {
+ if (o == null)
+ return 0;
+ if (o instanceof String)
+ return (((String) o).length() > 2 && o.toString().charAt(1) == 'x')
+ ? Long.parseLong(o.toString().substring(2), 16)
+ : Long.parseLong(o.toString(), 10);
+ if (o instanceof Integer)
+ return ((Integer) o).longValue();
+ return 0;
+ }
+
+ public static int asInt(Object o) {
+ if (o == null)
+ return 0;
+ if (o instanceof String)
+ return (((String) o).length() > 2 && o.toString().charAt(1) == 'x')
+ ? Integer.parseInt(o.toString().substring(2), 16)
+ : Integer.parseInt(o.toString(), 10);
+ if (o instanceof Number)
+ return ((Number) o).intValue();
+ return 0;
+ }
+
+ public static String asString(Object o) {
+ if (o == null)
+ return null;
+ if (o instanceof Integer)
+ return "0x" + Integer.toHexString((Integer) o);
+ if (o instanceof Long)
+ return "0x" + Long.toHexString((Long) o);
+ if (o instanceof BigInteger)
+ return "0x" + ((BigInteger) o).toString(16);
+ return o.toString();
+ }
+
+ public String toString() {
+ return "";
+ }
+
+ public static String toJson(Object ob) {
+ if (ob == null)
+ return "null";
+ if (ob instanceof String)
+ return "\"" + ob + "\"";
+ if (ob instanceof BigInteger)
+ return "\"0x" + ((BigInteger) ob).toString(16) + "\"";
+ if (ob instanceof Number)
+ return ob.toString();
+ if (ob instanceof Boolean)
+ return ob.toString();
+ if (ob instanceof Object[]) {
+ Object[] a = (Object[]) ob;
+ StringBuilder sb = new StringBuilder();
+ sb.append("[");
+ for (int i = 0; i < a.length; i++) {
+ if (i > 0)
+ sb.append(",");
+ sb.append(toJson(a[i]));
+ }
+ return sb.append("]").toString();
+ }
+ return ob.toString();
+ }
+
+ public static void appendKey(StringBuilder sb, String key, Object value) {
+ sb.append("\"").append(key).append("\":").append(toJson(value)).append(",");
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((map == null) ? 0 : map.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ JSON other = (JSON) obj;
+ if (map == null) {
+ if (other.map != null)
+ return false;
+ } else if (!map.equals(other.map))
+ return false;
+ return true;
+ }
+}
diff --git a/java/src/in3/utils/Signature.java b/java/src/in3/utils/Signature.java
new file mode 100644
index 000000000..dc4d3e67c
--- /dev/null
+++ b/java/src/in3/utils/Signature.java
@@ -0,0 +1,67 @@
+package in3.utils;
+
+/*
+ * Class that represents a Signature
+ */
+public class Signature {
+
+ private JSON data;
+
+ private static final String MESSAGE = "message";
+ private static final String MESSAGE_HASH = "messageHash";
+ private static final String SIGNATURE = "signature";
+ private static final String R = "r";
+ private static final String S = "s";
+ private static final String V = "v";
+
+ private Signature(JSON data) {
+ this.data = data;
+ }
+
+ protected static Signature asSignature(Object o) {
+ if (o == null)
+ return null;
+ return new Signature((JSON) o);
+ }
+
+ /*
+ * returns the message
+ */
+ public String getMessage() {
+ return data.getString(MESSAGE);
+ }
+ /*
+ * returns the hash of the message
+ */
+ public String getMessageHash() {
+ return data.getString(MESSAGE_HASH);
+ }
+
+ /*
+ * returns the signature
+ */
+ public String getSignature() {
+ return data.getString(SIGNATURE);
+ }
+
+ /*
+ * returns R
+ */
+ public String getR() {
+ return data.getString(R);
+ }
+
+ /*
+ * returns S
+ */
+ public String getS() {
+ return data.getString(S);
+ }
+
+ /*
+ * returns V
+ */
+ public long getV() {
+ return data.getLong(V);
+ }
+}
diff --git a/java/src/in3/utils/SignatureType.java b/java/src/in3/utils/SignatureType.java
new file mode 100644
index 000000000..52d330140
--- /dev/null
+++ b/java/src/in3/utils/SignatureType.java
@@ -0,0 +1,10 @@
+package in3.utils;
+
+/*
+ * Constants for the type of Signature
+ */
+public enum SignatureType {
+ eth_sign,
+ raw,
+ hash
+}
diff --git a/java/src/in3/Signer.java b/java/src/in3/utils/Signer.java
similarity index 86%
rename from java/src/in3/Signer.java
rename to java/src/in3/utils/Signer.java
index d3c7e8921..91444c767 100644
--- a/java/src/in3/Signer.java
+++ b/java/src/in3/utils/Signer.java
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -32,7 +32,7 @@
* with this program. If not, see .
*******************************************************************************/
-package in3;
+package in3.utils;
import in3.IN3;
import in3.eth1.TransactionRequest;
@@ -41,16 +41,15 @@
* a Interface responsible for signing data or transactions.
*/
public interface Signer {
- /**
+ /**
* optiional method which allows to change the transaction-data before sending
* it. This can be used for redirecting it through a multisig.
*/
- TransactionRequest prepareTransaction(IN3 in3, TransactionRequest tx);
+ TransactionRequest prepareTransaction(IN3 in3, TransactionRequest tx);
- /** returns true if the account is supported (or unlocked) */
- boolean hasAccount(String address);
-
- /** signing of the raw data. */
- String sign(String data, String address);
+ /** returns true if the account is supported (or unlocked) */
+ boolean canSign(String address);
+ /** signing of the raw data. */
+ String sign(String data, String address);
}
diff --git a/java/src/in3/StorageProvider.java b/java/src/in3/utils/StorageProvider.java
similarity index 87%
rename from java/src/in3/StorageProvider.java
rename to java/src/in3/utils/StorageProvider.java
index 9e686b95a..c710a8d31 100644
--- a/java/src/in3/StorageProvider.java
+++ b/java/src/in3/utils/StorageProvider.java
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -32,22 +32,26 @@
* with this program. If not, see .
*******************************************************************************/
-package in3;
-
+package in3.utils;
/**
* Provider methods to cache data.
* These data could be nodelists, contract codes or validator changes.
*/
public interface StorageProvider {
- /**
+ /**
* returns a item from cache ()
* @return the bytes or null if not found.
*/
- byte[] getItem(String key /** the key for the item */);
+ byte[] getItem(String key /** the key for the item */);
- /**
+ /**
* stores a item in the cache.
*/
- void setItem(String key/** the key for the item */, byte[] content /** the value to store */);
+ void setItem(String key /** the key for the item */, byte[] content /** the value to store */);
+
+ /**
+ * clear the cache.
+ */
+ boolean clear();
}
diff --git a/java/src/in3/TempStorageProvider.java b/java/src/in3/utils/TempStorageProvider.java
similarity index 62%
rename from java/src/in3/TempStorageProvider.java
rename to java/src/in3/utils/TempStorageProvider.java
index 5afea892e..4cc113982 100644
--- a/java/src/in3/TempStorageProvider.java
+++ b/java/src/in3/utils/TempStorageProvider.java
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -32,7 +32,7 @@
* with this program. If not, see .
*******************************************************************************/
-package in3;
+package in3.utils;
import java.io.BufferedInputStream;
import java.io.File;
@@ -45,43 +45,53 @@
*/
public class TempStorageProvider implements StorageProvider {
- private static File tmp = new File(System.getProperty("java.io.tmpdir"));
- private static String in3Prefix = "in3_cache_";
+ private static File tmp = new File(System.getProperty("java.io.tmpdir"));
+ private static String in3Prefix = "in3_cache_";
- @Override
- public byte[] getItem(String key) {
+ @Override
+ public byte[] getItem(String key) {
- File f = new File(tmp, in3Prefix + key);
- if (f.exists()) {
- BufferedInputStream is = null;
- try {
- is = new BufferedInputStream(new FileInputStream(f));
- byte[] content = new byte[(int) f.length()];
- int offset = 0;
- while (offset < content.length)
- offset += is.read(content, offset, content.length - offset);
- return content;
- } catch (Exception ex) {
- return null;
- } finally {
- try {
- if (is != null)
- is.close();
- } catch (IOException io) {
- }
- }
- }
+ File f = new File(tmp, in3Prefix + key);
+ if (f.exists()) {
+ BufferedInputStream is = null;
+ try {
+ is = new BufferedInputStream(new FileInputStream(f));
+ byte[] content = new byte[(int) f.length()];
+ int offset = 0;
+ while (offset < content.length)
+ offset += is.read(content, offset, content.length - offset);
+ return content;
+ } catch (Exception ex) {
return null;
- }
-
- @Override
- public void setItem(String key, byte[] content) {
+ } finally {
try {
- FileOutputStream os = new FileOutputStream(new File(tmp, in3Prefix + key));
- os.write(content);
- os.close();
- } catch (IOException ex) {
+ if (is != null)
+ is.close();
+ } catch (IOException io) {
}
+ }
}
+ return null;
+ }
+ @Override
+ public void setItem(String key, byte[] content) {
+ try {
+ FileOutputStream os = new FileOutputStream(new File(tmp, in3Prefix + key));
+ os.write(content);
+ os.close();
+ } catch (IOException ex) {
+ }
+ }
+
+ @Override
+ public boolean clear() {
+ try {
+ // TODO perform whatever action necessary to clear cache
+ return true;
+ } catch (Throwable t) {
+ t.printStackTrace();
+ return false;
+ }
+ }
}
\ No newline at end of file
diff --git a/java/src/in3_jni.c b/java/src/in3_jni.c
index ebb1b04a2..9857cd87e 100644
--- a/java/src/in3_jni.c
+++ b/java/src/in3_jni.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -34,6 +34,7 @@
#include "in3_jni.h"
#include "../../c/src/api/eth1/abi.h"
+#include "../../c/src/api/eth1/eth_api.h"
#include "../../c/src/core/client/cache.h"
#include "../../c/src/core/client/client.h"
#include "../../c/src/core/client/context.h"
@@ -51,6 +52,7 @@
#endif
static in3_t* get_in3(JNIEnv* env, jobject obj) {
+ if (obj == NULL || env == NULL || (*env)->GetObjectClass(env, obj) == NULL) return NULL;
jlong l = (*env)->GetLongField(env, obj, (*env)->GetFieldID(env, (*env)->GetObjectClass(env, obj), "ptr", "J"));
return (in3_t*) (size_t) l;
}
@@ -387,7 +389,7 @@ static JNIEnv* jni = NULL;
static jobject get_storage_handler(void* cptr) {
jclass cls = (*jni)->GetObjectClass(jni, (jobject) cptr);
- jmethodID mid = (*jni)->GetMethodID(jni, cls, "getStorageProvider", "()Lin3/StorageProvider;");
+ jmethodID mid = (*jni)->GetMethodID(jni, cls, "getStorageProvider", "()Lin3/utils/StorageProvider;");
return (*jni)->CallObjectMethod(jni, (jobject) cptr, mid);
}
@@ -415,7 +417,14 @@ void storage_set_item(void* cptr, char* key, bytes_t* content) {
jbyteArray bytes = (*jni)->NewByteArray(jni, content->len);
(*jni)->SetByteArrayRegion(jni, bytes, 0, content->len, (jbyte*) content->data);
- (*jni)->CallVoidMethod(jni, handler, (*jni)->GetMethodID(jni, (*jni)->GetObjectClass(jni, handler), "setItem", "(Ljava/lang/String;[B)V"), (*jni)->NewStringUTF(jni, key), bytes);
+ (*jni)->CallObjectMethod(jni, handler, (*jni)->GetMethodID(jni, (*jni)->GetObjectClass(jni, handler), "setItem", "(Ljava/lang/String;[B)V"), (*jni)->NewStringUTF(jni, key), bytes);
+}
+
+void storage_clear(void* cptr) {
+ jobject handler = get_storage_handler(cptr);
+ if (!handler) return;
+
+ (*jni)->CallObjectMethod(jni, handler, (*jni)->GetMethodID(jni, (*jni)->GetObjectClass(jni, handler), "clear", "(V)B"));
}
JNIEXPORT void JNICALL Java_in3_IN3_initcache(JNIEnv* env, jobject ob) {
@@ -424,10 +433,10 @@ JNIEXPORT void JNICALL Java_in3_IN3_initcache(JNIEnv* env, jobject ob) {
/*
* Class: in3_IN3
- * Method: send
+ * Method: sendinternal
* Signature: (Ljava/lang/String;)Ljava/lang/String;
*/
-JNIEXPORT jstring JNICALL Java_in3_IN3_send(JNIEnv* env, jobject ob, jstring jreq) {
+JNIEXPORT jstring JNICALL Java_in3_IN3_sendinternal(JNIEnv* env, jobject ob, jstring jreq) {
jni = env;
const char* str = (*env)->GetStringUTFChars(env, jreq, 0);
@@ -502,7 +511,7 @@ static jobject toObject(JNIEnv* env, d_token_t* t) {
return (*env)->NewStringUTF(env, tmp);
}
case T_OBJECT: {
- clz = (*env)->FindClass(env, "in3/JSON");
+ clz = (*env)->FindClass(env, "in3/utils/JSON");
jobject map = (*env)->NewObject(env, clz, (*env)->GetMethodID(env, clz, "", "()V"));
jmethodID put = (*env)->GetMethodID(env, clz, "put", "(ILjava/lang/Object;)V");
for (d_iterator_t iter = d_iter(t); iter.left; d_iter_next(&iter))
@@ -518,7 +527,7 @@ static jobject toObject(JNIEnv* env, d_token_t* t) {
return NULL;
}
-JNIEXPORT jint JNICALL Java_in3_JSON_key(JNIEnv* env, jclass ob, jstring k) {
+JNIEXPORT jint JNICALL Java_in3_utils_JSON_key(JNIEnv* env, jclass ob, jstring k) {
jint val = 0;
const char* str = (*env)->GetStringUTFChars(env, k, 0);
val = key(str);
@@ -528,10 +537,10 @@ JNIEXPORT jint JNICALL Java_in3_JSON_key(JNIEnv* env, jclass ob, jstring k) {
/*
* Class: in3_IN3
- * Method: send
+ * Method: Java_in3_IN3_sendobjectinternal
* Signature: (Ljava/lang/String;)Ljava/lang/String;
*/
-JNIEXPORT jobject JNICALL Java_in3_IN3_sendobject(JNIEnv* env, jobject ob, jstring jreq) {
+JNIEXPORT jobject JNICALL Java_in3_IN3_sendobjectinternal(JNIEnv* env, jobject ob, jstring jreq) {
jni = env;
const char* str = (*env)->GetStringUTFChars(env, jreq, 0);
@@ -591,7 +600,8 @@ JNIEXPORT jobject JNICALL Java_in3_IN3_sendobject(JNIEnv* env, jobject ob, jstri
*/
JNIEXPORT void JNICALL Java_in3_IN3_free(JNIEnv* env, jobject ob) {
in3_t* in3 = get_in3(env, ob);
- if (in3->cache)
+ if (!in3) return;
+ if (in3->cache && in3->cache->cptr)
(*env)->DeleteGlobalRef(env, (jobject) in3->cache->cptr);
in3_free(in3);
@@ -775,7 +785,7 @@ in3_ret_t jsign(void* pk, d_signature_type_t type, bytes_t message, bytes_t acco
in3_ctx_t* ctx = (in3_ctx_t*) pk;
UNUSED_VAR(type);
jclass cls = (*jni)->GetObjectClass(jni, ctx->client->cache->cptr);
- jmethodID mid = (*jni)->GetMethodID(jni, cls, "getSigner", "()Lin3/Signer;");
+ jmethodID mid = (*jni)->GetMethodID(jni, cls, "getSigner", "()Lin3/utils/Signer;");
jobject signer = (*jni)->CallObjectMethod(jni, ctx->client->cache->cptr, mid);
if (!signer) return -1;
@@ -820,8 +830,8 @@ void in3_set_jclient_config(in3_t* c, jobject jclient) {
jproof = (*jni)->GetStaticFieldID(jni, jproofcls, "standard", "Lin3/Proof;");
}
- jobject enumVal = (jobject)(*jni)->GetStaticObjectField(jni, jproofcls, jproof);
- (*jni)->CallVoidMethod(jni, jclientconfigurationobj, set_proof_mid, enumVal);
+ jobject proofval = (jobject)(*jni)->GetStaticObjectField(jni, jproofcls, jproof);
+ (*jni)->CallVoidMethod(jni, jclientconfigurationobj, set_proof_mid, proofval);
jmethodID set_max_attempts_mid = (*jni)->GetMethodID(jni, jconfigclass, "setMaxAttempts", "(I)V");
(*jni)->CallVoidMethod(jni, jclientconfigurationobj, set_max_attempts_mid, (jint) c->max_attempts);
@@ -844,6 +854,9 @@ void in3_set_jclient_config(in3_t* c, jobject jclient) {
jmethodID set_use_http_mid = (*jni)->GetMethodID(jni, jconfigclass, "setUseHttp", "(Z)V");
(*jni)->CallVoidMethod(jni, jclientconfigurationobj, set_use_http_mid, (jboolean)(c->flags & FLAGS_HTTP) != 0);
+ jmethodID set_stats_mid = (*jni)->GetMethodID(jni, jconfigclass, "setStats", "(Z)V");
+ (*jni)->CallVoidMethod(jni, jclientconfigurationobj, set_stats_mid, (jboolean)(c->flags & FLAGS_STATS) != 0);
+
jmethodID set_max_code_cache_mid = (*jni)->GetMethodID(jni, jconfigclass, "setMaxCodeCache", "(J)V");
(*jni)->CallVoidMethod(jni, jclientconfigurationobj, set_max_code_cache_mid, (jlong) c->max_code_cache);
@@ -857,53 +870,49 @@ void in3_set_jclient_config(in3_t* c, jobject jclient) {
(*jni)->CallVoidMethod(jni, jclientconfigurationobj, set_node_props_mid, (jlong) c->request_count);
jmethodID set_node_limit_mid = (*jni)->GetMethodID(jni, jconfigclass, "setNodeLimit", "(J)V");
- (*jni)->CallVoidMethod(jni, jclientconfigurationobj, set_node_limit_mid, (jlong) c->node_props);
+ (*jni)->CallVoidMethod(jni, jclientconfigurationobj, set_node_limit_mid, (jlong) c->node_limit);
jmethodID set_replace_latest_block_mid = (*jni)->GetMethodID(jni, jconfigclass, "setReplaceLatestBlock", "(I)V");
(*jni)->CallVoidMethod(jni, jclientconfigurationobj, set_replace_latest_block_mid, (jint) c->replace_latest_block);
- // jmethodID set_rpc_mid = (*jni)->GetMethodID(jni, jconfigclass, "setRpc", "(Ljava/lang/String;)V;");
- // (*jni)->CallVoidMethod(jni, jclientconfigurationobj, set_rpc_mid, (jstring) c->request_count);
-
jmethodID set_max_block_cache_mid = (*jni)->GetMethodID(jni, jconfigclass, "setMaxBlockCache", "(J)V");
(*jni)->CallVoidMethod(jni, jclientconfigurationobj, set_max_block_cache_mid, (jlong) c->max_block_cache);
for (int i = 0; i < c->chains_length; i++) {
- char tmp[67] = {'0', 'x'};
- in3_chain_t chain = c->chains[i];
- jclass jnodeconfigclass = (*jni)->FindClass(jni, "in3/config/NodeConfiguration");
- jobject jnodeconfigobj = (*jni)->NewObject(jni, jnodeconfigclass, (*jni)->GetMethodID(jni, jnodeconfigclass, "", "(JLin3/config/ClientConfiguration;)V"), (jlong) chain.chain_id, jclientconfigurationobj);
+ char tmp[67] = {'0', 'x'};
+ in3_chain_t chain = c->chains[i];
+ jclass jchainclass = (*jni)->FindClass(jni, "in3/config/ChainConfiguration");
+ jobject jchainconfigobj = (*jni)->NewObject(jni, jchainclass, (*jni)->GetMethodID(jni, jchainclass, "", "(JLin3/config/ClientConfiguration;)V"), (jlong) chain.chain_id, jclientconfigurationobj);
- jmethodID set_needs_update_mid = (*jni)->GetMethodID(jni, jnodeconfigclass, "setNeedsUpdate", "(Z)V");
- (*jni)->CallVoidMethod(jni, jnodeconfigobj, set_needs_update_mid, (jboolean)(chain.nodelist_upd8_params != NULL));
+ jmethodID set_needs_update_mid = (*jni)->GetMethodID(jni, jchainclass, "setNeedsUpdate", "(Z)V");
+ (*jni)->CallVoidMethod(jni, jchainconfigobj, set_needs_update_mid, (jboolean)(chain.nodelist_upd8_params != NULL));
- jmethodID set_contract_mid = (*jni)->GetMethodID(jni, jnodeconfigclass, "setContract", "(Ljava/lang/String;)V");
+ jmethodID set_contract_mid = (*jni)->GetMethodID(jni, jchainclass, "setContract", "(Ljava/lang/String;)V");
bytes_to_hex(chain.contract->data, chain.contract->len, tmp + 2);
- (*jni)->CallVoidMethod(jni, jnodeconfigobj, set_contract_mid, (*jni)->NewStringUTF(jni, tmp));
+ (*jni)->CallVoidMethod(jni, jchainconfigobj, set_contract_mid, (*jni)->NewStringUTF(jni, tmp));
- jmethodID set_registry_id_mid = (*jni)->GetMethodID(jni, jnodeconfigclass, "setRegistryId", "(Ljava/lang/String;)V");
+ jmethodID set_registry_id_mid = (*jni)->GetMethodID(jni, jchainclass, "setRegistryId", "(Ljava/lang/String;)V");
bytes_to_hex(chain.registry_id, 32, tmp + 2);
- (*jni)->CallVoidMethod(jni, jnodeconfigobj, set_registry_id_mid, (*jni)->NewStringUTF(jni, tmp));
+ (*jni)->CallVoidMethod(jni, jchainconfigobj, set_registry_id_mid, (*jni)->NewStringUTF(jni, tmp));
- jclass jnodelistconfigclass = (*jni)->FindClass(jni, "in3/config/NodeListConfiguration");
+ jclass jnodeconfigclass = (*jni)->FindClass(jni, "in3/config/NodeConfiguration");
for (int i = 0; i < chain.nodelist_length; i++) {
- in3_node_t node = chain.nodelist[i];
-
- jobject jnodelistconfigobj = (*jni)->NewObject(jni, jnodelistconfigclass, (*jni)->GetMethodID(jni, jnodelistconfigclass, "", "(Lin3/config/NodeConfiguration;)V"), jnodeconfigobj);
- jmethodID set_address_mid = (*jni)->GetMethodID(jni, jnodelistconfigclass, "setAddress", "(Ljava/lang/String;)V");
+ in3_node_t node = chain.nodelist[i];
+ jobject jnodeconfigobj = (*jni)->NewObject(jni, jnodeconfigclass, (*jni)->GetMethodID(jni, jnodeconfigclass, "", "(Lin3/config/ChainConfiguration;)V"), jchainconfigobj);
+ jmethodID set_address_mid = (*jni)->GetMethodID(jni, jnodeconfigclass, "setAddress", "(Ljava/lang/String;)V");
bytes_to_hex(node.address->data, node.address->len, tmp + 2);
- (*jni)->CallVoidMethod(jni, jnodelistconfigobj, set_address_mid, (*jni)->NewStringUTF(jni, tmp));
- jmethodID set_url_mid = (*jni)->GetMethodID(jni, jnodelistconfigclass, "setUrl", "(Ljava/lang/String;)V");
- (*jni)->CallVoidMethod(jni, jnodelistconfigobj, set_url_mid, (*jni)->NewStringUTF(jni, node.url));
- jmethodID set_props_mid = (*jni)->GetMethodID(jni, jnodelistconfigclass, "setProps", "(J)V");
- (*jni)->CallVoidMethod(jni, jnodelistconfigobj, set_props_mid, (jlong) node.props);
+ (*jni)->CallVoidMethod(jni, jnodeconfigobj, set_address_mid, (*jni)->NewStringUTF(jni, tmp));
+ jmethodID set_url_mid = (*jni)->GetMethodID(jni, jnodeconfigclass, "setUrl", "(Ljava/lang/String;)V");
+ (*jni)->CallVoidMethod(jni, jnodeconfigobj, set_url_mid, (*jni)->NewStringUTF(jni, node.url));
+ jmethodID set_props_mid = (*jni)->GetMethodID(jni, jnodeconfigclass, "setProps", "(J)V");
+ (*jni)->CallVoidMethod(jni, jnodeconfigobj, set_props_mid, (jlong) node.props);
}
if (chain.whitelist) {
- jmethodID set_white_list_contract_mid = (*jni)->GetMethodID(jni, jnodeconfigclass, "setWhiteListContract", "(Ljava/lang/String;)V");
+ jmethodID set_white_list_contract_mid = (*jni)->GetMethodID(jni, jchainclass, "setWhiteListContract", "(Ljava/lang/String;)V");
bytes_to_hex(chain.whitelist->contract, 20, tmp + 2);
- (*jni)->CallVoidMethod(jni, jnodeconfigobj, set_white_list_contract_mid, (*jni)->NewStringUTF(jni, tmp));
+ (*jni)->CallVoidMethod(jni, jchainconfigobj, set_white_list_contract_mid, (*jni)->NewStringUTF(jni, tmp));
jobjectArray jwhitelist = (jobjectArray)(*jni)->NewObjectArray(
jni,
@@ -917,7 +926,7 @@ void in3_set_jclient_config(in3_t* c, jobject jclient) {
}
jmethodID set_white_list_mid = (*jni)->GetMethodID(jni, jconfigclass, "setWhiteList", "([Ljava/lang/String;)V");
- (*jni)->CallVoidMethod(jni, jnodeconfigobj, set_white_list_mid, jwhitelist);
+ (*jni)->CallVoidMethod(jni, jchainconfigobj, set_white_list_mid, jwhitelist);
}
}
@@ -942,12 +951,14 @@ JNIEXPORT jlong JNICALL Java_in3_IN3_init(JNIEnv* env, jobject ob, jlong jchain)
#endif
in3_t* in3 = in3_for_chain(jchain);
+ in3_register_eth_api();
in3_log_set_level(LOG_DEBUG);
in3->transport = Java_in3_IN3_transport;
in3->cache = _malloc(sizeof(in3_storage_handler_t));
in3->cache->cptr = (*env)->NewGlobalRef(env, ob);
in3->cache->get_item = storage_get_item;
in3->cache->set_item = storage_set_item;
+ in3->cache->clear = storage_clear;
in3->signer = _malloc(sizeof(in3_signer_t));
in3->signer->sign = jsign;
in3->signer->prepare_tx = NULL;
diff --git a/java/src/in3_jni.h b/java/src/in3_jni.h
index a976589cc..f04fed902 100644
--- a/java/src/in3_jni.h
+++ b/java/src/in3_jni.h
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -282,17 +282,17 @@ JNIEXPORT void JNICALL Java_in3_IN3_setStorageProvider(JNIEnv*, jobject, jobject
/*
* Class: in3_IN3
- * Method: send
+ * Method: sendinternal
* Signature: (Ljava/lang/String;)Ljava/lang/String;
*/
-JNIEXPORT jstring JNICALL Java_in3_IN3_send(JNIEnv*, jobject, jstring);
+JNIEXPORT jstring JNICALL Java_in3_IN3_sendinternal(JNIEnv*, jobject, jstring);
/*
* Class: in3_IN3
- * Method: sendobject
+ * Method: sendobjectinternal
* Signature: (Ljava/lang/String;)Ljava/lang/Object;
*/
-JNIEXPORT jobject JNICALL Java_in3_IN3_sendobject(JNIEnv*, jobject, jstring);
+JNIEXPORT jobject JNICALL Java_in3_IN3_sendobjectinternal(JNIEnv*, jobject, jstring);
/*
* Class: in3_IN3
@@ -330,7 +330,7 @@ extern "C" {
* Method: key
* Signature: (Ljava/lang/String;)I
*/
-JNIEXPORT jint JNICALL Java_in3_JSON_key(JNIEnv*, jclass, jstring);
+JNIEXPORT jint JNICALL Java_in3_utils_JSON_key(JNIEnv*, jclass, jstring);
#ifdef __cplusplus
}
diff --git a/java/test/build_test.gradle b/java/test/build_test.gradle
new file mode 100644
index 000000000..008f53157
--- /dev/null
+++ b/java/test/build_test.gradle
@@ -0,0 +1,71 @@
+/*
+ * This file was generated by the Gradle 'init' task.
+ *
+ * This generated file contains a sample Java project to get you started.
+ * For more details take a look at the Java Quickstart chapter in the Gradle
+ * User Manual available at https://docs.gradle.org/6.0.1/userguide/tutorial_java_projects.html
+ */
+
+/*
+ Need to change this because its generating garbage in the build directory... consider on using a custom nonjava pipeline
+ it is also kind of schizophrenic to have a standalone build system for running tests
+*/
+apply plugin: 'java'
+apply plugin: "eclipse"
+
+def jarSourceFolder = "../build/lib/in3.jar"
+def jarOutputFolder = "./target"
+
+test.dependsOn 'copyJarToBindings'
+
+task createLibDir {
+ mkdir jarOutputFolder
+}
+
+task copyJarToBindings(type: Copy) {
+ dependsOn 'createLibDir'
+ from jarSourceFolder
+ into jarOutputFolder
+}
+
+sourceSets {
+ main {
+ java {
+ srcDirs = [jarOutputFolder]
+ }
+ resources {
+ srcDirs = [jarOutputFolder]
+ }
+ }
+ test {
+ java {
+ srcDirs = ['./test']
+ }
+ resources {
+ srcDirs = ['./resources']
+ }
+ }
+}
+
+test {
+ testLogging {
+ outputs.upToDateWhen { false }
+ showStandardStreams = true
+ }
+ useJUnitPlatform()
+}
+
+repositories {
+ // Use jcenter for resolving dependencies.
+ // You can declare any Maven/Ivy/file repository here.
+ mavenCentral()
+}
+
+dependencies {
+ // Use JUnit test framework
+ // https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-engine
+ compile fileTree(include: ['*.jar'], dir: jarOutputFolder)
+ testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.6.0-RC1'
+ testImplementation 'org.json:json:20190722'
+ testImplementation 'commons-io:commons-io:2.6'
+}
diff --git a/java/test/in3/IN3MockBuilder.java b/java/test/in3/IN3MockBuilder.java
index e02868ad9..8e8b84794 100644
--- a/java/test/in3/IN3MockBuilder.java
+++ b/java/test/in3/IN3MockBuilder.java
@@ -1,59 +1,64 @@
package in3;
-import java.util.HashMap;
-
-import org.json.JSONObject;
-
+import in3.config.ChainConfiguration;
import in3.config.ClientConfiguration;
-import in3.config.NodeConfiguration;
public class IN3MockBuilder {
- IN3 client;
+ private IN3 client;
+ private long chainId;
- public void createNewClient() {
- client = IN3.forChain(Chain.GOERLI);
- }
+ public IN3MockBuilder(long chainId) {
+ this.chainId = chainId;
+ }
- public void buildTransport(String[][] fileNameTuples) {
- IN3MockTransport newtransport = new IN3MockTransport();
+ public void createNewClient() {
+ client = IN3.forChain(getChainId());
+ }
- // TODO Consider on using Apache Commons Pair
- for (String[] fileNameTuple: fileNameTuples) {
- newtransport.setMockResponse(fileNameTuple[0], fileNameTuple[1]);
- }
+ public void buildTransport(String[][] fileNameTuples) {
+ IN3MockTransport newtransport = new IN3MockTransport();
- client.setTransport(newtransport);
+ // TODO Consider on using Apache Commons Pair
+ for (String[] fileNameTuple : fileNameTuples) {
+ newtransport.setMockResponse(fileNameTuple[0], fileNameTuple[1]);
}
- public void buildConfig() {
- ClientConfiguration clientConfig = client.getConfig();
-
- NodeConfiguration nodeConfig1 = new NodeConfiguration(Chain.MAINNET, clientConfig);
- nodeConfig1.setNeedsUpdate(false);
- nodeConfig1.setContract("0xac1b824795e1eb1f6e609fe0da9b9af8beaab60f");
- nodeConfig1.setRegistryId("0x23d5345c5c13180a8080bd5ddbe7cde64683755dcce6e734d95b7b573845facb");
-
- NodeConfiguration nodeConfig2 = new NodeConfiguration(Chain.GOERLI, clientConfig);
- nodeConfig2.setNeedsUpdate(false);
- nodeConfig2.setContract("0xac1b824795e1eb1f6e609fe0da9b9af8beaab60f");
- nodeConfig2.setRegistryId("0x23d5345c5c13180a8080bd5ddbe7cde64683755dcce6e734d95b7b573845facb");
-
- NodeConfiguration nodeConfig3 = new NodeConfiguration(Chain.KOVAN, clientConfig);
- nodeConfig3.setNeedsUpdate(false);
- nodeConfig3.setContract("0xac1b824795e1eb1f6e609fe0da9b9af8beaab60f");
- nodeConfig3.setRegistryId("0x23d5345c5c13180a8080bd5ddbe7cde64683755dcce6e734d95b7b573845facb");
-
- clientConfig.setRequestCount(1);
- clientConfig.setAutoUpdateList(false);
- clientConfig.setProof(Proof.none);
- clientConfig.setMaxAttempts(1);
- clientConfig.setSignatureCount(0);
- }
+ client.setTransport(newtransport);
+ }
- public IN3 constructClient(String[][] fileNameTuples) {
- createNewClient();
- buildTransport(fileNameTuples);
- buildConfig();
- return client;
- }
+ public void buildConfig() {
+ ClientConfiguration clientConfig = client.getConfig();
+
+ ChainConfiguration nodeConfig1 = new ChainConfiguration(Chain.MAINNET, clientConfig);
+ nodeConfig1.setNeedsUpdate(false);
+ nodeConfig1.setContract("0xac1b824795e1eb1f6e609fe0da9b9af8beaab60f");
+ nodeConfig1.setRegistryId("0x23d5345c5c13180a8080bd5ddbe7cde64683755dcce6e734d95b7b573845facb");
+
+ ChainConfiguration nodeConfig2 = new ChainConfiguration(Chain.GOERLI, clientConfig);
+ nodeConfig2.setNeedsUpdate(false);
+ nodeConfig2.setContract("0xac1b824795e1eb1f6e609fe0da9b9af8beaab60f");
+ nodeConfig2.setRegistryId("0x23d5345c5c13180a8080bd5ddbe7cde64683755dcce6e734d95b7b573845facb");
+
+ ChainConfiguration nodeConfig3 = new ChainConfiguration(Chain.KOVAN, clientConfig);
+ nodeConfig3.setNeedsUpdate(false);
+ nodeConfig3.setContract("0xac1b824795e1eb1f6e609fe0da9b9af8beaab60f");
+ nodeConfig3.setRegistryId("0x23d5345c5c13180a8080bd5ddbe7cde64683755dcce6e734d95b7b573845facb");
+
+ clientConfig.setRequestCount(1);
+ clientConfig.setAutoUpdateList(false);
+ clientConfig.setProof(Proof.none);
+ clientConfig.setMaxAttempts(1);
+ clientConfig.setSignatureCount(0);
+ }
+
+ public IN3 constructClient(String[][] fileNameTuples) {
+ createNewClient();
+ buildTransport(fileNameTuples);
+ buildConfig();
+ return client;
+ }
+
+ private long getChainId() {
+ return chainId;
+ }
}
diff --git a/java/test/in3/IN3Mocktransport.java b/java/test/in3/IN3Mocktransport.java
index d8dcba6c6..bd7baeaea 100644
--- a/java/test/in3/IN3Mocktransport.java
+++ b/java/test/in3/IN3Mocktransport.java
@@ -1,90 +1,89 @@
package in3;
-import java.util.*;
import java.io.*;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
-
+import java.util.*;
import org.json.*;
class IN3MockTransport implements IN3Transport {
- private static final String PROPERTIES_FILENAME = "config.properties";
- private static final String RESPONSES_DIR = "responsesDir";
+ private static final String PROPERTIES_FILENAME = "config.properties";
+ private static final String RESPONSES_DIR = "responsesDir";
- private static final int FIRST_INDEX = 0;
- private static final String METHOD = "method";
+ private static final int FIRST_INDEX = 0;
+ private static final String METHOD = "method";
- public Map requestToResponse;
+ public Map requestToResponse;
- public IN3MockTransport() {
- requestToResponse = new HashMap();
- }
+ public IN3MockTransport() {
+ requestToResponse = new HashMap();
+ }
- @Override
- public byte[][] handle(String[] urls, byte[] payload) {
- byte[][] result = new byte[urls.length][];
- String methodName = this.getPayloadMethod(new String(payload));
+ @Override
+ public byte[][] handle(String[] urls, byte[] payload) {
+ byte[][] result = new byte[urls.length][];
+ String methodName = this.getPayloadMethod(new String(payload));
- if (!"".equals(methodName)) {
- for (int i = 0; i < urls.length; i++) {
- // Assumes a single payload to be requested to multiple nodes
- result[i] = requestToResponse.get(methodName);
- }
- }
-
- return result;
+ if (!"".equals(methodName)) {
+ for (int i = 0; i < urls.length; i++) {
+ // Assumes a single payload to be requested to multiple nodes
+ result[i] = requestToResponse.get(methodName);
+ }
}
- public void clearResponses() {
- requestToResponse.clear();
- }
+ return result;
+ }
- public void setMockResponse(String key, String fileName) {
- try {
- File folder = new File(getResponsesFolder());
- File mockFile = new File(folder, fileName);
- setMockResponseFromFile(key, mockFile);
- } catch (Throwable ignored) {
- }
- }
+ public void clearResponses() {
+ requestToResponse.clear();
+ }
- private String getPayloadMethod(String payload) {
- JSONArray arr = new JSONArray(payload);
- if (arr != null && arr.length() > 0) {
- return arr.getJSONObject(FIRST_INDEX).getString(METHOD);
- }
-
- return "";
- }
-
- private boolean setMockResponseFromFile(String key, File source) {
- try {
- if (source.isFile() && source.canRead()) {
- requestToResponse.put(key, this.getFileContents(source));
- return true;
- }
- } catch (IOException ignored) {
- }
- return false;
+ public void setMockResponse(String key, String fileName) {
+ try {
+ File folder = new File(getResponsesFolder());
+ File mockFile = new File(folder, fileName);
+ setMockResponseFromFile(key, mockFile);
+ } catch (Throwable ignored) {
}
+ }
- private URI getResponsesFolder() throws IOException, URISyntaxException {
- return this.getClass().getClassLoader().getResource(this.getProperty(RESPONSES_DIR)).toURI();
+ private String getPayloadMethod(String payload) {
+ JSONArray arr = new JSONArray(payload);
+ if (arr != null && arr.length() > 0) {
+ return arr.getJSONObject(FIRST_INDEX).getString(METHOD);
}
- private byte[] getFileContents(File file) throws IOException {
- return Files.readAllBytes(file.toPath());
- }
-
- private String getProperty(String key) throws IOException {
- Properties props = new Properties();
- props.load(this.getFileResource(PROPERTIES_FILENAME));
- return props.getProperty(key);
- }
+ return "";
+ }
- private InputStream getFileResource(String fileName) {
- return this.getClass().getClassLoader().getResourceAsStream(fileName);
+ private boolean setMockResponseFromFile(String key, File source) {
+ try {
+ if (source.isFile() && source.canRead()) {
+ requestToResponse.put(key, this.getFileContents(source));
+ return true;
+ }
+ } catch (IOException ignored) {
}
+ return false;
+ }
+
+ private URI getResponsesFolder() throws IOException, URISyntaxException {
+ return this.getClass().getClassLoader().getResource(this.getProperty(RESPONSES_DIR)).toURI();
+ }
+
+ private byte[] getFileContents(File file) throws IOException {
+ return Files.readAllBytes(file.toPath());
+ }
+
+ private String getProperty(String key) throws IOException {
+ Properties props = new Properties();
+ props.load(this.getFileResource(PROPERTIES_FILENAME));
+ return props.getProperty(key);
+ }
+
+ private InputStream getFileResource(String fileName) {
+ return this.getClass().getClassLoader().getResourceAsStream(fileName);
+ }
}
\ No newline at end of file
diff --git a/java/test/in3/IN3Test.java b/java/test/in3/IN3Test.java
new file mode 100644
index 000000000..ddd19a8f2
--- /dev/null
+++ b/java/test/in3/IN3Test.java
@@ -0,0 +1,91 @@
+package in3;
+
+import org.junit.jupiter.api.*;
+
+public class IN3Test {
+
+ private IN3 in3;
+
+ @BeforeEach
+ public void setBuilder() {
+ String[][] mockedResponses = {
+ {"eth_call", "eth_call_2.json"},
+ {"in3_nodeList", "in3_nodeList.json"},
+ {"in3_sign", "in3_sign.json"}};
+ IN3MockBuilder builder = new IN3MockBuilder(Chain.MAINNET);
+ in3 = builder.constructClient(mockedResponses);
+ }
+
+ @Test
+ public void nodeList() {
+ String url = "https://in3-v2.slock.it/mainnet/nd-1";
+ String address = "0x45d45e6ff99e6c34a235d263965910298985fcfe";
+ int index = 0;
+ String deposit = "0x2386f26fc10000";
+ long props = 0x06000001ddL;
+ int timeout = 3456000;
+ int registerTime = 1576224418;
+ int weight = 2000;
+
+ IN3Node[] list = in3.nodeList();
+
+ Assertions.assertTrue(list.length > 0);
+ Assertions.assertEquals(url, list[0].getUrl());
+ Assertions.assertEquals(address, list[0].getAddress());
+ Assertions.assertEquals(index, list[0].getIndex());
+ Assertions.assertEquals(deposit, list[0].getDeposit());
+ Assertions.assertEquals(props, list[0].getProps());
+ Assertions.assertEquals(timeout, list[0].getTimeout());
+ Assertions.assertEquals(registerTime, list[0].getRegisterTime());
+ Assertions.assertEquals(weight, list[0].getWeight());
+ }
+
+ @Test
+ public void cacheClear() {
+ // This test, for now is a lie.
+ boolean result = in3.cacheClear();
+ Assertions.assertTrue(result);
+ }
+
+ @Test
+ public void sign() {
+ BlockID[] vR = new BlockID[] {
+ BlockID.fromHash("0x2a8bf38abe3fec478a2029e74ac95ecdbef95ff2fb832786ba4c5231c8cea480")};
+ String[] address = new String[] {"0x1fe2e9bf29aa1938859af64c413361227d04059a"};
+ SignedBlockHash[] result = in3.sign(vR, address);
+ Assertions.assertEquals("0x2a8bf38abe3fec478a2029e74ac95ecdbef95ff2fb832786ba4c5231c8cea480", result[0].getBlockHash());
+ Assertions.assertEquals(9551793, result[0].getBlock());
+ Assertions.assertEquals("0x16cf7b94a7276532ceff4bf6fd50fd01f2c2962a5f0887c70c75943ce9e08b77", result[0].getR());
+ Assertions.assertEquals("0x01f51c90e7f3493acf3c5b4efbed63534711f6209b2c47c34074f4882b92feaa", result[0].getS());
+ Assertions.assertEquals(27, result[0].getV());
+ Assertions.assertEquals("0x0284928ef6fd270bacbfdba3087d0c50ad2db74af54c8bda8209b8ac9e41cfe1", result[0].getMsgHash());
+ }
+
+ @Test
+ public void getConfig() {
+ // This test may seem pointless but it intends to test the proper conversion of the jni getConfig to a valid String.
+ String configJson = in3.getConfig().toJSON();
+ Assertions.assertNotNull(configJson);
+ }
+
+ @Test
+ public void handleEns() {
+ String[] params = new String[] {
+ "cryptokitties.eth",
+ "0x0102030405060708090a0b0c0d0e0f",
+ "0xa8b8759ec8b59d7c13ef3630e8530f47ddb47eba12f00f9024d3d48247b62852"};
+
+ String[] expected = new String[] {
+ "0x06012c8cf97bead5deae237070f9587f8e7a266d",
+ "0x0102030405060708090a0b0c0d0e0f",
+ "0xa8b8759ec8b59d7c13ef3630e8530f47ddb47eba12f00f9024d3d48247b62852"};
+
+ String[] transformed = (String[]) in3.handleEns(params);
+ Assertions.assertArrayEquals(expected, transformed);
+ }
+
+ @Test
+ public void free() {
+ in3.free();
+ }
+}
diff --git a/java/test/in3/config/IN3ConfigTest.java b/java/test/in3/config/IN3ConfigTest.java
index 9166d39af..f6fc685ff 100644
--- a/java/test/in3/config/IN3ConfigTest.java
+++ b/java/test/in3/config/IN3ConfigTest.java
@@ -1,87 +1,87 @@
package in3.config;
+import in3.*;
+import in3.utils.JSON;
import org.json.JSONObject;
import org.junit.jupiter.api.*;
-import in3.*;
public class IN3ConfigTest {
- // This class is more akin to integrated tests since, as you can see, it relies on multiple Objects.
- private IN3 client;
-
- @BeforeEach
- public void createClient() {
- client = IN3.forChain(Chain.MAINNET);
- }
-
- @Test
- public void objectHierarchy() {
- final String nodeConfigOutputKey = "nodes";
- final String nodeListConfigOutputKey = "nodeList";
-
- ClientConfiguration clientConfig = client.getConfig();
-
- NodeConfiguration nodeConfig = new NodeConfiguration(Chain.GOERLI, clientConfig);
- nodeConfig.setNeedsUpdate(false);
- nodeConfig.setContract("0xac1b824795e1eb1f6e609fe0da9b9af8beaab60f");
- nodeConfig.setRegistryId("0x23d5345c5c13180a8080bd5ddbe7cde64683755dcce6e734d95b7b573845facb");
- nodeConfig.setContract("0xdd80249a0631cf0f1593c7a9c9f9b8545e6c88ab");
- nodeConfig.setWhiteListContract("0xdd80249a0631cf0f1593c7a9c9f9b8545e6c88ab");
-
- JSONObject jsonObject1 = new JSONObject(clientConfig.toJSON());
- Assertions.assertTrue(jsonObject1.has(nodeConfigOutputKey));
-
- NodeListConfiguration nodeListConfig = new NodeListConfiguration(nodeConfig);
- nodeListConfig.setProps(Long.valueOf(0x0));
- nodeListConfig.setUrl("scheme://userinfo@host:port/path?query#fragment");
- nodeListConfig.setAddress("0x0");
-
- JSONObject jsonObject2 = new JSONObject(clientConfig.toJSON());
- Assertions.assertTrue(
- jsonObject2
- .getJSONObject(nodeConfigOutputKey)
- .getJSONObject(JSON.asString(Chain.GOERLI))
- .has(nodeListConfigOutputKey));
- }
-
- @Test
- public void isSynced() {
- ClientConfiguration config = client.getConfig();
- Assertions.assertTrue(config.isSynced());
-
- int requestCount = 1;
- boolean autoUpdateList = false;
- Proof proof = Proof.none;
- int maxAttempts = 1;
- int signatureCount = 0;
-
- config.setRequestCount(requestCount);
- config.setAutoUpdateList(autoUpdateList);
- config.setProof(proof);
- config.setMaxAttempts(maxAttempts);
- config.setSignatureCount(signatureCount);
-
- Assertions.assertTrue(!config.isSynced());
- client.getEth1API().getChainId();
- Assertions.assertTrue(config.isSynced());
- }
-
- @Test
- public void dispatchRequestInvalidConfig() {
- ClientConfiguration config = client.getConfig();
-
- NodeConfiguration nodeConfig = new NodeConfiguration(Chain.GOERLI, config);
- nodeConfig.setNeedsUpdate(false);
- nodeConfig.setContract("0xac1b824795e1eb1f6e609fe0da9b9af8beaab60f");
- nodeConfig.setRegistryId("0x23d5345c5c13180a8080bd5ddbe7cde64683755dcce6e734d95b7b573845facb");
- nodeConfig.setContract("0xdd80249a0631cf0f1593c7a9c9f9b8545e6c88ab");
- nodeConfig.setWhiteListContract("0xdd80249a0631cf0f1593c7a9c9f9b8545e6c88ab");
- nodeConfig.setWhiteList(new String[] {
- "0x0123456789012345678901234567890123456789",
- "0x1234567890123456789012345678901234567890"
- });
-
- Assertions.assertThrows(IllegalArgumentException.class, () -> {
- client.getEth1API().getGasPrice();
- });
- }
+ // This class is more akin to integrated tests since, as you can see, it relies on multiple Objects.
+ private IN3 client;
+
+ @BeforeEach
+ public void createClient() {
+ client = IN3.forChain(Chain.MAINNET);
+ }
+
+ @Test
+ public void objectHierarchy() {
+ final String nodeConfigOutputKey = "nodes";
+ final String nodeListConfigOutputKey = "nodeList";
+
+ ClientConfiguration clientConfig = client.getConfig();
+
+ ChainConfiguration nodeConfig = new ChainConfiguration(Chain.GOERLI, clientConfig);
+ nodeConfig.setNeedsUpdate(false);
+ nodeConfig.setContract("0xac1b824795e1eb1f6e609fe0da9b9af8beaab60f");
+ nodeConfig.setRegistryId("0x23d5345c5c13180a8080bd5ddbe7cde64683755dcce6e734d95b7b573845facb");
+ nodeConfig.setContract("0xdd80249a0631cf0f1593c7a9c9f9b8545e6c88ab");
+ nodeConfig.setWhiteListContract("0xdd80249a0631cf0f1593c7a9c9f9b8545e6c88ab");
+
+ JSONObject jsonObject1 = new JSONObject(clientConfig.toJSON());
+ Assertions.assertTrue(jsonObject1.has(nodeConfigOutputKey));
+
+ NodeConfiguration nodeListConfig = new NodeConfiguration(nodeConfig);
+ nodeListConfig.setProps(Long.valueOf(0x0));
+ nodeListConfig.setUrl("scheme://userinfo@host:port/path?query#fragment");
+ nodeListConfig.setAddress("0x0");
+
+ JSONObject jsonObject2 = new JSONObject(clientConfig.toJSON());
+ Assertions.assertTrue(
+ jsonObject2
+ .getJSONObject(nodeConfigOutputKey)
+ .getJSONObject(JSON.asString(Chain.GOERLI))
+ .has(nodeListConfigOutputKey));
+ }
+
+ @Test
+ public void isSynced() {
+ ClientConfiguration config = client.getConfig();
+ Assertions.assertTrue(config.isSynced());
+
+ int requestCount = 1;
+ boolean autoUpdateList = false;
+ Proof proof = Proof.none;
+ int maxAttempts = 1;
+ int signatureCount = 0;
+
+ config.setRequestCount(requestCount);
+ config.setAutoUpdateList(autoUpdateList);
+ config.setProof(proof);
+ config.setMaxAttempts(maxAttempts);
+ config.setSignatureCount(signatureCount);
+
+ Assertions.assertTrue(!config.isSynced());
+ client.getEth1API().getChainId();
+ Assertions.assertTrue(config.isSynced());
+ }
+
+ @Test
+ public void dispatchRequestInvalidConfig() {
+ ClientConfiguration config = client.getConfig();
+
+ ChainConfiguration nodeConfig = new ChainConfiguration(Chain.GOERLI, config);
+ nodeConfig.setNeedsUpdate(false);
+ nodeConfig.setContract("0xac1b824795e1eb1f6e609fe0da9b9af8beaab60f");
+ nodeConfig.setRegistryId("0x23d5345c5c13180a8080bd5ddbe7cde64683755dcce6e734d95b7b573845facb");
+ nodeConfig.setContract("0xdd80249a0631cf0f1593c7a9c9f9b8545e6c88ab");
+ nodeConfig.setWhiteListContract("0xdd80249a0631cf0f1593c7a9c9f9b8545e6c88ab");
+ nodeConfig.setWhiteList(new String[] {
+ "0x0123456789012345678901234567890123456789",
+ "0x1234567890123456789012345678901234567890"});
+
+ Assertions.assertThrows(IllegalArgumentException.class, () -> {
+ client.getEth1API().getGasPrice();
+ });
+ }
}
diff --git a/java/test/in3/eth1/APITest.java b/java/test/in3/eth1/APITest.java
index a56f1158e..53de64d35 100644
--- a/java/test/in3/eth1/APITest.java
+++ b/java/test/in3/eth1/APITest.java
@@ -5,394 +5,430 @@
import org.junit.jupiter.api.*;
public class APITest {
- private static IN3MockBuilder builder;
-
- @BeforeAll
- public static void setBuilder() {
- builder = new IN3MockBuilder();
- }
-
- @Test
- public void call() {
- String[][] mockedResponses = { { "eth_call", "eth_call.json" } };
- IN3 in3 = builder.constructClient(mockedResponses);
-
- String to = "0x2736D225f85740f42D17987100dc8d58e9e16252";
- String function = "servers(uint256):(string,address,uint32,uint256,uint256,address)";
- Object[] params = new Object[] { 1 };
-
- TransactionRequest request = new TransactionRequest();
- request.setTo(to);
- request.setFunction(function);
- request.setParams(params);
-
- Object[] res1 = (Object[]) in3.getEth1API().call(request, Block.LATEST);
-
- Assertions.assertEquals(6, res1.length);
- Assertions.assertEquals("https://in3.slock.it/mainnet/nd-4", res1[0]);
- Assertions.assertEquals("0xbc0ea09c1651a3d5d40bacb4356fb59159a99564", res1[1]);
- Assertions.assertEquals("0xffff", res1[2]);
- Assertions.assertEquals("0xffff", res1[3]);
- }
-
- @Test
- public void setTransaction() {
- String[][] mockedResponses = { { "eth_gasPrice", "eth_gasPrice.json" },
- { "eth_estimateGas", "eth_estimateGas.json" },
- { "eth_getTransactionCount", "eth_getTransactionCount.json" },
- { "eth_sendRawTransaction", "eth_sendRawTransaction.json" } };
- IN3 in3 = builder.constructClient(mockedResponses);
-
- String pk = "0829B3C639A3A8F2226C8057F100128D4F7AE8102C92048BA6DE38CF4D3BC6F1";
- SimpleWallet wallet = new SimpleWallet();
- String from = wallet.addRawKey(pk);
- in3.setSigner(wallet);
-
- TransactionRequest request = new TransactionRequest();
- request.setFrom(from);
- request.setTo("0x3940256B93c4BE0B1d5931A6A036608c25706B0c");
- request.setGas(21000);
- request.setValue(new BigInteger("100000000"));
-
- String hash = in3.getEth1API().sendTransaction(request);
-
- // expect multiple calls here too
-
- Assertions.assertEquals("0xd5651b7c0b396c16ad9dc44ef0770aa215ca795702158395713facfbc9b55f38", hash);
- }
-
- @Test
- public void blockNumber() {
- String[][] mockedResponses = { { "eth_blockNumber", "eth_blockNumber.json" } };
- IN3 in3 = builder.constructClient(mockedResponses);
-
- long response = in3.getEth1API().getBlockNumber();
- Assertions.assertEquals(3220, response);
- }
-
- @Test
- public void getLogs() {
- String[][] mockedResponses = { { "eth_getLogs", "eth_getLogs.json" } };
- IN3 in3 = builder.constructClient(mockedResponses);
-
- LogFilter filter = new LogFilter();
- filter.setFromBlock(new BigInteger("834B77", 16).longValue());
- filter.setToBlock(new BigInteger("834B77", 16).longValue());
- filter.setAddress("0xdac17f958d2ee523a2206206994597c13d831ec7");
- Log[] response = in3.getEth1API().getLogs(filter);
-
- Assertions.assertEquals("0x20be6d27ed6a4c99c5dbeeb9081e114a9b400c52b80c4d10096c94ad7d3c1af6",
- response[0].getTransactionHash());
- }
-
- @Test
- public void getTransactionReceipt() {
- String[][] mockedResponses = { { "eth_getTransactionReceipt", "eth_getTransactionReceipt.json" } };
- IN3 in3 = builder.constructClient(mockedResponses);
-
- TransactionReceipt receipt = in3.getEth1API()
- .getTransactionReceipt("0x6188bf0672c005e30ad7c2542f2f048521662e30c91539d976408adf379bdae2");
- Assertions.assertEquals("0x5b8174e20996ec743f01d3b55a35dd376429c596", receipt.getTo());
- Assertions.assertTrue(receipt.getStatus());
- Assertions.assertEquals("0x5b8174e20996ec743f01d3b55a35dd376429c596", receipt.getLogs()[0].getAddress());
- }
-
- @Test
- public void getTransactionByHash() {
- String[][] mockedResponses = { { "eth_getTransactionByHash", "eth_getTransactionByHash.json" } };
- IN3 in3 = builder.constructClient(mockedResponses);
-
- Transaction tx = in3.getEth1API()
- .getTransactionByHash("0x6188bf0672c005e30ad7c2542f2f048521662e30c91539d976408adf379bdae2");
- Assertions.assertEquals("0x8220e66456e40636bff3a440832c9f179e4811d4e28269c7ab70142c3e5f9be2",
- tx.getBlockHash());
- Assertions.assertEquals("0x3a9e354dee60df25c0389badafec8457e36ebfd2", tx.getFrom());
- }
-
- @Test
- public void getBalance() {
- String[][] mockedResponses = { { "eth_getBalance", "eth_getBalance.json" } };
- IN3 in3 = builder.constructClient(mockedResponses);
-
- BigInteger balance = in3.getEth1API().getBalance("0x4144FFD5430a8518fa2d84ef5606Fd7e1921cE27", Block.LATEST);
- Assertions.assertEquals(new BigInteger("3646260000000000000"), balance);
- }
-
- @Test
- public void getCode() {
- String[][] mockedResponses = { { "eth_getCode", "eth_getCode.json" } };
- IN3 in3 = builder.constructClient(mockedResponses);
-
- String response = in3.getEth1API().getCode("0xdAC17F958D2ee523a2206206994597C13D831ec7", Block.LATEST);
- Assertions.assertNotNull(response);
-// Assertions.assertEquals(contractCode.codetest.result, response);
- }
-
- @Test
- public void getStorageAt() {
- String[][] mockedResponses = { { "eth_getStorageAt", "eth_getStorageAt.json" } };
- IN3 in3 = builder.constructClient(mockedResponses);
-
- String storage = in3.getEth1API().getStorageAt("0x862174623bc39e57de552538f424806b947d3d05",
- new BigInteger("0"), Block.LATEST);
- Assertions.assertEquals("0x0000000000000000000000000000000000000000000000000000000000000000", storage);
- }
-
- @Test
- public void getUncleCountByBlockNumber() {
- String[][] mockedResponses = { { "eth_getUncleCountByBlockNumber", "eth_getUncleCountByBlockNumber.json" } };
- IN3 in3 = builder.constructClient(mockedResponses);
-
- long count = in3.getEth1API().getUncleCountByBlockNumber(9280006);
- Assertions.assertEquals(2, count);
- }
-
- @Test
- public void getChainId() {
- // This might be worth testing since there are some integration issues that might arise from the java <-> c interop even if, at the end, this is just a fancy getter.
- String[][] mockedResponses = {};
- IN3 in3 = builder.constructClient(mockedResponses);
- Assertions.assertEquals("0x5", in3.getEth1API().getChainId());
- }
-
- @Test
- public void getBlockByNumber() {
- String[][] mockedResponses = { { "eth_getBlockByNumber", "eth_getBlockByNumber.json" } };
-
- IN3 in3 = builder.constructClient(mockedResponses);
- Block latest = in3.getEth1API().getBlockByNumber(Block.EARLIEST, true);
-
- Assertions.assertEquals(0, latest.getNumber());
- Assertions.assertEquals(540, latest.getSize());
- }
-
- @Test
- public void getBlockByHash() {
- String[][] mockedResponses = { { "eth_getBlockByHash", "eth_getBlockByHash.json" } };
-
- IN3 in3 = builder.constructClient(mockedResponses);
- Block latest = in3.getEth1API()
- .getBlockByHash("0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3", true);
- Assertions.assertEquals(0, latest.getNumber());
- Assertions.assertEquals(540, latest.getSize());
- }
-
- @Test
- public void getGasPrice() {
- String[][] mockedResponses = { { "eth_gasPrice", "eth_gasPrice.json" } };
-
- IN3 in3 = builder.constructClient(mockedResponses);
- long currentGasPrice = in3.getEth1API().getGasPrice();
- Assertions.assertEquals(2100000000, currentGasPrice);
- }
-
- @Test
- public void estimateGas() {
- String[][] mockedResponses = { { "eth_estimateGas", "eth_estimateGas.json" } };
-
- IN3 in3 = builder.constructClient(mockedResponses);
- String pk = "0829B3C639A3A8F2226C8057F100128D4F7AE8102C92048BA6DE38CF4D3BC6F1";
- SimpleWallet wallet = new SimpleWallet();
- String from = wallet.addRawKey(pk);
- in3.setSigner(wallet);
-
- TransactionRequest tx = new TransactionRequest();
- ;
- tx.setGasPrice(1);
- tx.setFrom(from);
- tx.setTo("0xEA674fdDe714fd979de3EdF0F56AA9716B898ec8");
-
- long gasEstimate = in3.getEth1API().estimateGas(tx, Block.LATEST);
- Assertions.assertEquals(21000, gasEstimate);
- }
-
- @Test
- public void getBlockTransactionCountByHash() {
- String[][] mockedResponses = {
- { "eth_getBlockTransactionCountByHash", "eth_getBlockTransactionCountByHash.json" } };
-
- IN3 in3 = builder.constructClient(mockedResponses);
- long transactionCount = in3.getEth1API()
- .getBlockTransactionCountByHash("0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3");
- Assertions.assertEquals(0, transactionCount);
- }
-
- @Test
- public void getBlockTransactionCountByNumber() {
- String[][] mockedResponses = {
- { "eth_getBlockTransactionCountByNumber", "eth_getBlockTransactionCountByNumber.json" } };
-
- IN3 in3 = builder.constructClient(mockedResponses);
-
- long transactionCount = in3.getEth1API().getBlockTransactionCountByNumber(9298869);
- Assertions.assertEquals(121, transactionCount);
- }
-
- @Test
- public void getTransactionByBlockHashAndIndex() {
- String[][] mockedResponses = {
- { "eth_getTransactionByBlockHashAndIndex", "eth_getTransactionByBlockHashAndIndex.json" } };
-
- IN3 in3 = builder.constructClient(mockedResponses);
- Transaction tx = in3.getEth1API().getTransactionByBlockHashAndIndex(
- "0xd03f4a0ce830ce568be08aa37bc0a72374e92da5b388e839b35f24a144a5085d", 1);
-
- Assertions.assertEquals(tx.getValue(), new BigInteger("48958690000000000"));
- }
-
- @Test
- public void getTransactionByBlockNumberAndIndex() {
- String[][] mockedResponses = {
- { "eth_getTransactionByBlockNumberAndIndex", "eth_getTransactionByBlockNumberAndIndex.json" } };
-
- IN3 in3 = builder.constructClient(mockedResponses);
- Transaction tx = in3.getEth1API().getTransactionByBlockNumberAndIndex(9319093, 1);
-
- Assertions.assertEquals(tx.getValue(), new BigInteger("48958690000000000"));
- Assertions.assertEquals(tx.getFrom(), "0xe3649077ce21a48caf34041e983b92e332e80fd9");
- }
-
- @Test
- public void getTransactionCount() {
- String[][] mockedResponses = { { "eth_getTransactionCount", "eth_getTransactionCount.json" } };
-
- String from = "0x7fc7032e731f5bcbd4843406945acaf917087fde";
- IN3 in3 = builder.constructClient(mockedResponses);
-
- BigInteger transactionCount = in3.getEth1API().getTransactionCount(from, Block.LATEST);
- Assertions.assertEquals(transactionCount, BigInteger.valueOf(19));
- }
-
- @Test
- public void getUncleByBlockNumberAndIndex() {
- String[][] mockedResponses = {
- { "eth_getUncleByBlockNumberAndIndex", "eth_getUncleByBlockNumberAndIndex.json" } };
-
- IN3 in3 = builder.constructClient(mockedResponses);
- Block uncle = in3.getEth1API().getUncleByBlockNumberAndIndex(9317999, 0);
-
- Assertions.assertEquals(9317998, uncle.getNumber());
- Assertions.assertEquals(37088, uncle.getSize());
- }
-
- @Test
- public void getUncleCountByBlockHash() {
- String[][] mockedResponses = { { "eth_getUncleCountByBlockHash", "eth_getUncleCountByBlockHash.json" } };
-
- IN3 in3 = builder.constructClient(mockedResponses);
- long uncleCount = in3.getEth1API()
- .getUncleCountByBlockHash("0x211389bcc4b2ccc1f19d7f8470b0ad0778f7027e4cdf45b1c64c78895b0bee19");
-
- Assertions.assertEquals(1, uncleCount);
- }
-
- @Test
- public void sendRawTransaction() {
- String[][] mockedResponses = { { "eth_sendRawTransaction", "eth_sendRawTransaction_1.json" } };
-
- IN3 in3 = builder.constructClient(mockedResponses);
- String rawTransaction = "0xf8671b8477359400825208943940256b93c4be0b1d5931a6a036608c25706b0c8405f5e100802da0278d2c010a59688fc12a55563d81239b1dc7e3d9c6a535b34600329b0c640ad8a03894daf8d7c25b56caec71b695c5f6b1b6fd903ecfa441b2c4e15fd1c72c54a9";
- String hash = in3.getEth1API().sendRawTransaction(rawTransaction);
-
-// expect multiple calls here too
- Assertions.assertEquals("0xd55a8b0cf4896ffbbb10b125bf20d89c8006f42cc327a9859c59ac54e439b388", hash);
- }
-
- @Test
- public void newBlockFilter() {
- String[][] mockedResponses = { { "eth_blockNumber", "eth_blockNumber_1.json" } };
- IN3 in3 = builder.constructClient(mockedResponses);
-
- long filterId = in3.getEth1API().newBlockFilter();
- Assertions.assertTrue(filterId > 0);
-
- // Given the same mock response, this should increment the filter_id
- long filterId2 = in3.getEth1API().newBlockFilter();
- Assertions.assertEquals(filterId + 1, filterId2);
- }
-
- @Test
- public void newLogFilter() {
- String[][] mockedResponses = { { "eth_blockNumber", "eth_blockNumber_1.json" } };
- IN3 in3 = builder.constructClient(mockedResponses);
-
- LogFilter filter = new LogFilter();
- filter.setAddress("0xF0AD5cAd05e10572EfcEB849f6Ff0c68f9700455");
-
- long filterId = in3.getEth1API().newLogFilter(filter);
- Assertions.assertTrue(filterId > 0);
-
-// Given the same mock response, this should increment the filter_id
- long filterId2 = in3.getEth1API().newLogFilter(filter);
- Assertions.assertEquals(filterId + 1, filterId2);
- }
-
- @Test
- public void uninstallFilter() {
- String[][] mockedResponses = { { "eth_blockNumber", "eth_blockNumber_1.json" } };
- IN3 in3 = builder.constructClient(mockedResponses);
-
- LogFilter filter = new LogFilter();
- filter.setAddress("0xF0AD5cAd05e10572EfcEB849f6Ff0c68f9700455");
- long filterId = in3.getEth1API().newLogFilter(filter);
-
- boolean success1 = in3.getEth1API().uninstallFilter(filterId);
- Assertions.assertTrue(success1);
- boolean success2 = in3.getEth1API().uninstallFilter(filterId);
- Assertions.assertTrue(!success2);
- }
-
- @Test
- public void getFilterLogs() {
- String[][] mockedResponses = { { "eth_blockNumber", "eth_blockNumber_2.json" },
- { "eth_getLogs", "eth_getLogs_1.json" } };
- IN3 in3 = builder.constructClient(mockedResponses);
-
- LogFilter filter = new LogFilter();
- filter.setAddress("0x1c81079b0752881f3231318a1355e21de26bbeb5");
- filter.setFromBlock(2050343);
-
- long filterId = in3.getEth1API().newLogFilter(filter);
-
- Log[] logs1 = in3.getEth1API().getFilterLogs(filterId);
- Assertions.assertTrue(logs1.length > 0);
- Log[] logs2 = in3.getEth1API().getFilterLogs(filterId);
- Assertions.assertTrue(logs2.length == 0);
- }
-
- @Test
- public void getFilterChangesFromLogs() {
- String[][] mockedResponses = { { "eth_blockNumber", "eth_blockNumber_2.json" },
- { "eth_getLogs", "eth_getLogs_1.json" } };
- IN3 in3 = builder.constructClient(mockedResponses);
-
- LogFilter filter = new LogFilter();
- filter.setAddress("0x1c81079b0752881f3231318a1355e21de26bbeb5");
- filter.setFromBlock(2050343);
-
- long filterId = in3.getEth1API().newLogFilter(filter);
-
- Log[] logs1 = in3.getEth1API().getFilterLogs(filterId);
- Assertions.assertTrue(logs1.length > 0);
- Log[] logs2 = in3.getEth1API().getFilterLogs(filterId);
- Assertions.assertTrue(logs2.length == 0);
- }
-
- @Test
- public void getFilterChangesFromBlocks() {
- String[][] mockedResponses1 = { { "eth_blockNumber", "eth_blockNumber_3.json" } };
-
- String[][] mockedResponses2 = { { "eth_blockNumber", "eth_blockNumber_4.json" },
- { "eth_getBlockByNumber", "eth_getBlockByNumber_1.json" } };
-
- IN3 in3 = builder.constructClient(mockedResponses1);
- long filterId = in3.getEth1API().newBlockFilter();
-
- // This actually changes the internal state of mock transport with the new requests (not the best since relies on a side-effect).
- builder.buildTransport(mockedResponses2);
-
- String[] hashList = in3.getEth1API().getFilterChangesFromBlocks(filterId);
- Assertions.assertArrayEquals(
- new String[] { "0x03b1815a066ba71eab8e6622afa3e596b80580c2b1056990199dd974db66337e" }, hashList);
- }
+ private static IN3MockBuilder builder;
+
+ @BeforeAll
+ public static void setBuilder() {
+ builder = new IN3MockBuilder(Chain.MAINNET);
+ }
+
+ @Test
+ public void call() {
+ String[][] mockedResponses = {{"eth_call", "eth_call_1.json"}};
+ IN3 in3 = builder.constructClient(mockedResponses);
+
+ String to = "0x2736D225f85740f42D17987100dc8d58e9e16252";
+ String function = "servers(uint256):(string,address,uint32,uint256,uint256,address)";
+ Object[] params = new Object[] {1};
+
+ TransactionRequest request = new TransactionRequest();
+ request.setTo(to);
+ request.setFunction(function);
+ request.setParams(params);
+
+ Object[] res1 = (Object[]) in3.getEth1API().call(request, Block.LATEST);
+
+ Assertions.assertEquals(6, res1.length);
+ Assertions.assertEquals("https://in3.slock.it/mainnet/nd-4", res1[0]);
+ Assertions.assertEquals("0xbc0ea09c1651a3d5d40bacb4356fb59159a99564", res1[1]);
+ Assertions.assertEquals("0xffff", res1[2]);
+ Assertions.assertEquals("0xffff", res1[3]);
+ }
+
+ @Test
+ public void setTransaction() {
+ String[][] mockedResponses = {{"eth_gasPrice", "eth_gasPrice.json"},
+ {"eth_estimateGas", "eth_estimateGas.json"},
+ {"eth_getTransactionCount", "eth_getTransactionCount.json"},
+ {"eth_sendRawTransaction", "eth_sendRawTransaction.json"}};
+ IN3 in3 = builder.constructClient(mockedResponses);
+
+ String pk = "0829B3C639A3A8F2226C8057F100128D4F7AE8102C92048BA6DE38CF4D3BC6F1";
+ SimpleWallet wallet = new SimpleWallet();
+ String from = wallet.addRawKey(pk);
+ in3.setSigner(wallet);
+
+ TransactionRequest request = new TransactionRequest();
+ request.setFrom(from);
+ request.setTo("0x3940256B93c4BE0B1d5931A6A036608c25706B0c");
+ request.setGas(21000);
+ request.setValue(new BigInteger("100000000"));
+
+ String hash = in3.getEth1API().sendTransaction(request);
+
+ // expect multiple calls here too
+
+ Assertions.assertEquals("0xd5651b7c0b396c16ad9dc44ef0770aa215ca795702158395713facfbc9b55f38", hash);
+ }
+
+ @Test
+ public void blockNumber() {
+ String[][] mockedResponses = {{"eth_blockNumber", "eth_blockNumber.json"}};
+ IN3 in3 = builder.constructClient(mockedResponses);
+
+ long response = in3.getEth1API().getBlockNumber();
+ Assertions.assertEquals(3220, response);
+ }
+
+ @Test
+ public void getLogs() {
+ String[][] mockedResponses = {{"eth_getLogs", "eth_getLogs.json"}};
+ IN3 in3 = builder.constructClient(mockedResponses);
+
+ LogFilter filter = new LogFilter();
+ filter.setFromBlock(new BigInteger("834B77", 16).longValue());
+ filter.setToBlock(new BigInteger("834B77", 16).longValue());
+ filter.setAddress("0xdac17f958d2ee523a2206206994597c13d831ec7");
+ Log[] response = in3.getEth1API().getLogs(filter);
+
+ Assertions.assertEquals("0x20be6d27ed6a4c99c5dbeeb9081e114a9b400c52b80c4d10096c94ad7d3c1af6",
+ response[0].getTransactionHash());
+ }
+
+ @Test
+ public void getTransactionReceipt() {
+ String[][] mockedResponses = {{"eth_getTransactionReceipt", "eth_getTransactionReceipt.json"}};
+ IN3 in3 = builder.constructClient(mockedResponses);
+
+ TransactionReceipt receipt = in3.getEth1API()
+ .getTransactionReceipt("0x6188bf0672c005e30ad7c2542f2f048521662e30c91539d976408adf379bdae2");
+ Assertions.assertEquals("0x5b8174e20996ec743f01d3b55a35dd376429c596", receipt.getTo());
+ Assertions.assertTrue(receipt.getStatus());
+ Assertions.assertEquals("0x5b8174e20996ec743f01d3b55a35dd376429c596", receipt.getLogs()[0].getAddress());
+ }
+
+ @Test
+ public void getTransactionByHash() {
+ String[][] mockedResponses = {{"eth_getTransactionByHash", "eth_getTransactionByHash.json"}};
+ IN3 in3 = builder.constructClient(mockedResponses);
+
+ Transaction tx = in3.getEth1API()
+ .getTransactionByHash("0x6188bf0672c005e30ad7c2542f2f048521662e30c91539d976408adf379bdae2");
+ Assertions.assertEquals("0x8220e66456e40636bff3a440832c9f179e4811d4e28269c7ab70142c3e5f9be2",
+ tx.getBlockHash());
+ Assertions.assertEquals("0x3a9e354dee60df25c0389badafec8457e36ebfd2", tx.getFrom());
+ }
+
+ @Test
+ public void getBalance() {
+ String[][] mockedResponses = {{"eth_getBalance", "eth_getBalance.json"}};
+ IN3 in3 = builder.constructClient(mockedResponses);
+
+ BigInteger balance = in3.getEth1API().getBalance("0x4144FFD5430a8518fa2d84ef5606Fd7e1921cE27", Block.LATEST);
+ Assertions.assertEquals(new BigInteger("3646260000000000000"), balance);
+ }
+
+ @Test
+ public void getCode() {
+ String[][] mockedResponses = {{"eth_getCode", "eth_getCode.json"}};
+ IN3 in3 = builder.constructClient(mockedResponses);
+
+ String response = in3.getEth1API().getCode("0xdAC17F958D2ee523a2206206994597C13D831ec7", Block.LATEST);
+ Assertions.assertNotNull(response);
+ // Assertions.assertEquals(contractCode.codetest.result, response);
+ }
+
+ @Test
+ public void getStorageAt() {
+ String[][] mockedResponses = {{"eth_getStorageAt", "eth_getStorageAt.json"}};
+ IN3 in3 = builder.constructClient(mockedResponses);
+
+ String storage = in3.getEth1API().getStorageAt("0x862174623bc39e57de552538f424806b947d3d05",
+ new BigInteger("0"), Block.LATEST);
+ Assertions.assertEquals("0x0000000000000000000000000000000000000000000000000000000000000000", storage);
+ }
+
+ @Test
+ public void getUncleCountByBlockNumber() {
+ String[][] mockedResponses = {{"eth_getUncleCountByBlockNumber", "eth_getUncleCountByBlockNumber.json"}};
+ IN3 in3 = builder.constructClient(mockedResponses);
+
+ long count = in3.getEth1API().getUncleCountByBlockNumber(9280006);
+ Assertions.assertEquals(2, count);
+ }
+
+ @Test
+ public void getChainId() {
+ // This might be worth testing since there are some integration issues that might arise from the java <-> c interop even if, at the end, this is just a fancy getter.
+ String[][] mockedResponses = {};
+ IN3 in3 = builder.constructClient(mockedResponses);
+ Assertions.assertEquals("0x1", in3.getEth1API().getChainId());
+ }
+
+ @Test
+ public void getBlockByNumber() {
+ String[][] mockedResponses = {{"eth_getBlockByNumber", "eth_getBlockByNumber.json"}};
+
+ IN3 in3 = builder.constructClient(mockedResponses);
+ Block latest = in3.getEth1API().getBlockByNumber(Block.EARLIEST, true);
+
+ Assertions.assertEquals(0, latest.getNumber());
+ Assertions.assertEquals(540, latest.getSize());
+ }
+
+ @Test
+ public void getBlockByHash() {
+ String[][] mockedResponses = {{"eth_getBlockByHash", "eth_getBlockByHash.json"}};
+
+ IN3 in3 = builder.constructClient(mockedResponses);
+ Block latest = in3.getEth1API()
+ .getBlockByHash("0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3", true);
+ Assertions.assertEquals(0, latest.getNumber());
+ Assertions.assertEquals(540, latest.getSize());
+ }
+
+ @Test
+ public void getGasPrice() {
+ String[][] mockedResponses = {{"eth_gasPrice", "eth_gasPrice.json"}};
+
+ IN3 in3 = builder.constructClient(mockedResponses);
+ long currentGasPrice = in3.getEth1API().getGasPrice();
+ Assertions.assertEquals(2100000000, currentGasPrice);
+ }
+
+ @Test
+ public void estimateGas() {
+ String[][] mockedResponses = {{"eth_estimateGas", "eth_estimateGas.json"}};
+
+ IN3 in3 = builder.constructClient(mockedResponses);
+ String pk = "0829B3C639A3A8F2226C8057F100128D4F7AE8102C92048BA6DE38CF4D3BC6F1";
+ SimpleWallet wallet = new SimpleWallet();
+ String from = wallet.addRawKey(pk);
+ in3.setSigner(wallet);
+
+ TransactionRequest tx = new TransactionRequest();
+ ;
+ tx.setGasPrice(1);
+ tx.setFrom(from);
+ tx.setTo("0xEA674fdDe714fd979de3EdF0F56AA9716B898ec8");
+
+ long gasEstimate = in3.getEth1API().estimateGas(tx, Block.LATEST);
+ Assertions.assertEquals(21000, gasEstimate);
+ }
+
+ @Test
+ public void getBlockTransactionCountByHash() {
+ String[][] mockedResponses = {
+ {"eth_getBlockTransactionCountByHash", "eth_getBlockTransactionCountByHash.json"}};
+
+ IN3 in3 = builder.constructClient(mockedResponses);
+ long transactionCount = in3.getEth1API()
+ .getBlockTransactionCountByHash("0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3");
+ Assertions.assertEquals(0, transactionCount);
+ }
+
+ @Test
+ public void getBlockTransactionCountByNumber() {
+ String[][] mockedResponses = {
+ {"eth_getBlockTransactionCountByNumber", "eth_getBlockTransactionCountByNumber.json"}};
+
+ IN3 in3 = builder.constructClient(mockedResponses);
+
+ long transactionCount = in3.getEth1API().getBlockTransactionCountByNumber(9298869);
+ Assertions.assertEquals(121, transactionCount);
+ }
+
+ @Test
+ public void getTransactionByBlockHashAndIndex() {
+ String[][] mockedResponses = {
+ {"eth_getTransactionByBlockHashAndIndex", "eth_getTransactionByBlockHashAndIndex.json"}};
+
+ IN3 in3 = builder.constructClient(mockedResponses);
+ Transaction tx = in3.getEth1API().getTransactionByBlockHashAndIndex(
+ "0xd03f4a0ce830ce568be08aa37bc0a72374e92da5b388e839b35f24a144a5085d", 1);
+
+ Assertions.assertEquals(tx.getValue(), new BigInteger("48958690000000000"));
+ }
+
+ @Test
+ public void getTransactionByBlockNumberAndIndex() {
+ String[][] mockedResponses = {
+ {"eth_getTransactionByBlockNumberAndIndex", "eth_getTransactionByBlockNumberAndIndex.json"}};
+
+ IN3 in3 = builder.constructClient(mockedResponses);
+ Transaction tx = in3.getEth1API().getTransactionByBlockNumberAndIndex(9319093, 1);
+
+ Assertions.assertEquals(tx.getValue(), new BigInteger("48958690000000000"));
+ Assertions.assertEquals(tx.getFrom(), "0xe3649077ce21a48caf34041e983b92e332e80fd9");
+ }
+
+ @Test
+ public void getTransactionCount() {
+ String[][] mockedResponses = {{"eth_getTransactionCount", "eth_getTransactionCount.json"}};
+
+ String from = "0x7fc7032e731f5bcbd4843406945acaf917087fde";
+ IN3 in3 = builder.constructClient(mockedResponses);
+
+ BigInteger transactionCount = in3.getEth1API().getTransactionCount(from, Block.LATEST);
+ Assertions.assertEquals(transactionCount, BigInteger.valueOf(19));
+ }
+
+ @Test
+ public void getUncleByBlockNumberAndIndex() {
+ String[][] mockedResponses = {
+ {"eth_getUncleByBlockNumberAndIndex", "eth_getUncleByBlockNumberAndIndex.json"}};
+
+ IN3 in3 = builder.constructClient(mockedResponses);
+ Block uncle = in3.getEth1API().getUncleByBlockNumberAndIndex(9317999, 0);
+
+ Assertions.assertEquals(9317998, uncle.getNumber());
+ Assertions.assertEquals(37088, uncle.getSize());
+ }
+
+ @Test
+ public void getUncleCountByBlockHash() {
+ String[][] mockedResponses = {{"eth_getUncleCountByBlockHash", "eth_getUncleCountByBlockHash.json"}};
+
+ IN3 in3 = builder.constructClient(mockedResponses);
+ long uncleCount = in3.getEth1API()
+ .getUncleCountByBlockHash("0x211389bcc4b2ccc1f19d7f8470b0ad0778f7027e4cdf45b1c64c78895b0bee19");
+
+ Assertions.assertEquals(1, uncleCount);
+ }
+
+ @Test
+ public void sendRawTransaction() {
+ String[][] mockedResponses = {{"eth_sendRawTransaction", "eth_sendRawTransaction_1.json"}};
+
+ IN3 in3 = builder.constructClient(mockedResponses);
+ String rawTransaction = "0xf8671b8477359400825208943940256b93c4be0b1d5931a6a036608c25706b0c8405f5e100802da0278d2c010a59688fc12a55563d81239b1dc7e3d9c6a535b34600329b0c640ad8a03894daf8d7c25b56caec71b695c5f6b1b6fd903ecfa441b2c4e15fd1c72c54a9";
+ String hash = in3.getEth1API().sendRawTransaction(rawTransaction);
+
+ // expect multiple calls here too
+ Assertions.assertEquals("0xd55a8b0cf4896ffbbb10b125bf20d89c8006f42cc327a9859c59ac54e439b388", hash);
+ }
+
+ @Test
+ public void newBlockFilter() {
+ String[][] mockedResponses = {{"eth_blockNumber", "eth_blockNumber_1.json"}};
+ IN3 in3 = builder.constructClient(mockedResponses);
+
+ long filterId = in3.getEth1API().newBlockFilter();
+ Assertions.assertTrue(filterId > 0);
+
+ // Given the same mock response, this should increment the filter_id
+ long filterId2 = in3.getEth1API().newBlockFilter();
+ Assertions.assertEquals(filterId + 1, filterId2);
+ }
+
+ @Test
+ public void newLogFilter() {
+ String[][] mockedResponses = {{"eth_blockNumber", "eth_blockNumber_1.json"}};
+ IN3 in3 = builder.constructClient(mockedResponses);
+
+ LogFilter filter = new LogFilter();
+ filter.setAddress("0xF0AD5cAd05e10572EfcEB849f6Ff0c68f9700455");
+
+ long filterId = in3.getEth1API().newLogFilter(filter);
+ Assertions.assertTrue(filterId > 0);
+
+ // Given the same mock response, this should increment the filter_id
+ long filterId2 = in3.getEth1API().newLogFilter(filter);
+ Assertions.assertEquals(filterId + 1, filterId2);
+ }
+
+ @Test
+ public void uninstallFilter() {
+ String[][] mockedResponses = {{"eth_blockNumber", "eth_blockNumber_1.json"}};
+ IN3 in3 = builder.constructClient(mockedResponses);
+
+ LogFilter filter = new LogFilter();
+ filter.setAddress("0xF0AD5cAd05e10572EfcEB849f6Ff0c68f9700455");
+ long filterId = in3.getEth1API().newLogFilter(filter);
+
+ boolean success1 = in3.getEth1API().uninstallFilter(filterId);
+ Assertions.assertTrue(success1);
+ boolean success2 = in3.getEth1API().uninstallFilter(filterId);
+ Assertions.assertTrue(!success2);
+ }
+
+ @Test
+ public void getFilterLogs() {
+ String[][] mockedResponses = {{"eth_blockNumber", "eth_blockNumber_2.json"},
+ {"eth_getLogs", "eth_getLogs_1.json"}};
+ IN3 in3 = builder.constructClient(mockedResponses);
+
+ LogFilter filter = new LogFilter();
+ filter.setAddress("0x1c81079b0752881f3231318a1355e21de26bbeb5");
+ filter.setFromBlock(2050343);
+
+ long filterId = in3.getEth1API().newLogFilter(filter);
+
+ Log[] logs1 = in3.getEth1API().getFilterLogs(filterId);
+ Assertions.assertTrue(logs1.length > 0);
+ Log[] logs2 = in3.getEth1API().getFilterLogs(filterId);
+ Assertions.assertTrue(logs2.length == 0);
+ }
+
+ @Test
+ public void getFilterChangesFromLogs() {
+ String[][] mockedResponses = {{"eth_blockNumber", "eth_blockNumber_2.json"},
+ {"eth_getLogs", "eth_getLogs_1.json"}};
+ IN3 in3 = builder.constructClient(mockedResponses);
+
+ LogFilter filter = new LogFilter();
+ filter.setAddress("0x1c81079b0752881f3231318a1355e21de26bbeb5");
+ filter.setFromBlock(2050343);
+
+ long filterId = in3.getEth1API().newLogFilter(filter);
+
+ Log[] logs1 = in3.getEth1API().getFilterLogs(filterId);
+ Assertions.assertTrue(logs1.length > 0);
+ Log[] logs2 = in3.getEth1API().getFilterLogs(filterId);
+ Assertions.assertTrue(logs2.length == 0);
+ }
+
+ @Test
+ public void getFilterChangesFromBlocks() {
+ String[][] mockedResponses1 = {{"eth_blockNumber", "eth_blockNumber_3.json"}};
+
+ String[][] mockedResponses2 = {{"eth_blockNumber", "eth_blockNumber_4.json"},
+ {"eth_getBlockByNumber", "eth_getBlockByNumber_1.json"}};
+
+ IN3 in3 = builder.constructClient(mockedResponses1);
+ long filterId = in3.getEth1API().newBlockFilter();
+
+ // This actually changes the internal state of mock transport with the new requests (not the best since relies on a side-effect).
+ builder.buildTransport(mockedResponses2);
+
+ String[] hashList = in3.getEth1API().getFilterChangesFromBlocks(filterId);
+ Assertions.assertArrayEquals(
+ new String[] {"0x03b1815a066ba71eab8e6622afa3e596b80580c2b1056990199dd974db66337e"}, hashList);
+ }
+
+ @Test
+ public void abiEncode() {
+ IN3 in3 = builder.constructClient(new String[][] {});
+ String signature = "getBalance(address)";
+ String[] params = new String[] {"0x1234567890123456789012345678901234567890"};
+ String expected = "0xf8b2cb4f0000000000000000000000001234567890123456789012345678901234567890";
+ String result = in3.getEth1API().abiEncode(signature, params);
+ Assertions.assertEquals(expected, result);
+ }
+
+ @Test
+ public void abiDecode() {
+ IN3 in3 = builder.constructClient(new String[][] {});
+ String signature = "(address,uint256)";
+ String encoded = "0x00000000000000000000000012345678901234567890123456789012345678900000000000000000000000000000000000000000000000000000000000000005";
+ String[] expectedDecode = new String[] {"0x1234567890123456789012345678901234567890", "0x5"};
+ String[] result = in3.getEth1API().abiDecode(signature, encoded);
+ Assertions.assertArrayEquals(expectedDecode, result);
+ }
+
+ @Test
+ public void checkSumAddress() {
+ IN3 in3 = builder.constructClient(new String[][] {});
+ String address = "0xBc0ea09C1651A3D5D40Bacb4356FB59159A99564";
+ String result = in3.getEth1API().checksumAddress("0xbc0ea09c1651a3d5d40bacb4356fb59159a99564");
+ Assertions.assertEquals(address, result);
+ }
+
+ @Test
+ public void ens() {
+ IN3 in3 = builder.constructClient(new String[][] {
+ {"eth_call", "eth_call_2.json"}});
+ String result = in3.getEth1API().ens("cryptokitties.eth");
+ Assertions.assertEquals("0x06012c8cf97bead5deae237070f9587f8e7a266d", result);
+ }
}
diff --git a/java/test/in3/eth1/SimpleWalletTest.java b/java/test/in3/eth1/SimpleWalletTest.java
index d72ebc7d9..94f6f98c0 100644
--- a/java/test/in3/eth1/SimpleWalletTest.java
+++ b/java/test/in3/eth1/SimpleWalletTest.java
@@ -1,27 +1,37 @@
package in3.eth1;
+import in3.eth1.SimpleWallet;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
-import in3.eth1.SimpleWallet;
-
public class SimpleWalletTest {
- private SimpleWallet wallet;
-
- @BeforeEach
- public void setupSigner() {
- wallet = new SimpleWallet();
- }
-
- @Test
- public void sign() {
- String pk = "0x889dbed9450f7a4b68e0732ccb7cd016dab158e6946d16158f2736fda1143ca6";
- String address = wallet.addRawKey(pk);
-
- Assertions.assertEquals(address, "0x082977959d0C5A1bA627720ac753Ec2ADB5Bd7d0".toLowerCase());
- Assertions.assertEquals(
- wallet.sign("1e194c68360307cfb715bf17878791ad1ced8da7d2e5f42b691074c577f41eac", address),
- "0xf16dcaa830a3f710e28444df7df85fa927d8a66f789196fc2a3b934c829dbcaa5329be0711daba3b0c85ab23f1adb32c4e88fd8cb42b951d3be40af1bbd92e7400");
- }
+ private SimpleWallet wallet;
+
+ @BeforeEach
+ public void setupSigner() {
+ wallet = new SimpleWallet();
+ }
+
+ @Test
+ public void sign() {
+ String pk = "0x889dbed9450f7a4b68e0732ccb7cd016dab158e6946d16158f2736fda1143ca6";
+ String address = wallet.addRawKey(pk);
+
+ Assertions.assertEquals(address, "0x082977959d0C5A1bA627720ac753Ec2ADB5Bd7d0".toLowerCase());
+ Assertions.assertEquals(
+ wallet.sign("1e194c68360307cfb715bf17878791ad1ced8da7d2e5f42b691074c577f41eac", address),
+ "0xf16dcaa830a3f710e28444df7df85fa927d8a66f789196fc2a3b934c829dbcaa5329be0711daba3b0c85ab23f1adb32c4e88fd8cb42b951d3be40af1bbd92e7400");
+ }
+
+ @Test
+ public void canSign() {
+ String pk = "0x889dbed9450f7a4b68e0732ccb7cd016dab158e6946d16158f2736fda1143ca6";
+ String address = wallet.addRawKey(pk);
+
+ String anotherAddress = "0x06012c8cf97BEaD5deAe237070F9587f8E7A266d";
+
+ Assertions.assertTrue(wallet.canSign(address));
+ Assertions.assertFalse(wallet.canSign(anotherAddress));
+ }
}
diff --git a/java/test/in3/utils/CryptoTest.java b/java/test/in3/utils/CryptoTest.java
new file mode 100644
index 000000000..889bb9b38
--- /dev/null
+++ b/java/test/in3/utils/CryptoTest.java
@@ -0,0 +1,64 @@
+package in3.utils;
+
+import in3.Chain;
+import in3.IN3;
+import in3.IN3MockBuilder;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+class CryptoTest {
+
+ private static IN3 in3;
+
+ @BeforeAll
+ public static void setBuilder() {
+ String[][] mockedResponses = {};
+ IN3MockBuilder builder = new IN3MockBuilder(Chain.MAINNET);
+ in3 = builder.constructClient(mockedResponses);
+ }
+
+ @Test
+ public void signData() {
+ String msg = "0x0102030405060708090a0b0c0d0e0f";
+ String key = "0xa8b8759ec8b59d7c13ef3630e8530f47ddb47eba12f00f9024d3d48247b62852";
+ Signature signature = in3.getCrypto().signData(msg, key, SignatureType.raw);
+
+ Assertions.assertEquals(signature.getMessage(), "0x0102030405060708090a0b0c0d0e0f");
+ Assertions.assertEquals(signature.getMessageHash(), "0x1d4f6fccf1e27711667605e29b6f15adfda262e5aedfc5db904feea2baa75e67");
+ Assertions.assertEquals(signature.getSignature(), "0xa5dea9537d27e4e20b6dfc89fa4b3bc4babe9a2375d64fb32a2eab04559e95792264ad1fb83be70c145aec69045da7986b95ee957fb9c5b6d315daa5c0c3e1521b");
+ Assertions.assertEquals(signature.getR(), "0xa5dea9537d27e4e20b6dfc89fa4b3bc4babe9a2375d64fb32a2eab04559e9579");
+ Assertions.assertEquals(signature.getS(), "0x2264ad1fb83be70c145aec69045da7986b95ee957fb9c5b6d315daa5c0c3e152");
+ Assertions.assertEquals(signature.getV(), 27);
+ }
+
+ @Test
+ public void decryptKey() {
+ String key = "{\"version\": 3,\"id\": \"f6b5c0b1-ba7a-4b67-9086-a01ea54ec638\",\"address\": \"08aa30739030f362a8dd597fd3fcde283e36f4a1\",\"crypto\": {\"ciphertext\": \"d5c5aafdee81d25bb5ac4048c8c6954dd50c595ee918f120f5a2066951ef992d\",\"cipherparams\": {\"iv\": \"415440d2b1d6811d5c8a3f4c92c73f49\"},\"cipher\": \"aes-128-ctr\",\"kdf\": \"pbkdf2\",\"kdfparams\": {\"dklen\": 32,\"salt\": \"691e9ad0da2b44404f65e0a60cf6aabe3e92d2c23b7410fd187eeeb2c1de4a0d\",\"c\": 16384,\"prf\": \"hmac-sha256\"},\"mac\": \"de651c04fc67fd552002b4235fa23ab2178d3a500caa7070b554168e73359610\"}}";
+ String passphrase = "test";
+ String result = in3.getCrypto().decryptKey(key, passphrase);
+ Assertions.assertEquals("0x1ff25594a5e12c1e31ebd8112bdf107d217c1393da8dc7fc9d57696263457546", result);
+ }
+
+ @Test
+ public void pk2address() {
+ String result = in3.getCrypto().pk2address("0x0fd65f7da55d811634495754f27ab318a3309e8b4b8a978a50c20a661117435a");
+ Assertions.assertEquals("0xdc5c4280d8a286f0f9c8f7f55a5a0c67125efcfd", result);
+ }
+
+ @Test
+ public void pk2public() {
+ String result = in3.getCrypto().pk2public("0x0fd65f7da55d811634495754f27ab318a3309e8b4b8a978a50c20a661117435a");
+ Assertions.assertEquals("0x0903329708d9380aca47b02f3955800179e18bffbb29be3a644593c5f87e4c7fa960983f78186577eccc909cec71cb5763acd92ef4c74e5fa3c43f3a172c6de1", result);
+ }
+
+ @Test
+ public void ecrecover() {
+ String msg = "0x487b2cbb7997e45b4e9771d14c336b47c87dc2424b11590e32b3a8b9ab327999";
+ String signature = "0x0f804ff891e97e8a1c35a2ebafc5e7f129a630a70787fb86ad5aec0758d98c7b454dee5564310d497ddfe814839c8babd3a727692be40330b5b41e7693a445b71c";
+ Account result = in3.getCrypto().ecrecover(msg, signature, SignatureType.hash);
+
+ Assertions.assertEquals("0x94b26bafa6406d7b636fbb4de4edd62a2654eeecda9505e9a478a66c4f42e504c4481bad171e5ba6f15a5f11c26acfc620f802c6768b603dbcbe5151355bbffb", result.getPublicKey());
+ Assertions.assertEquals("0xf68a4703314e9a9cf65be688bd6d9b3b34594ab4", result.getAddress());
+ }
+}
\ No newline at end of file
diff --git a/scripts/build_clang9.sh b/scripts/build_clang9.sh
index 0bac55788..be4125621 100755
--- a/scripts/build_clang9.sh
+++ b/scripts/build_clang9.sh
@@ -4,5 +4,5 @@ docker run \
--rm \
-v $(pwd):/src \
docker.slock.it/build-images/cmake:clang9 \
- /bin/bash -c "cd /src; rm -rf build; mkdir build; cd build; cmake -DCMAKE_BUILD_TYPE=MINSIZEREL -DIN3_SERVER=true .. && make -j8"
+ /bin/bash -c "cd /src; rm -rf build; mkdir build; cd build; cmake -DCMAKE_BUILD_TYPE=MINSIZEREL -DIN3_SERVER=true .. && cmake --graphviz=graph . && make -j8"
cd scripts
diff --git a/scripts/build_pkg_size.sh b/scripts/build_pkg_size.sh
new file mode 100755
index 000000000..00235b3bb
--- /dev/null
+++ b/scripts/build_pkg_size.sh
@@ -0,0 +1,31 @@
+#!/bin/bash
+cd ..
+mkdir -p build
+cd build
+rm -rf *
+key="$1"
+case $key in
+ -s|--size)
+ in3size="$2"
+ case $in3size in
+ nano)
+ echo "nano"
+ cmake -DCMAKE_BUILD_TYPE=MINSIZEREL -DIN3_MATH_LITE=true -DIN3_LIB=false -DIN3_NANO=true -DETH_BASIC=false -DETH_FULL=false -DIN3_SERVER=true -DPOA=false .. && make -j8
+ ;;
+ basic)
+ echo "basic"
+ cmake -DCMAKE_BUILD_TYPE=MINSIZEREL -DIN3_MATH_LITE=true -DIN3_LIB=false -DIN3_NANO=false -DETH_BASIC=true -DETH_FULL=false -DIN3_SERVER=true -DPOA=false .. && make -j8
+ ;;
+ full)
+ echo "full"
+ cmake -DCMAKE_BUILD_TYPE=MINSIZEREL -DIN3_MATH_LITE=true -DETH_FULL=true -DIN3_SERVER=true -DPOA=false .. && make -j8
+ ;;
+ esac
+ ;;
+ -h|--help)
+ echo 'Usage: %s ...
+ -s, --size compilation size for in3 . (nano, basic, full)
+ -h, --help usage help'
+ ;;
+esac
+cd ../scripts
\ No newline at end of file
diff --git a/scripts/build_wasm.sh b/scripts/build_wasm.sh
index f6c2dc660..a629f7774 100755
--- a/scripts/build_wasm.sh
+++ b/scripts/build_wasm.sh
@@ -4,6 +4,6 @@ docker run \
--rm \
-v $(pwd):$(pwd) \
docker.slock.it/build-images/cmake:clang10 \
- /bin/bash -c "cd /$(pwd)/build; emconfigure cmake -DWASM=true -DASMJS=false -DWASM_EMMALLOC=true -DWASM_EMBED=false -DTRANSPORTS=false -DBUILD_DOC=false -DIN3API=true -DIN3_LIB=false -DCMD=false -DUSE_CURL=false -DCMAKE_BUILD_TYPE=DEBUG .. && make -j8 in3w"
+ /bin/bash -c "cd /$(pwd)/build; emconfigure cmake -DWASM=true -DASMJS=false -DWASM_EMMALLOC=true -DWASM_EMBED=true -DTRANSPORTS=false -DBUILD_DOC=false -DIN3API=true -DIN3_LIB=false -DCMD=false -DUSE_CURL=false -DCMAKE_BUILD_TYPE=DEBUG .. && make -j8 in3w"
cd scripts
diff --git a/scripts/format_all.sh b/scripts/format_all.sh
new file mode 100755
index 000000000..8e676bb3c
--- /dev/null
+++ b/scripts/format_all.sh
@@ -0,0 +1,6 @@
+#!/bin/sh
+cd ..
+docker run --rm -v $(pwd):$(pwd) docker.slock.it/build-images/cmake:clang10 /bin/bash -c \
+"cd $PWD; find c/src/core/ c/src/cmd/ c/src/api/ c/src/verifier/ c/src/transport/ java \\( -name \"*.c\" -o -name \"*.h\" -o -name \"*.java\" \\) | xargs clang-format -i"
+
+cd scripts
diff --git a/wasm/README.md b/wasm/README.md
index 0fd345b0a..a673c88f6 100644
--- a/wasm/README.md
+++ b/wasm/README.md
@@ -29,7 +29,6 @@ import * as web3 from 'web3'
const IN3Client c = new IN3Client({
proof : 'standard',
signatureCount : 1,
- requestCount : 2,
chainId : 'mainnet',
replaceLatestBlock : 10
})
@@ -62,7 +61,6 @@ import In3Client from 'in3-wasm'
const in3 = new In3Client({
proof : 'standard',
signatureCount : 1,
- requestCount : 2,
chainId : 'mainnet',
replaceLatestBlock : 10
})
diff --git a/wasm/src/CMakeLists.txt b/wasm/src/CMakeLists.txt
index b9ad7783a..bdef7240c 100644
--- a/wasm/src/CMakeLists.txt
+++ b/wasm/src/CMakeLists.txt
@@ -2,7 +2,7 @@
# This file is part of the Incubed project.
# Sources: https://github.com/slockit/in3-c
#
-# Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+# Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
#
#
# COMMERCIAL LICENSE USAGE
diff --git a/wasm/src/in3.d.ts b/wasm/src/in3.d.ts
index 6b810fce7..3c3c85ec6 100644
--- a/wasm/src/in3.d.ts
+++ b/wasm/src/in3.d.ts
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -762,7 +762,7 @@ export declare interface Signer {
prepareTransaction?: (client: IN3Generic, tx: Transaction) => Promise
/** returns true if the account is supported (or unlocked) */
- hasAccount(account: Address): Promise
+ canSign(address: Address): Promise
/**
* signing of any data.
@@ -995,7 +995,7 @@ export declare class SimpleSigner implements Signer, tx: Transaction) => Promise
/** returns true if the account is supported (or unlocked) */
- hasAccount(account: Address): Promise
+ canSign(address: Address): Promise
/**
* signing of any data.
diff --git a/wasm/src/in3.js b/wasm/src/in3.js
index b79e40c25..43d658d30 100644
--- a/wasm/src/in3.js
+++ b/wasm/src/in3.js
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -251,7 +251,7 @@ class IN3 {
try {
const [message, account] = Array.isArray(req.payload) ? req.payload[0].params : req.payload.params;
if (!this.signer) throw new Error('no signer set to handle signing')
- if (!(await this.signer.hasAccount(account))) throw new Error('unknown account ' + account)
+ if (!(await this.signer.canSign(account))) throw new Error('unknown account ' + account)
setResponse(toHex(await this.signer.sign(message, account, true, false)), 0, false)
} catch (ex) {
setResponse(ex.message || ex, 0, true)
diff --git a/wasm/src/in3_eth_api.js b/wasm/src/in3_eth_api.js
index 974bc3e93..6f25db108 100644
--- a/wasm/src/in3_eth_api.js
+++ b/wasm/src/in3_eth_api.js
@@ -305,7 +305,7 @@ class EthAPI {
if (account && account.length == 66) // use direct pk
s.signature = toHex(ecSign(account, s.messageHash, false))
- else if (this.client.signer && await this.client.signer.hasAccount(account)) // use signer
+ else if (this.client.signer && await this.client.signer.canSign(account)) // use signer
s.signature = toHex(await this.client.signer.sign(s.messageHash, account, false, true))
else throw new Error('no signer found to sign for this account')
return { ...splitSignature(s.signature, message, false), ...s, messageHash: toHex(s.messageHash) }
@@ -313,7 +313,7 @@ class EthAPI {
/** sends a Transaction */
async sendTransaction(args) {
- if (!args.pk && (!this.client.signer || !(await this.client.signer.hasAccount(args.from)))) throw new Error('missing signer!')
+ if (!args.pk && (!this.client.signer || !(await this.client.signer.canSign(args.from)))) throw new Error('missing signer!')
// prepare
const tx = await prepareTransaction(args, this)
diff --git a/wasm/src/in3_util.js b/wasm/src/in3_util.js
index e8b4f6877..23cb764c1 100644
--- a/wasm/src/in3_util.js
+++ b/wasm/src/in3_util.js
@@ -408,12 +408,12 @@ class SimpleSigner {
}
- async hasAccount(account) {
- return !!this.accounts[toChecksumAddress(account)]
+ async canSign(address) {
+ return !!this.accounts[toChecksumAddress(address)]
}
async sign(data, account, type, ethV = true) {
- const pk = this.accounts[toChecksumAddress(account)]
+ const pk = this.accounts[toChecksumAddress(account)]
if (!pk || pk.length != 32) throw new Error('Account not found for signing ' + account)
return ecSign(pk, data, type, ethV)
diff --git a/wasm/src/wasm.c b/wasm/src/wasm.c
index 8452c1c5b..47a211fee 100644
--- a/wasm/src/wasm.c
+++ b/wasm/src/wasm.c
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3-c
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/wasm/test/benchmarks.js b/wasm/test/benchmarks.js
index cdc831162..b2545aacc 100644
--- a/wasm/test/benchmarks.js
+++ b/wasm/test/benchmarks.js
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/wasm/test/package.json b/wasm/test/package.json
index 12b70acde..adb1b0dee 100644
--- a/wasm/test/package.json
+++ b/wasm/test/package.json
@@ -6,6 +6,7 @@
"scripts": {
"build": "tsc -p .",
"test": "mocha --timeout 15000 --full-trace testRunner.js testApi.js testUtil.js",
+ "test_report": "mocha --timeout 15000 --reporter mocha-junit-reporter --reporter-options mochaFile=mocha.xml --full-trace testRunner.js testApi.js testUtil.js",
"test_api": "mocha --inspect-brk --timeout 15000 --full-trace testApi.js",
"test_fail": "mocha --timeout 15000 --full-trace testApi.js testRunner.js ",
"test_all": "mocha --timeout 15000 --full-trace *.js",
@@ -41,6 +42,7 @@
"chai": "^4.1.2",
"handlebars": ">=4.1.2",
"mocha": "^5.1.1",
+ "mocha-junit-reporter": "^1.23.3",
"nyc": "^11.8.0",
"source-map-support": "^0.5.6"
},
@@ -58,4 +60,4 @@
"client",
"jsonrpc"
]
-}
\ No newline at end of file
+}
diff --git a/wasm/test/testApi.js b/wasm/test/testApi.js
index 9ec241eae..7fb018efa 100644
--- a/wasm/test/testApi.js
+++ b/wasm/test/testApi.js
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
@@ -151,7 +151,7 @@ describe('API-Tests', () => {
it('getStorageAt', async () => {
mockResponse('eth_getStorageAt', 'storage')
- const res = await createClient().eth.getStorageAt("0x862174623bc39e57de552538f424806b947d3d05","0x0")
+ const res = await createClient().eth.getStorageAt("0x862174623bc39e57de552538f424806b947d3d05", "0x0")
assert.equal(res, "0x0")
})
diff --git a/wasm/test/testRunner.js b/wasm/test/testRunner.js
index acdd875d5..8a18c217b 100644
--- a/wasm/test/testRunner.js
+++ b/wasm/test/testRunner.js
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE
diff --git a/wasm/test/testUtil.js b/wasm/test/testUtil.js
index 5ab5d9deb..cbdc7269a 100644
--- a/wasm/test/testUtil.js
+++ b/wasm/test/testUtil.js
@@ -2,7 +2,7 @@
* This file is part of the Incubed project.
* Sources: https://github.com/slockit/in3
*
- * Copyright (C) 2018-2019 slock.it GmbH, Blockchains LLC
+ * Copyright (C) 2018-2020 slock.it GmbH, Blockchains LLC
*
*
* COMMERCIAL LICENSE USAGE