From 285ab72888969eae2bab76153b8b55f6376edee1 Mon Sep 17 00:00:00 2001 From: duanyytop <duanyytop@gmail.com> Date: Sun, 5 May 2019 19:13:03 +0800 Subject: [PATCH 1/5] fix: remove private key length limit --- crypto/src/main/java/com/cryptape/cita/crypto/Keys.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crypto/src/main/java/com/cryptape/cita/crypto/Keys.java b/crypto/src/main/java/com/cryptape/cita/crypto/Keys.java index bc4334d4..2ab64423 100644 --- a/crypto/src/main/java/com/cryptape/cita/crypto/Keys.java +++ b/crypto/src/main/java/com/cryptape/cita/crypto/Keys.java @@ -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()); From c3474b552cdecec4f078ea92671c619048f098d9 Mon Sep 17 00:00:00 2001 From: duanyytop <duanyytop@gmail.com> Date: Sun, 5 May 2019 19:45:27 +0800 Subject: [PATCH 2/5] fix: update keys test cases --- crypto/src/main/java/com/cryptape/cita/crypto/Keys.java | 4 ++-- crypto/src/test/java/com/cryptape/cita/crypto/KeysTest.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/crypto/src/main/java/com/cryptape/cita/crypto/Keys.java b/crypto/src/main/java/com/cryptape/cita/crypto/Keys.java index 2ab64423..c5898c80 100644 --- a/crypto/src/main/java/com/cryptape/cita/crypto/Keys.java +++ b/crypto/src/main/java/com/cryptape/cita/crypto/Keys.java @@ -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]$"; - static final String PRIVATE_KEY_REGEX = "^(0x|0X)?[a-fA-F0-9]$"; + 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()); diff --git a/crypto/src/test/java/com/cryptape/cita/crypto/KeysTest.java b/crypto/src/test/java/com/cryptape/cita/crypto/KeysTest.java index 7a474ae0..5908d395 100644 --- a/crypto/src/test/java/com/cryptape/cita/crypto/KeysTest.java +++ b/crypto/src/test/java/com/cryptape/cita/crypto/KeysTest.java @@ -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")); } @@ -127,7 +127,7 @@ public void testVerifyPrivateKey() { assertFalse(Keys.verifyPrivateKey( "x02b8f18d92354b055bd02cd51449b05b7b97104931f10485d1df905e4e70fbca")); assertFalse(Keys.verifyPrivateKey( - "002b8f18d92354b055bd02cd51449b05b7b97104931f10485d1df905e4e70fbca")); + "00k2b8f18d92354b055bd02cd51449b05b7b97104931f10485d1df905e4e70fbca")); assertFalse(Keys.verifyPrivateKey( "h2b8f18d92354b055bd02cd51449b05b7b97104931f10485d1df905e4e70fbca")); } From a2278d6d19ea83dced4233720098955dfebe44ce Mon Sep 17 00:00:00 2001 From: duanyytop <duanyytop@gmail.com> Date: Fri, 10 May 2019 10:18:27 +0800 Subject: [PATCH 3/5] docs: fix document version data type error --- docs/account.md | 6 +++--- docs/index.md | 1 + docs/jsonrpc.md | 2 +- docs/transaction.md | 26 +++++++++++++------------- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/docs/account.md b/docs/account.md index 27b052dd..91a5ec59 100644 --- a/docs/account.md +++ b/docs/account.md @@ -1,4 +1,4 @@ -## Account +# Account Account 封装了 TransactionManager,通过 CITAj 和账户的私钥进行实例化。 @@ -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)` 部署合约。 @@ -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。 diff --git a/docs/index.md b/docs/index.md index 2ef4a712..05ee0b70 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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) \ No newline at end of file diff --git a/docs/jsonrpc.md b/docs/jsonrpc.md index 27b729bf..c36998b5 100644 --- a/docs/jsonrpc.md +++ b/docs/jsonrpc.md @@ -1,4 +1,4 @@ -## JSONRPC +# JSONRPC CITAj 接口继承了 CITA 和 CITAjRx 两个接口,CITAj 的实现类(比如JsonRpc2_0CITAj),提供了方法以发送交易的方式对合约进行部署和函数调用。 diff --git a/docs/transaction.md b/docs/transaction.md index 4a45ad89..1a8dc29b 100644 --- a/docs/transaction.md +++ b/docs/transaction.md @@ -1,4 +1,4 @@ -## Transaction +# Transaction Transction定义在core.request中,用于将交易数据封装并且签名(如果需要),交易数据或者签名后的交易数据被appCall()或者appSendRawTransaction()所使用进行合约的调用或者部署。 @@ -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)` 根据参数新建一个交易。 @@ -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}"; @@ -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)` 根据参数新建一个部署合约的交易。 @@ -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}"; @@ -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)` 根据参数新建一个合约调用的交易。 @@ -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}"; @@ -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发送交易。 @@ -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发送交易。 **参数** @@ -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); ``` \ No newline at end of file From c02945b4e240d3c1fc44c4a29c0acfe69ab18fbb Mon Sep 17 00:00:00 2001 From: Bao Jun <baojun.cz@gmail.com> Date: Wed, 22 May 2019 13:56:10 +0800 Subject: [PATCH 4/5] chore: update chain version to 2 --- .../protocol/core/methods/request/Transaction.java | 11 ++++++----- .../protocol/core/methods/response/AppMetaData.java | 4 ++-- .../java/com/cryptape/cita/utils/TransactionUtil.java | 3 ++- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/com/cryptape/cita/protocol/core/methods/request/Transaction.java b/core/src/main/java/com/cryptape/cita/protocol/core/methods/request/Transaction.java index 5f573d15..2c412424 100644 --- a/core/src/main/java/com/cryptape/cita/protocol/core/methods/request/Transaction.java +++ b/core/src/main/java/com/cryptape/cita/protocol/core/methods/request/Transaction.java @@ -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(); diff --git a/core/src/main/java/com/cryptape/cita/protocol/core/methods/response/AppMetaData.java b/core/src/main/java/com/cryptape/cita/protocol/core/methods/response/AppMetaData.java index d6efa8d6..9c53b45d 100644 --- a/core/src/main/java/com/cryptape/cita/protocol/core/methods/response/AppMetaData.java +++ b/core/src/main/java/com/cryptape/cita/protocol/core/methods/response/AppMetaData.java @@ -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"); } } diff --git a/core/src/main/java/com/cryptape/cita/utils/TransactionUtil.java b/core/src/main/java/com/cryptape/cita/utils/TransactionUtil.java index 56e2d42d..4cd7a4cf 100644 --- a/core/src/main/java/com/cryptape/cita/utils/TransactionUtil.java +++ b/core/src/main/java/com/cryptape/cita/utils/TransactionUtil.java @@ -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())); } From a584365aae6c781b4f22a6a0cd021f01d90c67fc Mon Sep 17 00:00:00 2001 From: Bao Jun <baojun.cz@gmail.com> Date: Thu, 23 May 2019 10:07:19 +0800 Subject: [PATCH 5/5] chore: update version and CHANGELOG --- CHANGELOG.md | 7 +++++++ README.md | 8 ++++---- build.gradle | 4 ++-- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 744e3317..232b035d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index 580e754b..a358b2e0 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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' ``` 手动安装 diff --git a/build.gradle b/build.gradle index 548883fe..5d16728f 100644 --- a/build.gradle +++ b/build.gradle @@ -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' @@ -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 {