Skip to content

Commit

Permalink
Merge pull request #116 from cryptape/rc/v0.24.0
Browse files Browse the repository at this point in the history
Rc/v0.24.0
  • Loading branch information
duanyytop authored May 30, 2019
2 parents 88e37d8 + a584365 commit 4243b93
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 35 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
All notable changes to this project will be documented in this file.

# [v0.24.0](https://github.com/cryptape/cita-sdk-java/compare/v0.23.0...v0.24.0) (2019-05-30)

### Feature

* Support new protocol version 2


# [v0.23.0](https://github.com/cryptape/cita-sdk-java/compare/v0.22.3...v0.23.0) (2019-04-30)

### Feature
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ maven
<dependency>
<groupId>com.cryptape.cita</groupId>
<artifactId>core</artifactId>
<version>0.23.0</version>
<version>0.24.0</version>
</dependency>
```
Gradle
```
compile 'com.cryptape.cita:core:0.23.0'
compile 'com.cryptape.cita:core:0.24.0'
```

Install manually
Expand Down Expand Up @@ -170,12 +170,12 @@ Gradle 4.3
<dependency>
<groupId>com.cryptape.cita</groupId>
<artifactId>core</artifactId>
<version>0.23.0</version>
<version>0.24.0</version>
</dependency>
```
Gradle
```
compile 'com.cryptape.cita:core:0.23.0'
compile 'com.cryptape.cita:core:0.24.0'
```

