Skip to content

Commit 419cc24

Browse files
committed
1.估算gas不传gasprice,2.新增获取chainId的rpc接口,3.新增获取领出快的节点列表接口
1 parent 5e16e13 commit 419cc24

12 files changed

Lines changed: 441 additions & 10 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</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"
3131
```
3232

3333
* use in project

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,7 @@ protected GasProvider getDefaultGasProvider(Function function) throws IOExceptio
247247
}
248248

249249
private GasProvider getDefaultGasProviderRemote(Function function) throws IOException, EstimateGasException {
250-
BigInteger gasPrice = getDefaultGasPrice(function.getType());
251-
Transaction transaction = Transaction.createFunctionCallTransaction(transactionManager.getFromAddress(), null, gasPrice, null, contractAddress, EncoderUtils.functionEncoder(function));
250+
Transaction transaction = Transaction.createEthCallTransaction(transactionManager.getFromAddress(), contractAddress, EncoderUtils.functionEncoder(function));
252251
PlatonEstimateGas platonEstimateGas = web3j.platonEstimateGas(transaction).send();
253252
if(platonEstimateGas.hasError()){
254253
if(platonEstimateGas.getError().getCode() == ErrorCode.PlatON_Precompiled_Contract_EXEC_FAILED) {
@@ -261,7 +260,7 @@ private GasProvider getDefaultGasProviderRemote(Function function) throws IOExce
261260
}
262261
}
263262
BigInteger gasLimit = Numeric.decodeQuantity(platonEstimateGas.getResult());
264-
263+
BigInteger gasPrice = getDefaultGasPrice(function.getType());
265264
return new ContractGasProvider(gasPrice, gasLimit);
266265
}
267266

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+
}

doc/Java-SDK-en.md

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Depending on the build tool, use the following methods to add related dependenci
2626
<dependency>
2727
<groupId>com.platon.sdk</groupId>
2828
<artifactId>core</artifactId>
29-
<version>0.15.1.9</version>
29+
<version>1.1.0</version>
3030
</dependency>
3131
```
3232

@@ -41,7 +41,7 @@ repositories {
4141

4242
> gradle way of reference:
4343
```
44-
compile "com.platon.client:core:0.15.1.9"
44+
compile "com.platon.client:core:1.1.0"
4545
```
4646

4747
## Basic API Usage
@@ -1374,6 +1374,55 @@ Request<?, DebugEconomicConfig> req = currentValidWeb3j.getEconomicConfig();
13741374
String debugEconomicConfig = req.send().getEconomicConfigStr();
13751375
```
13761376

1377+
1378+
### getChainId
1379+
1380+
> Get chain ID
1381+
- **parameters**
1382+
1383+
no
1384+
1385+
- **return value**
1386+
1387+
```java
1388+
Request<?, PlatonChainId>
1389+
```
1390+
1391+
The String in the PlatonChainId property is the corresponding stored data
1392+
1393+
- **Example**
1394+
1395+
```java
1396+
Web3j platonWeb3j = Web3j.build(new HttpService("http://127.0.0.1:6789"));
1397+
Request<?, PlatonChainId> req = platonWeb3j.getChainId();
1398+
BigInteger chainId = req.send().getChainId();
1399+
```
1400+
1401+
### getWaitSlashingNodeList
1402+
1403+
> Get the node with zero block, the list of nodes that are observed because of zero block
1404+
1405+
* **parameters**
1406+
1407+
no
1408+
1409+
* **return value**
1410+
1411+
```java
1412+
Request<?, DebugWaitSlashingNodeList>
1413+
```
1414+
1415+
The `WaitSlashingNode` List Object in the `DebugWaitSlashingNodeList` property is the corresponding stored data
1416+
1417+
* **Example**
1418+
1419+
```java
1420+
Web3j platonWeb3j = Web3j.build(new HttpService("http://127.0.0.1:6789"));
1421+
Request<?, DebugWaitSlashingNodeList> req = platonWeb3j.getWaitSlashingNodeList();
1422+
DebugWaitSlashingNodeList nodeList = req.send();
1423+
```
1424+
1425+
13771426
## System Contract Call
13781427

13791428
System contracts mainly include economic model and governance related contracts:

doc/Java-SDK-zh.md

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ sidebar_label: Java SDK
2626
<dependency>
2727
<groupId>com.platon.sdk</groupId>
2828
<artifactId>core</artifactId>
29-
<version>0.15.1.9</version>
29+
<version>1.1.0</version>
3030
</dependency>
3131
```
3232

@@ -41,7 +41,7 @@ repositories {
4141

4242
> gradle引用方式:
4343
```
44-
compile "com.platon.sdk:core:0.15.1.9"
44+
compile "com.platon.sdk:core:1.1.0"
4545
```
4646

4747
## 基础api使用
@@ -1373,6 +1373,53 @@ Request<?, DebugEconomicConfig> req = currentValidWeb3j.getEconomicConfig();
13731373
String debugEconomicConfig = req.send().getEconomicConfigStr();
13741374
```
13751375

1376+
### getChainId
1377+
1378+
> 获取链ID
1379+
* **参数**
1380+
1381+
1382+
1383+
* **返回值**
1384+
1385+
```java
1386+
Request<?, PlatonChainId>
1387+
```
1388+
1389+
PlatonChainId属性中的String即为对应存储数据
1390+
1391+
* **示例**
1392+
1393+
```java
1394+
Web3j platonWeb3j = Web3j.build(new HttpService("http://127.0.0.1:6789"));
1395+
Request<?, PlatonChainId> req = platonWeb3j.getChainId();
1396+
BigInteger chainId = req.send().getChainId();
1397+
```
1398+
1399+
### getWaitSlashingNodeList
1400+
1401+
> 获取零出块的节点,因为零出块而被观察的节点列表
1402+
1403+
* **参数**
1404+
1405+
1406+
1407+
* **返回值**
1408+
1409+
```java
1410+
Request<?, DebugWaitSlashingNodeList>
1411+
```
1412+
1413+
DebugWaitSlashingNodeList属性中的WaitSlashingNode列表对象即为对应存储数据
1414+
1415+
* **示例**
1416+
1417+
```java
1418+
Web3j platonWeb3j = Web3j.build(new HttpService("http://127.0.0.1:6789"));
1419+
Request<?, DebugWaitSlashingNodeList> req = platonWeb3j.getWaitSlashingNodeList();
1420+
DebugWaitSlashingNodeList nodeList = req.send();
1421+
```
1422+
13761423
## 系统合约调用
13771424

13781425
系统接口主要包含经济模型和治理相关的合约接口:

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
group=com.platon.sdk
2-
version=0.15.2.0
2+
version=1.1.0
33
mavenReleases=https://sdk.platon.network/nexus/content/repositories/releases/
44
mavenSnapshots=https://sdk.platon.network/nexus/content/repositories/snapshots/
55
systemProp.sonar.host.url=http://192.168.16.173:9000

0 commit comments

Comments
 (0)