Skip to content

Commit

Permalink
Merge branch 'master-2.0' into dev-2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
kyonRay committed Apr 25, 2024
2 parents d86103e + ecbcfe0 commit 4f6c702
Show file tree
Hide file tree
Showing 89 changed files with 6,659 additions and 413 deletions.
6 changes: 4 additions & 2 deletions .ci/ci_check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ download_tassl()
download_build_chain()
{
LOG_INFO "--- current tag: $tag"
# curl -LO "https://github.com/FISCO-BCOS/FISCO-BCOS/releases/download/${tag}/build_chain.sh" && chmod u+x build_chain.sh
curl -LO "https://raw.githubusercontent.com/FISCO-BCOS/FISCO-BCOS/master-2.0/tools/build_chain.sh" && chmod u+x build_chain.sh
curl -LO "https://github.com/FISCO-BCOS/FISCO-BCOS/releases/download/${tag}/build_chain.sh" && chmod u+x build_chain.sh
# curl -LO "https://raw.githubusercontent.com/FISCO-BCOS/FISCO-BCOS/master-2.0/tools/build_chain.sh" && chmod u+x build_chain.sh
}

get_sed_cmd()
Expand Down Expand Up @@ -112,6 +112,8 @@ check_sm_node()
## clean
clean_node
}
LOG_INFO "------ java version-------"
java -version
LOG_INFO "------ download_tassl---------"
download_tassl
LOG_INFO "------ download_build_chain---------"
Expand Down
13 changes: 10 additions & 3 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,25 @@ jobs:
build:
name: build
runs-on: ${{ matrix.os }}
continue-on-error: true
strategy:
fail-fast: false
matrix:
os: [ubuntu-18.04, ubuntu-20.04, macos-latest]
os: [ubuntu-20.04, ubuntu-22.04, macos-latest]
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 5
- name: install macOS dependencies
if: runner.os == 'macOS'
run: brew install [email protected] openjdk
run: brew install [email protected]
- name: install Ubuntu dependencies
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt install -y git curl libssl-dev default-jdk build-essential
run: sudo apt-get update && sudo apt install -y git curl libssl-dev build-essential
- name: Set up JDK 1.8
uses: actions/setup-java@v3
with:
distribution: 'zulu'
java-version: '8.0.345'
- name: run integration testing
run: /bin/bash .ci/ci_check.sh
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ gmsm2.param
integrationTestEnv.sh
gradle.properties
gpg.gpg
.DS_Store

49 changes: 49 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,52 @@
## v2.10.1

(2024-04-25)

请参考文档:

