Skip to content

Commit

Permalink
Merge pull request #107 from cryptape/rpc
Browse files Browse the repository at this point in the history
feat: Add peersInfo and getVersion RPC request method
  • Loading branch information
duanyytop authored Apr 10, 2019
2 parents dd2d13b + 1721dad commit 41dfe71
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 67 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -29,12 +29,12 @@ maven
<dependency>
<groupId>com.cryptape.cita</groupId>
<artifactId>core</artifactId>
<version>0.22.1</version>
<version>0.22.3</version>
</dependency>
```
Gradle
```
compile 'com.cryptape.cita:core:0.22.1'
compile 'com.cryptape.cita:core:0.22.3'
```

Install manually
Expand Down Expand Up @@ -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 方法。
Expand All @@ -166,12 +166,12 @@ Gradle 4.3
<dependency>
<groupId>com.cryptape.cita</groupId>
<artifactId>core</artifactId>
<version>0.22.1</version>
<version>0.22.3</version>
</dependency>
```
Gradle
```
compile 'com.cryptape.cita:core:0.22.1'
compile 'com.cryptape.cita:core:0.22.3'
```

手动安装
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 {
Expand Down
22 changes: 5 additions & 17 deletions core/src/main/java/com/cryptape/cita/protocol/core/CITA.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;


/**
Expand All @@ -29,6 +13,10 @@ public interface CITA {

Request<?, NetPeerCount> netPeerCount();

Request<?, NetPeersInfo> netPeersInfo();

Request<?, AppVersion> getVersion();

Request<?, AppAccounts> appAccounts();

Request<?, AppSign> appSign(String address, String sha3HashOfDataToSign);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -68,6 +50,24 @@ public Request<?, NetPeerCount> netPeerCount() {
NetPeerCount.class);
}

@Override
public Request<?, NetPeersInfo> netPeersInfo() {
return new Request<>(
"peersInfo",
Collections.<String>emptyList(),
CITAjService,
NetPeersInfo.class);
}

@Override
public Request<?, AppVersion> getVersion() {
return new Request<>(
"getVersion",
Collections.<String>emptyList(),
CITAjService,
AppVersion.class);
}


//2 methods: appAccount, appSign are not used
//keep them for wallet use in future.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<AppVersion.Version> {

public Version getVersion() {
return getResult();
}

public static class Version {
public String softwareVersion;
}

}
Original file line number Diff line number Diff line change
@@ -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<NetPeersInfo.PeersInfo> {

public PeersInfo getPeersInfo() {
return getResult();
}

public static class PeersInfo {
public long amount;
public Map<String, String> peers;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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));
Expand Down Expand Up @@ -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<String, String> peers = netPeersInfo.getPeersInfo().peers;
System.out.println("net_peersInfo amount:" + netPeersInfo.getPeersInfo().amount);
for (Map.Entry<String, String> 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();
Expand Down

0 comments on commit 41dfe71

Please sign in to comment.