From 925a0011c4a9959d22ff10824f248ecf66839f58 Mon Sep 17 00:00:00 2001 From: octopus <912554887@qq.com> Date: Mon, 17 Aug 2020 11:00:19 +0800 Subject: [PATCH 01/23] set jdk.disabled.namedCurves to resolved the issue of jdK14 unavailable --- src/main/java/org/fisco/bcos/channel/client/Service.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/fisco/bcos/channel/client/Service.java b/src/main/java/org/fisco/bcos/channel/client/Service.java index 6aef24e9f..80e01285d 100644 --- a/src/main/java/org/fisco/bcos/channel/client/Service.java +++ b/src/main/java/org/fisco/bcos/channel/client/Service.java @@ -18,6 +18,7 @@ import java.security.NoSuchProviderException; import java.security.PrivateKey; import java.security.PublicKey; +import java.security.Security; import java.security.cert.CertificateException; import java.security.spec.InvalidKeySpecException; import java.util.ArrayList; @@ -292,7 +293,11 @@ private void parseFromTopic2KeyInfo() } public void initJavaOpt() { - logger.trace(" initJavaOpt empty func ."); + + logger.info(" #jdk.disabled.namedCurves. "); + + Security.setProperty("jdk.disabled.namedCurves", ""); + /* System.setProperty("jdk.tls.namedGroups", "secp256k1"); logger.info( From 86c36e440eeb42dfe601b696b55fd27f9a67ebde Mon Sep 17 00:00:00 2001 From: octopus <912554887@qq.com> Date: Mon, 17 Aug 2020 11:07:53 +0800 Subject: [PATCH 02/23] add jdk14 travis ci --- .github/workflows/workflow.yml | 2 +- .travis.yml | 30 ++++++++++++++++++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 8e8b194a6..98798ec69 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -1,4 +1,4 @@ -name: Java-SDK GitHub Actions +name: Web3SDK GitHub Actions on: push: pull_request: diff --git a/.travis.yml b/.travis.yml index 7c4defeca..bb112bc19 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,6 +29,13 @@ jobs: dist: xenial sudo: required + # ubuntu 16 + - language: java + jdk: openjdk14 + os: linux + dist: xenial + sudo: required + # ubuntu 16 - language: java jdk: oraclejdk11 @@ -36,6 +43,13 @@ jobs: dist: xenial sudo: required + # ubuntu 16 + - language: java + jdk: oraclejdk14 + os: linux + dist: xenial + sudo: required + # ubuntu 18 - language: java jdk: openjdk8 @@ -50,6 +64,13 @@ jobs: dist: bionic sudo: required + # ubuntu 18 + - language: java + jdk: openjdk14 + os: linux + dist: bionic + sudo: required + # ubuntu 18 - language: java jdk: oraclejdk11 @@ -57,6 +78,13 @@ jobs: dist: bionic sudo: required + # ubuntu 18 + - language: java + jdk: oraclejdk14 + os: linux + dist: bionic + sudo: required + # # os # - language: java # os: osx @@ -73,7 +101,5 @@ cache: directories: - $HOME/.gradle/caches/ - $HOME/.gradle/wrapper/ -before_install: - - gradle wrapper script: | bash .ci/ci_check.sh From 6d3a62114efb4bc00845c58f6d45c677d059e165 Mon Sep 17 00:00:00 2001 From: octopus <912554887@qq.com> Date: Mon, 17 Aug 2020 12:22:32 +0800 Subject: [PATCH 03/23] update build.gradle to suitable jdK14 --- .ci/ci_check.sh | 2 +- build.gradle | 6 +++--- gradle/wrapper/gradle-wrapper.properties | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.ci/ci_check.sh b/.ci/ci_check.sh index f9a58352b..6007f722f 100755 --- a/.ci/ci_check.sh +++ b/.ci/ci_check.sh @@ -7,7 +7,7 @@ java -version # code format check bash gradlew verifyGoogleJavaFormat # build -bash gradlew build +bash gradlew build -x integrationTest # UT test bash gradlew test diff --git a/build.gradle b/build.gradle index 192de7d80..4dd18f476 100644 --- a/build.gradle +++ b/build.gradle @@ -141,9 +141,9 @@ tasks.clean.dependsOn(tasks.cleanBuildArtifacts) check.dependsOn integrationTest integrationTest.mustRunAfter test -check.dependsOn.remove(test) -check.dependsOn.remove(integrationTest) -check.dependsOn.remove(verifyGoogleJavaFormat) +//check.dependsOn.remove(test) +//check.dependsOn.remove(integrationTest) +//check.dependsOn.remove(verifyGoogleJavaFormat) jar { // destinationDir file('dist/apps') diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 7c4388a92..a4b442974 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists From 1b10d23547b9d35ab0d3bdc5a067d89d2caad5c3 Mon Sep 17 00:00:00 2001 From: octopus <912554887@qq.com> Date: Mon, 17 Aug 2020 14:28:29 +0800 Subject: [PATCH 04/23] update publish web3sdk version --- .github/workflows/workflow.yml | 3 --- publish.gradle | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index 98798ec69..b9e20da7c 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -18,9 +18,6 @@ jobs: - uses: actions/checkout@v2 with: fetch-depth: 5 - - name: check commit - if: ${{ runner.os == 'Linux' && github.base_ref != 'master' && github.event_name == 'pull_request' }} - run: bash .ci/ci_check_commit.sh - name: install macOS dependencies if: runner.os == 'macOS' run: brew install openssl@1.1 openjdk diff --git a/publish.gradle b/publish.gradle index 24f57488c..92007e1b1 100644 --- a/publish.gradle +++ b/publish.gradle @@ -94,7 +94,7 @@ dependencies { archivesBaseName = 'web3sdk' group = 'org.fisco-bcos' -version = '2.6.0-SNAPSHOT' +version = '2.6.1-SNAPSHOT' // Additional attribute definition From 3fa6a3ad2d509f51d2da3952d62f0ec7ad8a7e54 Mon Sep 17 00:00:00 2001 From: octopus <912554887@qq.com> Date: Fri, 21 Aug 2020 10:15:55 +0800 Subject: [PATCH 05/23] Table.sol getUint update --- solidity/Table.sol | 4 +- src/test/resources/contract/OkD.sol | 57 --------------- src/test/resources/contract/Table.sol | 56 --------------- src/test/resources/contract/TableTest.sol | 87 ----------------------- 4 files changed, 2 insertions(+), 202 deletions(-) delete mode 100644 src/test/resources/contract/OkD.sol delete mode 100644 src/test/resources/contract/Table.sol delete mode 100644 src/test/resources/contract/TableTest.sol diff --git a/solidity/Table.sol b/solidity/Table.sol index a590dabe7..2f172e191 100644 --- a/solidity/Table.sol +++ b/solidity/Table.sol @@ -26,7 +26,7 @@ contract Condition { //one record contract Entry { function getInt(string) public constant returns (int256); - function getUInt(string) public constant returns (int256); + function getUInt(string) public constant returns (uint256); function getAddress(string) public constant returns (address); function getBytes64(string) public constant returns (bytes1[64]); function getBytes32(string) public constant returns (bytes32); @@ -60,7 +60,7 @@ contract KVTableFactory { function createTable(string, string, string) public returns (int256); } -//KVTable per permiary key has only one Entry +//KVTable per primary key has only one Entry contract KVTable { function get(string) public constant returns (bool, Entry); function set(string, Entry) public returns (int256); diff --git a/src/test/resources/contract/OkD.sol b/src/test/resources/contract/OkD.sol deleted file mode 100644 index 3d07a6213..000000000 --- a/src/test/resources/contract/OkD.sol +++ /dev/null @@ -1,57 +0,0 @@ -import "./Table.sol"; - -contract OkD{ - event insertResult(int count); - - struct Account{ - address account; - int balance; - } - - Account from; - Account to; - - function OkD(){ - - from.account=0x1; - from.balance=10000000000; - to.account=0x2; - to.balance=0; - - TableFactory tf = TableFactory(0x1001); - tf.createTable("t_ok", "from_accout", "from_balance,to_accout,to_balance"); - tf = TableFactory(0x1001); - Table table = tf.openTable("t_ok"); - Entry entry = table.newEntry(); - entry.set("from_accout", "0x1"); - entry.set("from_balance", 10000000000); - entry.set("to_accout", "0x2"); - entry.set("to_balance", 0); - - } - function get()constant returns(int){ - return to.balance; - } - function trans(string from_accout, int num){ - - if (from.balance < num || to.balance + num < to.balance) - return; // Deny overflow - - from.balance = from.balance - num; - to.balance += num; - - TableFactory tf = TableFactory(0x1001); - Table table = tf.openTable("t_ok"); - Entry entry = table.newEntry(); - entry.set("from_accout", from_accout); - entry.set("from_balance", from.balance); - entry.set("to_accout", "0x2"); - entry.set("to_balance", to.balance); - int count = table.insert(from_accout, entry); - insertResult(count); - - // log.push(Translog("20170413",from.account,to.account,num)); - - } - -} diff --git a/src/test/resources/contract/Table.sol b/src/test/resources/contract/Table.sol deleted file mode 100644 index e275d4772..000000000 --- a/src/test/resources/contract/Table.sol +++ /dev/null @@ -1,56 +0,0 @@ -pragma solidity ^0.4.24; - -contract TableFactory { - function openTable(string) public constant returns (Table); //open table - function createTable(string,string,string) public returns(int); //create table -} - -//select condition -contract Condition { - function EQ(string, int) public; - function EQ(string, string) public; - - function NE(string, int) public; - function NE(string, string) public; - - function GT(string, int) public; - function GE(string, int) public; - - function LT(string, int) public; - function LE(string, int) public; - - function limit(int) public; - function limit(int, int) public; -} - -//one record -contract Entry { - function getInt(string) public constant returns(int); - function getAddress(string) public constant returns(address); - function getBytes64(string) public constant returns(byte[64]); - function getBytes32(string) public constant returns(bytes32); - - function set(string, int) public; - function set(string, string) public; -} - -//record sets -contract Entries { - function get(int) public constant returns(Entry); - function size() public constant returns(int); -} - -//Table main contract -contract Table { - //select api - function select(string, Condition) public constant returns(Entries); - //insert api - function insert(string, Entry) public returns(int); - //update api - function update(string, Entry, Condition) public returns(int); - //remove api - function remove(string, Condition) public returns(int); - - function newEntry() public constant returns(Entry); - function newCondition() public constant returns(Condition); -} diff --git a/src/test/resources/contract/TableTest.sol b/src/test/resources/contract/TableTest.sol deleted file mode 100644 index 8d57ee2aa..000000000 --- a/src/test/resources/contract/TableTest.sol +++ /dev/null @@ -1,87 +0,0 @@ -import "./Table.sol"; - -contract TableTest { - event createResult(int count); - event selectResult(bytes32 name, int item_id, bytes32 item_name); - event insertResult(int count); - event updateResult(int count); - event removeResult(int count); - - //create table - function create() public { - TableFactory tf = TableFactory(0x1001); //The fixed address is 0x1001 for TableFactory - int count = tf.createTable("t_test", "name", "item_id,item_name"); - emit createResult(count); - } - - //select records - function select(string name) public constant returns(bytes32[], int[], bytes32[]){ - TableFactory tf = TableFactory(0x1001); - Table table = tf.openTable("t_test"); - - Condition condition = table.newCondition(); - //condition.EQ("name", name); - - Entries entries = table.select(name, condition); - bytes32[] memory user_name_bytes_list = new bytes32[](uint256(entries.size())); - int[] memory item_id_list = new int[](uint256(entries.size())); - bytes32[] memory item_name_bytes_list = new bytes32[](uint256(entries.size())); - - for(int i=0; i Date: Mon, 24 Aug 2020 10:59:41 +0800 Subject: [PATCH 06/23] update release_node.txt and ChangeLog.md --- Changelog.md | 14 ++++++++++++++ publish.gradle | 2 +- release_note.txt | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Changelog.md b/Changelog.md index 3a7ea2eca..5934b4cf7 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,17 @@ +### v2.6.2 + +(2020-08-24) + +* 新增 +1. 支持JDK 14 + +* 修复 +1. 修复`Table.sol Entry::getUint`接口返回`int256`的bug + +* 兼容 +1. 适配fisco-bcos 2.6.0版本,支持Channel Message v1/V2/V3协议 + + ### v2.6.0 (2020-08-12) diff --git a/publish.gradle b/publish.gradle index 92007e1b1..9f6705922 100644 --- a/publish.gradle +++ b/publish.gradle @@ -94,7 +94,7 @@ dependencies { archivesBaseName = 'web3sdk' group = 'org.fisco-bcos' -version = '2.6.1-SNAPSHOT' +version = '2.6.2-SNAPSHOT' // Additional attribute definition diff --git a/release_note.txt b/release_note.txt index 8a965c116..382d9d40d 100644 --- a/release_note.txt +++ b/release_note.txt @@ -1 +1 @@ -v2.6.0 +v2.6.2 From 82dd937b40751acba3b552f3f9620440fa0d0e12 Mon Sep 17 00:00:00 2001 From: octopus <912554887@qq.com> Date: Mon, 24 Aug 2020 11:16:17 +0800 Subject: [PATCH 07/23] update abi wrapper --- .../web3j/abi/wrapper/ABICodecJsonWrapper.java | 18 +++++++++++------- .../abi/wrapper/ABIDefinitionFactory.java | 8 +++++--- .../bcos/web3j/abi/wrapper/ABIObject.java | 5 +++++ .../web3j/abi/wrapper/ABIObjectFactory.java | 4 +++- .../abi/wrapper/ContractABIDefinition.java | 18 +++++++++++------- 5 files changed, 35 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/fisco/bcos/web3j/abi/wrapper/ABICodecJsonWrapper.java b/src/main/java/org/fisco/bcos/web3j/abi/wrapper/ABICodecJsonWrapper.java index 7ecee1cc2..91ec8bfaf 100644 --- a/src/main/java/org/fisco/bcos/web3j/abi/wrapper/ABICodecJsonWrapper.java +++ b/src/main/java/org/fisco/bcos/web3j/abi/wrapper/ABICodecJsonWrapper.java @@ -37,6 +37,12 @@ private void errorReport(String path, String expected, String actual) throw new InvalidParameterException(errorMessage); } + private void errorReport(String path, String desc) throws InvalidParameterException { + String errorMessage = "Arguments invalid: " + path + ", message: " + desc; + logger.error(errorMessage); + throw new InvalidParameterException(errorMessage); + } + private ABIObject encodeNode(String path, ABIObject template, JsonNode node) { ABIObject abiObject = template.newObject(); @@ -110,9 +116,8 @@ private ABIObject encodeNode(String path, ABIObject template, JsonNode node) { abiObject.setAddressValue(new Address(node.asText())); } catch (Exception e) { errorReport( - "Invalid address value", - template.getValueType().toString(), - node.asText()); + path, + "Invalid address, address value: " + node.asText()); } break; } @@ -224,9 +229,8 @@ private ABIObject encodeNode(String path, ABIObject template, JsonNode node) { if (structNode == null) { errorReport( - path + "miss field value, field name: " + field.getName(), - template.getValueType().toString(), - node.getNodeType().toString()); + path, + " Missing struct field, field name: " + field.getName()); } abiObject @@ -321,7 +325,7 @@ public ABIObject encode(ABIObject template, List inputs) throws IOExcept } } catch (Exception e) { logger.error(" e: ", e); - errorReport("ROOT", argObject.getValueType().toString(), value); + errorReport("ROOT", e.getMessage()); } break; diff --git a/src/main/java/org/fisco/bcos/web3j/abi/wrapper/ABIDefinitionFactory.java b/src/main/java/org/fisco/bcos/web3j/abi/wrapper/ABIDefinitionFactory.java index 7c572f815..00d58867f 100644 --- a/src/main/java/org/fisco/bcos/web3j/abi/wrapper/ABIDefinitionFactory.java +++ b/src/main/java/org/fisco/bcos/web3j/abi/wrapper/ABIDefinitionFactory.java @@ -31,12 +31,14 @@ public static ContractABIDefinition loadABI(String abi) { // skip and do nothing } - if (logger.isInfoEnabled()) { - logger.info(" abiDefinition: {}", abiDefinition); + if (logger.isDebugEnabled()) { + logger.debug(" abiDefinition: {}", abiDefinition); } } - logger.info(" contractABIDefinition {} ", contractABIDefinition); + if (logger.isDebugEnabled()) { + logger.debug(" contractABIDefinition {} ", contractABIDefinition); + } return contractABIDefinition; diff --git a/src/main/java/org/fisco/bcos/web3j/abi/wrapper/ABIObject.java b/src/main/java/org/fisco/bcos/web3j/abi/wrapper/ABIObject.java index dc261c7b1..a9cf03ba3 100644 --- a/src/main/java/org/fisco/bcos/web3j/abi/wrapper/ABIObject.java +++ b/src/main/java/org/fisco/bcos/web3j/abi/wrapper/ABIObject.java @@ -1,5 +1,6 @@ package org.fisco.bcos.web3j.abi.wrapper; +import java.security.InvalidParameterException; import java.util.LinkedList; import java.util.List; import java.util.Objects; @@ -349,6 +350,10 @@ public String encode() { } case BYTES: { + if (bytesValue.getValue().length > 32) { + throw new InvalidParameterException( + "the length of bytesN must be equal or less than 32"); + } stringBuffer.append(TypeEncoder.encode(bytesValue)); break; } diff --git a/src/main/java/org/fisco/bcos/web3j/abi/wrapper/ABIObjectFactory.java b/src/main/java/org/fisco/bcos/web3j/abi/wrapper/ABIObjectFactory.java index a6903165c..7d2c5b61b 100644 --- a/src/main/java/org/fisco/bcos/web3j/abi/wrapper/ABIObjectFactory.java +++ b/src/main/java/org/fisco/bcos/web3j/abi/wrapper/ABIObjectFactory.java @@ -27,7 +27,9 @@ private static ABIObject createObject( abiObject.getStructFields().add(buildTypeObject(namedType)); } - logger.info(" name: {}", name); + if (logger.isTraceEnabled()) { + logger.trace(" name: {}", name); + } return abiObject; diff --git a/src/main/java/org/fisco/bcos/web3j/abi/wrapper/ContractABIDefinition.java b/src/main/java/org/fisco/bcos/web3j/abi/wrapper/ContractABIDefinition.java index 9a4c82a5b..96a57effb 100644 --- a/src/main/java/org/fisco/bcos/web3j/abi/wrapper/ContractABIDefinition.java +++ b/src/main/java/org/fisco/bcos/web3j/abi/wrapper/ContractABIDefinition.java @@ -65,19 +65,23 @@ public void addFunction(String name, ABIDefinition abiDefinition) { String methodId = abiDefinition.getMethodId(); methodIDToFunctions.put(methodId, abiDefinition); - logger.info( - " name: {}, methodId: {}, methodSignature: {}, abi: {}", - name, - methodId, - abiDefinition.getMethodSignatureAsString(), - abiDefinition); + if (logger.isDebugEnabled()) { + logger.debug( + " name: {}, methodId: {}, methodSignature: {}, abi: {}", + name, + methodId, + abiDefinition.getMethodSignatureAsString(), + abiDefinition); + } } public void addEvent(String name, ABIDefinition abiDefinition) { events.putIfAbsent(name, new ArrayList<>()); List abiDefinitions = events.get(name); abiDefinitions.add(abiDefinition); - logger.info(" name: {}, abi: {}", name, abiDefinition); + if (logger.isDebugEnabled()) { + logger.debug(" name: {}, abi: {}", name, abiDefinition); + } } public ABIDefinition getABIDefinitionByMethodId(String methodId) { From c908aa9342fe38b9b6478fb123b8be465d9cb06f Mon Sep 17 00:00:00 2001 From: octopus <912554887@qq.com> Date: Tue, 25 Aug 2020 20:39:17 +0800 Subject: [PATCH 08/23] add async method for CRUD Service --- .../web3j/precompile/crud/CRUDService.java | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/src/main/java/org/fisco/bcos/web3j/precompile/crud/CRUDService.java b/src/main/java/org/fisco/bcos/web3j/precompile/crud/CRUDService.java index b45968a9a..e3e2e7d71 100644 --- a/src/main/java/org/fisco/bcos/web3j/precompile/crud/CRUDService.java +++ b/src/main/java/org/fisco/bcos/web3j/precompile/crud/CRUDService.java @@ -4,6 +4,7 @@ import java.math.BigInteger; import java.util.List; import java.util.Map; +import org.fisco.bcos.channel.client.TransactionSucCallback; import org.fisco.bcos.fisco.EnumNodeVersion; import org.fisco.bcos.web3j.crypto.Credentials; import org.fisco.bcos.web3j.precompile.common.PrecompiledCommon; @@ -47,6 +48,11 @@ public int createTable(Table table) throws Exception { return PrecompiledCommon.handleTransactionReceiptForCRUD(receipt); } + public void createTable(Table table, TransactionSucCallback callback) throws Exception { + tableFactory.createTable( + table.getTableName(), table.getKey(), table.getValueFields(), callback); + } + public int insert(Table table, Entry entry) throws Exception { if (table.getKey().length() > PrecompiledCommon.TABLE_KEY_MAX_LENGTH) { @@ -64,6 +70,21 @@ public int insert(Table table, Entry entry) throws Exception { return PrecompiledCommon.handleTransactionReceiptForCRUD(receipt); } + public void insert(Table table, Entry entry, TransactionSucCallback callback) throws Exception { + + if (table.getKey().length() > PrecompiledCommon.TABLE_KEY_MAX_LENGTH) { + throw new PrecompileMessageException( + "The value of the table key exceeds the maximum limit(" + + PrecompiledCommon.TABLE_KEY_MAX_LENGTH + + ")."); + } + String entryJsonStr = + ObjectMapperFactory.getObjectMapper().writeValueAsString(entry.getFields()); + + crud.insert( + table.getTableName(), table.getKey(), entryJsonStr, table.getOptional(), callback); + } + public int update(Table table, Entry entry, Condition condition) throws Exception { if (table.getKey().length() > PrecompiledCommon.TABLE_KEY_MAX_LENGTH) { @@ -87,6 +108,30 @@ public int update(Table table, Entry entry, Condition condition) throws Exceptio return PrecompiledCommon.handleTransactionReceiptForCRUD(receipt); } + public void update( + Table table, Entry entry, Condition condition, TransactionSucCallback callback) + throws Exception { + + if (table.getKey().length() > PrecompiledCommon.TABLE_KEY_MAX_LENGTH) { + throw new PrecompileMessageException( + "The value of the table key exceeds the maximum limit(" + + PrecompiledCommon.TABLE_KEY_MAX_LENGTH + + ")."); + } + String entryJsonStr = + ObjectMapperFactory.getObjectMapper().writeValueAsString(entry.getFields()); + String conditionStr = + ObjectMapperFactory.getObjectMapper().writeValueAsString(condition.getConditions()); + + crud.update( + table.getTableName(), + table.getKey(), + entryJsonStr, + conditionStr, + table.getOptional(), + callback); + } + public int remove(Table table, Condition condition) throws Exception { if (table.getKey().length() > PrecompiledCommon.TABLE_KEY_MAX_LENGTH) { @@ -103,6 +148,22 @@ public int remove(Table table, Condition condition) throws Exception { return PrecompiledCommon.handleTransactionReceiptForCRUD(receipt); } + public void remove(Table table, Condition condition, TransactionSucCallback callback) + throws Exception { + + if (table.getKey().length() > PrecompiledCommon.TABLE_KEY_MAX_LENGTH) { + throw new PrecompileMessageException( + "The value of the table key exceeds the maximum limit(" + + PrecompiledCommon.TABLE_KEY_MAX_LENGTH + + ")."); + } + String conditionStr = + ObjectMapperFactory.getObjectMapper().writeValueAsString(condition.getConditions()); + + crud.remove( + table.getTableName(), table.getKey(), conditionStr, table.getOptional(), callback); + } + @SuppressWarnings("unchecked") public List> select(Table table, Condition condition) throws Exception { From 3d79127cf49f1a783d6aced3d4a56bfa907a7513 Mon Sep 17 00:00:00 2001 From: octopus <912554887@qq.com> Date: Wed, 26 Aug 2020 14:35:09 +0800 Subject: [PATCH 09/23] add getBlockLimit and Deprecated getBlockNumberCache --- .../java/org/fisco/bcos/web3j/Web3jApITest.java | 6 ++++++ .../fisco/bcos/web3j/protocol/core/Ethereum.java | 3 +++ .../bcos/web3j/protocol/core/JsonRpc2_0Web3j.java | 13 +++++++++++++ .../web3j/tx/ExtendedRawTransactionManager.java | 2 +- .../fisco/bcos/web3j/tx/RawTransactionManager.java | 2 +- .../bcos/web3j/tx/ManagedTransactionTester.java | 2 +- 6 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/integration-test/java/org/fisco/bcos/web3j/Web3jApITest.java b/src/integration-test/java/org/fisco/bcos/web3j/Web3jApITest.java index e7038eed8..7ab59bc11 100644 --- a/src/integration-test/java/org/fisco/bcos/web3j/Web3jApITest.java +++ b/src/integration-test/java/org/fisco/bcos/web3j/Web3jApITest.java @@ -56,6 +56,12 @@ public void getBlockNumberCache() throws IOException { assertNotNull(blockNumberCache); } + @Test + public void getBlockNumberLimit() throws IOException { + BigInteger blockLimit = web3j.getBlockLimit(); + assertNotNull(blockLimit); + } + @Test public void pbftView() throws Exception { PbftView pbftView = web3j.getPbftView().send(); diff --git a/src/main/java/org/fisco/bcos/web3j/protocol/core/Ethereum.java b/src/main/java/org/fisco/bcos/web3j/protocol/core/Ethereum.java index 7c5e895e3..e491fe7c1 100644 --- a/src/main/java/org/fisco/bcos/web3j/protocol/core/Ethereum.java +++ b/src/main/java/org/fisco/bcos/web3j/protocol/core/Ethereum.java @@ -106,8 +106,11 @@ Request getTransactionReceiptByHashWithProof( Request getPendingTransaction(); + @Deprecated BigInteger getBlockNumberCache(); + BigInteger getBlockLimit(); + Request getPendingTxSize(); @Deprecated diff --git a/src/main/java/org/fisco/bcos/web3j/protocol/core/JsonRpc2_0Web3j.java b/src/main/java/org/fisco/bcos/web3j/protocol/core/JsonRpc2_0Web3j.java index 362eeba38..c3cccca6f 100644 --- a/src/main/java/org/fisco/bcos/web3j/protocol/core/JsonRpc2_0Web3j.java +++ b/src/main/java/org/fisco/bcos/web3j/protocol/core/JsonRpc2_0Web3j.java @@ -132,6 +132,19 @@ public BigInteger getBlockNumberCache() { return getLocalBlockNumber().add(new BigInteger(BlockLimit.blockLimit.toString())); } + @Override + public BigInteger getBlockLimit() { + if (getLocalBlockNumber().intValue() == 1) { + try { + BlockNumber blockNumber = getBlockNumber().sendAsync().get(); + setBlockNumber(blockNumber.getBlockNumber()); + } catch (Exception e) { + logger.error("Exception: " + e); + } + } + return getLocalBlockNumber().add(new BigInteger(BlockLimit.blockLimit.toString())); + } + @Override public Request getGroupList() { return new Request<>("getGroupList", Arrays.asList(), web3jService, GroupList.class); diff --git a/src/main/java/org/fisco/bcos/web3j/tx/ExtendedRawTransactionManager.java b/src/main/java/org/fisco/bcos/web3j/tx/ExtendedRawTransactionManager.java index 79bc8f000..3133412d3 100644 --- a/src/main/java/org/fisco/bcos/web3j/tx/ExtendedRawTransactionManager.java +++ b/src/main/java/org/fisco/bcos/web3j/tx/ExtendedRawTransactionManager.java @@ -94,7 +94,7 @@ public ExtendedRawTransactionManager( @Override protected BigInteger getBlockLimit() throws IOException { - return web3j.getBlockNumberCache(); + return web3j.getBlockLimit(); } public TxHashVerifier getTxHashVerifier() { diff --git a/src/main/java/org/fisco/bcos/web3j/tx/RawTransactionManager.java b/src/main/java/org/fisco/bcos/web3j/tx/RawTransactionManager.java index 34fa49bfb..bab735002 100644 --- a/src/main/java/org/fisco/bcos/web3j/tx/RawTransactionManager.java +++ b/src/main/java/org/fisco/bcos/web3j/tx/RawTransactionManager.java @@ -65,7 +65,7 @@ public RawTransactionManager(Web3j web3j, Credentials credentials) { @Override protected BigInteger getBlockLimit() throws IOException { - return web3j.getBlockNumberCache(); + return web3j.getBlockLimit(); } public TxHashVerifier getTxHashVerifier() { diff --git a/src/test/java/org/fisco/bcos/web3j/tx/ManagedTransactionTester.java b/src/test/java/org/fisco/bcos/web3j/tx/ManagedTransactionTester.java index a70330fd2..0b41280d4 100644 --- a/src/test/java/org/fisco/bcos/web3j/tx/ManagedTransactionTester.java +++ b/src/test/java/org/fisco/bcos/web3j/tx/ManagedTransactionTester.java @@ -58,7 +58,7 @@ void prepareBlockNumberRequest() throws IOException { Request ethBlockNumberRequest = mock(Request.class); when(ethBlockNumberRequest.send()).thenReturn(ethBlockNumber); when(web3j.getBlockNumber()).thenReturn((Request) ethBlockNumberRequest); - when(web3j.getBlockNumberCache()).thenReturn(new BigInteger("1")); + when(web3j.getBlockLimit()).thenReturn(new BigInteger("1")); } @SuppressWarnings("unchecked") From f73e216fac0bc1dbbb126298ff80f4b3e3a39c3d Mon Sep 17 00:00:00 2001 From: octopus <912554887@qq.com> Date: Wed, 26 Aug 2020 16:17:09 +0800 Subject: [PATCH 10/23] fix queryCNS when constructor Contract object --- src/main/java/org/fisco/bcos/web3j/tx/Contract.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/fisco/bcos/web3j/tx/Contract.java b/src/main/java/org/fisco/bcos/web3j/tx/Contract.java index 142fa0507..8e7260576 100644 --- a/src/main/java/org/fisco/bcos/web3j/tx/Contract.java +++ b/src/main/java/org/fisco/bcos/web3j/tx/Contract.java @@ -72,7 +72,8 @@ protected Contract( TransactionManager transactionManager, ContractGasProvider gasProvider) { super(web3j, transactionManager); - this.contractAddress = cnsService.getAddressByContractNameAndVersion(contractAddress); + this.contractAddress = contractAddress; + // this.contractAddress = cnsService.getAddressByContractNameAndVersion(contractAddress); this.contractBinary = contractBinary; this.gasProvider = gasProvider; } From 4ea86bdd00383e5c85699ad1f59871c51bc3b59d Mon Sep 17 00:00:00 2001 From: octopus <912554887@qq.com> Date: Thu, 27 Aug 2020 10:09:43 +0800 Subject: [PATCH 11/23] fix integTest bug --- .../java/org/fisco/bcos/precompile/CnsServiceTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/integration-test/java/org/fisco/bcos/precompile/CnsServiceTest.java b/src/integration-test/java/org/fisco/bcos/precompile/CnsServiceTest.java index 14f960000..07b891262 100644 --- a/src/integration-test/java/org/fisco/bcos/precompile/CnsServiceTest.java +++ b/src/integration-test/java/org/fisco/bcos/precompile/CnsServiceTest.java @@ -79,7 +79,8 @@ public void getContractAddressFromNameAndVersion() throws Exception { "cnsResolver address" + cnsService.getAddressByContractNameAndVersion(okDemo.getContractAddress())); - Ok okLoaded = Ok.load(name, web3j, credentials, gasPrice, gasLimit); + String contractAddress = cnsService.getAddressByContractNameAndVersion(name + ":10.0"); + Ok okLoaded = Ok.load(contractAddress, web3j, credentials, gasPrice, gasLimit); System.out.println(okLoaded.isValid()); BigInteger balance = okLoaded.get().send(); System.out.println("balance = " + balance); From 419be9a639d05cb27f834ec7425d35b1ad1b71d6 Mon Sep 17 00:00:00 2001 From: octopus <912554887@qq.com> Date: Tue, 15 Sep 2020 19:24:58 +0800 Subject: [PATCH 12/23] update getAddress compatible with 03 04 public key --- .../org/fisco/bcos/web3j/crypto/Keys.java | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/fisco/bcos/web3j/crypto/Keys.java b/src/main/java/org/fisco/bcos/web3j/crypto/Keys.java index a9b9aa9c5..c2efe39da 100644 --- a/src/main/java/org/fisco/bcos/web3j/crypto/Keys.java +++ b/src/main/java/org/fisco/bcos/web3j/crypto/Keys.java @@ -26,6 +26,10 @@ public class Keys { public static final int ADDRESS_LENGTH_IN_HEX = ADDRESS_SIZE >> 2; public static final int PUBLIC_KEY_LENGTH_IN_HEX = PUBLIC_KEY_SIZE << 1; + public static final int PUBLIC_KEY_LENGTH_IN_HEX_WITH_COMPRESS_FLAG_1 = + (PUBLIC_KEY_LENGTH_IN_HEX + 1); + public static final int PUBLIC_KEY_LENGTH_IN_HEX_WITH_COMPRESS_FLAG_2 = + (PUBLIC_KEY_LENGTH_IN_HEX + 2); public static final int PRIVATE_KEY_LENGTH_IN_HEX = PRIVATE_KEY_SIZE << 1; static { @@ -88,8 +92,7 @@ public static String getAddress(ECKeyPair ecKeyPair) { } public static String getAddress(BigInteger publicKey) { - return getAddress( - Numeric.toHexStringWithPrefixZeroPadded(publicKey, PUBLIC_KEY_LENGTH_IN_HEX)); + return getAddress(Numeric.toHexStringNoPrefix(publicKey)); } public static String getAddress(String publicKey) { @@ -99,7 +102,27 @@ public static String getAddress(String publicKey) { publicKeyNoPrefix = Strings.zeros(PUBLIC_KEY_LENGTH_IN_HEX - publicKeyNoPrefix.length()) + publicKeyNoPrefix; + } else if (publicKeyNoPrefix.length() == PUBLIC_KEY_LENGTH_IN_HEX) { + // do nothing + } else if (publicKeyNoPrefix.length() == PUBLIC_KEY_LENGTH_IN_HEX_WITH_COMPRESS_FLAG_2) { + // 130 length,should start with 03 or 04 + if (!(publicKeyNoPrefix.startsWith("03") || publicKeyNoPrefix.startsWith("04"))) { + throw new IllegalArgumentException( + " publicKey not start with \"03\" or \"04\", publicKey: " + publicKey); + } + publicKeyNoPrefix = publicKeyNoPrefix.substring(2); + } else if (publicKeyNoPrefix.length() == PUBLIC_KEY_LENGTH_IN_HEX_WITH_COMPRESS_FLAG_1) { + // 129 length,should start with 3 or 4 + if (!(publicKeyNoPrefix.startsWith("3") || publicKeyNoPrefix.startsWith("4"))) { + throw new IllegalArgumentException( + " publicKey not start with \"3\" or \"4\", publicKey: " + publicKey); + } + publicKeyNoPrefix = publicKeyNoPrefix.substring(1); + } else { + // invalid public key + throw new IllegalArgumentException(" invalid publicKey: " + publicKey); } + String hash = Hash.sha3(publicKeyNoPrefix); return hash.substring(hash.length() - ADDRESS_LENGTH_IN_HEX); // right most 160 bits } From ecc51abe52de03768e7be37f4bcbba839914da3b Mon Sep 17 00:00:00 2001 From: octopus <912554887@qq.com> Date: Thu, 17 Sep 2020 10:18:27 +0800 Subject: [PATCH 13/23] fix ABIDefinition.isConstant bug when using solc 0.6.10 --- .../web3j/protocol/core/methods/response/AbiDefinition.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/fisco/bcos/web3j/protocol/core/methods/response/AbiDefinition.java b/src/main/java/org/fisco/bcos/web3j/protocol/core/methods/response/AbiDefinition.java index c53150502..49bb78c24 100644 --- a/src/main/java/org/fisco/bcos/web3j/protocol/core/methods/response/AbiDefinition.java +++ b/src/main/java/org/fisco/bcos/web3j/protocol/core/methods/response/AbiDefinition.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -18,6 +19,8 @@ public class AbiDefinition { private String stateMutability; + public static List CONSTANT_KEY = Arrays.asList("view"); + public AbiDefinition() {} public AbiDefinition( @@ -48,7 +51,7 @@ public AbiDefinition( } public boolean isConstant() { - return constant; + return constant || CONSTANT_KEY.contains(this.getStateMutability()); } public void setConstant(boolean constant) { From c0e3ae95a83b8ea4c592b42510eadc571f06ec07 Mon Sep 17 00:00:00 2001 From: octopus <912554887@qq.com> Date: Thu, 17 Sep 2020 14:34:33 +0800 Subject: [PATCH 14/23] add failedTxSum field --- .../methods/response/TotalTransactionCount.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/main/java/org/fisco/bcos/web3j/protocol/core/methods/response/TotalTransactionCount.java b/src/main/java/org/fisco/bcos/web3j/protocol/core/methods/response/TotalTransactionCount.java index fbba8334b..e928a30be 100644 --- a/src/main/java/org/fisco/bcos/web3j/protocol/core/methods/response/TotalTransactionCount.java +++ b/src/main/java/org/fisco/bcos/web3j/protocol/core/methods/response/TotalTransactionCount.java @@ -13,6 +13,7 @@ public TransactionCount getTotalTransactionCount() { public class TransactionCount { private String txSum; private String blockNumber; + private String failedTxSum; public TransactionCount() {} @@ -44,5 +45,17 @@ public String getBlockNumberRaw() { public void setBlockNumber(String blockNumber) { this.blockNumber = blockNumber; } + + public BigInteger getFailedTxSum() { + return Numeric.decodeQuantity(failedTxSum); + } + + public String getFailedTxSumRaw() { + return failedTxSum; + } + + public void setFailedTxSum(String failedTxSum) { + this.failedTxSum = failedTxSum; + } } } From 95f1d0f4af1e4ee961ab7b2d2a47e14d4293c23a Mon Sep 17 00:00:00 2001 From: octopus <912554887@qq.com> Date: Fri, 18 Sep 2020 11:10:23 +0800 Subject: [PATCH 15/23] add interface ret receipt for precompiled service --- .../bcos/web3j/precompile/cns/CnsService.java | 12 ++-- .../precompile/common/PrecompiledCommon.java | 2 +- .../config/SystemConfigService.java | 7 ++- .../consensus/ConsensusService.java | 14 ----- .../web3j/precompile/crud/CRUDService.java | 2 +- .../precompile/csm/ContractStatusService.java | 39 +++++-------- .../permission/ChainGovernanceService.java | 45 ++++++++++---- .../permission/PermissionService.java | 58 +++++++++++++------ .../web3j/protocol/channel/StatusCode.java | 2 +- 9 files changed, 106 insertions(+), 75 deletions(-) diff --git a/src/main/java/org/fisco/bcos/web3j/precompile/cns/CnsService.java b/src/main/java/org/fisco/bcos/web3j/precompile/cns/CnsService.java index 0d13036a1..539fc4b7a 100644 --- a/src/main/java/org/fisco/bcos/web3j/precompile/cns/CnsService.java +++ b/src/main/java/org/fisco/bcos/web3j/precompile/cns/CnsService.java @@ -99,14 +99,16 @@ public String getAddressByContractNameAndVersion(String contractNameAndVersion) public String registerCns(String name, String version, String address, String abi) throws Exception { - CNS cns = lookupResolver(); - if (version.length() > MAX_VERSION_LENGTH) { - return PrecompiledCommon.transferToJson(PrecompiledCommon.VersionExceeds); - } - TransactionReceipt receipt = cns.insert(name, version, address, abi).send(); + TransactionReceipt receipt = registerCnsAndRetReceipt(name, version, address, abi); return PrecompiledCommon.handleTransactionReceipt(receipt, web3j); } + public TransactionReceipt registerCnsAndRetReceipt( + String name, String version, String address, String abi) throws Exception { + CNS cns = lookupResolver(); + return cns.insert(name, version, address, abi).send(); + } + public List queryCnsByName(String name) throws Exception { CNS cns = lookupResolver(); String cnsInfo = cns.selectByName(name).send(); diff --git a/src/main/java/org/fisco/bcos/web3j/precompile/common/PrecompiledCommon.java b/src/main/java/org/fisco/bcos/web3j/precompile/common/PrecompiledCommon.java index 568bd3aab..7a7f2f29c 100644 --- a/src/main/java/org/fisco/bcos/web3j/precompile/common/PrecompiledCommon.java +++ b/src/main/java/org/fisco/bcos/web3j/precompile/common/PrecompiledCommon.java @@ -146,7 +146,7 @@ public static String transferToJson(int code) throws IOException { } else if (code == VersionExceeds) { msg = "version string length exceeds the maximum limit"; } else if (code == TableNameLengthOverflow) { - msg = "tablename string length exceeds the maximum limit"; + msg = "table name string length exceeds the maximum limit"; } else if (code == InvalidAddress) { msg = "invalid address format"; } else if (code == InvalidContractFrozen) { diff --git a/src/main/java/org/fisco/bcos/web3j/precompile/config/SystemConfigService.java b/src/main/java/org/fisco/bcos/web3j/precompile/config/SystemConfigService.java index 9becbc603..455cb44e7 100644 --- a/src/main/java/org/fisco/bcos/web3j/precompile/config/SystemConfigService.java +++ b/src/main/java/org/fisco/bcos/web3j/precompile/config/SystemConfigService.java @@ -25,7 +25,12 @@ public SystemConfigService(Web3j web3j, Credentials credentials) { } public String setValueByKey(String key, String value) throws Exception { - TransactionReceipt receipt = systemConfig.setValueByKey(key, value).send(); + TransactionReceipt receipt = setValueByKeyAndRetReceipt(key, value); return PrecompiledCommon.handleTransactionReceipt(receipt, web3j); } + + public TransactionReceipt setValueByKeyAndRetReceipt(String key, String value) + throws Exception { + return systemConfig.setValueByKey(key, value).send(); + } } diff --git a/src/main/java/org/fisco/bcos/web3j/precompile/consensus/ConsensusService.java b/src/main/java/org/fisco/bcos/web3j/precompile/consensus/ConsensusService.java index bf259c5dd..e9c7d1ece 100644 --- a/src/main/java/org/fisco/bcos/web3j/precompile/consensus/ConsensusService.java +++ b/src/main/java/org/fisco/bcos/web3j/precompile/consensus/ConsensusService.java @@ -26,25 +26,11 @@ public ConsensusService(Web3j web3j, Credentials credentials) { } public String addSealer(String nodeID) throws Exception { - if (!isValidNodeID(nodeID)) { - return PrecompiledCommon.transferToJson(PrecompiledCommon.P2pNetwork); - } - List sealerList = web3j.getSealerList().send().getResult(); - if (sealerList.contains(nodeID)) { - return PrecompiledCommon.transferToJson(PrecompiledCommon.SealerList); - } TransactionReceipt receipt = consensus.addSealer(nodeID).send(); return PrecompiledCommon.handleTransactionReceipt(receipt, web3j); } public String addObserver(String nodeID) throws Exception { - if (!isValidNodeID(nodeID)) { - return PrecompiledCommon.transferToJson(PrecompiledCommon.P2pNetwork); - } - List observerList = web3j.getObserverList().send().getResult(); - if (observerList.contains(nodeID)) { - return PrecompiledCommon.transferToJson(PrecompiledCommon.ObserverList); - } TransactionReceipt receipt = consensus.addObserver(nodeID).send(); return PrecompiledCommon.handleTransactionReceipt(receipt, web3j); } diff --git a/src/main/java/org/fisco/bcos/web3j/precompile/crud/CRUDService.java b/src/main/java/org/fisco/bcos/web3j/precompile/crud/CRUDService.java index e3e2e7d71..5488e9150 100644 --- a/src/main/java/org/fisco/bcos/web3j/precompile/crud/CRUDService.java +++ b/src/main/java/org/fisco/bcos/web3j/precompile/crud/CRUDService.java @@ -48,7 +48,7 @@ public int createTable(Table table) throws Exception { return PrecompiledCommon.handleTransactionReceiptForCRUD(receipt); } - public void createTable(Table table, TransactionSucCallback callback) throws Exception { + public void createTable(Table table, TransactionSucCallback callback) { tableFactory.createTable( table.getTableName(), table.getKey(), table.getValueFields(), callback); } diff --git a/src/main/java/org/fisco/bcos/web3j/precompile/csm/ContractStatusService.java b/src/main/java/org/fisco/bcos/web3j/precompile/csm/ContractStatusService.java index 25b0d00cb..55b2c4ffd 100644 --- a/src/main/java/org/fisco/bcos/web3j/precompile/csm/ContractStatusService.java +++ b/src/main/java/org/fisco/bcos/web3j/precompile/csm/ContractStatusService.java @@ -3,7 +3,6 @@ import java.math.BigInteger; import java.util.List; import org.fisco.bcos.web3j.crypto.Credentials; -import org.fisco.bcos.web3j.crypto.WalletUtils; import org.fisco.bcos.web3j.precompile.common.PrecompiledCommon; import org.fisco.bcos.web3j.protocol.ObjectMapperFactory; import org.fisco.bcos.web3j.protocol.Web3j; @@ -32,37 +31,33 @@ public ContractStatusService(Web3j web3j, Credentials credentials) { } public String freeze(String addr) throws Exception { - if (!WalletUtils.isValidAddress(addr)) { - return PrecompiledCommon.transferToJson(PrecompiledCommon.InvalidAddress); - } - - TransactionReceipt receipt = contractLifeCycle.freeze(addr).send(); + TransactionReceipt receipt = freezeAndRetReceipt(addr); return PrecompiledCommon.handleTransactionReceipt(receipt, web3j); } - public String unfreeze(String addr) throws Exception { - if (!WalletUtils.isValidAddress(addr)) { - return PrecompiledCommon.transferToJson(PrecompiledCommon.InvalidAddress); - } + public TransactionReceipt freezeAndRetReceipt(String addr) throws Exception { + return contractLifeCycle.freeze(addr).send(); + } - TransactionReceipt receipt = contractLifeCycle.unfreeze(addr).send(); + public String unfreeze(String addr) throws Exception { + TransactionReceipt receipt = unfreezeAndRetReceipt(addr); return PrecompiledCommon.handleTransactionReceipt(receipt, web3j); } - public String grantManager(String addr, String user) throws Exception { - if (!WalletUtils.isValidAddress(addr) || !WalletUtils.isValidAddress(user)) { - return PrecompiledCommon.transferToJson(PrecompiledCommon.InvalidAddress); - } + public TransactionReceipt unfreezeAndRetReceipt(String addr) throws Exception { + return contractLifeCycle.unfreeze(addr).send(); + } - TransactionReceipt receipt = contractLifeCycle.grantManager(addr, user).send(); + public String grantManager(String addr, String user) throws Exception { + TransactionReceipt receipt = grantManagerAndRetReceipt(addr, user); return PrecompiledCommon.handleTransactionReceipt(receipt, web3j); } - public String getStatus(String addr) throws Exception { - if (!WalletUtils.isValidAddress(addr)) { - return PrecompiledCommon.transferToJson(PrecompiledCommon.InvalidAddress); - } + public TransactionReceipt grantManagerAndRetReceipt(String addr, String user) throws Exception { + return contractLifeCycle.grantManager(addr, user).send(); + } + public String getStatus(String addr) throws Exception { Tuple2 send = contractLifeCycle.getStatus(addr).send(); if (!(send.getValue1().intValue() == PrecompiledCommon.Success)) { return PrecompiledCommon.transferToJson(send.getValue1().intValue()); @@ -71,10 +66,6 @@ public String getStatus(String addr) throws Exception { } public String listManager(String addr) throws Exception { - if (!WalletUtils.isValidAddress(addr)) { - return PrecompiledCommon.transferToJson(PrecompiledCommon.InvalidAddress); - } - Tuple2> send = contractLifeCycle.listManager(addr).send(); if (!(send.getValue1().intValue() == PrecompiledCommon.Success)) { diff --git a/src/main/java/org/fisco/bcos/web3j/precompile/permission/ChainGovernanceService.java b/src/main/java/org/fisco/bcos/web3j/precompile/permission/ChainGovernanceService.java index cf618cb49..12d0e8a19 100644 --- a/src/main/java/org/fisco/bcos/web3j/precompile/permission/ChainGovernanceService.java +++ b/src/main/java/org/fisco/bcos/web3j/precompile/permission/ChainGovernanceService.java @@ -69,11 +69,14 @@ public Tuple2 queryCommitteeMemberWeight(String account) th } public String grantCommitteeMember(String account) throws Exception { - TransactionReceipt transactionReceipt = - chainGovernance.grantCommitteeMember(account).send(); + TransactionReceipt transactionReceipt = grantCommitteeMemberAndRetReceipt(account); return PrecompiledCommon.handleTransactionReceipt(transactionReceipt, web3j); } + public TransactionReceipt grantCommitteeMemberAndRetReceipt(String account) throws Exception { + return chainGovernance.grantCommitteeMember(account).send(); + } + public List listCommitteeMembers() throws Exception { String committeeMembersInfo = chainGovernance.listCommitteeMembers().send(); ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper(); @@ -85,37 +88,59 @@ public List listCommitteeMembers() throws Exception { } public String updateThreshold(int threshold) throws Exception { - TransactionReceipt transactionReceipt = - chainGovernance.updateThreshold(BigInteger.valueOf(threshold)).send(); + TransactionReceipt transactionReceipt = updateThresholdAndRetReceipt(threshold); return PrecompiledCommon.handleTransactionReceipt(transactionReceipt, web3j); } + public TransactionReceipt updateThresholdAndRetReceipt(int threshold) throws Exception { + return chainGovernance.updateThreshold(BigInteger.valueOf(threshold)).send(); + } + public String revokeCommitteeMember(String account) throws Exception { - TransactionReceipt transactionReceipt = - chainGovernance.revokeCommitteeMember(account).send(); + TransactionReceipt transactionReceipt = revokeCommitteeMemberAndRetReceipt(account); return PrecompiledCommon.handleTransactionReceipt(transactionReceipt, web3j); } + public TransactionReceipt revokeCommitteeMemberAndRetReceipt(String account) throws Exception { + return chainGovernance.revokeCommitteeMember(account).send(); + } + public String grantOperator(String account) throws Exception { - TransactionReceipt transactionReceipt = chainGovernance.grantOperator(account).send(); + TransactionReceipt transactionReceipt = grantOperatorAndRetReceipt(account); return PrecompiledCommon.handleTransactionReceipt(transactionReceipt, web3j); } + public TransactionReceipt grantOperatorAndRetReceipt(String account) throws Exception { + return chainGovernance.grantOperator(account).send(); + } + public String revokeOperator(String account) throws Exception { - TransactionReceipt transactionReceipt = chainGovernance.revokeOperator(account).send(); + TransactionReceipt transactionReceipt = revokeOperatorAndRetReceipt(account); return PrecompiledCommon.handleTransactionReceipt(transactionReceipt, web3j); } + public TransactionReceipt revokeOperatorAndRetReceipt(String account) throws Exception { + return chainGovernance.revokeOperator(account).send(); + } + public String freezeAccount(String account) throws Exception { - TransactionReceipt transactionReceipt = chainGovernance.freezeAccount(account).send(); + TransactionReceipt transactionReceipt = freezeAccountAndRetReceipt(account); return PrecompiledCommon.handleTransactionReceipt(transactionReceipt, web3j); } + public TransactionReceipt freezeAccountAndRetReceipt(String account) throws Exception { + return chainGovernance.freezeAccount(account).send(); + } + public String unfreezeAccount(String account) throws Exception { - TransactionReceipt transactionReceipt = chainGovernance.unfreezeAccount(account).send(); + TransactionReceipt transactionReceipt = unfreezeAccountAndRetReceipt(account); return PrecompiledCommon.handleTransactionReceipt(transactionReceipt, web3j); } + public TransactionReceipt unfreezeAccountAndRetReceipt(String account) throws Exception { + return chainGovernance.unfreezeAccount(account).send(); + } + public String getAccountStatus(String account) throws Exception { return chainGovernance.getAccountStatus(account).send(); } diff --git a/src/main/java/org/fisco/bcos/web3j/precompile/permission/PermissionService.java b/src/main/java/org/fisco/bcos/web3j/precompile/permission/PermissionService.java index dc90fd0cd..8381d1472 100644 --- a/src/main/java/org/fisco/bcos/web3j/precompile/permission/PermissionService.java +++ b/src/main/java/org/fisco/bcos/web3j/precompile/permission/PermissionService.java @@ -5,7 +5,6 @@ import java.util.List; import org.fisco.bcos.web3j.crypto.Credentials; import org.fisco.bcos.web3j.precompile.common.PrecompiledCommon; -import org.fisco.bcos.web3j.precompile.crud.CRUDService; import org.fisco.bcos.web3j.protocol.ObjectMapperFactory; import org.fisco.bcos.web3j.protocol.Web3j; import org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt; @@ -31,28 +30,36 @@ public PermissionService(Web3j web3j, Credentials credentials) { } public List queryPermission(String address) throws Exception { - String permissionyInfo = permission.queryPermission(address).send(); + String permissionInfo = permission.queryPermission(address).send(); ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper(); return objectMapper.readValue( - permissionyInfo, + permissionInfo, objectMapper .getTypeFactory() .constructCollectionType(List.class, PermissionInfo.class)); } public String grantWrite(String address, String user) throws Exception { - TransactionReceipt receipt = permission.grantWrite(address, user).send(); - return PrecompiledCommon.handleTransactionReceipt(receipt, web3j); + TransactionReceipt transactionReceipt = grantWriteAndRetReceipt(address, user); + return PrecompiledCommon.handleTransactionReceipt(transactionReceipt, web3j); + } + + public TransactionReceipt grantWriteAndRetReceipt(String address, String user) + throws Exception { + return permission.grantWrite(address, user).send(); } public String revokeWrite(String address, String user) throws Exception { - TransactionReceipt receipt = permission.revokeWrite(address, user).send(); + TransactionReceipt receipt = revokeWriteAndRetReceipt(address, user); return PrecompiledCommon.handleTransactionReceipt(receipt, web3j); } + public TransactionReceipt revokeWriteAndRetReceipt(String address, String user) + throws Exception { + return permission.revokeWrite(address, user).send(); + } + public String grantUserTableManager(String tableName, String grantress) throws Exception { - CRUDService crudSerivce = new CRUDService(web3j, credentials); - crudSerivce.desc(tableName); return grant(tableName, grantress); } @@ -64,12 +71,12 @@ public List listUserTableManager(String tableName) throws Except return list(tableName); } - public String grantDeployAndCreateManager(String grantress) throws Exception { - return grant(PrecompiledCommon.SYS_TABLE, grantress); + public String grantDeployAndCreateManager(String grantees) throws Exception { + return grant(PrecompiledCommon.SYS_TABLE, grantees); } - public String revokeDeployAndCreateManager(String grantress) throws Exception { - return revoke(PrecompiledCommon.SYS_TABLE, grantress); + public String revokeDeployAndCreateManager(String grantees) throws Exception { + return revoke(PrecompiledCommon.SYS_TABLE, grantees); } public List listDeployAndCreateManager() throws Exception { @@ -120,25 +127,40 @@ public String revokeSysConfigManager(String grantress) throws Exception { return revoke(PrecompiledCommon.SYS_CONFIG, grantress); } + public TransactionReceipt revokeSysConfigManagerAndRetReceipt(String grantress) + throws Exception { + return revokeAndRetReceipt(PrecompiledCommon.SYS_CONFIG, grantress); + } + public List listSysConfigManager() throws Exception { return list(PrecompiledCommon.SYS_CONFIG); } - private String grant(String tableName, String grantress) throws Exception { - TransactionReceipt receipt = permission.insert(tableName, grantress).send(); + public String grant(String tableName, String grandness) throws Exception { + TransactionReceipt receipt = grantAndRetReceipt(tableName, grandness); return PrecompiledCommon.handleTransactionReceipt(receipt, web3j); } - private String revoke(String tableName, String address) throws Exception { - TransactionReceipt receipt = permission.remove(tableName, address).send(); + private TransactionReceipt grantAndRetReceipt(String tableName, String grantress) + throws Exception { + return permission.insert(tableName, grantress).send(); + } + + public String revoke(String tableName, String address) throws Exception { + TransactionReceipt receipt = revokeAndRetReceipt(tableName, address); return PrecompiledCommon.handleTransactionReceipt(receipt, web3j); } + private TransactionReceipt revokeAndRetReceipt(String tableName, String address) + throws Exception { + return permission.remove(tableName, address).send(); + } + private List list(String tableName) throws Exception { - String permissionyInfo = permission.queryByName(tableName).send(); + String permissionInfo = permission.queryByName(tableName).send(); ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper(); return objectMapper.readValue( - permissionyInfo, + permissionInfo, objectMapper .getTypeFactory() .constructCollectionType(List.class, PermissionInfo.class)); diff --git a/src/main/java/org/fisco/bcos/web3j/protocol/channel/StatusCode.java b/src/main/java/org/fisco/bcos/web3j/protocol/channel/StatusCode.java index 42c689b58..9ac4c0427 100644 --- a/src/main/java/org/fisco/bcos/web3j/protocol/channel/StatusCode.java +++ b/src/main/java/org/fisco/bcos/web3j/protocol/channel/StatusCode.java @@ -134,7 +134,7 @@ public static String getStatusMessage(String status, String errorMessage) { message = "permission denied"; break; case CallAddressError: - message = "call address error"; + message = "call contract address not exist"; break; case GasOverflow: message = "gas over flow"; From ab443a6f3c483dff6825286ff2e2aa3496a7adff Mon Sep 17 00:00:00 2001 From: octopus <912554887@qq.com> Date: Fri, 18 Sep 2020 15:26:02 +0800 Subject: [PATCH 16/23] fix getConsensusStatus response decode exception bug --- .../methods/response/ConsensusStatus.java | 454 +++++++++++++++++- 1 file changed, 452 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/fisco/bcos/web3j/protocol/core/methods/response/ConsensusStatus.java b/src/main/java/org/fisco/bcos/web3j/protocol/core/methods/response/ConsensusStatus.java index c8fe94b8e..d8bb09c65 100644 --- a/src/main/java/org/fisco/bcos/web3j/protocol/core/methods/response/ConsensusStatus.java +++ b/src/main/java/org/fisco/bcos/web3j/protocol/core/methods/response/ConsensusStatus.java @@ -1,10 +1,460 @@ package org.fisco.bcos.web3j.protocol.core.methods.response; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import org.fisco.bcos.web3j.protocol.ObjectMapperFactory; import org.fisco.bcos.web3j.protocol.core.Response; /** getConsensusStatus */ -public class ConsensusStatus extends Response { - public String getConsensusStatus() { +public class ConsensusStatus extends Response { + @Override + @JsonDeserialize(using = ConsensusStatusDeserializer.class) + public void setResult(ConsensusStatus.ConsensusInfo result) { + super.setResult(result); + } + + public ConsensusInfo getConsensusStatus() { return getResult(); } + + public static class ViewInfo { + private String nodeId; + private String view; + + public String getNodeId() { + return nodeId; + } + + public void setNodeId(String nodeId) { + this.nodeId = nodeId; + } + + public String getView() { + return view; + } + + public void setView(String view) { + this.view = view; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ViewInfo viewInfo = (ViewInfo) o; + return Objects.equals(nodeId, viewInfo.nodeId) && Objects.equals(view, viewInfo.view); + } + + @Override + public int hashCode() { + return Objects.hash(nodeId, view); + } + + @Override + public String toString() { + return "ViewInfo{" + "nodeId='" + nodeId + '\'' + ", view='" + view + '\'' + '}'; + } + } + + public static class BasicConsensusInfo { + private String nodeNum; + + @JsonProperty("node_index") + private String nodeIndex; + + @JsonProperty("node index") + private String raftNodeIndex; + + @JsonProperty("max_faulty_leader") + private String maxFaultyNodeNum; + + @JsonProperty("sealer.") + private List sealerList; + + private String consensusedBlockNumber; + private String highestblockNumber; + private String groupId; + private String protocolId; + private String accountType; + private String cfgErr; + private String omitEmptyBlock; + private String nodeId; + private String allowFutureBlocks; + private String connectedNodes; + private String currentView; + private String toView; + private String leaderFailed; + private String highestblockHash; + private String leaderId; + private String leaderIdx; + + public String getRaftNodeIndex() { + return raftNodeIndex; + } + + public void setRaftNodeIndex(String raftNodeIndex) { + this.raftNodeIndex = raftNodeIndex; + } + + public String getLeaderId() { + return leaderId; + } + + public void setLeaderId(String leaderId) { + this.leaderId = leaderId; + } + + public String getLeaderIdx() { + return leaderIdx; + } + + public void setLeaderIdx(String leaderIdx) { + this.leaderIdx = leaderIdx; + } + + public String getNodeIndex() { + return nodeIndex; + } + + public void setNodeIndex(String nodeIndex) { + this.nodeIndex = nodeIndex; + } + + public String getHighestblockHash() { + return highestblockHash; + } + + public void setHighestblockHash(String highestblockHash) { + this.highestblockHash = highestblockHash; + } + + public String getNodeNum() { + return nodeNum; + } + + public void setNodeNum(String nodeNum) { + this.nodeNum = nodeNum; + } + + public String getMaxFaultyNodeNum() { + return maxFaultyNodeNum; + } + + public void setMaxFaultyNodeNum(String maxFaultyNodeNum) { + this.maxFaultyNodeNum = maxFaultyNodeNum; + } + + public List getSealerList() { + return sealerList; + } + + public void setSealerList(List sealerList) { + this.sealerList = sealerList; + } + + public String getConsensusedBlockNumber() { + return consensusedBlockNumber; + } + + public void setConsensusedBlockNumber(String consensusedBlockNumber) { + this.consensusedBlockNumber = consensusedBlockNumber; + } + + public String getHighestblockNumber() { + return highestblockNumber; + } + + public void setHighestblockNumber(String highestblockNumber) { + this.highestblockNumber = highestblockNumber; + } + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getProtocolId() { + return protocolId; + } + + public void setProtocolId(String protocolId) { + this.protocolId = protocolId; + } + + public String getAccountType() { + return accountType; + } + + public void setAccountType(String accountType) { + this.accountType = accountType; + } + + public String getCfgErr() { + return cfgErr; + } + + public void setCfgErr(String cfgErr) { + this.cfgErr = cfgErr; + } + + public String getOmitEmptyBlock() { + return omitEmptyBlock; + } + + public void setOmitEmptyBlock(String omitEmptyBlock) { + this.omitEmptyBlock = omitEmptyBlock; + } + + public String getNodeId() { + return nodeId; + } + + public void setNodeId(String nodeId) { + this.nodeId = nodeId; + } + + public String getAllowFutureBlocks() { + return allowFutureBlocks; + } + + public void setAllowFutureBlocks(String allowFutureBlocks) { + this.allowFutureBlocks = allowFutureBlocks; + } + + public String getConnectedNodes() { + return connectedNodes; + } + + public void setConnectedNodes(String connectedNodes) { + this.connectedNodes = connectedNodes; + } + + public String getCurrentView() { + return currentView; + } + + public void setCurrentView(String currentView) { + this.currentView = currentView; + } + + public String getToView() { + return toView; + } + + public void setToView(String toView) { + this.toView = toView; + } + + public String getLeaderFailed() { + return leaderFailed; + } + + public void setLeaderFailed(String leaderFailed) { + this.leaderFailed = leaderFailed; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + BasicConsensusInfo that = (BasicConsensusInfo) o; + return Objects.equals(nodeNum, that.nodeNum) + && Objects.equals(nodeIndex, that.nodeIndex) + && Objects.equals(maxFaultyNodeNum, that.maxFaultyNodeNum) + && Objects.equals(sealerList, that.sealerList) + && Objects.equals(consensusedBlockNumber, that.consensusedBlockNumber) + && Objects.equals(highestblockNumber, that.highestblockNumber) + && Objects.equals(groupId, that.groupId) + && Objects.equals(protocolId, that.protocolId) + && Objects.equals(accountType, that.accountType) + && Objects.equals(cfgErr, that.cfgErr) + && Objects.equals(omitEmptyBlock, that.omitEmptyBlock) + && Objects.equals(nodeId, that.nodeId) + && Objects.equals(allowFutureBlocks, that.allowFutureBlocks) + && Objects.equals(connectedNodes, that.connectedNodes) + && Objects.equals(currentView, that.currentView) + && Objects.equals(toView, that.toView) + && Objects.equals(leaderFailed, that.leaderFailed) + && Objects.equals(highestblockHash, that.highestblockHash); + } + + @Override + public int hashCode() { + return Objects.hash( + nodeNum, + nodeIndex, + maxFaultyNodeNum, + sealerList, + consensusedBlockNumber, + highestblockNumber, + groupId, + protocolId, + accountType, + cfgErr, + omitEmptyBlock, + nodeId, + allowFutureBlocks, + connectedNodes, + currentView, + toView, + leaderFailed, + highestblockHash); + } + + @Override + public String toString() { + return "BasicConsensusInfo{" + + "nodeNum='" + + nodeNum + + '\'' + + ", nodeIndex='" + + nodeIndex + + '\'' + + ", maxFaultyNodeNum='" + + maxFaultyNodeNum + + '\'' + + ", sealerList=" + + sealerList + + ", consensusedBlockNumber='" + + consensusedBlockNumber + + '\'' + + ", highestblockNumber='" + + highestblockNumber + + '\'' + + ", groupId='" + + groupId + + '\'' + + ", protocolId='" + + protocolId + + '\'' + + ", accountType='" + + accountType + + '\'' + + ", cfgErr='" + + cfgErr + + '\'' + + ", omitEmptyBlock='" + + omitEmptyBlock + + '\'' + + ", nodeId='" + + nodeId + + '\'' + + ", allowFutureBlocks='" + + allowFutureBlocks + + '\'' + + ", connectedNodes='" + + connectedNodes + + '\'' + + ", currentView='" + + currentView + + '\'' + + ", toView='" + + toView + + '\'' + + ", leaderFailed='" + + leaderFailed + + '\'' + + ", highestblockHash='" + + highestblockHash + + '\'' + + '}'; + } + } + + public static class ConsensusInfo { + private BasicConsensusInfo baseConsensusInfo; + private List viewInfos; + + public ConsensusInfo() {} + + public ConsensusInfo(BasicConsensusInfo baseConsensusInfo, List viewInfos) { + this.baseConsensusInfo = baseConsensusInfo; + this.viewInfos = viewInfos; + } + + public BasicConsensusInfo getBaseConsensusInfo() { + return baseConsensusInfo; + } + + public void setBaseConsensusInfo(BasicConsensusInfo baseConsensusInfo) { + this.baseConsensusInfo = baseConsensusInfo; + } + + public List getViewInfos() { + return viewInfos; + } + + public void setViewInfos(List viewInfos) { + this.viewInfos = viewInfos; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ConsensusInfo that = (ConsensusInfo) o; + return Objects.equals(baseConsensusInfo, that.baseConsensusInfo) + && Objects.equals(viewInfos, that.viewInfos); + } + + @Override + public int hashCode() { + return Objects.hash(baseConsensusInfo, viewInfos); + } + + @Override + public String toString() { + return "ConsensusInfo{" + + "baseConsensusInfo=" + + baseConsensusInfo + + ", viewInfos=" + + viewInfos + + '}'; + } + } + + public static class ConsensusStatusDeserializer extends JsonDeserializer { + private ObjectMapper objecMapper = ObjectMapperFactory.getObjectMapper(); + + @Override + public ConsensusInfo deserialize( + JsonParser jsonParser, DeserializationContext deserializationContext) + throws IOException { + JsonNode node = jsonParser.getCodec().readTree(jsonParser); + BasicConsensusInfo baseConsensusInfo = null; + List viewInfos = null; + if (node.size() > 0) { + baseConsensusInfo = + objecMapper.readValue(node.get(0).toString(), BasicConsensusInfo.class); + Integer sealersNum = Integer.valueOf(baseConsensusInfo.getNodeNum()); + baseConsensusInfo.setSealerList(new ArrayList(sealersNum)); + // parse sealerList + for (Integer i = 0; i < sealersNum; i++) { + String key = "sealer." + String.valueOf(i); + if (node.get(0).has(key)) { + baseConsensusInfo.getSealerList().add(i, node.get(0).get(key).asText()); + } + } + } + if (node.size() > 1) { + viewInfos = + objecMapper.readValue( + node.get(1).toString(), new TypeReference>() {}); + } + return new ConsensusInfo(baseConsensusInfo, viewInfos); + } + } } From 27a3a804ebfe11f80a8ad390a7f4a78697036b86 Mon Sep 17 00:00:00 2001 From: octopus <912554887@qq.com> Date: Fri, 18 Sep 2020 16:59:16 +0800 Subject: [PATCH 17/23] add interface ret receipt for consensus precompiled service --- .../consensus/ConsensusService.java | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/fisco/bcos/web3j/precompile/consensus/ConsensusService.java b/src/main/java/org/fisco/bcos/web3j/precompile/consensus/ConsensusService.java index e9c7d1ece..435e6c72f 100644 --- a/src/main/java/org/fisco/bcos/web3j/precompile/consensus/ConsensusService.java +++ b/src/main/java/org/fisco/bcos/web3j/precompile/consensus/ConsensusService.java @@ -26,20 +26,50 @@ public ConsensusService(Web3j web3j, Credentials credentials) { } public String addSealer(String nodeID) throws Exception { - TransactionReceipt receipt = consensus.addSealer(nodeID).send(); + TransactionReceipt receipt = addSealerAndRetReceipt(nodeID); return PrecompiledCommon.handleTransactionReceipt(receipt, web3j); } + public TransactionReceipt addSealerAndRetReceipt(String nodeID) throws Exception { + return consensus.addSealer(nodeID).send(); + } + public String addObserver(String nodeID) throws Exception { - TransactionReceipt receipt = consensus.addObserver(nodeID).send(); + TransactionReceipt receipt = addObserverAndRetReceipt(nodeID); return PrecompiledCommon.handleTransactionReceipt(receipt, web3j); } + public TransactionReceipt addObserverAndRetReceipt(String nodeID) throws Exception { + return consensus.addObserver(nodeID).send(); + } + public String removeNode(String nodeId) throws Exception { List groupPeers = web3j.getGroupPeers().send().getResult(); if (!groupPeers.contains(nodeId)) { return PrecompiledCommon.transferToJson(PrecompiledCommon.GroupPeers); } + TransactionReceipt receipt = null; + try { + receipt = removeNodeAndRetReceipt(nodeId); + } catch (RuntimeException e) { + // firstly remove node that sdk connected to the node, return the request that present + // susscces + // because the exception is throwed by getTransactionReceipt, we need ignore it. + if (e.getMessage().contains("Don't send requests to this group")) { + return PrecompiledCommon.transferToJson(0); + } else { + throw e; + } + } + return PrecompiledCommon.handleTransactionReceipt(receipt, web3j); + } + + public TransactionReceipt removeNodeAndRetReceipt(String nodeId) throws Exception { + return consensus.remove(nodeId).send(); + /*List groupPeers = web3j.getGroupPeers().send().getResult(); + if (!groupPeers.contains(nodeId)) { + return PrecompiledCommon.transferToJson(PrecompiledCommon.GroupPeers); + } TransactionReceipt receipt = new TransactionReceipt(); try { receipt = consensus.remove(nodeId).send(); @@ -54,6 +84,7 @@ public String removeNode(String nodeId) throws Exception { } } return PrecompiledCommon.handleTransactionReceipt(receipt, web3j); + */ } private boolean isValidNodeID(String _nodeID) throws IOException, JsonProcessingException { From 0d331a0b75b0485f7d5040df009dec3864307138 Mon Sep 17 00:00:00 2001 From: octopus <912554887@qq.com> Date: Tue, 22 Sep 2020 07:35:14 +0800 Subject: [PATCH 18/23] add seq info for timeout message --- .../bcos/channel/client/BcosResponseCallback.java | 2 +- .../channel/client/ChannelResponseCallback2.java | 2 +- .../org/fisco/bcos/channel/client/Service.java | 15 +++++++++++++-- .../channel/client/TransactionSucCallback.java | 2 -- .../bcos/channel/handler/ConnectionCallback.java | 3 +++ 5 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/fisco/bcos/channel/client/BcosResponseCallback.java b/src/main/java/org/fisco/bcos/channel/client/BcosResponseCallback.java index 6c9340c2a..f193a86e1 100644 --- a/src/main/java/org/fisco/bcos/channel/client/BcosResponseCallback.java +++ b/src/main/java/org/fisco/bcos/channel/client/BcosResponseCallback.java @@ -14,7 +14,7 @@ public abstract class BcosResponseCallback { public abstract void onResponse(BcosResponse response); public void onTimeout() { - logger.error("Processing bcos message timeout:{}"); + // logger.error("Processing bcos message timeout:{}"); BcosResponse response = new BcosResponse(); response.setErrorCode(ChannelMessageError.MESSAGE_TIMEOUT.getError()); diff --git a/src/main/java/org/fisco/bcos/channel/client/ChannelResponseCallback2.java b/src/main/java/org/fisco/bcos/channel/client/ChannelResponseCallback2.java index 2d48900d9..59475adec 100644 --- a/src/main/java/org/fisco/bcos/channel/client/ChannelResponseCallback2.java +++ b/src/main/java/org/fisco/bcos/channel/client/ChannelResponseCallback2.java @@ -49,7 +49,7 @@ public final void onResponse(ChannelResponse response) { } public final void onTimeout() { - logger.error("send message timeout:{}", message.getSeq()); + // logger.error("send message timeout:{}", message.getSeq()); ChannelResponse response = new ChannelResponse(); response.setErrorCode(ChannelMessageError.MESSAGE_TIMEOUT.getError()); diff --git a/src/main/java/org/fisco/bcos/channel/client/Service.java b/src/main/java/org/fisco/bcos/channel/client/Service.java index 80e01285d..f31ffce47 100644 --- a/src/main/java/org/fisco/bcos/channel/client/Service.java +++ b/src/main/java/org/fisco/bcos/channel/client/Service.java @@ -490,9 +490,12 @@ public void asyncSendEthereumMessage( new TimerTask() { @Override public void run(Timeout timeout) throws Exception { - // 处理超时逻辑 + logger.error( + "transaction callback timeout, seq: {}, timeout: {}", + request.getMessageID(), + request.getTimeout()); + callbackInner.onTimeout(); - // timeout时清除map的数据,所以尽管后面有回包数据,也会找不到seq->callback的关系 seq2TransactionCallback.remove(request.getMessageID()); } }, @@ -593,6 +596,10 @@ public void asyncSendEthereumMessage(BcosRequest request, BcosResponseCallback c @Override public void run(Timeout timeout) throws Exception { + logger.error( + "process bcos message timeout, seq: {}, timeout: {}", + bcosMessage.getSeq(), + request.getTimeout()); // handle timer _callback.onTimeout(); } @@ -707,6 +714,10 @@ public void asyncSendChannelMessage2( public void run(Timeout timeout) throws Exception { // process timeout logic _callback.onTimeout(); + logger.error( + "process channel message timeout, seq: {}, timeout: {}", + channelMessage.getSeq(), + request.getTimeout()); } }, request.getTimeout(), diff --git a/src/main/java/org/fisco/bcos/channel/client/TransactionSucCallback.java b/src/main/java/org/fisco/bcos/channel/client/TransactionSucCallback.java index ce5641bfd..7ce432fc1 100644 --- a/src/main/java/org/fisco/bcos/channel/client/TransactionSucCallback.java +++ b/src/main/java/org/fisco/bcos/channel/client/TransactionSucCallback.java @@ -12,8 +12,6 @@ public abstract class TransactionSucCallback { public abstract void onResponse(TransactionReceipt response); public void onTimeout() { - logger.error("transactionSuc timeout"); - TransactionReceipt receipt = new TransactionReceipt(); receipt.setStatus("Transaction receipt timeout."); // For console can get error message when timeout diff --git a/src/main/java/org/fisco/bcos/channel/handler/ConnectionCallback.java b/src/main/java/org/fisco/bcos/channel/handler/ConnectionCallback.java index d397d311b..121839583 100644 --- a/src/main/java/org/fisco/bcos/channel/handler/ConnectionCallback.java +++ b/src/main/java/org/fisco/bcos/channel/handler/ConnectionCallback.java @@ -308,6 +308,9 @@ public void onResponse(BcosResponse response) { public void run(Timeout timeout) throws Exception { // handle timer _callback.onTimeout(); + logger.error( + "queryNodeVersion timeout, seq: {}", + bcosMessage.getSeq()); } }, queryNodeVersionTimeoutMS, From b31be1570d23b21609e68539408acc3f1f458b2a Mon Sep 17 00:00:00 2001 From: octopus <912554887@qq.com> Date: Tue, 22 Sep 2020 10:15:45 +0800 Subject: [PATCH 19/23] remove throw TransactionException when it's not necessary --- .../org/fisco/bcos/web3j/tx/Contract.java | 13 ++-------- .../bcos/web3j/tx/ManagedTransaction.java | 2 +- .../web3j/tx/txdecode/TransactionDecoder.java | 25 +++++++------------ .../txdecode/TransactionDecoderFactory.java | 6 ++--- 4 files changed, 14 insertions(+), 32 deletions(-) diff --git a/src/main/java/org/fisco/bcos/web3j/tx/Contract.java b/src/main/java/org/fisco/bcos/web3j/tx/Contract.java index 8e7260576..3b25e5324 100644 --- a/src/main/java/org/fisco/bcos/web3j/tx/Contract.java +++ b/src/main/java/org/fisco/bcos/web3j/tx/Contract.java @@ -367,8 +367,7 @@ public void onResponse(TransactionReceipt receipt) { public Semaphore semaphore = new Semaphore(1, true); }; - protected TransactionReceipt executeTransaction(Function function) - throws IOException, TransactionException { + protected TransactionReceipt executeTransaction(Function function) throws IOException { Callback callback = new Callback(); @@ -433,21 +432,13 @@ protected void asyncExecuteTransaction(Function function, TransactionSucCallback " IOException, contractAddress:{}, exception:{} ", getContractAddress(), e.getMessage()); - } catch (TransactionException e) { - logger.error( - " TransactionException, contractAddress:{}, transactionHash: {}, transactionStatus:{}, exception:{} ", - getContractAddress(), - e.getTransactionHash(), - e.getStatus(), - e.getMessage()); } // asyncExecuteTransaction(FunctionEncoder.encode(function), function.getName(), callback); } protected void asyncExecuteTransaction( - String data, String funName, TransactionSucCallback callback) - throws IOException, TransactionException { + String data, String funName, TransactionSucCallback callback) throws IOException { sendOnly( contractAddress, data, diff --git a/src/main/java/org/fisco/bcos/web3j/tx/ManagedTransaction.java b/src/main/java/org/fisco/bcos/web3j/tx/ManagedTransaction.java index 558adae15..e48421ff4 100644 --- a/src/main/java/org/fisco/bcos/web3j/tx/ManagedTransaction.java +++ b/src/main/java/org/fisco/bcos/web3j/tx/ManagedTransaction.java @@ -50,7 +50,7 @@ protected void sendOnly( BigInteger gasPrice, BigInteger gasLimit, TransactionSucCallback callback) - throws IOException, TransactionException { + throws IOException { transactionManager.sendTransaction(gasPrice, gasLimit, to, data, value, null, callback); } diff --git a/src/main/java/org/fisco/bcos/web3j/tx/txdecode/TransactionDecoder.java b/src/main/java/org/fisco/bcos/web3j/tx/txdecode/TransactionDecoder.java index 771237a9e..1f804e17e 100644 --- a/src/main/java/org/fisco/bcos/web3j/tx/txdecode/TransactionDecoder.java +++ b/src/main/java/org/fisco/bcos/web3j/tx/txdecode/TransactionDecoder.java @@ -21,7 +21,6 @@ import org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition; import org.fisco.bcos.web3j.protocol.core.methods.response.AbiDefinition.NamedType; import org.fisco.bcos.web3j.protocol.core.methods.response.Log; -import org.fisco.bcos.web3j.protocol.exceptions.TransactionException; import org.fisco.bcos.web3j.tuples.generated.Tuple2; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -62,11 +61,10 @@ private String addHexPrefixToString(String s) { * @param input * @return * @throws JsonProcessingException - * @throws TransactionException * @throws BaseException */ public String decodeInputReturnJson(String input) - throws JsonProcessingException, TransactionException, BaseException { + throws JsonProcessingException, BaseException { input = addHexPrefixToString(input); @@ -86,10 +84,8 @@ public String decodeInputReturnJson(String input) * @param input * @return * @throws BaseException - * @throws TransactionException */ - public InputAndOutputResult decodeInputReturnObject(String input) - throws BaseException, TransactionException { + public InputAndOutputResult decodeInputReturnObject(String input) throws BaseException { String updatedInput = addHexPrefixToString(input); @@ -125,10 +121,9 @@ public InputAndOutputResult decodeInputReturnObject(String input) * @return * @throws JsonProcessingException * @throws BaseException - * @throws TransactionException */ public String decodeOutputReturnJson(String input, String output) - throws JsonProcessingException, BaseException, TransactionException { + throws JsonProcessingException, BaseException { InputAndOutputResult inputAndOutputResult = decodeOutputReturnObject(input, output); @@ -141,11 +136,10 @@ public String decodeOutputReturnJson(String input, String output) * @param input * @param output * @return - * @throws TransactionException * @throws BaseException */ public InputAndOutputResult decodeOutputReturnObject(String input, String output) - throws TransactionException, BaseException { + throws BaseException { String updatedInput = addHexPrefixToString(input); String updatedOutput = addHexPrefixToString(output); @@ -375,16 +369,15 @@ public Tuple2> decodeEventReturnObject(Lo /** * @param input * @return - * @throws TransactionException + * @throws BaseException */ - private AbiDefinition selectAbiDefinition(String input) throws TransactionException { - if (input == null || input.length() < 10) { - throw new TransactionException("The input is invalid."); - } + private AbiDefinition selectAbiDefinition(String input) throws BaseException { String methodID = input.substring(0, 10); AbiDefinition abiDefinition = methodIDMap.get(methodID); if (abiDefinition == null) { - throw new TransactionException("The method is not included in the contract abi."); + throw new BaseException( + 201203, + String.format("the method is not found in abi, method id:[%s]", methodID)); } return abiDefinition; } diff --git a/src/main/java/org/fisco/bcos/web3j/tx/txdecode/TransactionDecoderFactory.java b/src/main/java/org/fisco/bcos/web3j/tx/txdecode/TransactionDecoderFactory.java index 661b734b1..8d3c041cb 100644 --- a/src/main/java/org/fisco/bcos/web3j/tx/txdecode/TransactionDecoderFactory.java +++ b/src/main/java/org/fisco/bcos/web3j/tx/txdecode/TransactionDecoderFactory.java @@ -7,7 +7,6 @@ import java.io.File; import java.io.IOException; -import org.fisco.bcos.web3j.protocol.exceptions.TransactionException; import org.fisco.bcos.web3j.solidity.compiler.CompilationResult; import org.fisco.bcos.web3j.solidity.compiler.SolidityCompiler; @@ -29,13 +28,12 @@ public static TransactionDecoder buildTransactionDecoder(String abi, String bin) /** * @param contractName * @return TransactionDecoder - * @throws TransactionException * @throws IOException */ public static TransactionDecoder buildTransactionDecoder(String contractName) - throws TransactionException, IOException { + throws IOException { if (contractName.startsWith(PREFIX_LIB)) { - throw new TransactionException("Please don't provide a library solidity file."); + throw new IOException("Please don't provide a library solidity file."); } if (!contractName.endsWith(SOL_POSTFIX)) { contractName = contractName + SOL_POSTFIX; From be3cc6926548f4b108f69bb87a8ac20a47ae26d9 Mon Sep 17 00:00:00 2001 From: octopus <912554887@qq.com> Date: Tue, 22 Sep 2020 10:35:21 +0800 Subject: [PATCH 20/23] add TransactionReceipt to TransactionException --- .../bcos/precompile/PermissionServiceTest.java | 16 +++++++++++----- .../bcos/channel/handler/ChannelConnections.java | 12 +++++------- .../permission/ChainGovernanceService.java | 11 ++++++++--- .../precompile/permission/PermissionService.java | 4 ++-- .../exceptions/TransactionException.java | 10 ++++++++++ .../java/org/fisco/bcos/web3j/tx/Contract.java | 6 +++++- 6 files changed, 41 insertions(+), 18 deletions(-) diff --git a/src/integration-test/java/org/fisco/bcos/precompile/PermissionServiceTest.java b/src/integration-test/java/org/fisco/bcos/precompile/PermissionServiceTest.java index 5fb32fa4a..59c4778a1 100644 --- a/src/integration-test/java/org/fisco/bcos/precompile/PermissionServiceTest.java +++ b/src/integration-test/java/org/fisco/bcos/precompile/PermissionServiceTest.java @@ -1,10 +1,13 @@ package org.fisco.bcos.precompile; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import org.fisco.bcos.TestBase; -import org.fisco.bcos.web3j.precompile.exception.PrecompileMessageException; +import org.fisco.bcos.web3j.precompile.common.PrecompiledCommon; import org.fisco.bcos.web3j.precompile.permission.PermissionService; +import org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt; +import org.junit.Assert; import org.junit.Test; public class PermissionServiceTest extends TestBase { @@ -12,11 +15,14 @@ public class PermissionServiceTest extends TestBase { private PermissionService permissionService = new PermissionService(web3j, credentials); - @Test(expected= PrecompileMessageException.class) + @Test public void userTableManager() throws Exception { - - permissionService.grantUserTableManager("tt", Common.TX_ORIGIN); - + + TransactionReceipt transactionReceipt = permissionService.grantAndRetReceipt("tt", Common.TX_ORIGIN); + Assert.assertTrue(transactionReceipt.isStatusOK()); + int i = PrecompiledCommon.handleTransactionReceiptForCRUD(transactionReceipt); + System.out.println(" ===> " + i); + assertTrue(i == PrecompiledCommon.InvalidTableNotExist); } @Test diff --git a/src/main/java/org/fisco/bcos/channel/handler/ChannelConnections.java b/src/main/java/org/fisco/bcos/channel/handler/ChannelConnections.java index c95fb36af..9547c3a4a 100644 --- a/src/main/java/org/fisco/bcos/channel/handler/ChannelConnections.java +++ b/src/main/java/org/fisco/bcos/channel/handler/ChannelConnections.java @@ -91,10 +91,10 @@ public class ChannelConnections { private long sslHandShakeTimeout = (long) 10000; private static final String helpInfo = - "The reasons for failure may be: " - + "1. the configured certificate is not the same set of certificates as the node's certificate; " - + "2. the configured certificate is not issued by the same authority as the node's certificate. " - + "Please refer to https://fisco-bcos-documentation.readthedocs.io/zh_CN/latest/docs/sdk/java_sdk.html#id24"; + "The reasons for failure may be: \n" + + "\t1. the configured certificate is not the same set of certificates as the node's certificate; \n" + + "\t2. the configured certificate is not issued by the same authority as the node's certificate. \n" + + "\tPlease refer to https://fisco-bcos-documentation.readthedocs.io/zh_CN/latest/docs/sdk/java_sdk.html#id24 \n"; public Map networkConnections = new ConcurrentHashMap(); @@ -459,7 +459,6 @@ public void initChannel(SocketChannel ch) throws Exception { tuple3.getValue1(), tuple3.getValue2()); errorMessageList.add(sslHandshakeFailedMessage); - errorMessageList.add(helpInfo); continue; } @@ -478,7 +477,6 @@ public void initChannel(SocketChannel ch) throws Exception { + tuple3.getValue2(); errorMessageList.add(sslHandshakeFailedMessage); - errorMessageList.add(helpInfo); } } } @@ -487,7 +485,7 @@ public void initChannel(SocketChannel ch) throws Exception { if (!atLeastOneConnectSuccess) { logger.error(" all connections have failed, " + errorMessageList.toString()); throw new RuntimeException( - " Failed to connect to nodes: " + errorMessageList.toString()); + " Failed to connect to nodes: " + errorMessageList.toString() + helpInfo); } running = true; diff --git a/src/main/java/org/fisco/bcos/web3j/precompile/permission/ChainGovernanceService.java b/src/main/java/org/fisco/bcos/web3j/precompile/permission/ChainGovernanceService.java index 12d0e8a19..ca6ef13d3 100644 --- a/src/main/java/org/fisco/bcos/web3j/precompile/permission/ChainGovernanceService.java +++ b/src/main/java/org/fisco/bcos/web3j/precompile/permission/ChainGovernanceService.java @@ -54,12 +54,17 @@ public List listOperators() throws Exception { public String updateCommitteeMemberWeight(String account, int weight) throws Exception { TransactionReceipt transactionReceipt = - chainGovernance - .updateCommitteeMemberWeight(account, BigInteger.valueOf(weight)) - .send(); + updateCommitteeMemberWeightAndRetReceipt(account, weight); return PrecompiledCommon.handleTransactionReceipt(transactionReceipt, web3j); } + public TransactionReceipt updateCommitteeMemberWeightAndRetReceipt(String account, int weight) + throws Exception { + return chainGovernance + .updateCommitteeMemberWeight(account, BigInteger.valueOf(weight)) + .send(); + } + public BigInteger queryThreshold() throws Exception { return chainGovernance.queryThreshold().send(); } diff --git a/src/main/java/org/fisco/bcos/web3j/precompile/permission/PermissionService.java b/src/main/java/org/fisco/bcos/web3j/precompile/permission/PermissionService.java index 8381d1472..4de79cd3f 100644 --- a/src/main/java/org/fisco/bcos/web3j/precompile/permission/PermissionService.java +++ b/src/main/java/org/fisco/bcos/web3j/precompile/permission/PermissionService.java @@ -141,7 +141,7 @@ public String grant(String tableName, String grandness) throws Exception { return PrecompiledCommon.handleTransactionReceipt(receipt, web3j); } - private TransactionReceipt grantAndRetReceipt(String tableName, String grantress) + public TransactionReceipt grantAndRetReceipt(String tableName, String grantress) throws Exception { return permission.insert(tableName, grantress).send(); } @@ -151,7 +151,7 @@ public String revoke(String tableName, String address) throws Exception { return PrecompiledCommon.handleTransactionReceipt(receipt, web3j); } - private TransactionReceipt revokeAndRetReceipt(String tableName, String address) + public TransactionReceipt revokeAndRetReceipt(String tableName, String address) throws Exception { return permission.remove(tableName, address).send(); } diff --git a/src/main/java/org/fisco/bcos/web3j/protocol/exceptions/TransactionException.java b/src/main/java/org/fisco/bcos/web3j/protocol/exceptions/TransactionException.java index 98ae74429..23806ac21 100644 --- a/src/main/java/org/fisco/bcos/web3j/protocol/exceptions/TransactionException.java +++ b/src/main/java/org/fisco/bcos/web3j/protocol/exceptions/TransactionException.java @@ -2,11 +2,13 @@ import java.math.BigInteger; import java.util.Optional; +import org.fisco.bcos.web3j.protocol.core.methods.response.TransactionReceipt; public class TransactionException extends Exception { private Optional transactionHash = Optional.empty(); private String status; private BigInteger gasUsed; + private TransactionReceipt receipt; public String getStatus() { return status; @@ -57,4 +59,12 @@ public TransactionException(Throwable cause) { public Optional getTransactionHash() { return transactionHash; } + + public TransactionReceipt getReceipt() { + return receipt; + } + + public void setReceipt(TransactionReceipt receipt) { + this.receipt = receipt; + } } diff --git a/src/main/java/org/fisco/bcos/web3j/tx/Contract.java b/src/main/java/org/fisco/bcos/web3j/tx/Contract.java index 3b25e5324..018166e75 100644 --- a/src/main/java/org/fisco/bcos/web3j/tx/Contract.java +++ b/src/main/java/org/fisco/bcos/web3j/tx/Contract.java @@ -417,7 +417,11 @@ protected TransactionReceipt executeTransaction( receipt.getMessage(), receipt.getGasUsed()); - throw new TransactionException(message, status, gasUsed, receipt.getTransactionHash()); + TransactionException transactionException = + new TransactionException( + message, status, gasUsed, receipt.getTransactionHash()); + transactionException.setReceipt(receipt); + throw transactionException; } return receipt; From 691fae3d82df12089583ab588268ccadf98efe7e Mon Sep 17 00:00:00 2001 From: octopus <912554887@qq.com> Date: Mon, 28 Sep 2020 09:58:19 +0800 Subject: [PATCH 21/23] gradle update --- .ci/ci_check.sh | 2 +- build.gradle | 2 +- .../fisco/bcos/precompile/PermissionServiceTest.java | 10 ++++------ 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/.ci/ci_check.sh b/.ci/ci_check.sh index 6007f722f..acb4d8597 100755 --- a/.ci/ci_check.sh +++ b/.ci/ci_check.sh @@ -11,7 +11,7 @@ bash gradlew build -x integrationTest # UT test bash gradlew test -curl -LO https://github.com/FISCO-BCOS/FISCO-BCOS/releases/download/v2.5.0/build_chain.sh && chmod u+x build_chain.sh +curl -LO https://github.com/FISCO-BCOS/FISCO-BCOS/releases/download/v2.6.0/build_chain.sh && chmod u+x build_chain.sh echo "127.0.0.1:4 agency1 1,2,3" > ipconf # bash build_chain.sh -h diff --git a/build.gradle b/build.gradle index 4dd18f476..84c137e1a 100644 --- a/build.gradle +++ b/build.gradle @@ -195,7 +195,7 @@ jar { test { testLogging { - // showStandardStreams = true + showStandardStreams = true // events "started","passed","skipped","failed" events "passed","skipped","failed" } diff --git a/src/integration-test/java/org/fisco/bcos/precompile/PermissionServiceTest.java b/src/integration-test/java/org/fisco/bcos/precompile/PermissionServiceTest.java index 59c4778a1..c5a0b39da 100644 --- a/src/integration-test/java/org/fisco/bcos/precompile/PermissionServiceTest.java +++ b/src/integration-test/java/org/fisco/bcos/precompile/PermissionServiceTest.java @@ -17,12 +17,10 @@ public class PermissionServiceTest extends TestBase { @Test public void userTableManager() throws Exception { - - TransactionReceipt transactionReceipt = permissionService.grantAndRetReceipt("tt", Common.TX_ORIGIN); - Assert.assertTrue(transactionReceipt.isStatusOK()); - int i = PrecompiledCommon.handleTransactionReceiptForCRUD(transactionReceipt); - System.out.println(" ===> " + i); - assertTrue(i == PrecompiledCommon.InvalidTableNotExist); + TransactionReceipt transactionReceipt = permissionService.grantAndRetReceipt("tt", Common.TX_ORIGIN); + Assert.assertTrue(transactionReceipt.isStatusOK()); + int i = PrecompiledCommon.handleTransactionReceiptForCRUD(transactionReceipt); + assertEquals(i , 1); } @Test From 991b265cc490da5a61389983dbaf3cfa268440a0 Mon Sep 17 00:00:00 2001 From: octopus <912554887@qq.com> Date: Mon, 28 Sep 2020 19:35:49 +0800 Subject: [PATCH 22/23] remove . of Transaction receipt timeout message --- .../org/fisco/bcos/channel/client/TransactionSucCallback.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/fisco/bcos/channel/client/TransactionSucCallback.java b/src/main/java/org/fisco/bcos/channel/client/TransactionSucCallback.java index 7ce432fc1..cf067950e 100644 --- a/src/main/java/org/fisco/bcos/channel/client/TransactionSucCallback.java +++ b/src/main/java/org/fisco/bcos/channel/client/TransactionSucCallback.java @@ -13,9 +13,9 @@ public abstract class TransactionSucCallback { public void onTimeout() { TransactionReceipt receipt = new TransactionReceipt(); - receipt.setStatus("Transaction receipt timeout."); + receipt.setStatus("Transaction receipt timeout"); // For console can get error message when timeout - receipt.setMessage("Transaction receipt timeout."); + receipt.setMessage("Transaction receipt timeout"); onResponse(receipt); } From 95828177508c4fc05f7c32d41749134d6b65160f Mon Sep 17 00:00:00 2001 From: octopus <912554887@qq.com> Date: Wed, 30 Sep 2020 11:08:03 +0800 Subject: [PATCH 23/23] update StatusCode --- .../java/org/fisco/bcos/web3j/protocol/channel/StatusCode.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/fisco/bcos/web3j/protocol/channel/StatusCode.java b/src/main/java/org/fisco/bcos/web3j/protocol/channel/StatusCode.java index 9ac4c0427..21776e7df 100644 --- a/src/main/java/org/fisco/bcos/web3j/protocol/channel/StatusCode.java +++ b/src/main/java/org/fisco/bcos/web3j/protocol/channel/StatusCode.java @@ -49,7 +49,7 @@ public class StatusCode { public static final String OverGroupMemoryLimit = "0x2716"; public static String getStatusMessage(String status) { - return getStatusMessage(status, " Error code: " + status); + return getStatusMessage(status, status); } public static String getStatusMessage(String status, String errorMessage) {