add interface ret receipt for consensus precompiled service
@@ -26,20 +26,50 @@ public class ConsensusService {
}
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<String> 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<String> 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 class ConsensusService {
}
}
return PrecompiledCommon.handleTransactionReceipt(receipt, web3j);
+ */
}
private boolean isValidNodeID(String _nodeID) throws IOException, JsonProcessingException {