手动安装
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ allprojects {
targetCompatibility = 1.8

group 'com.cryptape.cita'
version '0.23.0'
version '0.24.0'

apply plugin: 'java'
apply plugin: 'jacoco'
Expand Down Expand Up @@ -141,7 +141,7 @@ configure(subprojects.findAll { it.name != 'integration-tests' }) {
publications {
mavenJava(MavenPublication) {
groupId 'com.cryptape.cita'
version '0.23.0'
version '0.24.0'
from components.java

artifact sourcesJar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,14 +158,15 @@ public byte[] serializeRawTransaction(boolean isByteArray) {


/*
* version 0: cita 0.19
* version 1: cita 0.20
* */
* version 0: cita 0.19
* version 1: cita 0.20
* version 2: cita 0.24
* */
if (version == 0) {
builder.setTo(to).setChainId(chainId.intValue());
} else if (version == 1) {
} else if (version == 1 || version == 2) {
builder.setToV1(ByteString.copyFrom(ConvertStrByte.hexStringToBytes(to)))
.setChainIdV1(ByteString.copyFrom(ConvertStrByte.hexStringToBytes(Numeric.toHexStringNoPrefix(chainId), 256)));
.setChainIdV1(ByteString.copyFrom(ConvertStrByte.hexStringToBytes(Numeric.toHexStringNoPrefix(chainId), 256)));
}

return builder.build().toByteArray();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ public void setChainId(String chainId) {
public BigInteger getChainId() {
if (this.version == 0) {
return Numeric.toBigInt(chainId);
} else if (this.version == 1) {
} else if (this.version == 1 || this.version == 2) {
return Numeric.toBigInt(this.chainIdV1);
} else {
throw new IllegalArgumentException("version number can only be 1 or 2");
throw new IllegalArgumentException("version number can only be 0 , 1 or 2");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,11 @@ public static boolean verifySignature(String addr, String content)

//version 0: cita 0.19
//version 1: cita 0.20
//version 2: cita 0.24
if (version == 0) {
to = blockChainTx.getTo();
chainId = BigInteger.valueOf(blockChainTx.getChainId());
} else if (version == 1) {
} else if (version == 1 || version == 2) {
to = bytesToHexString(blockChainTx.getToV1());
chainId = Numeric.toBigInt(bytesToHexString(blockChainTx.getChainIdV1()));
}
Expand Down
4 changes: 2 additions & 2 deletions crypto/src/main/java/com/cryptape/cita/crypto/Keys.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public class Keys {
static final int PUBLIC_KEY_LENGTH_IN_HEX = PUBLIC_KEY_SIZE << 1;
public static final int PRIVATE_KEY_LENGTH_IN_HEX = PRIVATE_KEY_SIZE << 1;

static final String ADDR_REGEX = "^(0x|0X)?[a-fA-F0-9]{40}$";
static final String PRIVATE_KEY_REGEX = "^(0x|0X)?[a-fA-F0-9]{64}$";
static final String ADDR_REGEX = "^(0x|0X)?[a-fA-F0-9]+$";
static final String PRIVATE_KEY_REGEX = "^(0x|0X)?[a-fA-F0-9]+$";

static {
Security.addProvider(new BouncyCastleProvider());
Expand Down
4 changes: 2 additions & 2 deletions crypto/src/test/java/com/cryptape/cita/crypto/KeysTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void testVerifyAddress() {
assertTrue(Keys.verifyAddress("0Xbac68e5cb986ead0253e0632da1131a0a96efa18"));
assertTrue(Keys.verifyAddress("bac68e5cb986ead0253e0632da1131a0a96efa18"));
assertFalse(Keys.verifyPrivateKey("xbac68e5cb986ead0253e0632da1131a0a96efa18"));
assertFalse(Keys.verifyPrivateKey("0bac68e5cb986ead0253e0632da1131a0a96efa18"));
assertFalse(Keys.verifyPrivateKey("0bac68re5cb986ead0253e0632da1131a0a96efa18"));
assertFalse(Keys.verifyPrivateKey("gac68e5cb986ead0253e0632da1131a0a96efa18"));
}

Expand All @@ -127,7 +127,7 @@ public void testVerifyPrivateKey() {
assertFalse(Keys.verifyPrivateKey(
"x02b8f18d92354b055bd02cd51449b05b7b97104931f10485d1df905e4e70fbca"));
assertFalse(Keys.verifyPrivateKey(
"002b8f18d92354b055bd02cd51449b05b7b97104931f10485d1df905e4e70fbca"));
"00k2b8f18d92354b055bd02cd51449b05b7b97104931f10485d1df905e4e70fbca"));
assertFalse(Keys.verifyPrivateKey(
"h2b8f18d92354b055bd02cd51449b05b7b97104931f10485d1df905e4e70fbca"));
}
Expand Down
6 changes: 3 additions & 3 deletions docs/account.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Account
# Account

Account 封装了 TransactionManager,通过 CITAj 和账户的私钥进行实例化。

Expand Down Expand Up @@ -36,7 +36,7 @@ Account account = new Account(privateKey, service);

**方法名**

`AppSendTransaction deploy(File contractFile, BigInteger nonce, long quota, int version, int chainId, String value)`
`AppSendTransaction deploy(File contractFile, BigInteger nonce, long quota, BigInteger version, int chainId, String value)`

部署合约。

Expand Down Expand Up @@ -65,7 +65,7 @@ AppSendTransaction appSendTransaction = account.deploy(new File(path), randomNon

**方法名**

`Object callContract(String contractAddress, String funcName, BigInteger nonce, long quota, int version, int chainId, String value, Object... args)`
`Object callContract(String contractAddress, String funcName, BigInteger nonce, long quota, BigInteger version, int chainId, String value, Object... args)`

调用合约方法,根据Abi中对方法的定义判断使用sendRawTransaction还是app_call。

Expand Down
1 change: 1 addition & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ cita-sdk-java 是对于 CITA 进行交互的 Java SDK 包,cita-sdk-java 使用
第三种: 通过封装在Account中的方法来构建并发送交易,Account会实例化TransactionManager,TransactionManager 提供了异步和同步方式对合约进行部署和调用。

## 目录:

1. [JSON-RPC](jsonrpc.md)
2. [Transaction](transaction.md)
3. [Account](account.md)
2 changes: 1 addition & 1 deletion docs/jsonrpc.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## JSONRPC
# JSONRPC

CITAj 接口继承了 CITA 和 CITAjRx 两个接口,CITAj 的实现类(比如JsonRpc2_0CITAj),提供了方法以发送交易的方式对合约进行部署和函数调用。

Expand Down
26 changes: 13 additions & 13 deletions docs/transaction.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Transaction
# Transaction

Transction定义在core.request中,用于将交易数据封装并且签名(如果需要),交易数据或者签名后的交易数据被appCall()或者appSendRawTransaction()所使用进行合约的调用或者部署。

Expand All @@ -13,7 +13,7 @@ Transction定义在core.request中,用于将交易数据封装并且签名(

**方法名**

`Transaction(String to, BigInteger nonce, long quota, long valid_until_block, int version, int chainId, String value, String data)`
`Transaction(String to, BigInteger nonce, long quota, long valid_until_block, BigInteger version, int chainId, String value, String data)`

根据参数新建一个交易。

Expand All @@ -39,7 +39,7 @@ String to = "{address to which the tx is sent}";
BigInteger nonce = BigInteger.valueOf(Math.abs(this.random.nextLong()));
long quota = 9999;
long valid_until_block = service.appBlockNumber().send().getBlockNumber() + 88;
int version = 0;
BigInteger version = BigInteger.valueOf(0);
in chainId = 1;
String value = "100000000";
String init = "{encoded abi}";
Expand All @@ -49,7 +49,7 @@ Transaction tx = Transction.createContractTransaction(nonce, quota, valid_until_

**方法名**

`createContractTransaction(BigInteger nonce, long quota, long valid_until_block, int version, int chainId, String value, String init)`
`createContractTransaction(BigInteger nonce, long quota, long valid_until_block, BigInteger version, int chainId, String value, String init)`

根据参数新建一个部署合约的交易。

Expand All @@ -76,7 +76,7 @@ CITAj service = CITAj.build(new HttpService("127.0.0.1"));
BigInteger nonce = BigInteger.valueOf(Math.abs(this.random.nextLong()));
long quota = 9999;
long valid_until_block = service.appBlockNumber().send().getBlockNumber() + 88;
int version = 0;
BigInteger version = BigInteger.valueOf(0);
in chainId = 1;
String value = "100000000";
String init = "{encoded abi}";
Expand All @@ -91,7 +91,7 @@ AppSendTransaction appSendTx = service.sendRawTransaction(signedTx);

**方法名**

`createFunctionCallTransaction(String to, BigInteger nonce, long quota, long valid_until_block, int version, int chainId, String value, String data)`
`createFunctionCallTransaction(String to, BigInteger nonce, long quota, long valid_until_block, BigInteger version, int chainId, String value, String data)`

根据参数新建一个合约调用的交易。

Expand Down Expand Up @@ -121,7 +121,7 @@ String to = "{smart contract address}";
BigInteger nonce = BigInteger.valueOf(Math.abs(this.random.nextLong()));
long quota = 9999;
long valid_until_block = service.appBlockNumber().send().getBlockNumber() + 88;
int version = 0;
BigInteger version = BigInteger.valueOf(0);
in chainId = 1;
String value = "100000000";
String init = "{encoded abi}";
Expand Down Expand Up @@ -157,7 +157,7 @@ TransactionManager transactionManager = new TransactionManager(service, credenti

**方法名**

`AppSendTransaction sendTransaction(String to, String data, long quota, BigInteger nonce, long validUntilBlock, int version, int chainId, String value)`
`AppSendTransaction sendTransaction(String to, String data, long quota, BigInteger nonce, long validUntilBlock, BigInteger version, int chainId, String value)`

通过TransactionManager发送交易。

Expand Down Expand Up @@ -185,17 +185,17 @@ String contractBin = "{contract bin or function call bin}";
BigInteger quota = 99999;
BigInteger nonce = BigInteger.valueOf(Math.abs(this.random.nextLong()));
long valid_until_block = service.appBlockNumber().send().getBlockNumber() + 88;
int version = 0;
BigInteger version = BigInteger.valueOf(0);
int chainId = 1;
String value = "0";
AppSendTransaction appSendTransaction = citaTransactionManager.sendTransaction(to, contractBin, quota, nonce, valid_until_block, BigInteger.valueOf(version), chainId, value);
AppSendTransaction appSendTransaction = citaTransactionManager.sendTransaction(to, contractBin, quota, nonce, valid_until_block, version, chainId, value);
```

### sendTransactionAsync

**方法名**

`Flowable<AppSendTransaction> sendTransactionAsync(String to, String data, long quota, BigInteger nonce, long validUntilBlock, int version, int chainId, String value)`
`Flowable<AppSendTransaction> sendTransactionAsync(String to, String data, long quota, BigInteger nonce, long validUntilBlock, BigInteger version, int chainId, String value)`
通过TransactionManager发送交易。

**参数**
Expand All @@ -222,8 +222,8 @@ String contractBin = "{contract bin or function call bin}";
BigInteger quota = 99999;
BigInteger nonce = BigInteger.valueOf(Math.abs(this.random.nextLong()));
long valid_until_block = service.appBlockNumber().send().getBlockNumber() + 88;
int version = 0;
BigInteger version = BigInteger.valueOf(0);
int chainId = 1;
String value = "0";
Flowable<AppSendTransaction> appSendTransaction = transactionManager.sendTransaction(to, contractBin, quota, nonce, valid_until_block, BigInteger.valueOf(version), chainId, value);
Flowable<AppSendTransaction> appSendTransaction = transactionManager.sendTransaction(to, contractBin, quota, nonce, valid_until_block, version, chainId, value);
```

0 comments on commit 4243b93

Please sign in to comment.