* [英文版用户手册](https://fisco-bcos-documentation.readthedocs.io/en/latest/docs/sdk/java_sdk/index.html)
* [中文版用户手册](https://fisco-bcos-documentation.readthedocs.io/zh_CN/latest/docs/sdk/java_sdk/index.html#)
* [中文版WIKI](https://github.com/FISCO-BCOS/java-sdk/wiki)

新增:

- 新增启动配置fisco.netty.enable.openssl.provider,置为true时使用openssl provider,置为false时使用JDK provider。

更新:

- Java SDK不再强依赖tcnative,解决在部分环境下无法加载tcnative的问题。
- 非国密环境下默认采用JDK的provider模式建立ssl连接。需要能提供给更高性能的openssl provider时,可以通过开关切换。

修复:

- 修复部分场景不能配置相对路径的问题。

## v2.10.0

(2024-03-08)

请参考文档:

* [英文版用户手册](https://fisco-bcos-documentation.readthedocs.io/en/latest/docs/sdk/java_sdk/index.html)
* [中文版用户手册](https://fisco-bcos-documentation.readthedocs.io/zh_CN/latest/docs/sdk/java_sdk/index.html#)
* [中文版WIKI](https://github.com/FISCO-BCOS/java-sdk/wiki)

修复:

- 解决在使用Solidity复杂数据结构(如struct,二维数组等)、复杂事件场景(如重载event,有复杂数据结构参数)时,Java SDK在发交易/调用请求时出现的编解码错误;
- 修复了读取密钥时可能存在的安全问题;

更新:

- 废弃 `sdk-codegen` 模块,合约生成Java文件的功能建议开发者使用`org.fisco-bcos.code-generator:bcos-code-generator`中的方法。以解决在使用Solidity复杂数据结构、复杂事件场景时,生成的Java文件出现编译、运行错误的问题;
- 依赖变更:
- `org.apache.commons:commons-lang3` 更新到3.14.0版本
- `org.bouncycastle:bcprov-jdk15on` 变更为使用`org.bouncycastle:bcprov-jdk18on:1.77`版本
- `io.netty:netty-all` 更新到 4.1.100.Final版本
- `com.google.code.gson:gson` 更新到 2.10.1版本
- `com.webank:webank-blockchain-java-crypto` 更新到1.0.3版本
- 删除不必要的`com.google.guava:guava`

## v2.9.2

(2022-10-31)
Expand Down
40 changes: 24 additions & 16 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,27 @@ ext {
ossrhPassword="xxx"
}
// jackson version
jacksonVersion = "2.13.4.2"
commonsIOVersion = "2.4"
commonsLang3Version = "3.1"
jacksonVersion = "2.15.4"
commonsIOVersion = '2.7'
commonsLang3Version = '3.14.0'
javapoetVersion = "1.7.0"
picocliVersion = "3.6.0"
nettySMSSLContextVersion = "1.5.0"
nettySMSSLContextVersion = "1.5.2"
toml4jVersion = "0.7.2"
bcprovJDK15onVersion = "1.60"
webankJavaCryptoVersion = "1.0.2"
bcprovJDK18onVersion = '1.77'
webankJavaCryptoVersion = '1.0.3'
webankHsmCryptoVersion = "1.0.0-GMT0018"

slf4jVersion = "1.7.32"
junitVersion = "4.12"
gsonVersion = '2.10.1'
slf4jVersion = "1.7.36"
junitVersion = '4.13.1'
commonsCollections4Version = "4.4"
guavaVersion = "29.0-jre"
}

// check.dependsOn integrationTest
// integrationTest.mustRunAfter test
allprojects {
group = 'org.fisco-bcos.java-sdk'
version = '2.9.2'
version = '2.10.1-SNAPSHOT'
apply plugin: 'maven'
apply plugin: 'maven-publish'
apply plugin: 'idea'
Expand Down Expand Up @@ -189,18 +188,27 @@ task integrationTest(type: Test) {
}

dependencies {
compile ("org.bouncycastle:bcprov-jdk15on:${bcprovJDK15onVersion}")
compile ("org.bouncycastle:bcprov-jdk18on:${bcprovJDK18onVersion}")
compile ("org.apache.commons:commons-lang3:${commonsLang3Version}")
compile ("org.fisco-bcos:netty-sm-ssl-context:${nettySMSSLContextVersion}")
compile ("org.fisco-bcos:netty-sm-ssl-context:${nettySMSSLContextVersion}"){
exclude group: "org.bouncycastle"
}
compile ('io.netty:netty-all:4.1.100.Final')
compile ("com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}")
compile ("commons-io:commons-io:${commonsIOVersion}")
compile ("com.squareup:javapoet:${javapoetVersion}")
compile ("info.picocli:picocli:${picocliVersion}")
compile ("com.webank:webank-blockchain-java-crypto:${webankJavaCryptoVersion}")
compile ("com.moandjiezana.toml:toml4j:${toml4jVersion}")
compile ("com.webank:webank-blockchain-hsm-crypto:${webankHsmCryptoVersion}")
compile ("com.google.code.gson:gson:${gsonVersion}")
compile ("com.moandjiezana.toml:toml4j:${toml4jVersion}"){
exclude group: "com.google.code.gson"
}
compile ("com.webank:webank-blockchain-hsm-crypto:${webankHsmCryptoVersion}") {
exclude group: "junit", module: "junit"
}
testCompile ("org.apache.commons:commons-collections4:${commonsCollections4Version}")
testCompile ("com.google.guava:guava:${guavaVersion}")
testImplementation('io.netty:netty-all:4.1.100.Final')
integrationTestImplementation('io.netty:netty-all:4.1.100.Final')
}

javadoc {
Expand Down
21 changes: 14 additions & 7 deletions sdk-abi/src/main/java/org/fisco/bcos/sdk/abi/ABICodec.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ public ABICodec(CryptoSuite cryptoSuite) {
abiDefinitionFactory = new ABIDefinitionFactory(cryptoSuite);
}

public ABICodec(CryptoSuite cryptoSuite, boolean decodeBytesDataAsHexFormat) {
super();
this.cryptoSuite = cryptoSuite;
abiDefinitionFactory = new ABIDefinitionFactory(cryptoSuite);
abiCodecJsonWrapper.setDecodeBytesDataAsHexFormat(decodeBytesDataAsHexFormat);
logger.info("decodeBytesDataAsHexFormat: {}", decodeBytesDataAsHexFormat);
}

private boolean decodeBytesDataAsHexFormat = false;

public boolean isDecodeBytesDataAsHexFormat() {
return decodeBytesDataAsHexFormat;
}

public CryptoSuite getCryptoSuite() {
return cryptoSuite;
}
Expand Down Expand Up @@ -202,7 +216,6 @@ public String encodeMethodFromString(String ABI, String methodName, List<String>
for (ABIDefinition abiDefinition : methods) {
if (abiDefinition.getInputs().size() == params.size()) {
ABIObject inputABIObject = abiObjectFactory.createInputObject(abiDefinition);
ABICodecJsonWrapper abiCodecJsonWrapper = new ABICodecJsonWrapper();
try {
String methodId = abiDefinition.getMethodId(cryptoSuite);
return methodId + abiCodecJsonWrapper.encode(inputABIObject, params).encode();
Expand All @@ -228,7 +241,6 @@ public String encodeMethodByIdFromString(String ABI, String methodId, List<Strin
throw new ABICodecException(errorMsg);
}
ABIObject inputABIObject = abiObjectFactory.createInputObject(abiDefinition);
ABICodecJsonWrapper abiCodecJsonWrapper = new ABICodecJsonWrapper();
try {
return methodId + abiCodecJsonWrapper.encode(inputABIObject, params).encode();
} catch (IOException e) {
Expand All @@ -247,7 +259,6 @@ public String encodeMethodByInterfaceFromString(String methodInterface, List<Str
if (abiDefinition.getInputs().size() == params.size()) {
@SuppressWarnings("static-access")
ABIObject inputABIObject = abiObjectFactory.createInputObject(abiDefinition);
ABICodecJsonWrapper abiCodecJsonWrapper = new ABICodecJsonWrapper();
try {
String methodId = abiDefinition.getMethodId(cryptoSuite);
return methodId + abiCodecJsonWrapper.encode(inputABIObject, params).encode();
Expand Down Expand Up @@ -426,7 +437,6 @@ public List<String> decodeMethodToString(String ABI, String methodName, String o
}
for (ABIDefinition abiDefinition : methods) {
ABIObject outputABIObject = abiObjectFactory.createOutputObject(abiDefinition);
ABICodecJsonWrapper abiCodecJsonWrapper = new ABICodecJsonWrapper();
try {
return abiCodecJsonWrapper.decode(outputABIObject, output);
} catch (Exception e) {
Expand Down Expand Up @@ -459,7 +469,6 @@ public List<String> decodeMethodByIdToString(
} else {
outputABIObject = abiObjectFactory.createInputObject(abiDefinition);
}
ABICodecJsonWrapper abiCodecJsonWrapper = new ABICodecJsonWrapper();
try {
return abiCodecJsonWrapper.decode(outputABIObject, data);
} catch (UnsupportedOperationException e) {
Expand Down Expand Up @@ -554,7 +563,6 @@ public List<String> decodeEventToString(String ABI, String eventName, EventLog l
}
for (ABIDefinition abiDefinition : events) {
ABIObject inputObject = abiObjectFactory.createEventInputObject(abiDefinition);
ABICodecJsonWrapper abiCodecJsonWrapper = new ABICodecJsonWrapper();
try {
List<String> params = new ArrayList<>();
if (!log.getData().equals("0x")) {
Expand All @@ -578,7 +586,6 @@ public List<String> decodeEventByTopicToString(String ABI, String eventTopic, Ev
ABIDefinition abiDefinition =
contractABIDefinition.getABIDefinitionByEventTopic(eventTopic);
ABIObject inputObject = abiObjectFactory.createEventInputObject(abiDefinition);
ABICodecJsonWrapper abiCodecJsonWrapper = new ABICodecJsonWrapper();
try {
List<String> params = new ArrayList<>();
if (!log.getData().equals("0x")) {
Expand Down
5 changes: 5 additions & 0 deletions sdk-abi/src/main/java/org/fisco/bcos/sdk/abi/Constant.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ public class Constant {
new BigInteger("7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16);
public static final BigInteger MIN_INT256 =
new BigInteger("-7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", 16);
public static final BigInteger MAX_UINT128 =
new BigInteger("ffffffffffffffffffffffffffffffff", 16);
public static final BigInteger MAX_INT128 =
new BigInteger("7fffffffffffffffffffffffffffffff", 16);
public static final BigInteger MIN_INT128 = MAX_INT128.negate();

public static String NO_APPROPRIATE_ABI_METHOD =
"Cann't encode in encodeMethodFromObject with appropriate interface ABI, please check your method name or ABI file";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private <T extends Type> String buildMethodSignature(
result.append(methodName);
result.append("(");
String params =
parameters.stream().map(p -> Utils.getTypeName(p)).collect(Collectors.joining(","));
parameters.stream().map(Utils::getMethodSign).collect(Collectors.joining(","));
result.append(params);
result.append(")");
return result.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.fisco.bcos.sdk.abi.datatypes.Bytes;
import org.fisco.bcos.sdk.abi.datatypes.BytesType;
import org.fisco.bcos.sdk.abi.datatypes.DynamicArray;
import org.fisco.bcos.sdk.abi.datatypes.DynamicBytes;
import org.fisco.bcos.sdk.abi.datatypes.DynamicStruct;
import org.fisco.bcos.sdk.abi.datatypes.StaticArray;
import org.fisco.bcos.sdk.abi.datatypes.StaticStruct;
Expand Down Expand Up @@ -76,7 +77,7 @@ public static <T extends Type> Type decodeIndexedValue(
|| Utf8String.class.isAssignableFrom(type)) {
return TypeDecoder.decodeBytes(input, Bytes32.class);
} else {
return TypeDecoder.decode(input, 0, type);
return TypeDecoder.decode(input, 0, typeReference);
}
} catch (ClassNotFoundException e) {
throw new UnsupportedOperationException("Invalid class reference provided", e);
Expand Down Expand Up @@ -139,7 +140,7 @@ private static List<Type> build(String input, List<TypeReference<Type>> outputPa
offset += TypeDecoder.MAX_BYTE_LENGTH_FOR_HEX_STRING * length;
}
} else {
result = TypeDecoder.decode(input, hexStringDataOffset, cls);
result = TypeDecoder.decode(input, hexStringDataOffset, typeReference);
offset +=
Utils.getOffset(typeReference.getType())
* TypeDecoder.MAX_BYTE_LENGTH_FOR_HEX_STRING;
Expand All @@ -156,10 +157,42 @@ private static List<Type> build(String input, List<TypeReference<Type>> outputPa

public static <T extends Type> int getDataOffset(
String input, int offset, java.lang.reflect.Type type) throws ClassNotFoundException {
if (Utils.dynamicType(type)) {
Class<Type> classType = Utils.getClassType(type);

if (DynamicBytes.class.isAssignableFrom(classType)
|| Utf8String.class.isAssignableFrom(classType)
|| DynamicArray.class.isAssignableFrom(classType)
|| hasDynamicOffsetInStaticArray(type)) {
return TypeDecoder.decodeUintAsInt(input, offset) << 1;
} else {
return offset;
}
}

public static <T extends Type> int getDataOffset(
String input, int offset, TypeReference<?> typeReference)
throws ClassNotFoundException {
@SuppressWarnings("unchecked")
Class<Type> type = (Class<Type>) typeReference.getClassType();
if (DynamicBytes.class.isAssignableFrom(type)
|| Utf8String.class.isAssignableFrom(type)
|| DynamicArray.class.isAssignableFrom(type)
|| hasDynamicOffsetInStaticArray(typeReference.getType())) {
return TypeDecoder.decodeUintAsInt(input, offset);
} else {
return offset;
}
}

private static boolean hasDynamicOffsetInStaticArray(java.lang.reflect.Type type)
throws ClassNotFoundException {
try {
return StaticArray.class.isAssignableFrom(Utils.getClassType(type))
&& (DynamicStruct.class.isAssignableFrom(
Utils.getParameterizedTypeFromArray(type))
|| TypeDecoder.isDynamic(Utils.getParameterizedTypeFromArray(type)));
} catch (ClassCastException e) {
return false;
}
}
}
Loading

0 comments on commit 4f6c702

Please sign in to comment.