From e405a99d0546d9bbdf2ac5c873a0ae35465ef23a Mon Sep 17 00:00:00 2001 From: cyjseagull Date: Wed, 22 Jul 2020 21:07:44 +0800 Subject: [PATCH] 1. add groupManager related interfaces 2. Place the files that both the transaction and client modules depend on in the model module 3. When gradlew build is executed, integrationTest is not run --- .ci/ci_check.sh | 5 +- build.gradle | 4 +- .../org/fisco/bcos/sdk/client/Client.java | 7 +- .../org/fisco/bcos/sdk/client/ClientImpl.java | 39 +- .../fisco/bcos/sdk/client/JsonRpcService.java | 18 +- .../response/BcosTransactionReceipt.java | 2 +- .../response/TransactionReceiptWithProof.java | 4 +- .../response/TransactionWithProof.java | 2 +- .../protocol => }/model/MerkleProofUnit.java | 2 +- .../model/TransactionReceipt.java | 2 +- .../bcos/sdk/service/GroupManagerService.java | 136 ++++++ .../fisco/bcos/sdk/service/GroupService.java | 39 ++ .../impl/executor/TransactionDecoder.java | 2 +- .../core/impl/executor/TransactionPusher.java | 2 +- .../executor/TransactionDecoderInterface.java | 2 +- .../executor/TransactionPusherInterface.java | 2 +- .../transaction/domain/MerkleProofUnit.java | 75 ---- .../domain/TransactionReceipt.java | 386 ------------------ .../domain/dto/TransactionResponse.java | 2 +- .../manager/TransactionManager.java | 2 +- .../manager/TransactionManagerInterface.java | 2 +- 21 files changed, 236 insertions(+), 499 deletions(-) rename src/main/java/org/fisco/bcos/sdk/{client/protocol => }/model/MerkleProofUnit.java (96%) rename src/main/java/org/fisco/bcos/sdk/{client/protocol => }/model/TransactionReceipt.java (99%) create mode 100644 src/main/java/org/fisco/bcos/sdk/service/GroupManagerService.java create mode 100644 src/main/java/org/fisco/bcos/sdk/service/GroupService.java delete mode 100644 src/main/java/org/fisco/bcos/sdk/transaction/domain/MerkleProofUnit.java delete mode 100644 src/main/java/org/fisco/bcos/sdk/transaction/domain/TransactionReceipt.java diff --git a/.ci/ci_check.sh b/.ci/ci_check.sh index 12ddd08ca..4af4a4294 100755 --- a/.ci/ci_check.sh +++ b/.ci/ci_check.sh @@ -4,7 +4,7 @@ set -e # check code format bash gradlew verifyGoogleJavaFormat # build -bash gradlew build -x integrationTest +bash gradlew build # check integration-test ## start up FISCO BCOS nodes. @@ -12,7 +12,6 @@ curl -LO https://raw.githubusercontent.com/FISCO-BCOS/FISCO-BCOS/master/tools/bu ./build_chain.sh -l 127.0.0.1:4 ./nodes/127.0.0.1/fisco-bcos -v ./nodes/127.0.0.1/start_all.sh -# ./build_chain.sh -l 127.0.0.1:4 -o nodes ## prepare resources for integration test mkdir -p src/integration-test/resources/ @@ -25,6 +24,4 @@ bash gradlew integrationTest ## clean bash nodes/127.0.0.1/stop_all.sh -bash nodes/127.0.0.1/stop_all.sh -bash nodes/127.0.0.1/stop_all.sh rm -rf nodes \ No newline at end of file diff --git a/build.gradle b/build.gradle index 73831c3ba..088b43301 100644 --- a/build.gradle +++ b/build.gradle @@ -92,8 +92,8 @@ dependencies { integrationTestCompile 'org.mockito:mockito-core:2.23.0' } -check.dependsOn integrationTest -integrationTest.mustRunAfter test +// check.dependsOn integrationTest +// integrationTest.mustRunAfter test archivesBaseName = 'java-sdk' group = 'org.fisco-bcos' diff --git a/src/main/java/org/fisco/bcos/sdk/client/Client.java b/src/main/java/org/fisco/bcos/sdk/client/Client.java index 6ee10ee62..d2287a86e 100644 --- a/src/main/java/org/fisco/bcos/sdk/client/Client.java +++ b/src/main/java/org/fisco/bcos/sdk/client/Client.java @@ -50,6 +50,7 @@ import org.fisco.bcos.sdk.client.protocol.response.TotalTransactionCount; import org.fisco.bcos.sdk.client.protocol.response.TransactionReceiptWithProof; import org.fisco.bcos.sdk.client.protocol.response.TransactionWithProof; +import org.fisco.bcos.sdk.service.GroupManagerService; /** * This is the interface of client module. @@ -64,7 +65,7 @@ public interface Client { * @param GroupId * @return a client instance */ - Client build(Channel channel, String GroupId); + Client build(GroupManagerService groupManagerService, Channel channel, String GroupId); /** * Build a client instance Can only call interfaces relate to group management and node @@ -73,7 +74,7 @@ public interface Client { * @param channel * @return a client instance */ - Client build(Channel channel); + Client build(GroupManagerService groupManagerService, Channel channel); /** * Ledger operation: send transaction @@ -368,7 +369,7 @@ void getTransactionReceiptByHashWithProofAsync( * * @return block number */ - BigInteger getBlockNumberCache(); + BigInteger getBlockLimit(); /** * Group operation: generate a new group diff --git a/src/main/java/org/fisco/bcos/sdk/client/ClientImpl.java b/src/main/java/org/fisco/bcos/sdk/client/ClientImpl.java index 9eef078f7..74928aeb9 100644 --- a/src/main/java/org/fisco/bcos/sdk/client/ClientImpl.java +++ b/src/main/java/org/fisco/bcos/sdk/client/ClientImpl.java @@ -52,14 +52,18 @@ import org.fisco.bcos.sdk.client.protocol.response.TotalTransactionCount; import org.fisco.bcos.sdk.client.protocol.response.TransactionReceiptWithProof; import org.fisco.bcos.sdk.client.protocol.response.TransactionWithProof; +import org.fisco.bcos.sdk.service.GroupManagerService; import org.fisco.bcos.sdk.utils.Numeric; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class ClientImpl implements Client { + private static Logger logger = LoggerFactory.getLogger(ClientImpl.class); private final JsonRpcService jsonRpcService; - private final String groupId; + private final Integer groupId; - ClientImpl(Channel channel, String groupId) { - this.jsonRpcService = new JsonRpcService(channel, groupId); + ClientImpl(GroupManagerService groupManagerService, Channel channel, Integer groupId) { + this.jsonRpcService = new JsonRpcService(groupManagerService, channel, groupId); this.groupId = groupId; } @@ -67,12 +71,18 @@ public class ClientImpl implements Client { * Build a client instance GroupId is identified, all interfaces are available * * @param channel - * @param groupId + * @param groupIdStr * @return a client instance */ @Override - public Client build(Channel channel, String groupId) { - return new ClientImpl(channel, groupId); + public Client build( + GroupManagerService groupManagerService, Channel channel, String groupIdStr) { + Integer groupId = Integer.valueOf(groupIdStr); + if (groupId == null) { + logger.warn("build client failed for invalid groupId, groupId: {}", groupIdStr); + return null; + } + return new ClientImpl(groupManagerService, channel, groupId); } /** @@ -83,8 +93,8 @@ public Client build(Channel channel, String groupId) { * @return a client instance */ @Override - public Client build(Channel channel) { - return new ClientImpl(channel, "1"); + public Client build(GroupManagerService groupManagerService, Channel channel) { + return new ClientImpl(groupManagerService, channel, 1); } @Override @@ -418,9 +428,16 @@ public void getPendingTxSizeAsync(RespCallback callback) { } @Override - public BigInteger getBlockNumberCache() { - // TODO: get the cache of the latest block number of the group, and return the blockLimit - return null; + public BigInteger getBlockLimit() { + Integer groupId = Integer.valueOf(this.groupId); + if (this.jsonRpcService.getGroupManagerService().getBlockLimitByGroup(groupId) + == BigInteger.ZERO) { + BigInteger blockNumber = this.getBlockNumber().getBlockNumber(); + // update the blockNumber of groupManagerService + this.jsonRpcService.getGroupManagerService().updateBlockNumber(groupId, blockNumber); + return blockNumber; + } + return this.jsonRpcService.getGroupManagerService().getBlockLimitByGroup(groupId); } @Override diff --git a/src/main/java/org/fisco/bcos/sdk/client/JsonRpcService.java b/src/main/java/org/fisco/bcos/sdk/client/JsonRpcService.java index 9609ad5b5..dccf0fe5f 100644 --- a/src/main/java/org/fisco/bcos/sdk/client/JsonRpcService.java +++ b/src/main/java/org/fisco/bcos/sdk/client/JsonRpcService.java @@ -23,6 +23,7 @@ import org.fisco.bcos.sdk.model.Message; import org.fisco.bcos.sdk.model.MsgType; import org.fisco.bcos.sdk.model.Response; +import org.fisco.bcos.sdk.service.GroupManagerService; import org.fisco.bcos.sdk.utils.ChannelUtils; import org.fisco.bcos.sdk.utils.ObjectMapperFactory; import org.slf4j.Logger; @@ -31,10 +32,13 @@ public class JsonRpcService { protected final ObjectMapper objectMapper = ObjectMapperFactory.getObjectMapper(); private static Logger logger = LoggerFactory.getLogger(JsonRpcService.class); + private final GroupManagerService groupManagerService; public final Channel channel; - private final String groupId; + private final int groupId; - public JsonRpcService(Channel channel, String groupId) { + public JsonRpcService( + GroupManagerService groupManagerService, Channel channel, Integer groupId) { + this.groupManagerService = groupManagerService; this.channel = channel; this.groupId = groupId; } @@ -43,6 +47,10 @@ public Channel getChannel() { return this.channel; } + public GroupManagerService getGroupManagerService() { + return this.groupManagerService; + } + public T sendRequestToPeer( JsonRpcRequest request, String peerIpPort, Class responseType) { return this.sendRequestToPeer( @@ -66,7 +74,7 @@ public T sendRequestToGroup( JsonRpcRequest request, MsgType messageType, Class responseType) { Message message = encodeRequestToMessage(request, Short.valueOf((short) messageType.ordinal())); - Response response = channel.sendToGroup(message, this.groupId); + Response response = this.groupManagerService.sendMessageToGroup(this.groupId, message); return this.parseResponseIntoJsonRpcResponse(request, response, responseType); } @@ -118,9 +126,9 @@ public void asyncSendRequestToGroup( RespCallback callback) { Message message = encodeRequestToMessage(request, Short.valueOf((short) messageType.ordinal())); - this.channel.asyncSendToGroup( - message, + this.groupManagerService.asyncSendMessageToGroup( this.groupId, + message, new ResponseCallback() { @Override public void onResponse(Response response) { diff --git a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/BcosTransactionReceipt.java b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/BcosTransactionReceipt.java index d46636ece..6230232e3 100644 --- a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/BcosTransactionReceipt.java +++ b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/BcosTransactionReceipt.java @@ -22,7 +22,7 @@ import com.fasterxml.jackson.databind.ObjectReader; import java.io.IOException; import java.util.Optional; -import org.fisco.bcos.sdk.client.protocol.model.TransactionReceipt; +import org.fisco.bcos.sdk.model.TransactionReceipt; import org.fisco.bcos.sdk.utils.ObjectMapperFactory; /** getTransactionReceipt. */ diff --git a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/TransactionReceiptWithProof.java b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/TransactionReceiptWithProof.java index 833806588..726ca02ca 100644 --- a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/TransactionReceiptWithProof.java +++ b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/TransactionReceiptWithProof.java @@ -18,8 +18,8 @@ import com.fasterxml.jackson.annotation.JsonProperty; import java.util.List; import java.util.Objects; -import org.fisco.bcos.sdk.client.protocol.model.MerkleProofUnit; -import org.fisco.bcos.sdk.client.protocol.model.TransactionReceipt; +import org.fisco.bcos.sdk.model.MerkleProofUnit; +import org.fisco.bcos.sdk.model.TransactionReceipt; /** getTransactionReceiptWithProof. */ public class TransactionReceiptWithProof diff --git a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/TransactionWithProof.java b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/TransactionWithProof.java index 29bc70728..ce123747a 100644 --- a/src/main/java/org/fisco/bcos/sdk/client/protocol/response/TransactionWithProof.java +++ b/src/main/java/org/fisco/bcos/sdk/client/protocol/response/TransactionWithProof.java @@ -19,7 +19,7 @@ import java.util.List; import java.util.Objects; import org.fisco.bcos.sdk.client.protocol.model.JsonTransactionResponse; -import org.fisco.bcos.sdk.client.protocol.model.MerkleProofUnit; +import org.fisco.bcos.sdk.model.MerkleProofUnit; /** getTransactionWithProof. */ public class TransactionWithProof diff --git a/src/main/java/org/fisco/bcos/sdk/client/protocol/model/MerkleProofUnit.java b/src/main/java/org/fisco/bcos/sdk/model/MerkleProofUnit.java similarity index 96% rename from src/main/java/org/fisco/bcos/sdk/client/protocol/model/MerkleProofUnit.java rename to src/main/java/org/fisco/bcos/sdk/model/MerkleProofUnit.java index c81022bc8..5098b47a8 100644 --- a/src/main/java/org/fisco/bcos/sdk/client/protocol/model/MerkleProofUnit.java +++ b/src/main/java/org/fisco/bcos/sdk/model/MerkleProofUnit.java @@ -13,7 +13,7 @@ * */ -package org.fisco.bcos.sdk.client.protocol.model; +package org.fisco.bcos.sdk.model; import java.util.List; import java.util.Objects; diff --git a/src/main/java/org/fisco/bcos/sdk/client/protocol/model/TransactionReceipt.java b/src/main/java/org/fisco/bcos/sdk/model/TransactionReceipt.java similarity index 99% rename from src/main/java/org/fisco/bcos/sdk/client/protocol/model/TransactionReceipt.java rename to src/main/java/org/fisco/bcos/sdk/model/TransactionReceipt.java index 54e1515b3..56bf8bac2 100644 --- a/src/main/java/org/fisco/bcos/sdk/client/protocol/model/TransactionReceipt.java +++ b/src/main/java/org/fisco/bcos/sdk/model/TransactionReceipt.java @@ -12,7 +12,7 @@ * the License. * */ -package org.fisco.bcos.sdk.client.protocol.model; +package org.fisco.bcos.sdk.model; import java.util.List; import java.util.Objects; diff --git a/src/main/java/org/fisco/bcos/sdk/service/GroupManagerService.java b/src/main/java/org/fisco/bcos/sdk/service/GroupManagerService.java new file mode 100644 index 000000000..15df77f9e --- /dev/null +++ b/src/main/java/org/fisco/bcos/sdk/service/GroupManagerService.java @@ -0,0 +1,136 @@ +/** + * Copyright 2014-2020 [fisco-dev] + * + *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software distributed under the + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.fisco.bcos.sdk.service; + +import java.math.BigInteger; +import java.util.List; +import java.util.Set; +import org.fisco.bcos.sdk.channel.PeerSelectRule; +import org.fisco.bcos.sdk.channel.ResponseCallback; +import org.fisco.bcos.sdk.model.Message; +import org.fisco.bcos.sdk.model.Response; + +public interface GroupManagerService { + + /** + * Update the group list information of the node + * + * @param peerIpAndPort: Node ip and port information + * @param groupList: Group list of nodes + */ + void updateGroupInfo(String peerIpAndPort, List groupList); + + /** + * Get the blockNumber notify message from the AMOP module, parse the package and update the + * latest block height of each group + * + * @param peerIpAndPort: Node ip and port + * @param blockNumberNotifyMessage: the blockNumber notify message + */ + void updateBlockNumberInfo(String peerIpAndPort, Message blockNumberNotifyMessage); + + /** + * update the block number information for the specified group + * + * @param groupId: the specified groupId + * @param currentBlockNumber: the current blockNumber + */ + void updateBlockNumber(int groupId, BigInteger currentBlockNumber); + + /** + * Get block limit of specified group + * + * @param groupId: The specified groupId + * @return: the blockLimit(needed by the transaction module) + */ + BigInteger getBlockLimitByGroup(int groupId); + + /** + * Get the node list of the specified group + * + * @param groupId: The group id + * @return: The node list that started the group + */ + Set getGroupNodeList(int groupId); + + /** + * Get the group list of specified node + * + * @param nodeAddress: The ip and port info of the node + * @return: List of groups started by the node + */ + Set getGroupInfoByNodeInfo(String nodeAddress); + + /** + * Send a message to a node in the group and select the node with the highest block height in + * the group + * + * @param groupId: The group the message is sent to + * @param message: The message to be sent + * @return: response of the node located in the specified group + */ + Response sendMessageToGroup(int groupId, Message message); + + /** + * Send messages to nodes in the group according to specified rules (If multiple nodes are + * filtered out, only select one of them to send the message) + * + * @param groupId: The group the message is sent to + * @param message: The message to be sent + * @param rule: Rule for filtering the target nodes + * @return: callback to be called after receiving response + * @param callback: + */ + Response sendMessageToGroupByRule( + int groupId, Message message, PeerSelectRule rule, ResponseCallback callback); + + /** + * Send a message to a node in the group and select the node with the highest block height in + * the group + * + * @param groupId: The group the message is sent to + * @param message: The message to be sent + * @param callback: callback to be called after receiving response + */ + void asyncSendMessageToGroup(int groupId, Message message, ResponseCallback callback); + + /** + * Send messages to nodes in the group according to specified rules (If multiple nodes are + * filtered out, only select one of them to send the message) + * + * @param groupId: The group the message is sent to + * @param message: The message to be sent + * @param rule: Rules for filtering the target nodes + * @param callback:: Function to be called after receiving response + */ + void asyncSendMessageToGroupByRule( + int groupId, Message message, PeerSelectRule rule, ResponseCallback callback); + + /** + * Send messages to nodes in the group according to specified rules + * + * @param groupId: The group the message is sent to + * @param message: The message to be sent + * @param rule: Rules for filtering the target nodes + */ + void multicastMessageToGroup(int groupId, Message message, PeerSelectRule rule); + + /** + * Broadcast messages to all the nodes of the specified group + * + * @param groupId: The group the message is sent to + * @param message: The message to be sent + */ + void broadcastMessageToGroup(int groupId, Message message); +} diff --git a/src/main/java/org/fisco/bcos/sdk/service/GroupService.java b/src/main/java/org/fisco/bcos/sdk/service/GroupService.java new file mode 100644 index 000000000..3f4769ff0 --- /dev/null +++ b/src/main/java/org/fisco/bcos/sdk/service/GroupService.java @@ -0,0 +1,39 @@ +/** + * Copyright 2014-2020 [fisco-dev] + * + *

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of the License at + * + *

