Skip to content

Commit ea18bed

Browse files
authored
Merge pull request #84 from PlatONnetwork/develop
1.1.0.0
2 parents f4aba87 + f935a20 commit ea18bed

18 files changed

Lines changed: 611 additions & 11 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
<dependency>
2121
<groupId>com.platon.sdk</groupId>
2222
<artifactId>core</artifactId>
23-
<version>0.15.1.14</version>
23+
<version>1.1.0.0</version>
2424
</dependency>
2525
```
2626

2727
or
2828

2929
```
30-
compile "com.platon.sdk:core:0.15.1.14"
30+
compile "com.platon.sdk:core:1.1.0.0"
3131
```
3232

3333
* use in project

core/src/main/java/com/platon/contracts/ppos/BaseContract.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@
3030
import com.platon.tx.ReadonlyTransactionManager;
3131
import com.platon.tx.TransactionManager;
3232
import com.platon.tx.exceptions.ContractCallException;
33+
import com.platon.tx.exceptions.PlatonCallException;
34+
import com.platon.tx.exceptions.PlatonCallTimeoutException;
3335
import com.platon.tx.gas.ContractGasProvider;
3436
import com.platon.tx.gas.GasProvider;
3537
import com.platon.utils.JSONUtil;
3638
import com.platon.utils.Numeric;
39+
import com.platon.utils.Strings;
3740
import org.bouncycastle.util.encoders.Hex;
3841
import org.slf4j.Logger;
3942
import org.slf4j.LoggerFactory;
@@ -87,6 +90,20 @@ private <T> CallResponse<T> executeCallObjectValueReturn(Function function, Clas
8790
DefaultBlockParameterName.LATEST)
8891
.send();
8992

93+
//判断底层返回的错误信息是否包含超时信息
94+
if(ethCall.hasError()){
95+
Response.Error error = ethCall.getError();
96+
String message = error.getMessage();
97+
String lowMessage = !Strings.isBlank(message)? message.toLowerCase() : null;
98+
//包含timeout则抛超时异常,其他错误则直接抛出runtime异常
99+
if(!Strings.isBlank(lowMessage)
100+
&& lowMessage.contains("timeout")){
101+
throw new PlatonCallTimeoutException(error.getCode(),error.getMessage(),ethCall);
102+
} else {
103+
throw new PlatonCallException(error.getCode(),error.getMessage(),ethCall);
104+
}
105+
}
106+
90107
String result = Numeric.cleanHexPrefix(ethCall.getValue());
91108
if(result==null || "".equals(result)){
92109
throw new ContractCallException("Empty value (0x) returned from contract");
@@ -131,6 +148,20 @@ private <T> CallResponse<List<T>> executeCallListValueReturn(Function function,
131148
DefaultBlockParameterName.LATEST)
132149
.send();
133150

151+
//判断底层返回的错误信息是否包含超时信息
152+
if(ethCall.hasError()){
153+
Response.Error error = ethCall.getError();
154+
String message = error.getMessage();
155+
String lowMessage = !Strings.isBlank(message)? message.toLowerCase() : null;
156+
//包含timeout则抛超时异常,其他错误则直接抛出runtime异常
157+
if(!Strings.isBlank(lowMessage)
158+
&& lowMessage.contains("timeout")){
159+
throw new PlatonCallTimeoutException(error.getCode(),error.getMessage(),ethCall);
160+
} else {
161+
throw new PlatonCallException(error.getCode(),error.getMessage(),ethCall);
162+
}
163+
}
164+
134165
String result = Numeric.cleanHexPrefix(ethCall.getValue());
135166
if(result==null || "".equals(result)){
136167
throw new ContractCallException("Empty value (0x) returned from contract");

core/src/main/java/com/platon/protocol/core/JsonRpc2_0Web3j.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.platon.protocol.Web3j;
44
import com.platon.protocol.Web3jService;
5+
import com.platon.protocol.core.methods.DebugWaitSlashingNodeList;
56
import com.platon.protocol.core.methods.request.ShhFilter;
67
import com.platon.protocol.core.methods.response.*;
78
import com.platon.protocol.rx.JsonRpc2_0Rx;
@@ -690,4 +691,22 @@ public Request<?, DebugEconomicConfig> getEconomicConfig() {
690691
web3jService,
691692
DebugEconomicConfig.class);
692693
}
694+
695+
@Override
696+
public Request<?, PlatonChainId> getChainId() {
697+
return new Request<>(
698+
"platon_chainId",
699+
Collections.<String>emptyList(),
700+
web3jService,
701+
PlatonChainId.class);
702+
}
703+
704+
@Override
705+
public Request<?, DebugWaitSlashingNodeList> getWaitSlashingNodeList() {
706+
return new Request<>(
707+
"debug_getWaitSlashingNodeList",
708+
Collections.<String>emptyList(),
709+
web3jService,
710+
DebugWaitSlashingNodeList.class);
711+
}
693712
}

core/src/main/java/com/platon/protocol/core/Platon.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.platon.protocol.core;
22

3+
import com.platon.protocol.core.methods.DebugWaitSlashingNodeList;
34
import com.platon.protocol.core.methods.request.ShhFilter;
45
import com.platon.protocol.core.methods.response.*;
56

@@ -130,4 +131,8 @@ Request<?, ShhPost> shhPost(
130131
Request<?, AdminSchnorrNIZKProve> getSchnorrNIZKProve();
131132

132133
Request<?, DebugEconomicConfig> getEconomicConfig();
134+
135+
Request<?, PlatonChainId> getChainId();
136+
137+
Request<?, DebugWaitSlashingNodeList> getWaitSlashingNodeList();
133138
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.platon.protocol.core.methods;
2+
3+
import com.platon.protocol.core.Response;
4+
import com.platon.protocol.core.methods.response.bean.WaitSlashingNode;
5+
import com.platon.utils.JSONUtil;
6+
7+
import java.util.List;
8+
9+
/**
10+
* debug_getWaitSlashingNodeList
11+
*/
12+
public class DebugWaitSlashingNodeList extends Response<String> {
13+
14+
public List<WaitSlashingNode> get() {
15+
return JSONUtil.parseArray(getResult(), WaitSlashingNode.class);
16+
}
17+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2019 Web3 Labs Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5+
* the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11+
* specific language governing permissions and limitations under the License.
12+
*/
13+
package com.platon.protocol.core.methods.response;
14+
15+
16+
import com.platon.protocol.core.Response;
17+
import com.platon.utils.Numeric;
18+
19+
import java.math.BigInteger;
20+
21+
/** platon_chainId. */
22+
public class PlatonChainId extends Response<String> {
23+
public BigInteger getChainId() {
24+
return Numeric.decodeQuantity(getResult());
25+
}
26+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package com.platon.protocol.core.methods.response.bean;
2+
3+
import com.fasterxml.jackson.annotation.JsonIgnore;
4+
import com.fasterxml.jackson.annotation.JsonProperty;
5+
6+
import java.math.BigInteger;
7+
8+
/**
9+
* @Author liushuyu
10+
* @Date 2021/7/6 14:38
11+
* @Version
12+
* @Desc
13+
*/
14+
public class WaitSlashingNode {
15+
16+
//零出块的节点ID
17+
@JsonProperty("NodeId")
18+
private String nodeId;
19+
20+
//观察期内第一次零出块时所处共识轮数
21+
@JsonProperty("Round")
22+
private BigInteger round;
23+
24+
//零出块次数位图(从Round开始,1表示该轮未出块)
25+
@JsonProperty("CountBit")
26+
private BigInteger countBit;
27+
28+
29+
public String getNodeId() {
30+
return nodeId;
31+
}
32+
33+
@JsonIgnore
34+
public void setNodeId(String nodeId) {
35+
this.nodeId = nodeId;
36+
}
37+
38+
public BigInteger getRound() {
39+
return round;
40+
}
41+
42+
@JsonIgnore
43+
public void setRound(BigInteger round) {
44+
this.round = round;
45+
}
46+
47+
public BigInteger getCountBit() {
48+
return countBit;
49+
}
50+
51+
@JsonIgnore
52+
public void setCountBit(BigInteger countBit) {
53+
this.countBit = countBit;
54+
}
55+
56+
@Override
57+
public String toString() {
58+
return "WaitSlashingNode{" +
59+
"nodeId='" + nodeId + '\'' +
60+
", round=" + round +
61+
", countBit=" + countBit +
62+
'}';
63+
}
64+
}

core/src/main/java/com/platon/protocol/websocket/WebSocketService.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import java.io.IOException;
1919
import java.net.ConnectException;
20+
import java.net.SocketTimeoutException;
2021
import java.net.URI;
2122
import java.net.URISyntaxException;
2223
import java.util.Collections;

core/src/main/java/com/platon/tx/Contract.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,20 @@
1010
import com.platon.protocol.core.DefaultBlockParameter;
1111
import com.platon.protocol.core.DefaultBlockParameterName;
1212
import com.platon.protocol.core.RemoteCall;
13+
import com.platon.protocol.core.Response;
1314
import com.platon.protocol.core.methods.request.Transaction;
1415
import com.platon.protocol.core.methods.response.Log;
1516
import com.platon.protocol.core.methods.response.PlatonCall;
1617
import com.platon.protocol.core.methods.response.PlatonGetCode;
1718
import com.platon.protocol.core.methods.response.TransactionReceipt;
1819
import com.platon.protocol.exceptions.TransactionException;
1920
import com.platon.tx.exceptions.ContractCallException;
21+
import com.platon.tx.exceptions.PlatonCallException;
22+
import com.platon.tx.exceptions.PlatonCallTimeoutException;
2023
import com.platon.tx.gas.DefaultGasProvider;
2124
import com.platon.tx.gas.GasProvider;
2225
import com.platon.utils.Numeric;
26+
import com.platon.utils.Strings;
2327

2428
import java.io.IOException;
2529
import java.lang.reflect.Constructor;
@@ -149,6 +153,20 @@ private List<Type> executeCall(
149153
defaultBlockParameter)
150154
.send();
151155

156+
//判断底层返回的错误信息是否包含超时信息
157+
if(ethCall.hasError()){
158+
Response.Error error = ethCall.getError();
159+
String message = error.getMessage();
160+
String lowMessage = !Strings.isBlank(message)? message.toLowerCase() : null;
161+
//包含timeout则抛超时异常,其他错误则直接抛出runtime异常
162+
if(!Strings.isBlank(lowMessage)
163+
&& lowMessage.contains("timeout")){
164+
throw new PlatonCallTimeoutException(error.getCode(),error.getMessage(),ethCall);
165+
} else {
166+
throw new PlatonCallException(error.getCode(),error.getMessage(),ethCall);
167+
}
168+
}
169+
152170
String value = ethCall.getValue();
153171
return FunctionReturnDecoder.decode(value, function.getOutputParameters());
154172
}
@@ -268,7 +286,7 @@ private static <T extends Contract> T create(
268286
return contract;
269287
}
270288

271-
protected static <T extends Contract> T deploy(Class<T> type, Web3j web3j, Credentials credentials, GasProvider contractGasProvider, String binary, String encodedConstructor, BigInteger value) throws RuntimeException, TransactionException {
289+
protected static <T extends Contract> T deploy(Class<T> type, Web3j web3j, Credentials credentials, GasProvider contractGasProvider, String binary, String encodedConstructor, BigInteger value) throws RuntimeException, TransactionException, IOException {
272290

273291
try {
274292
Constructor<T> constructor = type.getDeclaredConstructor(String.class, Web3j.class, Credentials.class, GasProvider.class);
@@ -280,12 +298,14 @@ protected static <T extends Contract> T deploy(Class<T> type, Web3j web3j, Crede
280298
return create(contract, binary, encodedConstructor, value);
281299
} catch (TransactionException e) {
282300
throw e;
301+
} catch (IOException e) {
302+
throw e;
283303
} catch (Exception e) {
284304
throw new RuntimeException(e);
285305
}
286306
}
287307

288-
protected static <T extends Contract> T deploy(Class<T> type, Web3j web3j, TransactionManager transactionManager, GasProvider contractGasProvider, String binary, String encodedConstructor, BigInteger value) throws RuntimeException, TransactionException {
308+
protected static <T extends Contract> T deploy(Class<T> type, Web3j web3j, TransactionManager transactionManager, GasProvider contractGasProvider, String binary, String encodedConstructor, BigInteger value) throws RuntimeException, TransactionException, IOException{
289309

290310
try {
291311
Constructor<T> constructor = type.getDeclaredConstructor(String.class, Web3j.class, TransactionManager.class, GasProvider.class);
@@ -296,6 +316,8 @@ protected static <T extends Contract> T deploy(Class<T> type, Web3j web3j, Trans
296316
return create(contract, binary, encodedConstructor, value);
297317
} catch (TransactionException e) {
298318
throw e;
319+
} catch (IOException e) {
320+
throw e;
299321
} catch (Exception e) {
300322
throw new RuntimeException(e);
301323
}

core/src/main/java/com/platon/tx/WasmContract.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.platon.protocol.core.DefaultBlockParameter;
1010
import com.platon.protocol.core.DefaultBlockParameterName;
1111
import com.platon.protocol.core.RemoteCall;
12+
import com.platon.protocol.core.Response;
1213
import com.platon.protocol.core.methods.request.Transaction;
1314
import com.platon.protocol.core.methods.response.Log;
1415
import com.platon.protocol.core.methods.response.PlatonCall;
@@ -19,8 +20,11 @@
1920
import com.platon.rlp.wasm.RLPList;
2021
import com.platon.rlp.wasm.datatypes.Int;
2122
import com.platon.rlp.wasm.datatypes.Uint;
23+
import com.platon.tx.exceptions.PlatonCallException;
24+
import com.platon.tx.exceptions.PlatonCallTimeoutException;
2225
import com.platon.tx.gas.GasProvider;
2326
import com.platon.utils.Numeric;
27+
import com.platon.utils.Strings;
2428

2529
import java.io.IOException;
2630
import java.lang.reflect.Constructor;
@@ -127,6 +131,20 @@ protected <T> T executeCall(WasmFunction function, Class<T> clazz) throws IOExce
127131
defaultBlockParameter)
128132
.send();
129133

134+
//判断底层返回的错误信息是否包含超时信息
135+
if(ethCall.hasError()){
136+
Response.Error error = ethCall.getError();
137+
String message = error.getMessage();
138+
String lowMessage = !Strings.isBlank(message)? message.toLowerCase() : null;
139+
//包含timeout则抛超时异常,其他错误则直接抛出runtime异常
140+
if(!Strings.isBlank(lowMessage)
141+
&& lowMessage.contains("timeout")){
142+
throw new PlatonCallTimeoutException(error.getCode(),error.getMessage(),ethCall);
143+
} else {
144+
throw new PlatonCallException(error.getCode(),error.getMessage(),ethCall);
145+
}
146+
}
147+
130148
String value = ethCall.getValue();
131149
if (null != function.getOutputParameterizedType()) {
132150
return WasmReturnDecoder.decode(value, clazz, function.getOutputParameterizedType());

0 commit comments

Comments
 (0)