diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 9817bda8b..cece5dc3c 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -5,6 +5,7 @@ on: types: [ published, created, edited ] env: CCACHE_DIR: ${{ github.workspace }}/ccache + ACTIONS_ALLOW_USE_UNSECURE_NODE_VERSION: true jobs: build: @@ -86,7 +87,14 @@ jobs: distribution: 'zulu' java-version: '8.0.345' - name: install CentOS dependencies - run: yum install -y epel-release centos-release-scl wget which git openssl-devel openssl tree + run: | + sed -i s/mirror.centos.org/mirrors.aliyun.com/g /etc/yum.repos.d/*.repo + sed -i s/^#.*baseurl=http/baseurl=http/g /etc/yum.repos.d/*.repo + sed -i s/^mirrorlist=http/#mirrorlist=http/g /etc/yum.repos.d/*.repo + yum clean all + yum makecache + yum update -y + yum install -y epel-release centos-release-scl wget which git openssl-devel openssl tree - name: Set up JDK 1.8.0.345 uses: actions/setup-java@v3 with: diff --git a/Changelog.md b/Changelog.md index 0deb86c93..4c818b885 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,9 +1,34 @@ +## v3.8.0 +(2024-08-20) + +请阅读Java SDK v3.x+文档: + +- [中文用户手册](https://fisco-bcos-doc.readthedocs.io/zh-cn/latest/docs/sdk/java_sdk/index.html) + +### 新增 + +- 新增[FISCO BCOS 3.9.0](https://github.com/FISCO-BCOS/FISCO-BCOS/releases/tag/v3.9.0) 版本新增的获取合约事件接口,用户可用主动获取的方式自定义查询合约事件、区块事件等,**目前仍是体验版**。详情见:[#920](https://github.com/FISCO-BCOS/java-sdk/pull/920) 。 +- 在Client类中新增获取当前链上所有配置项的接口,用户可以通过该接口获取链上所有配置项的信息。详情见:[#922](https://github.com/FISCO-BCOS/java-sdk/pull/922) 。 +- 在配置文件中新增 `enableSsl` 的配置字段,该字段的设置将会覆盖旧的 `disabalSsl` 的设置。原先 `disabalSsl` 的配置字段仍然支持,保持配置文件兼容。详情见:[#922](https://github.com/FISCO-BCOS/java-sdk/pull/923) 。 + +### 修复 + +- 修复 `TransactionManager` 在设置`extension`字段时会清除版本号,导致交易哈希计算错误不能上链的问题。详情见:[#922](https://github.com/FISCO-BCOS/java-sdk/pull/922) 。 +- 修复在大整数负数编解码场景中ABI和Scale编解码错误的问题。详情见:[#922](https://github.com/FISCO-BCOS/java-sdk/pull/925) 。 +- 修复存在重载事件时,ABI编解码错误的问题。 +- 修复在使用 `ContractCodec` 类中事件解析时没有解析事件中 `indexed` 值的问题。详情见:[#922](https://github.com/FISCO-BCOS/java-sdk/pull/925) 。 +- 修复在 `Contract` 类以及继承类中,订阅事件的接口没有返回订阅ID的问题。详情见:[#922](https://github.com/FISCO-BCOS/java-sdk/pull/925) 。 + +### 更新 + +- 更新 `org.bouncycastle:bcprov-jdk18on` 依赖版本到 `1.78`。 + ## v3.7.0 (2024-03-25) 请阅读Java SDK v3.x+文档: -- [中文用户手册](https://fisco-bcos-doc.readthedocs.io/zh_CN/latest/docs/develop/sdk/java_sdk/index.html) +- [中文用户手册](https://fisco-bcos-doc.readthedocs.io/zh-cn/latest/docs/sdk/java_sdk/index.html) ### 新增 @@ -51,7 +76,7 @@ 请阅读Java SDK v3.x+文档: -- [中文用户手册](https://fisco-bcos-doc.readthedocs.io/zh_CN/latest/docs/develop/sdk/java_sdk/index.html) +- [中文用户手册](https://fisco-bcos-doc.readthedocs.io/zh-cn/latest/docs/sdk/java_sdk/index.html) ### 新增 @@ -105,7 +130,7 @@ 请阅读Java SDK v3.x+文档: -- [中文用户手册](https://fisco-bcos-doc.readthedocs.io/zh_CN/latest/docs/develop/sdk/java_sdk/index.html) +- [中文用户手册](https://fisco-bcos-doc.readthedocs.io/zh-cn/latest/docs/sdk/java_sdk/index.html) ### 新增 @@ -153,7 +178,7 @@ Please refer to the Java SDK v3.x+ documentation: -- [Chinese User Manual](https://fisco-bcos-doc.readthedocs.io/zh_CN/latest/docs/develop/sdk/java_sdk/index.html) +- [Chinese User Manual](https://fisco-bcos-doc.readthedocs.io/zh-cn/latest/docs/sdk/java_sdk/index.html) ### Added @@ -202,7 +227,7 @@ After balancing the workload and benefits, there are still potential issues in t 请阅读Java SDK v3.x+文档: -- [中文用户手册](https://fisco-bcos-doc.readthedocs.io/zh_CN/latest/docs/develop/sdk/java_sdk/index.html) +- [中文用户手册](https://fisco-bcos-doc.readthedocs.io/zh-cn/latest/docs/sdk/java_sdk/index.html) ### 新增 @@ -243,7 +268,7 @@ After balancing the workload and benefits, there are still potential issues in t (2023-06-09) Please refer to the Java SDK v3.x+ documentation: -- [Chinese User Manual](https://fisco-bcos-doc.readthedocs.io/zh_CN/latest/docs/develop/sdk/java_sdk/index.html) +- [Chinese User Manual](https://fisco-bcos-doc.readthedocs.io/zh-cn/latest/docs/sdk/java_sdk/index.html) ### Added @@ -285,7 +310,7 @@ After balancing the workload and benefits, there are still potential issues with 请阅读Java SDK v3.x+文档: -- [中文用户手册](https://fisco-bcos-doc.readthedocs.io/zh_CN/latest/docs/develop/sdk/java_sdk/index.html) +- [中文用户手册](https://fisco-bcos-doc.readthedocs.io/zh-cn/latest/docs/sdk/java_sdk/index.html) ### 新增 @@ -342,7 +367,7 @@ After balancing the workload and benefits, there are still potential issues with Please refer to the Java SDK v3.x+ documentation: -- [Chinese User Manual](https://fisco-bcos-doc.readthedocs.io/zh_CN/latest/docs/develop/sdk/java_sdk/index.html) +- [Chinese User Manual](https://fisco-bcos-doc.readthedocs.io/zh-cn/latest/docs/sdk/java_sdk/index.html) ### Added @@ -396,7 +421,7 @@ After balancing the workload and benefits, there are still several scenarios whe 请阅读Java SDK v3.x+文档: -- [中文用户手册](https://fisco-bcos-doc.readthedocs.io/zh_CN/latest/docs/develop/sdk/java_sdk/index.html) +- [中文用户手册](https://fisco-bcos-doc.readthedocs.io/zh-cn/latest/docs/sdk/java_sdk/index.html) ### 新增 @@ -434,7 +459,7 @@ After balancing the workload and benefits, there are still several scenarios whe Please read the Java SDK v3.x+ documentation: -- [Chinese User Manual](https://fisco-bcos-doc.readthedocs.io/zh_CN/latest/docs/develop/sdk/java_sdk/index.html) +- [Chinese User Manual](https://fisco-bcos-doc.readthedocs.io/zh-cn/latest/docs/sdk/java_sdk/index.html) ### New @@ -468,7 +493,7 @@ Please read the Java SDK v3.x+ documentation: Please read the Java SDK v3.x+ documentation: -- [Chinese User Manual](https://fisco-bcos-doc.readthedocs.io/zh_CN/latest/docs/develop/sdk/java_sdk/index.html) +- [Chinese User Manual](https://fisco-bcos-doc.readthedocs.io/zh-cn/latest/docs/sdk/java_sdk/index.html) ### New @@ -504,7 +529,7 @@ Please read the Java SDK v3.x+ documentation: 请阅读Java SDK v3.x+文档: -- [中文用户手册](https://fisco-bcos-doc.readthedocs.io/zh_CN/latest/docs/develop/sdk/java_sdk/index.html) +- [中文用户手册](https://fisco-bcos-doc.readthedocs.io/zh-cn/latest/docs/sdk/java_sdk/index.html) ### 新增 @@ -521,7 +546,7 @@ Please read the Java SDK v3.x+ documentation: 请阅读Java SDK v3.x+文档: -- [中文用户手册](https://fisco-bcos-doc.readthedocs.io/zh_CN/latest/docs/develop/sdk/java_sdk/index.html) +- [中文用户手册](https://fisco-bcos-doc.readthedocs.io/zh-cn/latest/docs/sdk/java_sdk/index.html) ### 修复 @@ -537,7 +562,7 @@ Please read the Java SDK v3.x+ documentation: 请阅读Java SDK v3.x+文档: -- [中文用户手册](https://fisco-bcos-doc.readthedocs.io/zh_CN/latest/docs/develop/sdk/java_sdk/index.html) +- [中文用户手册](https://fisco-bcos-doc.readthedocs.io/zh-cn/latest/docs/sdk/java_sdk/index.html) ### 新增 @@ -571,7 +596,7 @@ Please read the Java SDK v3.x+ documentation: Please read the Java SDK v3.x+ documentation: -- [Chinese User Manual](https://fisco-bcos-doc.readthedocs.io/zh_CN/latest/docs/develop/sdk/java_sdk/index.html) +- [Chinese User Manual](https://fisco-bcos-doc.readthedocs.io/zh-cn/latest/docs/sdk/java_sdk/index.html) ### New @@ -603,7 +628,7 @@ Please read the Java SDK v3.x+ documentation: 请阅读Java SDK v3.x+文档: -- [中文用户手册](https://fisco-bcos-doc.readthedocs.io/zh_CN/latest/docs/develop/sdk/java_sdk/index.html) +- [中文用户手册](https://fisco-bcos-doc.readthedocs.io/zh-cn/latest/docs/sdk/java_sdk/index.html) ### 新增 @@ -630,7 +655,7 @@ Please read the Java SDK v3.x+ documentation: Please read documentation of Java SDK v3.x. * English User Handbook:Working in progress... -* [Chinese User Handbook](https://fisco-bcos-doc.readthedocs.io/zh_CN/latest/docs/develop/sdk/java_sdk/index.html) +* [Chinese User Handbook](https://fisco-bcos-doc.readthedocs.io/zh-cn/latest/docs/sdk/java_sdk/index.html) ### Add @@ -658,7 +683,7 @@ Please read documentation of Java SDK v3.x. 请阅读Java SDK v3.x+文档: -- [中文用户手册](https://fisco-bcos-doc.readthedocs.io/zh_CN/latest/docs/develop/sdk/java_sdk/index.html) +- [中文用户手册](https://fisco-bcos-doc.readthedocs.io/zh-cn/latest/docs/sdk/java_sdk/index.html) ### 新增 @@ -689,7 +714,7 @@ Please read documentation of Java SDK v3.x. Please read documentation of Java SDK v3.x. * English User Handbook:Working in progress... -* [Chinese User Handbook](https://fisco-bcos-doc.readthedocs.io/zh_CN/latest/docs/develop/sdk/java_sdk/index.html) +* [Chinese User Handbook](https://fisco-bcos-doc.readthedocs.io/zh-cn/latest/docs/sdk/java_sdk/index.html) ### Added @@ -720,7 +745,7 @@ Please read documentation of Java SDK v3.x. 请阅读Java SDK v3.x+文档: -- [中文用户手册](https://fisco-bcos-doc.readthedocs.io/zh_CN/latest/docs/develop/sdk/java_sdk/index.html) +- [中文用户手册](https://fisco-bcos-doc.readthedocs.io/zh-cn/latest/docs/sdk/java_sdk/index.html) ### 新增 @@ -754,7 +779,7 @@ Please read documentation of Java SDK v3.x. Please read documentation of Java SDK v3.x. * English User Handbook:Working in progress... -* [Chinese User Handbook](https://fisco-bcos-doc.readthedocs.io/zh_CN/latest/docs/develop/sdk/java_sdk/index.html) +* [Chinese User Handbook](https://fisco-bcos-doc.readthedocs.io/zh-cn/latest/docs/sdk/java_sdk/index.html) ### Added @@ -789,7 +814,7 @@ Please read documentation of Java SDK v3.x. 请阅读Java SDK v3.x+文档: -- [中文用户手册](https://fisco-bcos-doc.readthedocs.io/zh_CN/latest/docs/develop/sdk/java_sdk/index.html) +- [中文用户手册](https://fisco-bcos-doc.readthedocs.io/zh-cn/latest/docs/sdk/java_sdk/index.html) ### 新增 @@ -823,7 +848,7 @@ Please read documentation of Java SDK v3.x. Please read documentation of Java SDK v3.x. * English User Handbook:Working in progress... -* [Chinese User Handbook](https://fisco-bcos-doc.readthedocs.io/zh_CN/latest/docs/develop/sdk/java_sdk/index.html) +* [Chinese User Handbook](https://fisco-bcos-doc.readthedocs.io/zh-cn/latest/docs/sdk/java_sdk/index.html) ### Added @@ -855,7 +880,7 @@ Please read documentation of Java SDK v3.x. 请阅读Java SDK v3.x+文档: -- [中文用户手册](https://fisco-bcos-doc.readthedocs.io/zh_CN/latest/docs/develop/sdk/java_sdk/index.html) +- [中文用户手册](https://fisco-bcos-doc.readthedocs.io/zh-cn/latest/docs/sdk/java_sdk/index.html) ### 更新 @@ -880,7 +905,7 @@ Please read documentation of Java SDK v3.x. Please read documentation of Java SDK v3.x. * English User Handbook:Working in progress... -* [Chinese User Handbook](https://fisco-bcos-doc.readthedocs.io/zh_CN/latest/docs/develop/sdk/java_sdk/index.html) +* [Chinese User Handbook](https://fisco-bcos-doc.readthedocs.io/zh-cn/latest/docs/sdk/java_sdk/index.html) ### Changed @@ -906,7 +931,7 @@ Please read documentation of Java SDK v3.x. 请阅读Java SDK文档: -- [中文用户手册](https://fisco-bcos-doc.readthedocs.io/zh_CN/latest/docs/develop/sdk/java_sdk/index.html) +- [中文用户手册](https://fisco-bcos-doc.readthedocs.io/zh-cn/latest/docs/sdk/java_sdk/index.html) ### 新特性 Java SDK包含如下几个新特性: @@ -936,7 +961,7 @@ Java SDK包含如下几个新特性: Please read documentation of Java SDK. * English User Handbook:Working in progress... -* [Chinese User Handbook](https://fisco-bcos-doc.readthedocs.io/zh_CN/latest/docs/develop/sdk/java_sdk/index.html) +* [Chinese User Handbook](https://fisco-bcos-doc.readthedocs.io/zh-cn/latest/docs/sdk/java_sdk/index.html) ### New Features diff --git a/build.gradle b/build.gradle index 1d1cb98fe..14fca8703 100644 --- a/build.gradle +++ b/build.gradle @@ -20,7 +20,7 @@ ext { commonsIOVersion = '2.11.0' commonsLang3Version = '3.12.0' toml4jVersion = "0.7.2" - bcprovJDK18onVersion = '1.75' + bcprovJDK18onVersion = '1.78' webankJavaCryptoVersion = "1.0.3" junitVersion = '4.13.2' commonsCollections4Version = "4.4" @@ -35,7 +35,7 @@ ext { // integrationTest.mustRunAfter test allprojects { group = 'org.fisco-bcos.java-sdk' - version = '3.7.0' + version = '3.8.0-SNAPSHOT' apply plugin: 'maven-publish' apply plugin: 'idea' diff --git a/src/integration-test/java/org/fisco/bcos/sdk/v3/test/BcosSDKTest.java b/src/integration-test/java/org/fisco/bcos/sdk/v3/test/BcosSDKTest.java index e3f4f713a..dd5619f86 100644 --- a/src/integration-test/java/org/fisco/bcos/sdk/v3/test/BcosSDKTest.java +++ b/src/integration-test/java/org/fisco/bcos/sdk/v3/test/BcosSDKTest.java @@ -21,6 +21,8 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Map; +import java.util.Optional; import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; @@ -92,6 +94,16 @@ public void testClient() { System.out.println( "New block, group: " + groupId + ", blockNumber: " + blockNumber)); + Map> systemConfigList = client.getSystemConfigList(); + systemConfigList.forEach( + (key, value) -> + System.out.println( + key + + " : " + + (value.isPresent() + ? value.get().getSystemConfig() + : "null"))); + // test getBlockNumber BlockNumber blockNumber = client.getBlockNumber(); Assert.assertTrue(blockNumber.getBlockNumber().compareTo(BigInteger.ZERO) >= 0); diff --git a/src/main/java/org/fisco/bcos/sdk/v3/BcosSDK.java b/src/main/java/org/fisco/bcos/sdk/v3/BcosSDK.java index 986e3de34..cafb07148 100644 --- a/src/main/java/org/fisco/bcos/sdk/v3/BcosSDK.java +++ b/src/main/java/org/fisco/bcos/sdk/v3/BcosSDK.java @@ -22,6 +22,7 @@ import org.fisco.bcos.sdk.v3.config.ConfigOption; import org.fisco.bcos.sdk.v3.config.exceptions.ConfigException; import org.fisco.bcos.sdk.v3.eventsub.EventSubscribe; +import org.fisco.bcos.sdk.v3.filter.FilterSystem; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -150,6 +151,38 @@ public EventSubscribe getEventSubscribe(String groupId) throws BcosSDKException } } + /** + * Get an event subscribe instance of a specific group + * + * @param client + * @param poolSize the size of scheduledExecutorService + * @return FilterSystem + */ + public FilterSystem getFilterSystem(Client client, int poolSize) throws BcosSDKException { + try { + return new FilterSystem(client, poolSize); + } catch (Exception e) { + throw new BcosSDKException("get filter system failed, e: " + e.getMessage()); + } + } + + /** + * Get an event subscribe instance of a specific group + * + * @param client + * @param poolSize the size of scheduledExecutorService + * @param pollingInterval The time interval for polling getFilterChange + * @return FilterSystem + */ + public FilterSystem getFilterSystem(Client client, int poolSize, long pollingInterval) + throws BcosSDKException { + try { + return new FilterSystem(client, poolSize, pollingInterval); + } catch (Exception e) { + throw new BcosSDKException("get filter system failed, e: " + e.getMessage()); + } + } + /** Stop all module of BcosSDK */ public void stopAll() {} } diff --git a/src/main/java/org/fisco/bcos/sdk/v3/client/Client.java b/src/main/java/org/fisco/bcos/sdk/v3/client/Client.java index 887437ce0..2e657efe2 100644 --- a/src/main/java/org/fisco/bcos/sdk/v3/client/Client.java +++ b/src/main/java/org/fisco/bcos/sdk/v3/client/Client.java @@ -16,7 +16,11 @@ package org.fisco.bcos.sdk.v3.client; import java.math.BigInteger; +import java.util.Map; +import java.util.Optional; +import java.util.Set; import org.fisco.bcos.sdk.jni.BcosSDKJniObj; +import org.fisco.bcos.sdk.v3.client.protocol.request.LogFilterRequest; import org.fisco.bcos.sdk.v3.client.protocol.request.Transaction; import org.fisco.bcos.sdk.v3.client.protocol.response.Abi; import org.fisco.bcos.sdk.v3.client.protocol.response.BcosBlock; @@ -32,6 +36,8 @@ import org.fisco.bcos.sdk.v3.client.protocol.response.Code; import org.fisco.bcos.sdk.v3.client.protocol.response.ConsensusStatus; import org.fisco.bcos.sdk.v3.client.protocol.response.GroupPeers; +import org.fisco.bcos.sdk.v3.client.protocol.response.LogFilterResponse; +import org.fisco.bcos.sdk.v3.client.protocol.response.LogWrapper; import org.fisco.bcos.sdk.v3.client.protocol.response.ObserverList; import org.fisco.bcos.sdk.v3.client.protocol.response.PbftView; import org.fisco.bcos.sdk.v3.client.protocol.response.Peers; @@ -40,6 +46,7 @@ import org.fisco.bcos.sdk.v3.client.protocol.response.SyncStatus; import org.fisco.bcos.sdk.v3.client.protocol.response.SystemConfig; import org.fisco.bcos.sdk.v3.client.protocol.response.TotalTransactionCount; +import org.fisco.bcos.sdk.v3.client.protocol.response.UninstallLogFilter; import org.fisco.bcos.sdk.v3.config.ConfigOption; import org.fisco.bcos.sdk.v3.crypto.CryptoSuite; import org.fisco.bcos.sdk.v3.model.EnumNodeVersion; @@ -837,6 +844,13 @@ void getTransactionReceiptAsync( */ SystemConfig getSystemConfigByKey(String node, String key); + /** + * Peer operation: get system config list, witch will fetch all config + * + * @return all config value + */ + Map> getSystemConfigList(); + /** * Peer operation: async get system config * @@ -854,6 +868,20 @@ void getTransactionReceiptAsync( */ void getSystemConfigByKeyAsync(String node, String key, RespCallback callback); + /** + * async get all connect nodes support keys + * + * @param callback the callback instance + */ + void getSupportSysConfigKeysAsync(RespCallback> callback); + + /** + * Peer operation: async get system config list, witch will fetch all config + * + * @param callback the callback instance + */ + void getSystemConfigListAsync(RespCallback>> callback); + /** * Peer operation: get sync status * @@ -1016,6 +1044,34 @@ void getChainCompatibilityVersionAsync( */ int getNegotiatedProtocol(); + LogFilterResponse newFilter(LogFilterRequest filter); + + void newFilterAsync(LogFilterRequest filter, RespCallback callback); + + LogFilterResponse newBlockFilter(); + + void newBlockFilterAsync(RespCallback callback); + + LogFilterResponse newPendingTransactionFilter(); + + void newPendingTransactionFilterAsync(RespCallback callback); + + LogWrapper getFilterChanges(LogFilterResponse filter); + + void getFilterChangesAsync(LogFilterResponse filter, RespCallback callback); + + UninstallLogFilter uninstallFilter(LogFilterResponse filter); + + void uninstallFilterAsync(LogFilterResponse filter, RespCallback callback); + + LogWrapper getLogs(LogFilterRequest filter); + + void getLogsAsync(LogFilterRequest filter, RespCallback callback); + + LogWrapper getFilterLogs(LogFilterResponse filter); + + void getFilterLogsAsync(LogFilterResponse filter, RespCallback callback); + void start(); void stop(); diff --git a/src/main/java/org/fisco/bcos/sdk/v3/client/ClientImpl.java b/src/main/java/org/fisco/bcos/sdk/v3/client/ClientImpl.java index 5c1dfa5d4..b343db54f 100644 --- a/src/main/java/org/fisco/bcos/sdk/v3/client/ClientImpl.java +++ b/src/main/java/org/fisco/bcos/sdk/v3/client/ClientImpl.java @@ -13,15 +13,25 @@ */ package org.fisco.bcos.sdk.v3.client; +import static org.fisco.bcos.sdk.v3.utils.ObjectMapperFactory.getObjectMapper; + import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import java.math.BigInteger; import java.util.Arrays; import java.util.Collections; import java.util.List; +import java.util.Map; import java.util.Objects; +import java.util.Optional; +import java.util.Set; +import java.util.TreeSet; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ConcurrentSkipListMap; import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import java.util.stream.Collectors; import org.fisco.bcos.sdk.jni.BcosSDKJniObj; import org.fisco.bcos.sdk.jni.rpc.RpcJniObj; import org.fisco.bcos.sdk.v3.client.exceptions.ClientException; @@ -29,6 +39,7 @@ import org.fisco.bcos.sdk.v3.client.protocol.model.GroupNodeIniInfo; import org.fisco.bcos.sdk.v3.client.protocol.request.JsonRpcMethods; import org.fisco.bcos.sdk.v3.client.protocol.request.JsonRpcRequest; +import org.fisco.bcos.sdk.v3.client.protocol.request.LogFilterRequest; import org.fisco.bcos.sdk.v3.client.protocol.request.Transaction; import org.fisco.bcos.sdk.v3.client.protocol.response.Abi; import org.fisco.bcos.sdk.v3.client.protocol.response.BcosBlock; @@ -44,6 +55,8 @@ import org.fisco.bcos.sdk.v3.client.protocol.response.Code; import org.fisco.bcos.sdk.v3.client.protocol.response.ConsensusStatus; import org.fisco.bcos.sdk.v3.client.protocol.response.GroupPeers; +import org.fisco.bcos.sdk.v3.client.protocol.response.LogFilterResponse; +import org.fisco.bcos.sdk.v3.client.protocol.response.LogWrapper; import org.fisco.bcos.sdk.v3.client.protocol.response.ObserverList; import org.fisco.bcos.sdk.v3.client.protocol.response.PbftView; import org.fisco.bcos.sdk.v3.client.protocol.response.Peers; @@ -52,7 +65,9 @@ import org.fisco.bcos.sdk.v3.client.protocol.response.SyncStatus; import org.fisco.bcos.sdk.v3.client.protocol.response.SystemConfig; import org.fisco.bcos.sdk.v3.client.protocol.response.TotalTransactionCount; +import org.fisco.bcos.sdk.v3.client.protocol.response.UninstallLogFilter; import org.fisco.bcos.sdk.v3.config.ConfigOption; +import org.fisco.bcos.sdk.v3.contract.precompiled.sysconfig.SystemConfigFeature; import org.fisco.bcos.sdk.v3.contract.precompiled.sysconfig.SystemConfigService; import org.fisco.bcos.sdk.v3.crypto.CryptoSuite; import org.fisco.bcos.sdk.v3.model.CryptoType; @@ -63,7 +78,6 @@ import org.fisco.bcos.sdk.v3.model.callback.ResponseCallback; import org.fisco.bcos.sdk.v3.model.callback.TransactionCallback; import org.fisco.bcos.sdk.v3.utils.Hex; -import org.fisco.bcos.sdk.v3.utils.ObjectMapperFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -94,7 +108,7 @@ public class ClientImpl implements Client { private CryptoSuite cryptoSuite; private RpcJniObj rpcJniObj; - protected final ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper(); + protected final ObjectMapper objectMapper = getObjectMapper(); protected void initGroupInfo() { this.groupInfo = getGroupInfo().getResult(); @@ -1004,6 +1018,32 @@ public SystemConfig getSystemConfigByKey(String node, String key) { SystemConfig.class); } + @Override + public Map> getSystemConfigList() { + CompletableFuture>> future = new CompletableFuture<>(); + this.getSystemConfigListAsync( + new RespCallback>>() { + @Override + public void onResponse(Map> configMap) { + future.complete(configMap); + } + + @Override + public void onError(Response errorResponse) { + future.completeExceptionally( + new ClientException( + "getSystemConfigList failed, error: " + + errorResponse.getErrorMessage())); + } + }); + try { + return future.get(configOption.getNetworkConfig().getTimeout(), TimeUnit.MILLISECONDS); + } catch (Exception e) { + logger.warn("getSystemConfigList failed, error: {}", e.getMessage(), e); + throw new ClientException("getSystemConfigList failed, error: " + e.getMessage(), e); + } + } + @Override public void getSystemConfigByKeyAsync(String key, RespCallback callback) { this.getSystemConfigByKeyAsync(nodeToSendRequest, key, callback); @@ -1022,6 +1062,89 @@ public void getSystemConfigByKeyAsync( callback); } + @Override + public void getSupportSysConfigKeysAsync(RespCallback> callback) { + this.getGroupInfoListAsync( + new RespCallback() { + @Override + public void onResponse(BcosGroupInfoList bcosGroupInfoList) { + Optional group = + bcosGroupInfoList.getResult().stream() + .filter(gInfo -> gInfo.getGroupID().equals(getGroup())) + .findFirst(); + Set keys = new TreeSet<>(); + keys.addAll( + Arrays.stream(SystemConfigFeature.Features.values()) + .map(SystemConfigFeature.Features::toString) + .collect(Collectors.toList())); + keys.addAll(SystemConfigService.getConfigKeys()); + if (group.isPresent() && !group.get().getNodeList().isEmpty()) { + group.get() + .getNodeList() + .forEach( + groupNodeInfo -> { + keys.addAll(groupNodeInfo.getFeatureKeys()); + keys.addAll(groupNodeInfo.getSupportConfigs()); + }); + } + callback.onResponse(keys); + } + + @Override + public void onError(Response errorResponse) { + callback.onError(errorResponse); + } + }); + } + + @Override + public void getSystemConfigListAsync( + RespCallback>> callback) { + + this.getSupportSysConfigKeysAsync( + new RespCallback>() { + @Override + public void onResponse(Set keys) { + Map> configMap = + new ConcurrentSkipListMap<>(); + if (keys.isEmpty()) { + callback.onResponse(configMap); + return; + } + keys.forEach( + key -> + getSystemConfigByKeyAsync( + key, + new RespCallback() { + @Override + public void onResponse( + SystemConfig systemConfig) { + configMap.put( + key, + Optional.ofNullable(systemConfig)); + if (configMap.size() == keys.size()) { + callback.onResponse(configMap); + } + } + + @Override + public void onError(Response errorResponse) { + // maybe not exist + configMap.put(key, Optional.empty()); + if (configMap.size() == keys.size()) { + callback.onResponse(configMap); + } + } + })); + } + + @Override + public void onError(Response errorResponse) { + callback.onError(errorResponse); + } + }); + } + @Override public SyncStatus getSyncStatus(String node) { node = Objects.isNull(node) ? "" : node; @@ -1126,7 +1249,8 @@ public BcosGroupInfo getGroupInfo() { future.complete(response); }); - Response response = future.get(); + Response response = + future.get(configOption.getNetworkConfig().getTimeout(), TimeUnit.MILLISECONDS); return ClientImpl.parseResponseIntoJsonRpcResponse( JsonRpcMethods.GET_GROUP_INFO, response, BcosGroupInfo.class); } catch (ClientException e) { @@ -1142,6 +1266,12 @@ public BcosGroupInfo getGroupInfo() { "getGroupInfo failed for decode the message exception, error message:" + e.getMessage(), e); + } catch (TimeoutException e) { + logger.error("e: ", e); + throw new ClientException( + "getGroupInfo failed for get group info timeout, error message:" + + e.getMessage(), + e); } } @@ -1306,13 +1436,163 @@ public String getNodeToSendRequest() { * with max and min version bits combined, which is (max|min). Max protocol version is in first * 16 bit, and min protocol version in the second 16 bit. * - * @return (max|min) bits combined. + * @return (max | min) bits combined. */ @Override public int getNegotiatedProtocol() { return negotiatedProtocol; } + @Override + public LogFilterResponse newFilter(LogFilterRequest params) { + return this.callRemoteMethod( + this.groupID, + "", + new JsonRpcRequest<>( + JsonRpcMethods.NEW_FILTER, Arrays.asList(this.groupID, params)), + LogFilterResponse.class); + } + + @Override + public void newFilterAsync(LogFilterRequest params, RespCallback callback) { + this.asyncCallRemoteMethod( + this.groupID, + "", + new JsonRpcRequest<>(JsonRpcMethods.NEW_FILTER, Arrays.asList(groupID, params)), + LogFilterResponse.class, + callback); + } + + @Override + public LogFilterResponse newBlockFilter() { + return this.callRemoteMethod( + this.groupID, + "", + new JsonRpcRequest<>(JsonRpcMethods.NEW_BLOCK_FILTER, Arrays.asList(this.groupID)), + LogFilterResponse.class); + } + + @Override + public void newBlockFilterAsync(RespCallback callback) { + this.asyncCallRemoteMethod( + this.groupID, + "", + new JsonRpcRequest<>(JsonRpcMethods.NEW_BLOCK_FILTER, Arrays.asList(this.groupID)), + LogFilterResponse.class, + callback); + } + + @Override + public LogFilterResponse newPendingTransactionFilter() { + return this.callRemoteMethod( + this.groupID, + "", + new JsonRpcRequest<>( + JsonRpcMethods.NEW_PENDING_TX_FILTER, Arrays.asList(this.groupID)), + LogFilterResponse.class); + } + + @Override + public void newPendingTransactionFilterAsync(RespCallback callback) { + this.asyncCallRemoteMethod( + this.groupID, + "", + new JsonRpcRequest<>( + JsonRpcMethods.NEW_PENDING_TX_FILTER, Arrays.asList(this.groupID)), + LogFilterResponse.class, + callback); + } + + @Override + public LogWrapper getFilterChanges(LogFilterResponse filter) { + return this.callRemoteMethod( + this.groupID, + "", + new JsonRpcRequest<>( + JsonRpcMethods.GET_FILTER_CHANGES, + Arrays.asList(this.groupID, filter.getResult())), + LogWrapper.class); + } + + @Override + public void getFilterChangesAsync(LogFilterResponse filter, RespCallback callback) { + this.asyncCallRemoteMethod( + this.groupID, + "", + new JsonRpcRequest<>( + JsonRpcMethods.GET_FILTER_CHANGES, + Arrays.asList(this.groupID, filter.getResult())), + LogWrapper.class, + callback); + } + + @Override + public UninstallLogFilter uninstallFilter(LogFilterResponse filter) { + return this.callRemoteMethod( + this.groupID, + "", + new JsonRpcRequest<>( + JsonRpcMethods.UNINSTALL_FILTER, + Arrays.asList(this.groupID, filter.getResult())), + UninstallLogFilter.class); + } + + @Override + public void uninstallFilterAsync( + LogFilterResponse filter, RespCallback callback) { + this.asyncCallRemoteMethod( + this.groupID, + "", + new JsonRpcRequest<>( + JsonRpcMethods.UNINSTALL_FILTER, + Arrays.asList(this.groupID, filter.getResult())), + UninstallLogFilter.class, + callback); + } + + @Override + public LogWrapper getLogs(LogFilterRequest params) { + return this.callRemoteMethod( + this.groupID, + "", + new JsonRpcRequest<>(JsonRpcMethods.GET_LOGS, Arrays.asList(this.groupID, params)), + LogWrapper.class); + } + + @Override + public void getLogsAsync(LogFilterRequest params, RespCallback callback) { + this.asyncCallRemoteMethod( + this.groupID, + "", + new JsonRpcRequest<>(JsonRpcMethods.GET_LOGS, Arrays.asList(this.groupID, params)), + LogWrapper.class, + callback); + } + + @Override + public LogWrapper getFilterLogs(LogFilterResponse filter) { + return this.callRemoteMethod( + this.groupID, + "", + new JsonRpcRequest<>( + JsonRpcMethods.GET_FILTER_LOGS, + Arrays.asList(this.groupID, filter.getResult())), + LogWrapper.class); + } + + @Override + public void getFilterLogsAsync(LogFilterResponse filter, RespCallback callback) { + + this.asyncCallRemoteMethod( + this.groupID, + "", + new JsonRpcRequest<>( + JsonRpcMethods.GET_FILTER_LOGS, + Arrays.asList(this.groupID, filter.getResult())), + LogWrapper.class, + callback); + } + @Override public void start() { if (rpcJniObj != null) { @@ -1388,7 +1668,7 @@ public > T callRemoteMethod( return ClientImpl.parseResponseIntoJsonRpcResponse( request.getMethod(), response, responseType); } catch (ClientException e) { - logger.error("e: ", e); + logger.info("callRemoteMethod ClientException, raw request:{} ", request, e); throw new ClientException( e.getErrorCode(), e.getErrorMessage(), @@ -1396,7 +1676,7 @@ public > T callRemoteMethod( + e.getMessage(), e); } catch (JsonProcessingException | InterruptedException | ExecutionException e) { - logger.error("e: ", e); + logger.error("callRemoteMethod exception, raw request:{} ", request, e); throw new ClientException( "callRemoteMethod failed for decode the message exception, error message:" + e.getMessage(), @@ -1446,43 +1726,45 @@ public static > T parseResponseIntoJsonRpcResponse( if (response.getErrorCode() == 0) { // parse the response into JsonRPCResponse T jsonRpcResponse = - ObjectMapperFactory.getObjectMapper() - .readValue(response.getContent(), responseType); - if (jsonRpcResponse.getError() != null) { - logger.error( - "parseResponseIntoJsonRpcResponse failed for non-empty error message, method: {}, retErrorMessage: {}, retErrorCode: {}", + getObjectMapper().readValue(response.getContent(), responseType); + // error code inside json rpc response + if (jsonRpcResponse.hasError()) { + logger.info( + "parseResponseIntoJsonRpcResponse failed for non-empty error message, method: {}, msg: {}, code: {}, rawRsp: {}", method, jsonRpcResponse.getError().getMessage(), - jsonRpcResponse.getError().getCode()); + jsonRpcResponse.getError().getCode(), + response.getContentString()); throw new ClientException( jsonRpcResponse.getError().getCode(), jsonRpcResponse.getError().getMessage(), - "ErrorMessage: " + jsonRpcResponse.getError().getMessage()); + "msg: " + jsonRpcResponse.getError().getMessage()); } return jsonRpcResponse; } else { - logger.error( - "parseResponseIntoJsonRpcResponse failed, method: {}, retErrorMessage: {}, retErrorCode: {}", + logger.info( + "parseResponseIntoJsonRpcResponse failed, method: {}, msg: {}, code: {}, rawRsp: {}", method, response.getErrorMessage(), - response.getErrorCode()); + response.getErrorCode(), + response.getContent()); throw new ClientException( response.getErrorCode(), response.getErrorMessage(), - "get response failed, errorCode: " + "get response failed, code: " + response.getErrorCode() - + ", error message: " + + ", msg: " + response.getErrorMessage()); } } catch (ClientException e) { - logger.error( + logger.info( "parseResponseIntoJsonRpcResponse failed for decode the message exception, response: {}, errorMessage: {}", response, e.getMessage(), e); throw e; } catch (Exception e) { - logger.error( + logger.info( "parseResponseIntoJsonRpcResponse failed for decode the message exception, response: {}, errorMessage: {}", response, e.getMessage(), diff --git a/src/main/java/org/fisco/bcos/sdk/v3/client/exceptions/ClientException.java b/src/main/java/org/fisco/bcos/sdk/v3/client/exceptions/ClientException.java index 1d0997bf6..f54adf5f3 100644 --- a/src/main/java/org/fisco/bcos/sdk/v3/client/exceptions/ClientException.java +++ b/src/main/java/org/fisco/bcos/sdk/v3/client/exceptions/ClientException.java @@ -64,6 +64,8 @@ public String toString() { + ", errorMessage='" + errorMessage + '\'' + + ", msg=" + + getMessage() + '}'; } diff --git a/src/main/java/org/fisco/bcos/sdk/v3/client/protocol/request/DefaultBlockParameter.java b/src/main/java/org/fisco/bcos/sdk/v3/client/protocol/request/DefaultBlockParameter.java new file mode 100644 index 000000000..6919c5a95 --- /dev/null +++ b/src/main/java/org/fisco/bcos/sdk/v3/client/protocol/request/DefaultBlockParameter.java @@ -0,0 +1,32 @@ +package org.fisco.bcos.sdk.v3.client.protocol.request; + +import java.math.BigInteger; + +/** + * Wrapper for parameter that takes either a block number or block name as input + * + *

See the + * specification for further information. + */ +public interface DefaultBlockParameter { + static DefaultBlockParameter valueOf(BigInteger blockNumber) { + if (BigInteger.ZERO.compareTo(blockNumber) >= 0) { + blockNumber = BigInteger.ZERO; + } + return new DefaultBlockParameterNumber(blockNumber); + } + + static DefaultBlockParameter valueOf(int blockNumber) { + return valueOf(BigInteger.valueOf(blockNumber)); + } + + static DefaultBlockParameter valueOf(String blockName) { + return DefaultBlockParameterName.fromString(blockName); + } + + String getValue(); + + public boolean isLatest(); + + public boolean isEarliest(); +} diff --git a/src/main/java/org/fisco/bcos/sdk/v3/client/protocol/request/DefaultBlockParameterName.java b/src/main/java/org/fisco/bcos/sdk/v3/client/protocol/request/DefaultBlockParameterName.java new file mode 100644 index 000000000..b9127835c --- /dev/null +++ b/src/main/java/org/fisco/bcos/sdk/v3/client/protocol/request/DefaultBlockParameterName.java @@ -0,0 +1,47 @@ +package org.fisco.bcos.sdk.v3.client.protocol.request; + +import com.fasterxml.jackson.annotation.JsonValue; + +/** https://github.com/ethereum/wiki/wiki/JSON-RPC#the-default-block-parameter */ +public enum DefaultBlockParameterName implements DefaultBlockParameter { + EARLIEST("earliest"), + LATEST("latest"); + // PENDING("pending"), + // FINALIZED("finalized"), + // SAFE("safe"), + // ACCEPTED("accepted"); + + private String name; + + DefaultBlockParameterName(String name) { + this.name = name; + } + + @JsonValue + @Override + public String getValue() { + return name; + } + + public static DefaultBlockParameterName fromString(String name) { + if (name != null) { + for (DefaultBlockParameterName defaultBlockParameterName : + DefaultBlockParameterName.values()) { + if (name.equalsIgnoreCase(defaultBlockParameterName.name)) { + return defaultBlockParameterName; + } + } + } + return valueOf(name); + } + + @Override + public boolean isLatest() { + return this == LATEST; + } + + @Override + public boolean isEarliest() { + return this == EARLIEST; + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/v3/client/protocol/request/DefaultBlockParameterNumber.java b/src/main/java/org/fisco/bcos/sdk/v3/client/protocol/request/DefaultBlockParameterNumber.java new file mode 100644 index 000000000..c631236c1 --- /dev/null +++ b/src/main/java/org/fisco/bcos/sdk/v3/client/protocol/request/DefaultBlockParameterNumber.java @@ -0,0 +1,39 @@ +package org.fisco.bcos.sdk.v3.client.protocol.request; + +import com.fasterxml.jackson.annotation.JsonValue; +import java.math.BigInteger; +import org.fisco.bcos.sdk.v3.utils.Numeric; + +/** DefaultBlockParameter implementation that takes a numeric value. */ +public class DefaultBlockParameterNumber implements DefaultBlockParameter { + + private BigInteger blockNumber; + + public DefaultBlockParameterNumber(BigInteger blockNumber) { + this.blockNumber = blockNumber; + } + + public DefaultBlockParameterNumber(long blockNumber) { + this(BigInteger.valueOf(blockNumber)); + } + + @Override + @JsonValue + public String getValue() { + return Numeric.encodeQuantity(blockNumber); + } + + public BigInteger getBlockNumber() { + return blockNumber; + } + + @Override + public boolean isLatest() { + return false; + } + + @Override + public boolean isEarliest() { + return false; + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/v3/client/protocol/request/Filter.java b/src/main/java/org/fisco/bcos/sdk/v3/client/protocol/request/Filter.java new file mode 100644 index 000000000..ed8688263 --- /dev/null +++ b/src/main/java/org/fisco/bcos/sdk/v3/client/protocol/request/Filter.java @@ -0,0 +1,107 @@ +package org.fisco.bcos.sdk.v3.client.protocol.request; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonValue; +import java.util.ArrayList; +import java.util.List; + +/** + * Filter implementation as per docs + */ +@JsonInclude(JsonInclude.Include.NON_NULL) +public abstract class Filter { + + private static int MAX_TOPICS_SIZE = 4; + private T thisObj; + private List topics; + + Filter() { + thisObj = getThis(); + topics = new ArrayList<>(); + } + + Filter(List topics) { + this.topics = topics; + } + + public T addSingleTopic(String topic) { + topics.add(new SingleTopic(topic)); + return getThis(); + } + + public T addNullTopic() { + topics.add(new SingleTopic()); + return getThis(); + } + + // how to pass in null topic? + public T addOptionalTopics(String... optionalTopics) { + topics.add(new ListTopic(optionalTopics)); + return getThis(); + } + + public List getTopics() { + return topics; + } + + abstract T getThis(); + + public interface FilterTopic { + @JsonValue + T getValue(); + } + + public static class SingleTopic implements FilterTopic { + + private String topic; + + public SingleTopic() { + this.topic = null; // null topic + } + + public SingleTopic(String topic) { + this.topic = topic; + } + + @Override + public String getValue() { + return topic; + } + } + + public static class ListTopic implements FilterTopic> { + private List topics; + + public ListTopic(String... optionalTopics) { + topics = new ArrayList<>(); + for (String topic : optionalTopics) { + if (topic != null) { + topics.add(new SingleTopic(topic)); + } else { + topics.add(new SingleTopic()); + } + } + } + + public ListTopic(List topics) { + this.topics = new ArrayList<>(); + for (String topic : topics) { + if (topic != null) { + this.topics.add(new SingleTopic(topic)); + } else { + this.topics.add(new SingleTopic()); + } + } + } + + @Override + public List getValue() { + return topics; + } + } + + public boolean checkParams() { + return topics.size() <= MAX_TOPICS_SIZE; + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/v3/client/protocol/request/JsonRpcMethods.java b/src/main/java/org/fisco/bcos/sdk/v3/client/protocol/request/JsonRpcMethods.java index 97d762f23..dfc31b183 100644 --- a/src/main/java/org/fisco/bcos/sdk/v3/client/protocol/request/JsonRpcMethods.java +++ b/src/main/java/org/fisco/bcos/sdk/v3/client/protocol/request/JsonRpcMethods.java @@ -44,5 +44,14 @@ public class JsonRpcMethods { public static final String GET_GROUP_INFO_LIST = "getGroupInfoList"; public static final String GET_GROUP_NODE_INFO = "getGroupNodeInfo"; + // event related interface + public static final String NEW_BLOCK_FILTER = "newBlockFilter"; + public static final String NEW_PENDING_TX_FILTER = "newPendingTransactionFilter"; + public static final String NEW_FILTER = "newFilter"; + public static final String GET_FILTER_CHANGES = "getFilterChanges"; + public static final String UNINSTALL_FILTER = "uninstallFilter"; + public static final String GET_LOGS = "getLogs"; + public static final String GET_FILTER_LOGS = "getFilterLogs"; + private JsonRpcMethods() {} } diff --git a/src/main/java/org/fisco/bcos/sdk/v3/client/protocol/request/LogFilterRequest.java b/src/main/java/org/fisco/bcos/sdk/v3/client/protocol/request/LogFilterRequest.java new file mode 100644 index 000000000..aae49c4a5 --- /dev/null +++ b/src/main/java/org/fisco/bcos/sdk/v3/client/protocol/request/LogFilterRequest.java @@ -0,0 +1,115 @@ +package org.fisco.bcos.sdk.v3.client.protocol.request; + +import com.fasterxml.jackson.annotation.JsonIgnore; +import java.math.BigInteger; +import java.util.Collections; +import java.util.List; + +public class LogFilterRequest extends Filter { + private DefaultBlockParameter fromBlock; // optional, params - defaults to latest for both + private DefaultBlockParameter toBlock; + private String blockHash; // optional, cannot be used together with fromBlock/toBlock + private List address; // spec. implies this can be single address as string or list + + public LogFilterRequest() { + super(); + } + + public LogFilterRequest(DefaultBlockParameter fromBlock, DefaultBlockParameter toBlock) { + super(); + this.fromBlock = fromBlock; + this.toBlock = toBlock; + } + + public LogFilterRequest( + DefaultBlockParameter fromBlock, DefaultBlockParameter toBlock, List address) { + super(); + this.fromBlock = fromBlock; + this.toBlock = toBlock; + this.address = address; + } + + public LogFilterRequest( + DefaultBlockParameter fromBlock, DefaultBlockParameter toBlock, String address) { + this(fromBlock, toBlock, Collections.singletonList(address)); + } + + public LogFilterRequest(String blockHash) { + super(); + this.blockHash = blockHash; + } + + public LogFilterRequest(String blockHash, String address) { + this(null, null, Collections.singletonList(address)); + this.blockHash = blockHash; + } + + public LogFilterRequest(List address, List topics) { + super(topics); + this.address = address; + } + + public LogFilterRequest setFromBlock(BigInteger from) { + fromBlock = DefaultBlockParameter.valueOf(from); + return getThis(); + } + + public LogFilterRequest setToBlock(BigInteger to) { + toBlock = DefaultBlockParameter.valueOf(to); + return getThis(); + } + + public DefaultBlockParameter getFromBlock() { + return fromBlock; + } + + public DefaultBlockParameter getToBlock() { + return toBlock; + } + + public String getBlockHash() { + return blockHash; + } + + public List getAddress() { + return address; + } + + @Override + @JsonIgnore + LogFilterRequest getThis() { + return this; + } + + @Override + public boolean checkParams() { + BigInteger fromBlockI = BigInteger.valueOf(0); + BigInteger toBlockI = BigInteger.valueOf(0); + + if (!super.checkParams()) { + return false; + } + + if (fromBlock.isLatest() && toBlock.isLatest()) { + return true; + } + + if (fromBlock instanceof DefaultBlockParameterNumber) { + fromBlockI = ((DefaultBlockParameterNumber) fromBlock).getBlockNumber(); + } + + if (toBlock instanceof DefaultBlockParameterNumber) { + toBlockI = ((DefaultBlockParameterNumber) toBlock).getBlockNumber(); + } + + if (fromBlockI.compareTo(BigInteger.ZERO) < 0 || toBlockI.compareTo(BigInteger.ZERO) < 0) { + return false; + } + + if (!fromBlock.isLatest() && !toBlock.isLatest() && fromBlockI.compareTo(toBlockI) <= 0) { + return true; + } + + return !fromBlock.isLatest() && toBlock.isLatest(); + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/v3/client/protocol/response/BcosGroupNodeInfo.java b/src/main/java/org/fisco/bcos/sdk/v3/client/protocol/response/BcosGroupNodeInfo.java index cf484812e..07aa85466 100644 --- a/src/main/java/org/fisco/bcos/sdk/v3/client/protocol/response/BcosGroupNodeInfo.java +++ b/src/main/java/org/fisco/bcos/sdk/v3/client/protocol/response/BcosGroupNodeInfo.java @@ -12,6 +12,7 @@ import com.fasterxml.jackson.databind.type.TypeFactory; import com.fasterxml.jackson.databind.util.Converter; import java.io.IOException; +import java.util.ArrayList; import java.util.List; import org.fisco.bcos.sdk.v3.client.protocol.model.GroupNodeIniInfo; import org.fisco.bcos.sdk.v3.model.JsonRpcResponse; @@ -80,7 +81,8 @@ public static class GroupNodeInfo { private String name; private List serviceInfoList; private Protocol protocol; - private List featureKeys; + private List featureKeys = new ArrayList<>(); + private List supportConfigs = new ArrayList<>(); @Override public String toString() { @@ -150,6 +152,14 @@ public void setFeatureKeys(List featureKeys) { this.featureKeys = featureKeys; } + public List getSupportConfigs() { + return supportConfigs; + } + + public void setSupportConfigs(List supportConfigs) { + this.supportConfigs = supportConfigs; + } + static class ServiceInfo { private String serviceName; private int type; diff --git a/src/main/java/org/fisco/bcos/sdk/v3/client/protocol/response/Log.java b/src/main/java/org/fisco/bcos/sdk/v3/client/protocol/response/Log.java new file mode 100644 index 000000000..5bfe19946 --- /dev/null +++ b/src/main/java/org/fisco/bcos/sdk/v3/client/protocol/response/Log.java @@ -0,0 +1,249 @@ +package org.fisco.bcos.sdk.v3.client.protocol.response; + +import java.math.BigInteger; +import java.util.List; +import org.fisco.bcos.sdk.v3.utils.Numeric; + +public class Log { + private boolean removed; + private String logIndex; + private String transactionIndex; + private String transactionHash; + private String blockHash; + private String blockNumber; + private String address; + private String data; + private String type; + private List topics; + + public Log() {} + + public Log( + boolean removed, + String logIndex, + String transactionIndex, + String transactionHash, + String blockHash, + String blockNumber, + String address, + String data, + String type, + List topics) { + this.removed = removed; + this.logIndex = logIndex; + this.transactionIndex = transactionIndex; + this.transactionHash = transactionHash; + this.blockHash = blockHash; + this.blockNumber = blockNumber; + this.address = address; + this.data = data; + this.type = type; + this.topics = topics; + } + + public boolean isRemoved() { + return removed; + } + + public void setRemoved(boolean removed) { + this.removed = removed; + } + + public BigInteger getLogIndex() { + return convert(logIndex); + } + + public String getLogIndexRaw() { + return logIndex; + } + + public void setLogIndex(String logIndex) { + this.logIndex = logIndex; + } + + public BigInteger getTransactionIndex() { + return convert(transactionIndex); + } + + public String getTransactionIndexRaw() { + return transactionIndex; + } + + public void setTransactionIndex(String transactionIndex) { + this.transactionIndex = transactionIndex; + } + + public String getTransactionHash() { + return transactionHash; + } + + public void setTransactionHash(String transactionHash) { + this.transactionHash = transactionHash; + } + + public String getBlockHash() { + return blockHash; + } + + public void setBlockHash(String blockHash) { + this.blockHash = blockHash; + } + + public BigInteger getBlockNumber() { + return convert(blockNumber); + } + + public String getBlockNumberRaw() { + return blockNumber; + } + + public void setBlockNumber(String blockNumber) { + this.blockNumber = blockNumber; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public List getTopics() { + return topics; + } + + public void setTopics(List topics) { + this.topics = topics; + } + + private BigInteger convert(String value) { + if (value != null) { + return Numeric.decodeQuantity(value); + } else { + return null; + } + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof Log)) { + return false; + } + + Log log = (Log) o; + + if (isRemoved() != log.isRemoved()) { + return false; + } + if (getLogIndexRaw() != null + ? !getLogIndexRaw().equals(log.getLogIndexRaw()) + : log.getLogIndexRaw() != null) { + return false; + } + if (getTransactionIndexRaw() != null + ? !getTransactionIndexRaw().equals(log.getTransactionIndexRaw()) + : log.getTransactionIndexRaw() != null) { + return false; + } + if (getTransactionHash() != null + ? !getTransactionHash().equals(log.getTransactionHash()) + : log.getTransactionHash() != null) { + return false; + } + if (getBlockHash() != null + ? !getBlockHash().equals(log.getBlockHash()) + : log.getBlockHash() != null) { + return false; + } + if (getBlockNumberRaw() != null + ? !getBlockNumberRaw().equals(log.getBlockNumberRaw()) + : log.getBlockNumberRaw() != null) { + return false; + } + if (getAddress() != null + ? !getAddress().equals(log.getAddress()) + : log.getAddress() != null) { + return false; + } + if (getData() != null ? !getData().equals(log.getData()) : log.getData() != null) { + return false; + } + if (getType() != null ? !getType().equals(log.getType()) : log.getType() != null) { + return false; + } + return getTopics() != null ? getTopics().equals(log.getTopics()) : log.getTopics() == null; + } + + @Override + public int hashCode() { + int result = (isRemoved() ? 1 : 0); + result = 31 * result + (getLogIndexRaw() != null ? getLogIndexRaw().hashCode() : 0); + result = + 31 * result + + (getTransactionIndexRaw() != null + ? getTransactionIndexRaw().hashCode() + : 0); + result = 31 * result + (getTransactionHash() != null ? getTransactionHash().hashCode() : 0); + result = 31 * result + (getBlockHash() != null ? getBlockHash().hashCode() : 0); + result = 31 * result + (getBlockNumberRaw() != null ? getBlockNumberRaw().hashCode() : 0); + result = 31 * result + (getAddress() != null ? getAddress().hashCode() : 0); + result = 31 * result + (getData() != null ? getData().hashCode() : 0); + result = 31 * result + (getType() != null ? getType().hashCode() : 0); + result = 31 * result + (getTopics() != null ? getTopics().hashCode() : 0); + return result; + } + + @Override + public String toString() { + return "Log{" + + "removed=" + + removed + + ", logIndex='" + + logIndex + + '\'' + + ", transactionIndex='" + + transactionIndex + + '\'' + + ", transactionHash='" + + transactionHash + + '\'' + + ", blockHash='" + + blockHash + + '\'' + + ", blockNumber='" + + blockNumber + + '\'' + + ", address='" + + address + + '\'' + + ", data='" + + data + + '\'' + + ", type='" + + type + + '\'' + + ", topics=" + + topics + + '}'; + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/v3/client/protocol/response/LogFilterResponse.java b/src/main/java/org/fisco/bcos/sdk/v3/client/protocol/response/LogFilterResponse.java new file mode 100644 index 000000000..4832aa381 --- /dev/null +++ b/src/main/java/org/fisco/bcos/sdk/v3/client/protocol/response/LogFilterResponse.java @@ -0,0 +1,26 @@ +/* + * Copyright 2014-2020 [fisco-dev] + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + * + */ + +package org.fisco.bcos.sdk.v3.client.protocol.response; + +import java.math.BigInteger; +import org.fisco.bcos.sdk.v3.model.JsonRpcResponse; +import org.fisco.bcos.sdk.v3.utils.Numeric; + +public class LogFilterResponse extends JsonRpcResponse { + public BigInteger getFilterId() { + return Numeric.decodeQuantity(getResult()); + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/v3/client/protocol/response/LogWrapper.java b/src/main/java/org/fisco/bcos/sdk/v3/client/protocol/response/LogWrapper.java new file mode 100644 index 000000000..292cff42f --- /dev/null +++ b/src/main/java/org/fisco/bcos/sdk/v3/client/protocol/response/LogWrapper.java @@ -0,0 +1,149 @@ +/* + * Copyright 2014-2020 [fisco-dev] + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + * + */ + +package org.fisco.bcos.sdk.v3.client.protocol.response; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.ObjectReader; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import org.fisco.bcos.sdk.v3.model.JsonRpcResponse; +import org.fisco.bcos.sdk.v3.utils.ObjectMapperFactory; + +public class LogWrapper extends JsonRpcResponse> { + + @Override + @JsonDeserialize(using = LogResultDeserializer.class) + public void setResult(List result) { + super.setResult(result); + } + + public List getLogs() { + return getResult(); + } + + public interface LogResult { + T get(); + } + + public static class LogObject extends Log implements LogResult { + + public LogObject() {} + + public LogObject( + boolean removed, + String logIndex, + String transactionIndex, + String transactionHash, + String blockHash, + String blockNumber, + String address, + String data, + String type, + List topics) { + super( + removed, + logIndex, + transactionIndex, + transactionHash, + blockHash, + blockNumber, + address, + data, + type, + topics); + } + + @Override + public Log get() { + return this; + } + } + + public static class Hash implements LogResult { + private String value; + + public Hash() {} + + public Hash(String value) { + this.value = value; + } + + @Override + public String get() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (!(o instanceof Hash)) { + return false; + } + + Hash hash = (Hash) o; + + return value != null ? value.equals(hash.value) : hash.value == null; + } + + @Override + public int hashCode() { + return value != null ? value.hashCode() : 0; + } + } + + public static class LogResultDeserializer extends JsonDeserializer> { + + private ObjectReader objectReader = ObjectMapperFactory.getObjectReader(); + + @Override + public List deserialize( + JsonParser jsonParser, DeserializationContext deserializationContext) + throws IOException { + + List logResults = new ArrayList<>(); + JsonToken nextToken = jsonParser.nextToken(); + + if (nextToken == JsonToken.START_OBJECT) { + Iterator logObjectIterator = + objectReader.readValues(jsonParser, LogObject.class); + while (logObjectIterator.hasNext()) { + logResults.add(logObjectIterator.next()); + } + } else if (nextToken == JsonToken.VALUE_STRING) { + jsonParser.getValueAsString(); + + Iterator transactionHashIterator = + objectReader.readValues(jsonParser, Hash.class); + while (transactionHashIterator.hasNext()) { + logResults.add(transactionHashIterator.next()); + } + } + return logResults; + } + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/v3/client/protocol/response/UninstallLogFilter.java b/src/main/java/org/fisco/bcos/sdk/v3/client/protocol/response/UninstallLogFilter.java new file mode 100644 index 000000000..97ae0dafb --- /dev/null +++ b/src/main/java/org/fisco/bcos/sdk/v3/client/protocol/response/UninstallLogFilter.java @@ -0,0 +1,24 @@ +/* + * Copyright 2014-2020 [fisco-dev] + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + * + */ + +package org.fisco.bcos.sdk.v3.client.protocol.response; + +import org.fisco.bcos.sdk.v3.model.JsonRpcResponse; + +public class UninstallLogFilter extends JsonRpcResponse { + public boolean isUninstalled() { + return getResult(); + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/v3/codec/ContractCodec.java b/src/main/java/org/fisco/bcos/sdk/v3/codec/ContractCodec.java index 03073a956..3e21e854c 100644 --- a/src/main/java/org/fisco/bcos/sdk/v3/codec/ContractCodec.java +++ b/src/main/java/org/fisco/bcos/sdk/v3/codec/ContractCodec.java @@ -1017,7 +1017,7 @@ public List decodeEvent(String abi, String eventName, EventLog log) params = ContractCodecTools.decodeJavaObject(inputObject, log.getData(), isWasm); } - List topics = log.getTopics(); + List topics = decodeIndexedEvent(log, abiDefinition); return this.mergeEventParamsAndTopics(abiDefinition, params, topics); } catch (Exception e) { logger.error(" exception in decodeEventToObject : {}", e.getMessage()); @@ -1029,6 +1029,30 @@ public List decodeEvent(String abi, String eventName, EventLog log) throw new ContractCodecException(errorMsg); } + public List decodeIndexedEvent(EventLog log, ABIDefinition abiDefinition) + throws ClassNotFoundException { + List eventIndexedObject = + ABIObjectFactory.createEventIndexedObject(abiDefinition); + List topics = new ArrayList<>(); + if (!log.getTopics().isEmpty()) { + topics.add(log.getTopics().get(0)); + for (int i = 1; i < log.getTopics().size(); i++) { + ABIObject indexedObject = eventIndexedObject.get(i - 1); + if (indexedObject.isDynamic()) { + topics.add(log.getTopics().get(i)); + } else { + List objects = + contractCodecJsonWrapper.decode( + indexedObject, Hex.decode(log.getTopics().get(i)), isWasm); + if (!objects.isEmpty()) { + topics.add(objects.get(0)); + } + } + } + } + return topics; + } + public List decodeEventByTopic(String abi, String eventTopic, EventLog log) throws ContractCodecException { ContractABIDefinition contractABIDefinition = this.abiDefinitionFactory.loadABI(abi); @@ -1040,7 +1064,7 @@ public List decodeEventByTopic(String abi, String eventTopic, EventLog l if (!log.getData().equals("0x")) { params = ContractCodecTools.decodeJavaObject(inputObject, log.getData(), isWasm); } - List topics = log.getTopics(); + List topics = decodeIndexedEvent(log, abiDefinition); return this.mergeEventParamsAndTopics(abiDefinition, params, topics); } catch (Exception e) { logger.error(" exception in decodeEventByTopicToObject : {}", e.getMessage()); @@ -1078,7 +1102,7 @@ public List decodeEventToString(String abi, String eventName, EventLog l contractCodecJsonWrapper.decode( inputObject, Hex.decode(log.getData()), isWasm); } - List topics = log.getTopics(); + List topics = decodeIndexedEvent(log, abiDefinition); return this.mergeEventParamsAndTopicsToString(abiDefinition, params, topics); } catch (Exception e) { logger.error(" exception in decodeEventToString : {}", e.getMessage()); @@ -1103,7 +1127,7 @@ public List decodeEventByTopicToString(String abi, String eventTopic, Ev contractCodecJsonWrapper.decode( inputObject, Hex.decode(log.getData()), isWasm); } - List topics = log.getTopics(); + List topics = decodeIndexedEvent(log, abiDefinition); return this.mergeEventParamsAndTopicsToString(abiDefinition, params, topics); } catch (Exception e) { logger.error(" exception in decodeEventByTopicToString : {}", e.getMessage()); diff --git a/src/main/java/org/fisco/bcos/sdk/v3/codec/abi/TypeDecoder.java b/src/main/java/org/fisco/bcos/sdk/v3/codec/abi/TypeDecoder.java index d393e83ae..8f731b19d 100644 --- a/src/main/java/org/fisco/bcos/sdk/v3/codec/abi/TypeDecoder.java +++ b/src/main/java/org/fisco/bcos/sdk/v3/codec/abi/TypeDecoder.java @@ -85,7 +85,8 @@ public static T decodeNumeric(byte[] inputByteArray, Cla byte[] resultByteArray = new byte[typeLengthAsBytes + 1]; if (Int.class.isAssignableFrom(type) || Fixed.class.isAssignableFrom(type)) { - resultByteArray[0] = inputByteArray[0]; // take MSB as sign bit + // NOTE (first byte & 0xffff) >> 7 means take the MSB as sign bit + resultByteArray[0] = (byte) ((inputByteArray[0] & 0xffff) >> 7); } int valueOffset = Type.MAX_BYTE_LENGTH - typeLengthAsBytes; diff --git a/src/main/java/org/fisco/bcos/sdk/v3/codec/datatypes/Event.java b/src/main/java/org/fisco/bcos/sdk/v3/codec/datatypes/Event.java index ba6e5b15a..ffe045343 100644 --- a/src/main/java/org/fisco/bcos/sdk/v3/codec/datatypes/Event.java +++ b/src/main/java/org/fisco/bcos/sdk/v3/codec/datatypes/Event.java @@ -2,7 +2,9 @@ import java.util.List; import java.util.stream.Collectors; +import org.fisco.bcos.sdk.v3.codec.EventEncoder; import org.fisco.bcos.sdk.v3.codec.Utils; +import org.fisco.bcos.sdk.v3.crypto.hash.Hash; /** Event wrapper type. */ public class Event { @@ -29,4 +31,9 @@ public List> getIndexedParameters() { public List> getNonIndexedParameters() { return parameters.stream().filter(p -> !p.isIndexed()).collect(Collectors.toList()); } + + public String encodeToTopic(Hash hashImpl) { + EventEncoder encoder = new EventEncoder(hashImpl); + return encoder.encode(this); + } } diff --git a/src/main/java/org/fisco/bcos/sdk/v3/codec/wrapper/ABIObjectFactory.java b/src/main/java/org/fisco/bcos/sdk/v3/codec/wrapper/ABIObjectFactory.java index 701f1c308..dd14f0950 100644 --- a/src/main/java/org/fisco/bcos/sdk/v3/codec/wrapper/ABIObjectFactory.java +++ b/src/main/java/org/fisco/bcos/sdk/v3/codec/wrapper/ABIObjectFactory.java @@ -1,6 +1,7 @@ package org.fisco.bcos.sdk.v3.codec.wrapper; import java.math.BigInteger; +import java.util.ArrayList; import java.util.List; import org.fisco.bcos.sdk.v3.utils.Numeric; import org.slf4j.Logger; @@ -37,6 +38,16 @@ private static ABIObject createObject(String name, List return null; } + public static List createEventIndexedObject(ABIDefinition abiDefinition) { + ArrayList abiObjects = new ArrayList<>(); + for (ABIDefinition.NamedType namedType : abiDefinition.getInputs()) { + if (namedType.isIndexed()) { + abiObjects.add(buildTypeObject(namedType)); + } + } + return abiObjects; + } + public static ABIObject createEventInputObject(ABIDefinition abiDefinition) { return creatEventObjectWithOutIndexed(abiDefinition.getInputs()); } diff --git a/src/main/java/org/fisco/bcos/sdk/v3/codec/wrapper/ContractABIDefinition.java b/src/main/java/org/fisco/bcos/sdk/v3/codec/wrapper/ContractABIDefinition.java index a5c75e7dc..a30649ca3 100644 --- a/src/main/java/org/fisco/bcos/sdk/v3/codec/wrapper/ContractABIDefinition.java +++ b/src/main/java/org/fisco/bcos/sdk/v3/codec/wrapper/ContractABIDefinition.java @@ -93,7 +93,7 @@ public void addFunction(String name, ABIDefinition abiDefinition) { this.functions.put(name, new ArrayList<>()); abiDefinitions = this.functions.get(name); } else { - logger.info(" overload method ??? name: {}, abiDefinition: {}", name, abiDefinition); + logger.trace(" overload method ??? name: {}, abiDefinition: {}", name, abiDefinition); } abiDefinitions.add(abiDefinition); @@ -112,8 +112,14 @@ public void addFunction(String name, ABIDefinition abiDefinition) { } public void addEvent(String name, ABIDefinition abiDefinition) { - this.events.putIfAbsent(name, new ArrayList<>()); List abiDefinitions = this.events.get(name); + if (abiDefinitions == null) { + this.events.put(name, new ArrayList<>()); + abiDefinitions = this.events.get(name); + } else { + logger.trace(" overload event ??? name: {}, abiDefinition: {}", name, abiDefinition); + } + // reference to the events abiDefinitions.add(abiDefinition); if (logger.isTraceEnabled()) { logger.trace(" name: {}, abi: {}", name, abiDefinition); diff --git a/src/main/java/org/fisco/bcos/sdk/v3/config/model/CryptoMaterialConfig.java b/src/main/java/org/fisco/bcos/sdk/v3/config/model/CryptoMaterialConfig.java index 364645c0c..a8de417ed 100644 --- a/src/main/java/org/fisco/bcos/sdk/v3/config/model/CryptoMaterialConfig.java +++ b/src/main/java/org/fisco/bcos/sdk/v3/config/model/CryptoMaterialConfig.java @@ -52,11 +52,19 @@ public CryptoMaterialConfig(ConfigProperty configProperty) throws ConfigExceptio Map cryptoMaterialProperty = configProperty.getCryptoMaterial(); String useSMCrypto = (String) cryptoMaterialProperty.get("useSMCrypto"); - String disableSsl = (String) cryptoMaterialProperty.get("disableSsl"); + Object disableSsl = cryptoMaterialProperty.get("disableSsl"); + Object enableSsl = cryptoMaterialProperty.get("enableSsl"); String enableHsm = (String) cryptoMaterialProperty.get("enableHsm"); this.useSmCrypto = Boolean.valueOf(useSMCrypto); - this.disableSsl = Boolean.valueOf(disableSsl); + if (disableSsl != null) { + this.disableSsl = Boolean.parseBoolean((String) disableSsl); + } + if (enableSsl != null) { + // if enableSsl is set, disableSsl will be ignored + this.disableSsl = !Boolean.parseBoolean((String) enableSsl); + } + this.enableHsm = Boolean.valueOf(enableHsm); if (this.enableHsm) { diff --git a/src/main/java/org/fisco/bcos/sdk/v3/config/model/NetworkConfig.java b/src/main/java/org/fisco/bcos/sdk/v3/config/model/NetworkConfig.java index 828b25816..54945f33b 100644 --- a/src/main/java/org/fisco/bcos/sdk/v3/config/model/NetworkConfig.java +++ b/src/main/java/org/fisco/bcos/sdk/v3/config/model/NetworkConfig.java @@ -28,7 +28,7 @@ public class NetworkConfig { private List peers; private List tarsPeers; - private int timeout = -1; + private int timeout = 10000; // ms private String defaultGroup; private boolean sendRpcRequestToHighestBlockNode = true; diff --git a/src/main/java/org/fisco/bcos/sdk/v3/contract/Contract.java b/src/main/java/org/fisco/bcos/sdk/v3/contract/Contract.java index 95e1bd8a7..8dc1856d5 100644 --- a/src/main/java/org/fisco/bcos/sdk/v3/contract/Contract.java +++ b/src/main/java/org/fisco/bcos/sdk/v3/contract/Contract.java @@ -81,12 +81,12 @@ public class Contract { protected TransactionManager transactionManager = null; protected final Client client; public static final String FUNC_DEPLOY = "deploy"; - protected final FunctionEncoderInterface functionEncoder; - protected final FunctionReturnDecoderInterface functionReturnDecoder; + public final FunctionEncoderInterface functionEncoder; + public final FunctionReturnDecoderInterface functionReturnDecoder; protected final CryptoKeyPair credential; protected final CryptoSuite cryptoSuite; - protected final EventEncoder eventEncoder; - private final EventSubscribe eventSubscribe; + public final EventEncoder eventEncoder; + public final EventSubscribe eventSubscribe; private boolean enableDAG = false; /** @@ -735,24 +735,24 @@ protected String createSignedTransaction(Function function) { return txPair.getSignedTx(); } - public void subscribeEvent(EventSubParams params, EventSubCallback callback) { - this.eventSubscribe.subscribeEvent(params, callback); + public String subscribeEvent(EventSubParams params, EventSubCallback callback) { + return this.eventSubscribe.subscribeEvent(params, callback); } - public void subscribeEvent(String topic0, EventSubCallback callback) { - subscribeEvent(topic0, BigInteger.valueOf(-1), BigInteger.valueOf(-1), callback); + public String subscribeEvent(String topic0, EventSubCallback callback) { + return subscribeEvent(topic0, BigInteger.valueOf(-1), BigInteger.valueOf(-1), callback); } - public void subscribeEvent( + public String subscribeEvent( String topic0, BigInteger fromBlock, BigInteger toBlock, EventSubCallback callback) { - subscribeEvent( + return subscribeEvent( fromBlock, toBlock, Collections.singletonList(Collections.singletonList(topic0)), callback); } - public void subscribeEvent( + public String subscribeEvent( String topic0, List otherTopics, BigInteger fromBlock, @@ -763,10 +763,10 @@ public void subscribeEvent( for (String otherTopic : otherTopics) { topics.add(Collections.singletonList(otherTopic)); } - subscribeEvent(fromBlock, toBlock, topics, callback); + return subscribeEvent(fromBlock, toBlock, topics, callback); } - public void subscribeEvent( + public String subscribeEvent( BigInteger fromBlock, BigInteger toBlock, List> topics, @@ -781,7 +781,11 @@ public void subscribeEvent( eventSubParams.addTopic(i, topic); } } - subscribeEvent(eventSubParams, callback); + return subscribeEvent(eventSubParams, callback); + } + + public void unsubscribeEvent(String eventId) { + this.eventSubscribe.unsubscribeEvent(eventId); } public static EventValues staticExtractEventParameters( diff --git a/src/main/java/org/fisco/bcos/sdk/v3/contract/auth/manager/AuthManager.java b/src/main/java/org/fisco/bcos/sdk/v3/contract/auth/manager/AuthManager.java index 6617119b8..faf1c8866 100644 --- a/src/main/java/org/fisco/bcos/sdk/v3/contract/auth/manager/AuthManager.java +++ b/src/main/java/org/fisco/bcos/sdk/v3/contract/auth/manager/AuthManager.java @@ -898,20 +898,29 @@ private RetCode getRetCode( private void getExecEvent(TransactionReceipt tr, BigInteger proposalId) throws ContractException { - List execResultEvents = - committeeManager.getExecResultEvents(tr); - if (!execResultEvents.isEmpty()) { - BigInteger execResultParam0 = execResultEvents.get(0).execResultParam0; - if (!BigInteger.ZERO.equals(execResultParam0)) { - RetCode precompiledResponse = - PrecompiledRetCode.getPrecompiledResponse(execResultParam0.intValue(), ""); - throw new ContractException( - "Exec proposal finished with error occurs, proposalId: " - + proposalId - + ", exec error msg: " - + precompiledResponse.getMessage(), - precompiledResponse.getCode()); + try { + List execResultEvents = + committeeManager.getExecResultEvents(tr); + if (!execResultEvents.isEmpty()) { + BigInteger execResultParam0 = execResultEvents.get(0).execResultParam0; + if (!BigInteger.ZERO.equals(execResultParam0)) { + RetCode precompiledResponse = + PrecompiledRetCode.getPrecompiledResponse( + execResultParam0.intValue(), ""); + throw new ContractException( + "Exec proposal finished with error occurs, proposalId: " + + proposalId + + ", exec error msg: " + + precompiledResponse.getMessage(), + precompiledResponse.getCode()); + } } + } catch (Exception e) { + throw new ContractException( + "Exec proposal finished with exception, proposalId: " + + proposalId + + ", exception msg: " + + e.getMessage()); } } } diff --git a/src/main/java/org/fisco/bcos/sdk/v3/contract/precompiled/sysconfig/SystemConfigService.java b/src/main/java/org/fisco/bcos/sdk/v3/contract/precompiled/sysconfig/SystemConfigService.java index 42c597b8f..eec128f30 100644 --- a/src/main/java/org/fisco/bcos/sdk/v3/contract/precompiled/sysconfig/SystemConfigService.java +++ b/src/main/java/org/fisco/bcos/sdk/v3/contract/precompiled/sysconfig/SystemConfigService.java @@ -20,6 +20,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.Set; import java.util.function.Predicate; import java.util.stream.Collectors; import org.fisco.bcos.sdk.v3.client.Client; @@ -56,6 +57,7 @@ public class SystemConfigService { predicateMap.put( TX_GAS_LIMIT, value -> value.compareTo(BigInteger.valueOf(TX_GAS_LIMIT_MIN)) >= 0); predicateMap.put(TX_GAS_PRICE, value -> value.compareTo(BigInteger.ZERO) >= 0); + predicateMap.put(COMPATIBILITY_VERSION, value -> true); } public SystemConfigService(Client client, CryptoKeyPair credential) { @@ -150,6 +152,10 @@ public static boolean isCheckableInValueValidation(String key) { return predicateMap.containsKey(key); } + public static Set getConfigKeys() { + return predicateMap.keySet(); + } + public static boolean checkCompatibilityVersion(Client client, String version) { try { EnumNodeVersion.Version setVersion = EnumNodeVersion.getClassVersion(version); diff --git a/src/main/java/org/fisco/bcos/sdk/v3/filter/BlockFilter.java b/src/main/java/org/fisco/bcos/sdk/v3/filter/BlockFilter.java new file mode 100644 index 000000000..2790d1423 --- /dev/null +++ b/src/main/java/org/fisco/bcos/sdk/v3/filter/BlockFilter.java @@ -0,0 +1,32 @@ +package org.fisco.bcos.sdk.v3.filter; + +import java.util.List; +import org.fisco.bcos.sdk.v3.client.Client; +import org.fisco.bcos.sdk.v3.client.protocol.response.LogFilterResponse; +import org.fisco.bcos.sdk.v3.client.protocol.response.LogWrapper; + +/** Handler for working with block filter requests. */ +public class BlockFilter extends Filter { + + public BlockFilter(Client client, Callback callback) { + super(client, callback); + } + + @Override + protected LogFilterResponse sendRequest() { + return client.newBlockFilter(); + } + + @Override + protected void process(List logResults) { + for (LogWrapper.LogResult logResult : logResults) { + if (logResult instanceof LogWrapper.Hash) { + String blockHash = ((LogWrapper.Hash) logResult).get(); + callback.onEvent(blockHash); + } else { + throw new FilterException( + "Unexpected result type: " + logResult.get() + ", required Hash"); + } + } + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/v3/filter/Callback.java b/src/main/java/org/fisco/bcos/sdk/v3/filter/Callback.java new file mode 100644 index 000000000..876b83e92 --- /dev/null +++ b/src/main/java/org/fisco/bcos/sdk/v3/filter/Callback.java @@ -0,0 +1,6 @@ +package org.fisco.bcos.sdk.v3.filter; + +/** Filter callback interface. */ +public interface Callback { + void onEvent(T value); +} diff --git a/src/main/java/org/fisco/bcos/sdk/v3/filter/Filter.java b/src/main/java/org/fisco/bcos/sdk/v3/filter/Filter.java new file mode 100644 index 000000000..69d4f57e1 --- /dev/null +++ b/src/main/java/org/fisco/bcos/sdk/v3/filter/Filter.java @@ -0,0 +1,117 @@ +package org.fisco.bcos.sdk.v3.filter; + +import java.util.List; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; +import java.util.regex.Pattern; +import org.fisco.bcos.sdk.v3.client.Client; +import org.fisco.bcos.sdk.v3.client.protocol.response.LogFilterResponse; +import org.fisco.bcos.sdk.v3.client.protocol.response.LogWrapper; +import org.fisco.bcos.sdk.v3.client.protocol.response.UninstallLogFilter; +import org.fisco.bcos.sdk.v3.model.JsonRpcResponse; +import org.fisco.bcos.sdk.v3.model.Response; +import org.fisco.bcos.sdk.v3.model.callback.RespCallback; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** Class for creating managed filter requests with callbacks. */ +public abstract class Filter { + + private static final Logger log = LoggerFactory.getLogger(Filter.class); + + protected final Client client; + protected Callback callback; + + protected volatile LogFilterResponse filter; + + protected ScheduledFuture schedule; + + protected ScheduledExecutorService scheduledExecutorService; + + protected long blockTime; + + private static final String FILTER_NOT_FOUND_PATTERN = "(?i)\\bfilter\\s+not\\s+found\\b"; + + public Filter(Client client, Callback callback) { + this.client = client; + this.callback = callback; + } + + public void run(ScheduledExecutorService scheduledExecutorService, long blockTime) + throws FilterException { + try { + LogFilterResponse logFilterResponse = sendRequest(); + filter = logFilterResponse; + } catch (Exception e) { + throwException(e); + } + this.scheduledExecutorService = scheduledExecutorService; + this.blockTime = blockTime; + + // wait for the completion of obtaining historical logs before starting to obtain new logs + schedule = + scheduledExecutorService.scheduleAtFixedRate( + () -> { + this.pollFilter(this.filter); + }, + 0, + blockTime, + TimeUnit.MILLISECONDS); + } + + private void pollFilter(LogFilterResponse logFilterResponse) { + client.getFilterChangesAsync( + logFilterResponse, + new RespCallback() { + @Override + public void onResponse(LogWrapper logWrapper) { + process(logWrapper.getLogs()); + } + + @Override + public void onError(Response error) { + String message = error.getErrorMessage(); + if (Pattern.compile(FILTER_NOT_FOUND_PATTERN).matcher(message).find()) { + reinstallFilter(); + } else { + log.warn("Error sending request, ", error); + } + } + }); + } + + protected abstract LogFilterResponse sendRequest(); + + protected abstract void process(List logResults); + + private void reinstallFilter() { + log.warn( + "Previously installed filter has not been found, trying to re-install. Filter id: {}", + filter.getFilterId()); + schedule.cancel(false); + this.run(scheduledExecutorService, blockTime); + } + + public void cancel() throws FilterException { + schedule.cancel(false); + try { + UninstallLogFilter uninstallLogFilter = client.uninstallFilter(filter); + if (!uninstallLogFilter.isUninstalled()) { + throw new FilterException( + "Filter with id '" + filter.getFilterId() + "' failed to uninstall"); + } + } catch (Exception e) { + throwException(e); + } + } + + void throwException(JsonRpcResponse.Error error) { + throw new FilterException( + "Invalid request: " + (error == null ? "Unknown Error" : error.getMessage())); + } + + void throwException(Throwable cause) { + throw new FilterException("Error sending request", cause); + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/v3/filter/FilterException.java b/src/main/java/org/fisco/bcos/sdk/v3/filter/FilterException.java new file mode 100644 index 000000000..b954fbf4f --- /dev/null +++ b/src/main/java/org/fisco/bcos/sdk/v3/filter/FilterException.java @@ -0,0 +1,13 @@ +package org.fisco.bcos.sdk.v3.filter; + +/** Filter exception wrapper. */ +public class FilterException extends RuntimeException { + + public FilterException(String message) { + super(message); + } + + public FilterException(String message, Throwable cause) { + super(message, cause); + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/v3/filter/FilterSystem.java b/src/main/java/org/fisco/bcos/sdk/v3/filter/FilterSystem.java new file mode 100644 index 000000000..c99ccf65a --- /dev/null +++ b/src/main/java/org/fisco/bcos/sdk/v3/filter/FilterSystem.java @@ -0,0 +1,66 @@ +package org.fisco.bcos.sdk.v3.filter; + +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import org.fisco.bcos.sdk.v3.client.Client; +import org.fisco.bcos.sdk.v3.client.protocol.request.LogFilterRequest; +import org.fisco.bcos.sdk.v3.client.protocol.response.Log; + +public class FilterSystem { + private ScheduledExecutorService scheduledExecutorService; + private Client client; + private long pollingInterval = 1 * 1000; + + public FilterSystem(Client client, int poolSize, long pollingInterval) { + this.client = client; + this.scheduledExecutorService = Executors.newScheduledThreadPool(poolSize); + this.pollingInterval = pollingInterval; + } + + public FilterSystem(Client client, int poolSize) { + this.client = client; + this.scheduledExecutorService = Executors.newScheduledThreadPool(poolSize); + } + + private void run(Filter filter, long pollingInterval) { + filter.run(scheduledExecutorService, pollingInterval); + } + + public Publisher logPublisher(LogFilterRequest filter) { + Publisher publisher = new Publisher(); + run(new LogFilter(client, log -> publisher.publish(log), filter), pollingInterval); + return publisher; + } + + public Publisher blockHashPublisher() { + Publisher publisher = new Publisher(); + run(new BlockFilter(client, log -> publisher.publish(log)), pollingInterval); + return publisher; + } + + public Publisher transactionHashPublisher() { + Publisher publisher = new Publisher(); + run(new PendingTransactionFilter(client, log -> publisher.publish(log)), pollingInterval); + return publisher; + } + + public void stop() { + // Disable new tasks from being submitted + scheduledExecutorService.shutdown(); + try { + // Wait a while for existing tasks to terminate + if (!scheduledExecutorService.awaitTermination(10, TimeUnit.SECONDS)) { + // Cancel currently executing tasks + scheduledExecutorService.shutdownNow(); + // Wait a while for tasks to respond to being cancelled + if (!scheduledExecutorService.awaitTermination(10, TimeUnit.SECONDS)) { + System.err.println("Pool did not terminate"); + } + } + } catch (InterruptedException ie) { + scheduledExecutorService.shutdownNow(); + Thread.currentThread().interrupt(); + } + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/v3/filter/LogFilter.java b/src/main/java/org/fisco/bcos/sdk/v3/filter/LogFilter.java new file mode 100644 index 000000000..501115cc4 --- /dev/null +++ b/src/main/java/org/fisco/bcos/sdk/v3/filter/LogFilter.java @@ -0,0 +1,37 @@ +package org.fisco.bcos.sdk.v3.filter; + +import java.util.List; +import org.fisco.bcos.sdk.v3.client.Client; +import org.fisco.bcos.sdk.v3.client.protocol.request.LogFilterRequest; +import org.fisco.bcos.sdk.v3.client.protocol.response.Log; +import org.fisco.bcos.sdk.v3.client.protocol.response.LogFilterResponse; +import org.fisco.bcos.sdk.v3.client.protocol.response.LogWrapper; + +/** Log filter handler. */ +public class LogFilter extends Filter { + + protected final LogFilterRequest params; + + public LogFilter(Client client, Callback callback, LogFilterRequest params) { + super(client, callback); + this.params = params; + } + + @Override + protected LogFilterResponse sendRequest() { + return client.newFilter(params); + } + + @Override + protected void process(List logResults) { + for (LogWrapper.LogResult logResult : logResults) { + if (logResult instanceof LogWrapper.LogObject) { + Log log = ((LogWrapper.LogObject) logResult).get(); + callback.onEvent(log); + } else { + throw new FilterException( + "Unexpected result type: " + logResult.get() + " required LogObject"); + } + } + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/v3/filter/PendingTransactionFilter.java b/src/main/java/org/fisco/bcos/sdk/v3/filter/PendingTransactionFilter.java new file mode 100644 index 000000000..7912535ea --- /dev/null +++ b/src/main/java/org/fisco/bcos/sdk/v3/filter/PendingTransactionFilter.java @@ -0,0 +1,32 @@ +package org.fisco.bcos.sdk.v3.filter; + +import java.util.List; +import org.fisco.bcos.sdk.v3.client.Client; +import org.fisco.bcos.sdk.v3.client.protocol.response.LogFilterResponse; +import org.fisco.bcos.sdk.v3.client.protocol.response.LogWrapper; + +/** Handler for working with transaction filter requests. */ +public class PendingTransactionFilter extends Filter { + + public PendingTransactionFilter(Client client, Callback callback) { + super(client, callback); + } + + @Override + protected LogFilterResponse sendRequest() { + return client.newPendingTransactionFilter(); + } + + @Override + protected void process(List logResults) { + for (LogWrapper.LogResult logResult : logResults) { + if (logResult instanceof LogWrapper.Hash) { + String transactionHash = ((LogWrapper.Hash) logResult).get(); + callback.onEvent(transactionHash); + } else { + throw new FilterException( + "Unexpected result type: " + logResult.get() + ", required Hash"); + } + } + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/v3/filter/Publisher.java b/src/main/java/org/fisco/bcos/sdk/v3/filter/Publisher.java new file mode 100644 index 000000000..8328d8f40 --- /dev/null +++ b/src/main/java/org/fisco/bcos/sdk/v3/filter/Publisher.java @@ -0,0 +1,24 @@ +package org.fisco.bcos.sdk.v3.filter; + +import java.util.ArrayList; +import java.util.List; +import java.util.function.Consumer; + +public class Publisher { + private List> subscribers = new ArrayList<>(); + + public Subscription subscribe(Consumer subscriber) { + subscribers.add(subscriber); + return new Subscription<>(this, subscriber); + } + + public void unsubscribe(Consumer subscriber) { + subscribers.remove(subscriber); + } + + public void publish(T event) { + for (Consumer subscriber : subscribers) { + subscriber.accept(event); + } + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/v3/filter/Subscription.java b/src/main/java/org/fisco/bcos/sdk/v3/filter/Subscription.java new file mode 100644 index 000000000..22ef708e6 --- /dev/null +++ b/src/main/java/org/fisco/bcos/sdk/v3/filter/Subscription.java @@ -0,0 +1,17 @@ +package org.fisco.bcos.sdk.v3.filter; + +import java.util.function.Consumer; + +public class Subscription { + private Publisher publisher; + private Consumer consumer; + + public Subscription(Publisher publisher, Consumer consumer) { + this.publisher = publisher; + this.consumer = consumer; + } + + public void unsubscribe() { + publisher.unsubscribe(consumer); + } +} diff --git a/src/main/java/org/fisco/bcos/sdk/v3/model/Response.java b/src/main/java/org/fisco/bcos/sdk/v3/model/Response.java index 5211edbb1..0e98fabb5 100644 --- a/src/main/java/org/fisco/bcos/sdk/v3/model/Response.java +++ b/src/main/java/org/fisco/bcos/sdk/v3/model/Response.java @@ -47,6 +47,10 @@ public byte[] getContent() { return content; } + public String getContentString() { + return new String(content); + } + public void setContent(byte[] content) { this.content = content; } diff --git a/src/main/java/org/fisco/bcos/sdk/v3/transaction/codec/decode/TransactionDecoderService.java b/src/main/java/org/fisco/bcos/sdk/v3/transaction/codec/decode/TransactionDecoderService.java index b2790eea6..83a099d5d 100644 --- a/src/main/java/org/fisco/bcos/sdk/v3/transaction/codec/decode/TransactionDecoderService.java +++ b/src/main/java/org/fisco/bcos/sdk/v3/transaction/codec/decode/TransactionDecoderService.java @@ -92,6 +92,11 @@ public String decodeRevertMessage(String output) { if (output.length() <= 8) { return null; } else { + // only decode evm Error(string) message now + if (!RevertMessageParser.isOutputStartWithRevertMethod(output)) { + throw new RuntimeException( + "Output is not start with revert method, maybe not a standard evm error."); + } // This revert msg encoder/decoder only use ABI FunctionReturnDecoderInterface functionReturnDecoderInterface = new org.fisco.bcos.sdk.v3.codec.abi.FunctionReturnDecoder(); diff --git a/src/main/java/org/fisco/bcos/sdk/v3/transaction/manager/transactionv1/dto/BasicRequest.java b/src/main/java/org/fisco/bcos/sdk/v3/transaction/manager/transactionv1/dto/BasicRequest.java index 6e9973dc0..ba99e67ba 100644 --- a/src/main/java/org/fisco/bcos/sdk/v3/transaction/manager/transactionv1/dto/BasicRequest.java +++ b/src/main/java/org/fisco/bcos/sdk/v3/transaction/manager/transactionv1/dto/BasicRequest.java @@ -119,6 +119,10 @@ public TransactionVersion getVersion() { } public void setVersion(TransactionVersion version) { + if (this.version.getValue() < version.getValue()) this.version = version; + } + + public void setVersionForce(TransactionVersion version) { this.version = version; } diff --git a/src/main/java/org/fisco/bcos/sdk/v3/transaction/manager/transactionv1/utils/TransactionRequestBuilder.java b/src/main/java/org/fisco/bcos/sdk/v3/transaction/manager/transactionv1/utils/TransactionRequestBuilder.java index e9ac22aa6..82bfab0aa 100644 --- a/src/main/java/org/fisco/bcos/sdk/v3/transaction/manager/transactionv1/utils/TransactionRequestBuilder.java +++ b/src/main/java/org/fisco/bcos/sdk/v3/transaction/manager/transactionv1/utils/TransactionRequestBuilder.java @@ -39,6 +39,18 @@ public TransactionRequestBuilder(String abi, String bin) { this.bin = bin; } + public TransactionRequestBuilder setVersion(TransactionVersion version) { + if (this.version.getValue() < version.getValue()) { + this.version = version; + } + return this; + } + + public TransactionRequestBuilder setVersionForce(TransactionVersion version) { + this.version = version; + return this; + } + public TransactionRequestBuilder setMethod(String method) { this.method = method; return this; @@ -66,31 +78,41 @@ public TransactionRequestBuilder setNonce(String nonce) { public TransactionRequestBuilder setValue(BigInteger value) { this.value = value; - if (value != null) this.version = TransactionVersion.V1; + if (value != null) { + return setVersion(TransactionVersion.V1); + } return this; } public TransactionRequestBuilder setGasPrice(BigInteger gasPrice) { this.gasPrice = gasPrice; - if (gasPrice != null) this.version = TransactionVersion.V1; + if (gasPrice != null) { + return setVersion(TransactionVersion.V1); + } return this; } public TransactionRequestBuilder setGasLimit(BigInteger gasLimit) { this.gasLimit = gasLimit; - if (gasLimit != null) this.version = TransactionVersion.V1; + if (gasLimit != null) { + return setVersion(TransactionVersion.V1); + } return this; } public TransactionRequestBuilder setEIP1559Struct(EIP1559Struct eip1559Struct) { this.eip1559Struct = eip1559Struct; - if (eip1559Struct != null) this.version = TransactionVersion.V1; + if (eip1559Struct != null) { + setVersion(TransactionVersion.V1); + } return this; } public TransactionRequestBuilder setExtension(byte[] extension) { this.extension = extension; - if (extension != null && extension.length > 0) this.version = TransactionVersion.V2; + if (extension != null && extension.length > 0) { + setVersion(TransactionVersion.V2); + } return this; } @@ -116,7 +138,6 @@ public TransactionRequest buildRequest(List params) throws ContractExcep this.gasLimit, this.eip1559Struct, this.extension); - sendTransactionRequest.setVersion(version); sendTransactionRequest.setParams(params); return sendTransactionRequest; } diff --git a/src/main/java/org/fisco/bcos/sdk/v3/transaction/model/dto/TransactionResponse.java b/src/main/java/org/fisco/bcos/sdk/v3/transaction/model/dto/TransactionResponse.java index 1afe41abb..737547baa 100644 --- a/src/main/java/org/fisco/bcos/sdk/v3/transaction/model/dto/TransactionResponse.java +++ b/src/main/java/org/fisco/bcos/sdk/v3/transaction/model/dto/TransactionResponse.java @@ -32,7 +32,7 @@ public class TransactionResponse extends CommonResponse { private TransactionReceipt transactionReceipt; private String contractAddress; - private String values; + @Deprecated private String values; private String events; private String receiptMessages; private List returnObject; diff --git a/src/test/resources/applicationContext-sample.xml b/src/test/resources/applicationContext-sample.xml index 25fc1d544..4efc9e5b3 100644 --- a/src/test/resources/applicationContext-sample.xml +++ b/src/test/resources/applicationContext-sample.xml @@ -9,7 +9,7 @@ - + diff --git a/src/test/resources/config-example.toml b/src/test/resources/config-example.toml index b99d1ce45..794cce926 100644 --- a/src/test/resources/config-example.toml +++ b/src/test/resources/config-example.toml @@ -2,7 +2,7 @@ certPath = "conf" # The certification path useSMCrypto = "false" -disableSsl = "false" # Communication with nodes without SSL +enableSsl = "true" # Communication with nodes without SSL # The following configurations take the certPath by default if commented # caCert = "conf/ca.crt" # CA cert file path diff --git a/src/test/resources/config.toml b/src/test/resources/config.toml index b99d1ce45..794cce926 100644 --- a/src/test/resources/config.toml +++ b/src/test/resources/config.toml @@ -2,7 +2,7 @@ certPath = "conf" # The certification path useSMCrypto = "false" -disableSsl = "false" # Communication with nodes without SSL +enableSsl = "true" # Communication with nodes without SSL # The following configurations take the certPath by default if commented # caCert = "conf/ca.crt" # CA cert file path