diff --git a/CHANGELOG.md b/CHANGELOG.md index 69f1c402..985e18d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,18 @@ All notable changes to this project will be documented in this file. +# [v0.22.3](https://github.com/cryptape/cita-sdk-java/compare/v0.22.2...v0.22.3) (2019-04-10) + +### Feature + +* add peersInfo RPC request +* add getVersion RPC request + +# [v0.22.2](https://github.com/cryptape/cita-sdk-java/compare/v0.22.1...v0.22.2) (2019-04-09) + +### Feature + +* refactor http json response handle method + # [v0.22.1](https://github.com/cryptape/cita-sdk-java/compare/v0.22...v0.22.1) (2019-03-29) ### Feature diff --git a/README.md b/README.md index 07e692eb..46e2a0f8 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ cita-sdk-java, originally adapted from Ethereum web3j, is a Java library for working with Smart Contract and integrating with clients on CITA. -Here is [detail documentation](docs/index.md) +For detailed documentation, see [documentation](docs/index.md). ## Features @@ -29,12 +29,12 @@ maven com.cryptape.cita core - 0.22.1 + 0.22.3 ``` Gradle ``` -compile 'com.cryptape.cita:core:0.22.1' +compile 'com.cryptape.cita:core:0.22.3' ``` Install manually @@ -147,7 +147,7 @@ Please find complete code in [TokenAccountExample](https://github.com/cryptape/c ## 简介 cita-sdk-java 是对以太坊 Web3j 进行改写,适配 CITA 的一个 Java 开发包。cita-sdk-java 集成了与 CITA 客户端交互的功能,可以用来对 CITA 发送交易,系统配置,信息查询。 -开发请参考[详细文档](docs/index.md) +开发请参考[详细文档](docs/index.md)。 ## 特性 - 通过 HTTP 协议,实现了 CITA 所定义的所有 JSON-RPC 方法。 @@ -166,12 +166,12 @@ Gradle 4.3 com.cryptape.cita core - 0.22.1 + 0.22.3 ``` Gradle ``` -compile 'com.cryptape.cita:core:0.22.1' +compile 'com.cryptape.cita:core:0.22.3' ``` 手动安装 diff --git a/build.gradle b/build.gradle index 94da240c..9e833c64 100644 --- a/build.gradle +++ b/build.gradle @@ -46,7 +46,7 @@ allprojects { targetCompatibility = 1.8 group 'com.cryptape.cita' - version '0.22.1' + version '0.22.3' apply plugin: 'java' apply plugin: 'jacoco' @@ -142,7 +142,7 @@ configure(subprojects.findAll {it.name != 'integration-tests'}) { publications { mavenJava(MavenPublication) { groupId 'com.cryptape.cita' - version '0.22.1' + version '0.22.3' from components.java artifact sourcesJar { diff --git a/core/src/main/java/com/cryptape/cita/protocol/core/CITA.java b/core/src/main/java/com/cryptape/cita/protocol/core/CITA.java index 743d1478..cbe940e7 100644 --- a/core/src/main/java/com/cryptape/cita/protocol/core/CITA.java +++ b/core/src/main/java/com/cryptape/cita/protocol/core/CITA.java @@ -3,23 +3,7 @@ import java.math.BigInteger; import com.cryptape.cita.protocol.core.methods.request.Call; -import com.cryptape.cita.protocol.core.methods.response.AppAccounts; -import com.cryptape.cita.protocol.core.methods.response.AppBlock; -import com.cryptape.cita.protocol.core.methods.response.AppBlockNumber; -import com.cryptape.cita.protocol.core.methods.response.AppCall; -import com.cryptape.cita.protocol.core.methods.response.AppFilter; -import com.cryptape.cita.protocol.core.methods.response.AppGetAbi; -import com.cryptape.cita.protocol.core.methods.response.AppGetBalance; -import com.cryptape.cita.protocol.core.methods.response.AppGetCode; -import com.cryptape.cita.protocol.core.methods.response.AppGetTransactionCount; -import com.cryptape.cita.protocol.core.methods.response.AppGetTransactionReceipt; -import com.cryptape.cita.protocol.core.methods.response.AppLog; -import com.cryptape.cita.protocol.core.methods.response.AppMetaData; -import com.cryptape.cita.protocol.core.methods.response.AppSendTransaction; -import com.cryptape.cita.protocol.core.methods.response.AppSign; -import com.cryptape.cita.protocol.core.methods.response.AppTransaction; -import com.cryptape.cita.protocol.core.methods.response.AppUninstallFilter; -import com.cryptape.cita.protocol.core.methods.response.NetPeerCount; +import com.cryptape.cita.protocol.core.methods.response.*; /** @@ -29,6 +13,10 @@ public interface CITA { Request netPeerCount(); + Request netPeersInfo(); + + Request getVersion(); + Request appAccounts(); Request appSign(String address, String sha3HashOfDataToSign); diff --git a/core/src/main/java/com/cryptape/cita/protocol/core/JsonRpc2_0CITAj.java b/core/src/main/java/com/cryptape/cita/protocol/core/JsonRpc2_0CITAj.java index 66541d2c..46ac3221 100644 --- a/core/src/main/java/com/cryptape/cita/protocol/core/JsonRpc2_0CITAj.java +++ b/core/src/main/java/com/cryptape/cita/protocol/core/JsonRpc2_0CITAj.java @@ -6,28 +6,10 @@ import java.util.concurrent.ScheduledExecutorService; import com.cryptape.cita.protocol.core.methods.request.Call; +import com.cryptape.cita.protocol.core.methods.response.*; import io.reactivex.Flowable; import com.cryptape.cita.protocol.CITAj; import com.cryptape.cita.protocol.CITAjService; -import com.cryptape.cita.protocol.core.methods.response.AppAccounts; -import com.cryptape.cita.protocol.core.methods.response.AppBlock; -import com.cryptape.cita.protocol.core.methods.response.AppBlockNumber; -import com.cryptape.cita.protocol.core.methods.response.AppCall; -import com.cryptape.cita.protocol.core.methods.response.AppFilter; -import com.cryptape.cita.protocol.core.methods.response.AppGetAbi; -import com.cryptape.cita.protocol.core.methods.response.AppGetBalance; -import com.cryptape.cita.protocol.core.methods.response.AppGetCode; -import com.cryptape.cita.protocol.core.methods.response.AppGetTransactionCount; -import com.cryptape.cita.protocol.core.methods.response.AppGetTransactionReceipt; -import com.cryptape.cita.protocol.core.methods.response.AppLog; -import com.cryptape.cita.protocol.core.methods.response.AppMetaData; -import com.cryptape.cita.protocol.core.methods.response.AppSendTransaction; -import com.cryptape.cita.protocol.core.methods.response.AppSign; -import com.cryptape.cita.protocol.core.methods.response.AppTransaction; -import com.cryptape.cita.protocol.core.methods.response.AppUninstallFilter; -import com.cryptape.cita.protocol.core.methods.response.Log; -import com.cryptape.cita.protocol.core.methods.response.NetPeerCount; -import com.cryptape.cita.protocol.core.methods.response.Transaction; import com.cryptape.cita.protocol.rx.JsonRpc2_0Rx; import com.cryptape.cita.utils.Async; import com.cryptape.cita.utils.Numeric; @@ -68,6 +50,24 @@ public Request netPeerCount() { NetPeerCount.class); } + @Override + public Request netPeersInfo() { + return new Request<>( + "peersInfo", + Collections.emptyList(), + CITAjService, + NetPeersInfo.class); + } + + @Override + public Request getVersion() { + return new Request<>( + "getVersion", + Collections.emptyList(), + CITAjService, + AppVersion.class); + } + //2 methods: appAccount, appSign are not used //keep them for wallet use in future. diff --git a/core/src/main/java/com/cryptape/cita/protocol/core/methods/response/AppBlock.java b/core/src/main/java/com/cryptape/cita/protocol/core/methods/response/AppBlock.java index e94f4cc0..66c8cd26 100644 --- a/core/src/main/java/com/cryptape/cita/protocol/core/methods/response/AppBlock.java +++ b/core/src/main/java/com/cryptape/cita/protocol/core/methods/response/AppBlock.java @@ -79,7 +79,7 @@ public static class Header { private String stateRoot; private String transactionsRoot; private String receiptsRoot; - private String gasUsed; + private String quotaUsed; private Proof proof; private String proposer; @@ -89,14 +89,14 @@ public Header() { public Header(long timestamp, String prevHash, String number, String stateRoot, String transactionsRoot, String receiptsRoot, - String gasUsed, Proof proof, String proposer) { + String quotaUsed, Proof proof, String proposer) { this.timestamp = timestamp; this.prevHash = prevHash; this.number = number; this.stateRoot = stateRoot; this.transactionsRoot = transactionsRoot; this.receiptsRoot = receiptsRoot; - this.gasUsed = gasUsed; + this.quotaUsed = quotaUsed; this.proof = proof; this.proposer = proposer; } @@ -158,15 +158,15 @@ public void setReceiptsRoot(String receiptsRoot) { } public BigInteger getGasUsedDec() { - return Numeric.decodeQuantity(gasUsed); + return Numeric.decodeQuantity(quotaUsed); } - public String getGasUsed() { - return gasUsed; + public String getQuotaUsed() { + return quotaUsed; } - public void setGasUsed(String gasUsed) { - this.gasUsed = gasUsed; + public void setQuotaUsed(String quotaUsed) { + this.quotaUsed = quotaUsed; } public Proof getProof() { diff --git a/core/src/main/java/com/cryptape/cita/protocol/core/methods/response/AppVersion.java b/core/src/main/java/com/cryptape/cita/protocol/core/methods/response/AppVersion.java new file mode 100644 index 00000000..7d6316b7 --- /dev/null +++ b/core/src/main/java/com/cryptape/cita/protocol/core/methods/response/AppVersion.java @@ -0,0 +1,19 @@ +package com.cryptape.cita.protocol.core.methods.response; + +import com.cryptape.cita.protocol.core.Response; + +/** + * Created by duanyytop on 2019-04-09. + * Copyright © 2018 Cryptape. All rights reserved. + */ +public class AppVersion extends Response { + + public Version getVersion() { + return getResult(); + } + + public static class Version { + public String softwareVersion; + } + +} diff --git a/core/src/main/java/com/cryptape/cita/protocol/core/methods/response/NetPeersInfo.java b/core/src/main/java/com/cryptape/cita/protocol/core/methods/response/NetPeersInfo.java new file mode 100644 index 00000000..5c9c051f --- /dev/null +++ b/core/src/main/java/com/cryptape/cita/protocol/core/methods/response/NetPeersInfo.java @@ -0,0 +1,22 @@ +package com.cryptape.cita.protocol.core.methods.response; + +import com.cryptape.cita.protocol.core.Response; + +import java.util.Map; + +/** + * Created by duanyytop on 2019-04-09. + * Copyright © 2018 Cryptape. All rights reserved. + */ +public class NetPeersInfo extends Response { + + public PeersInfo getPeersInfo() { + return getResult(); + } + + public static class PeersInfo { + public long amount; + public Map peers; + } + +} diff --git a/tests/src/main/java/com/cryptape/cita/tests/InterfaceTest.java b/tests/src/main/java/com/cryptape/cita/tests/RpcTest.java similarity index 93% rename from tests/src/main/java/com/cryptape/cita/tests/InterfaceTest.java rename to tests/src/main/java/com/cryptape/cita/tests/RpcTest.java index 24b717dc..011df252 100644 --- a/tests/src/main/java/com/cryptape/cita/tests/InterfaceTest.java +++ b/tests/src/main/java/com/cryptape/cita/tests/RpcTest.java @@ -3,6 +3,8 @@ import java.io.IOException; import java.math.BigInteger; import java.util.Arrays; +import java.util.Map; +import java.util.Set; import com.cryptape.cita.abi.FunctionEncoder; import com.cryptape.cita.abi.TypeReference; @@ -15,23 +17,12 @@ import com.cryptape.cita.protocol.core.DefaultBlockParameterName; import com.cryptape.cita.protocol.core.methods.request.Call; import com.cryptape.cita.protocol.core.methods.request.Transaction; +import com.cryptape.cita.protocol.core.methods.response.*; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.cryptape.cita.protocol.core.methods.response.AppBlock; -import com.cryptape.cita.protocol.core.methods.response.AppBlockNumber; -import com.cryptape.cita.protocol.core.methods.response.AppCall; -import com.cryptape.cita.protocol.core.methods.response.AppGetBalance; -import com.cryptape.cita.protocol.core.methods.response.AppGetCode; -import com.cryptape.cita.protocol.core.methods.response.AppGetTransactionCount; -import com.cryptape.cita.protocol.core.methods.response.AppGetTransactionReceipt; -import com.cryptape.cita.protocol.core.methods.response.AppMetaData; -import com.cryptape.cita.protocol.core.methods.response.AppSendTransaction; -import com.cryptape.cita.protocol.core.methods.response.AppTransaction; -import com.cryptape.cita.protocol.core.methods.response.NetPeerCount; -import com.cryptape.cita.protocol.core.methods.response.TransactionReceipt; import com.google.gson.Gson; -public class InterfaceTest { +public class RpcTest { private static int version; private static BigInteger chainId; @@ -56,14 +47,18 @@ public class InterfaceTest { public static void main(String[] args) throws Exception { + testNetPeerCount(); + + testNetPeersInfo(); + + testGetVersion(); + testGetBlockByNumber(BigInteger.valueOf(47)); testGetBalance(); testMetaData(); - testNetPeerCount(); - BigInteger validBlockNumber = testBlockNumber(); System.out.println(validBlockNumber.toString(10)); @@ -167,6 +162,20 @@ private static void testNetPeerCount() throws Exception { System.out.println("net_peerCount:" + netPeerCount.getQuantity()); } + private static void testNetPeersInfo() throws Exception { + NetPeersInfo netPeersInfo = service.netPeersInfo().send(); + Map peers = netPeersInfo.getPeersInfo().peers; + System.out.println("net_peersInfo amount:" + netPeersInfo.getPeersInfo().amount); + for (Map.Entry entry : peers.entrySet()) { + System.out.println("Address : " + entry.getKey() + " Node : " + entry.getValue()); + } + } + + private static void testGetVersion() throws Exception { + AppVersion appVersion = service.getVersion().send(); + System.out.println("version:" + appVersion.getVersion().softwareVersion); + } + private static BigInteger testBlockNumber() throws Exception { AppBlockNumber appBlockNumber = service.appBlockNumber().send();