http://www.apache.org/licenses/LICENSE-2.0 + * + *

Unless required by applicable law or agreed to in writing, software distributed under the + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.fisco.bcos.sdk.service; + +import java.util.Set; + +public interface GroupService { + /** + * Get the node information of the group + * + * @return: Nodes' ip and port list + */ + Set getGroupNodesInfo(); + + /** + * remove node from the group + * + * @param nodeAddress: the ip and port of the removed node + */ + void removeNode(String nodeAddress); + + /** + * add nodeInfo to the group + * + * @param nodeAddress: the node ip and port + */ + void insertNode(String nodeAddress); +} diff --git a/src/main/java/org/fisco/bcos/sdk/transaction/core/impl/executor/TransactionDecoder.java b/src/main/java/org/fisco/bcos/sdk/transaction/core/impl/executor/TransactionDecoder.java index 4298b5c0c..683863401 100644 --- a/src/main/java/org/fisco/bcos/sdk/transaction/core/impl/executor/TransactionDecoder.java +++ b/src/main/java/org/fisco/bcos/sdk/transaction/core/impl/executor/TransactionDecoder.java @@ -16,12 +16,12 @@ import java.util.List; import java.util.Map; +import org.fisco.bcos.sdk.model.TransactionReceipt; import org.fisco.bcos.sdk.transaction.core.interf.executor.TransactionDecoderInterface; import org.fisco.bcos.sdk.transaction.domain.EventLog; import org.fisco.bcos.sdk.transaction.domain.EventResultEntity; import org.fisco.bcos.sdk.transaction.domain.InputAndOutputResult; import org.fisco.bcos.sdk.transaction.domain.RawTransaction; -import org.fisco.bcos.sdk.transaction.domain.TransactionReceipt; import org.fisco.bcos.sdk.transaction.domain.TransactionResponse; public class TransactionDecoder implements TransactionDecoderInterface { diff --git a/src/main/java/org/fisco/bcos/sdk/transaction/core/impl/executor/TransactionPusher.java b/src/main/java/org/fisco/bcos/sdk/transaction/core/impl/executor/TransactionPusher.java index 7ed7b3b29..b2193f957 100644 --- a/src/main/java/org/fisco/bcos/sdk/transaction/core/impl/executor/TransactionPusher.java +++ b/src/main/java/org/fisco/bcos/sdk/transaction/core/impl/executor/TransactionPusher.java @@ -17,8 +17,8 @@ import java.util.concurrent.CompletableFuture; import org.fisco.bcos.sdk.client.RespCallback; import org.fisco.bcos.sdk.client.protocol.response.Call; +import org.fisco.bcos.sdk.model.TransactionReceipt; import org.fisco.bcos.sdk.transaction.core.interf.executor.TransactionPusherInterface; -import org.fisco.bcos.sdk.transaction.domain.TransactionReceipt; public class TransactionPusher implements TransactionPusherInterface { diff --git a/src/main/java/org/fisco/bcos/sdk/transaction/core/interf/executor/TransactionDecoderInterface.java b/src/main/java/org/fisco/bcos/sdk/transaction/core/interf/executor/TransactionDecoderInterface.java index 2ee6542ec..2931019a0 100644 --- a/src/main/java/org/fisco/bcos/sdk/transaction/core/interf/executor/TransactionDecoderInterface.java +++ b/src/main/java/org/fisco/bcos/sdk/transaction/core/interf/executor/TransactionDecoderInterface.java @@ -16,11 +16,11 @@ import java.util.List; import java.util.Map; +import org.fisco.bcos.sdk.model.TransactionReceipt; import org.fisco.bcos.sdk.transaction.domain.EventLog; import org.fisco.bcos.sdk.transaction.domain.EventResultEntity; import org.fisco.bcos.sdk.transaction.domain.InputAndOutputResult; import org.fisco.bcos.sdk.transaction.domain.RawTransaction; -import org.fisco.bcos.sdk.transaction.domain.TransactionReceipt; import org.fisco.bcos.sdk.transaction.domain.TransactionResponse; /** diff --git a/src/main/java/org/fisco/bcos/sdk/transaction/core/interf/executor/TransactionPusherInterface.java b/src/main/java/org/fisco/bcos/sdk/transaction/core/interf/executor/TransactionPusherInterface.java index 3a093cd37..f6d9c991e 100644 --- a/src/main/java/org/fisco/bcos/sdk/transaction/core/interf/executor/TransactionPusherInterface.java +++ b/src/main/java/org/fisco/bcos/sdk/transaction/core/interf/executor/TransactionPusherInterface.java @@ -17,7 +17,7 @@ import java.util.concurrent.CompletableFuture; import org.fisco.bcos.sdk.client.RespCallback; import org.fisco.bcos.sdk.client.protocol.response.Call; -import org.fisco.bcos.sdk.transaction.domain.TransactionReceipt; +import org.fisco.bcos.sdk.model.TransactionReceipt; /** * TransactionPusher @Description: TransactionPusherInterface diff --git a/src/main/java/org/fisco/bcos/sdk/transaction/domain/MerkleProofUnit.java b/src/main/java/org/fisco/bcos/sdk/transaction/domain/MerkleProofUnit.java deleted file mode 100644 index 13fdd48dd..000000000 --- a/src/main/java/org/fisco/bcos/sdk/transaction/domain/MerkleProofUnit.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2014-2020 [fisco-dev] - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - * - */ -package org.fisco.bcos.sdk.transaction.domain; - -import java.util.List; -import java.util.Objects; -import org.fisco.bcos.sdk.client.protocol.response.TransactionReceiptWithProof; -import org.fisco.bcos.sdk.client.protocol.response.TransactionWithProof; - -/** - * MerkleProofUnit object used by both {@link TransactionReceiptWithProof} and {@link - * TransactionWithProof}. - */ -public class MerkleProofUnit { - private List left; - private List right; - - public MerkleProofUnit() {} - - public MerkleProofUnit(List left, List right) { - this.left = left; - this.right = right; - } - - public List getLeft() { - return left; - } - - public void setLeft(List left) { - this.left = left; - } - - public List getRight() { - return right; - } - - public void setRight(List right) { - this.right = right; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof MerkleProofUnit)) { - return false; - } - MerkleProofUnit that = (MerkleProofUnit) o; - return Objects.equals(getLeft(), that.getLeft()) - && Objects.equals(getRight(), that.getRight()); - } - - @Override - public int hashCode() { - return Objects.hash(getLeft(), getRight()); - } - - @Override - public String toString() { - return "MerkleProofUnit{" + "left=" + left + ", right=" + right + '}'; - } -} diff --git a/src/main/java/org/fisco/bcos/sdk/transaction/domain/TransactionReceipt.java b/src/main/java/org/fisco/bcos/sdk/transaction/domain/TransactionReceipt.java deleted file mode 100644 index 59c8c73c5..000000000 --- a/src/main/java/org/fisco/bcos/sdk/transaction/domain/TransactionReceipt.java +++ /dev/null @@ -1,386 +0,0 @@ -/* - * Copyright 2014-2020 [fisco-dev] - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software distributed under the License - * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express - * or implied. See the License for the specific language governing permissions and limitations under - * the License. - * - */ -package org.fisco.bcos.sdk.transaction.domain; - -import com.fasterxml.jackson.annotation.JsonIgnore; -import java.math.BigInteger; -import java.util.List; -import org.fisco.bcos.sdk.client.protocol.response.BcosTransactionReceipt; -import org.fisco.bcos.sdk.utils.Numeric; - -/** TransactionReceipt object used by {@link BcosTransactionReceipt}. */ -public class TransactionReceipt { - private String transactionHash; - private String transactionIndex; - private String blockHash; - private String blockNumber; - private String gasUsed; - private String contractAddress; - private String root; - // status is only present on Byzantium transactions onwards - // see EIP 658 https://github.com/ethereum/EIPs/pull/658 - private String status; - private String message; - private String from; - private String to; - private String input; - private String output; - private List logs; - private String logsBloom; - private List txProof; - private List receiptProof; - - public TransactionReceipt() {} - - public TransactionReceipt( - String transactionHash, - String transactionIndex, - String blockHash, - String blockNumber, - String gasUsed, - String contractAddress, - String root, - String status, - String message, - String from, - String to, - String input, - String output, - List logs, - String logsBloom) { - this.transactionHash = transactionHash; - this.transactionIndex = transactionIndex; - this.blockHash = blockHash; - this.blockNumber = blockNumber; - this.gasUsed = gasUsed; - this.contractAddress = contractAddress; - this.root = root; - this.status = status; - this.message = message; - this.from = from; - this.to = to; - this.input = input; - this.output = output; - this.logs = logs; - this.logsBloom = logsBloom; - } - - public String getTransactionHash() { - return transactionHash; - } - - public void setTransactionHash(String transactionHash) { - this.transactionHash = transactionHash; - } - - public BigInteger getTransactionIndex() { - return Numeric.decodeQuantity(transactionIndex); - } - - @JsonIgnore - public String getTransactionIndexRaw() { - return transactionIndex; - } - - public void setTransactionIndex(String transactionIndex) { - this.transactionIndex = transactionIndex; - } - - public String getBlockHash() { - return blockHash; - } - - public void setBlockHash(String blockHash) { - this.blockHash = blockHash; - } - - public BigInteger getBlockNumber() { - return Numeric.decodeQuantity(blockNumber); - } - - @JsonIgnore - public String getBlockNumberRaw() { - return blockNumber; - } - - public String getOutput() { - return output; - } - - public void setOutput(String output) { - this.output = output; - } - - public String getInput() { - return input; - } - - public void setInput(String input) { - this.input = input; - } - - public void setBlockNumber(String blockNumber) { - this.blockNumber = blockNumber; - } - - public BigInteger getGasUsed() { - return Numeric.decodeQuantity(gasUsed); - } - - @JsonIgnore - public String getGasUsedRaw() { - return gasUsed; - } - - public void setGasUsed(String gasUsed) { - this.gasUsed = gasUsed; - } - - public String getContractAddress() { - return contractAddress; - } - - public void setContractAddress(String contractAddress) { - this.contractAddress = contractAddress; - } - - public String getRoot() { - return root; - } - - public void setRoot(String root) { - this.root = root; - } - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - @JsonIgnore - public boolean isStatusOK() { - if (null == status) { - return true; - } - - try { - BigInteger statusQuantity = Numeric.decodeQuantity(status); - return BigInteger.ZERO.equals(statusQuantity); - } catch (Exception e) { - return false; - } - } - - public String getFrom() { - return from; - } - - public void setFrom(String from) { - this.from = from; - } - - public String getTo() { - return to; - } - - public void setTo(String to) { - this.to = to; - } - - public List getLogs() { - return logs; - } - - public void setLogs(List logs) { - this.logs = logs; - } - - public String getLogsBloom() { - return logsBloom; - } - - public void setLogsBloom(String logsBloom) { - this.logsBloom = logsBloom; - } - - public List getTxProof() { - return txProof; - } - - public void setTxProof(List txProof) { - this.txProof = txProof; - } - - public List getReceiptProof() { - return receiptProof; - } - - public void setReceiptProof(List receiptProof) { - this.receiptProof = receiptProof; - } - - @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (!(o instanceof TransactionReceipt)) { - return false; - } - - TransactionReceipt that = (TransactionReceipt) o; - - if (getTransactionHash() != null - ? !getTransactionHash().equals(that.getTransactionHash()) - : that.getTransactionHash() != null) { - return false; - } - if (transactionIndex != null - ? !transactionIndex.equals(that.transactionIndex) - : that.transactionIndex != null) { - return false; - } - if (getBlockHash() != null - ? !getBlockHash().equals(that.getBlockHash()) - : that.getBlockHash() != null) { - return false; - } - if (blockNumber != null - ? !blockNumber.equals(that.blockNumber) - : that.blockNumber != null) { - return false; - } - if (gasUsed != null ? !gasUsed.equals(that.gasUsed) : that.gasUsed != null) { - return false; - } - if (getContractAddress() != null - ? !getContractAddress().equals(that.getContractAddress()) - : that.getContractAddress() != null) { - return false; - } - if (getRoot() != null ? !getRoot().equals(that.getRoot()) : that.getRoot() != null) { - return false; - } - if (getStatus() != null - ? !getStatus().equals(that.getStatus()) - : that.getStatus() != null) { - return false; - } - if (getFrom() != null ? !getFrom().equals(that.getFrom()) : that.getFrom() != null) { - return false; - } - if (getTo() != null ? !getTo().equals(that.getTo()) : that.getTo() != null) { - return false; - } - if (getLogs() != null ? !getLogs().equals(that.getLogs()) : that.getLogs() != null) { - return false; - } - if (getOutput() != null - ? !getOutput().equals(that.getOutput()) - : that.getOutput() != null) { - return false; - } - if (getInput() != null ? !getInput().equals(that.getInput()) : that.getInput() != null) { - return false; - } - return getLogsBloom() != null - ? getLogsBloom().equals(that.getLogsBloom()) - : that.getLogsBloom() == null; - } - - @Override - public int hashCode() { - int result = getTransactionHash() != null ? getTransactionHash().hashCode() : 0; - result = 31 * result + (transactionIndex != null ? transactionIndex.hashCode() : 0); - result = 31 * result + (getBlockHash() != null ? getBlockHash().hashCode() : 0); - result = 31 * result + (blockNumber != null ? blockNumber.hashCode() : 0); - result = 31 * result + (gasUsed != null ? gasUsed.hashCode() : 0); - result = 31 * result + (getContractAddress() != null ? getContractAddress().hashCode() : 0); - result = 31 * result + (getRoot() != null ? getRoot().hashCode() : 0); - result = 31 * result + (getStatus() != null ? getStatus().hashCode() : 0); - result = 31 * result + (getFrom() != null ? getFrom().hashCode() : 0); - result = 31 * result + (getTo() != null ? getTo().hashCode() : 0); - result = 31 * result + (getOutput() != null ? getOutput().hashCode() : 0); - result = 31 * result + (getInput() != null ? getInput().hashCode() : 0); - result = 31 * result + (getLogs() != null ? getLogs().hashCode() : 0); - result = 31 * result + (getLogsBloom() != null ? getLogsBloom().hashCode() : 0); - return result; - } - - @Override - public String toString() { - return "TransactionReceipt{" - + "transactionHash='" - + transactionHash - + '\'' - + ", transactionIndex='" - + transactionIndex - + '\'' - + ", blockHash='" - + blockHash - + '\'' - + ", blockNumber='" - + blockNumber - + '\'' - + ", gasUsed='" - + gasUsed - + '\'' - + ", contractAddress='" - + contractAddress - + '\'' - + ", root='" - + root - + '\'' - + ", status='" - + status - + '\'' - + ", message='" - + message - + '\'' - + ", from='" - + from - + '\'' - + ", to='" - + to - + '\'' - + ", input='" - + input - + '\'' - + ", output='" - + output - + '\'' - + ", logs=" - + logs - + ", logsBloom='" - + logsBloom - + '\'' - + ", transAndProof=" - + txProof - + ", receiptAndProof=" - + receiptProof - + '}'; - } -} diff --git a/src/main/java/org/fisco/bcos/sdk/transaction/domain/dto/TransactionResponse.java b/src/main/java/org/fisco/bcos/sdk/transaction/domain/dto/TransactionResponse.java index 04fd88ef6..a71e67296 100644 --- a/src/main/java/org/fisco/bcos/sdk/transaction/domain/dto/TransactionResponse.java +++ b/src/main/java/org/fisco/bcos/sdk/transaction/domain/dto/TransactionResponse.java @@ -14,7 +14,7 @@ */ package org.fisco.bcos.sdk.transaction.domain.dto; -import org.fisco.bcos.sdk.transaction.domain.TransactionReceipt; +import org.fisco.bcos.sdk.model.TransactionReceipt; /** * TransactionResponse @Description: TransactionResponse diff --git a/src/main/java/org/fisco/bcos/sdk/transaction/manager/TransactionManager.java b/src/main/java/org/fisco/bcos/sdk/transaction/manager/TransactionManager.java index 4c560595a..5d0e00b90 100644 --- a/src/main/java/org/fisco/bcos/sdk/transaction/manager/TransactionManager.java +++ b/src/main/java/org/fisco/bcos/sdk/transaction/manager/TransactionManager.java @@ -16,7 +16,7 @@ import java.util.concurrent.CompletableFuture; import org.fisco.bcos.sdk.client.RespCallback; -import org.fisco.bcos.sdk.transaction.domain.TransactionReceipt; +import org.fisco.bcos.sdk.model.TransactionReceipt; import org.fisco.bcos.sdk.transaction.domain.dto.CallRequest; import org.fisco.bcos.sdk.transaction.domain.dto.CallResponse; import org.fisco.bcos.sdk.transaction.domain.dto.TransactionRequest; diff --git a/src/main/java/org/fisco/bcos/sdk/transaction/manager/TransactionManagerInterface.java b/src/main/java/org/fisco/bcos/sdk/transaction/manager/TransactionManagerInterface.java index 5915e1256..bab5c4324 100644 --- a/src/main/java/org/fisco/bcos/sdk/transaction/manager/TransactionManagerInterface.java +++ b/src/main/java/org/fisco/bcos/sdk/transaction/manager/TransactionManagerInterface.java @@ -16,7 +16,7 @@ import java.util.concurrent.CompletableFuture; import org.fisco.bcos.sdk.client.RespCallback; -import org.fisco.bcos.sdk.transaction.domain.TransactionReceipt; +import org.fisco.bcos.sdk.model.TransactionReceipt; import org.fisco.bcos.sdk.transaction.domain.dto.CallRequest; import org.fisco.bcos.sdk.transaction.domain.dto.CallResponse; import org.fisco.bcos.sdk.transaction.domain.dto.TransactionRequest;