From 7ba54d68faa701acf4b144512eb24e346ed6d01d Mon Sep 17 00:00:00 2001 From: yangzhenlong Date: Mon, 19 Aug 2019 19:26:06 +0800 Subject: [PATCH 1/6] fix update com.cryptape.cita.protocol.system.CITASystemContract#USER_MANAGER_ADDR to match CITA docs --- .../com/cryptape/cita/protocol/system/CITASystemContract.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/com/cryptape/cita/protocol/system/CITASystemContract.java b/core/src/main/java/com/cryptape/cita/protocol/system/CITASystemContract.java index c0a25ba8..0b724b38 100644 --- a/core/src/main/java/com/cryptape/cita/protocol/system/CITASystemContract.java +++ b/core/src/main/java/com/cryptape/cita/protocol/system/CITASystemContract.java @@ -89,7 +89,7 @@ public interface CITASystemContract { String Authorization_MANAGER_CHECK_RESOURCE = "checkResource"; //User manager - String USER_MANAGER_ADDR = "0xffffffffffffffffffffffffffffffffff020010"; + String USER_MANAGER_ADDR = "0xffffffffffffffffffffffffffffffffff02000a"; //User manager manipulation String USER_MANAGER_NEW_GROUP = "newGroup"; String USER_MANAGER_DELETE_GROUP = "deleteGroup"; From 3125cc6065596cc6b14695bd1ebc11f7b2127bfa Mon Sep 17 00:00:00 2001 From: yangzhenlong Date: Mon, 19 Aug 2019 19:40:20 +0800 Subject: [PATCH 2/6] add unit testing of system contract queryGroups --- .../protocol/system/CITAjSystemContract.java | 21 +++++++++++++++++++ .../cita/tests/SystemContractExample.java | 4 ++++ 2 files changed, 25 insertions(+) diff --git a/core/src/main/java/com/cryptape/cita/protocol/system/CITAjSystemContract.java b/core/src/main/java/com/cryptape/cita/protocol/system/CITAjSystemContract.java index a9c8152b..6b4f2613 100644 --- a/core/src/main/java/com/cryptape/cita/protocol/system/CITAjSystemContract.java +++ b/core/src/main/java/com/cryptape/cita/protocol/system/CITAjSystemContract.java @@ -580,6 +580,27 @@ public QueryResourceResult queryResource(String fromAddr, String permissionAddr) return new QueryResourceResult(contracts, functions); } + /** + * query all groups + * @param senderAddress sender address + * @return list addresses of all groups + * @throws IOException + */ + public List queryGroups(String senderAddress) throws IOException { + String callData = CITASystemContract.encodeCall(USER_MANAGER_QUERY_GROUPS); + AppCall callResult = CITASystemContract.sendCall( + senderAddress, USER_MANAGER_ADDR, callData, service); + List> outputParamters + = Collections.singletonList(new TypeReference>() {}); + List resultTypes = CITASystemContract.decodeCallResult(callResult, outputParamters); + ArrayList
results = (ArrayList
) resultTypes.get(0).getValue(); + List list = new ArrayList<>(results.size()); + for (Address address : results) { + list.add(address.getValue()); + } + return list; + } + public Transaction constructStoreTransaction(String data, int version, BigInteger chainId) { return new Transaction( STORE_ADDR, Util.getNonce(), DEFAULT_QUOTA, diff --git a/tests/src/main/java/com/cryptape/cita/tests/SystemContractExample.java b/tests/src/main/java/com/cryptape/cita/tests/SystemContractExample.java index 5bddab7b..affbb0cf 100644 --- a/tests/src/main/java/com/cryptape/cita/tests/SystemContractExample.java +++ b/tests/src/main/java/com/cryptape/cita/tests/SystemContractExample.java @@ -68,5 +68,9 @@ public static void main(String[] args) throws Exception { //if (setStake) { // System.out.println("success"); //} + + //test query groups + List allGroups = sysContract.queryGroups("0xe2066149012e6c1505e3549d103068bd0f2f0577"); + System.out.println("addresses of all groups: " + allGroups); } } From 066691b3dac33ea3bb555830b926a0ade2d2b943 Mon Sep 17 00:00:00 2001 From: yangzhenlong Date: Mon, 26 Aug 2019 18:09:10 +0800 Subject: [PATCH 3/6] fix move the initialization of sysControl object to the static block --- .../java/com/cryptape/cita/tests/SystemContractExample.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/src/main/java/com/cryptape/cita/tests/SystemContractExample.java b/tests/src/main/java/com/cryptape/cita/tests/SystemContractExample.java index affbb0cf..4797cbaf 100644 --- a/tests/src/main/java/com/cryptape/cita/tests/SystemContractExample.java +++ b/tests/src/main/java/com/cryptape/cita/tests/SystemContractExample.java @@ -13,6 +13,7 @@ public class SystemContractExample { static String adminPriavteKey; static int version; static BigInteger chainId; + static CITAjSystemContract sysContract; static { Config conf = new Config(); @@ -22,11 +23,11 @@ public class SystemContractExample { adminPriavteKey = conf.adminPrivateKey; version = TestUtil.getVersion(service); chainId = TestUtil.getChainId(service); + sysContract = new CITAjSystemContract(service); } public static void main(String[] args) throws Exception { - CITAjSystemContract sysContract = new CITAjSystemContract(service); long quotaPrice = sysContract.getQuotaPrice(senderAddr); System.out.println("Quota price is: " + quotaPrice); From afef1b5a3990a53e9aa5700dd7a79cc914660f8b Mon Sep 17 00:00:00 2001 From: yangzhenlong Date: Tue, 27 Aug 2019 15:20:25 +0800 Subject: [PATCH 4/6] add GroupManagerExample and move queryGroup method from SystemContractExample to GroupManagerExample. --- .../cita/tests/GroupManagerExample.java | 18 ++++++++++++++++++ .../cita/tests/SystemContractExample.java | 4 ---- 2 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 tests/src/main/java/com/cryptape/cita/tests/GroupManagerExample.java diff --git a/tests/src/main/java/com/cryptape/cita/tests/GroupManagerExample.java b/tests/src/main/java/com/cryptape/cita/tests/GroupManagerExample.java new file mode 100644 index 00000000..026c3c6a --- /dev/null +++ b/tests/src/main/java/com/cryptape/cita/tests/GroupManagerExample.java @@ -0,0 +1,18 @@ +package com.cryptape.cita.tests; + + +import java.io.IOException; +import java.util.List; + +/** + * Group and Account Management + * If you want to know more about the documentation, please click on the link below. + * https://docs.citahub.com/zh-CN/cita/account-permission/account + */ +public class GroupManagerExample extends SystemContractExample { + public static void main(String[] args) throws IOException { + // query groups + List groupAddress = sysContract.queryGroups("0xfFFfFFFFFffFFfffFFFFfffffFffffFFfF020009"); + System.out.println("groupAddress: " + groupAddress); + } +} diff --git a/tests/src/main/java/com/cryptape/cita/tests/SystemContractExample.java b/tests/src/main/java/com/cryptape/cita/tests/SystemContractExample.java index 4797cbaf..ac95be7a 100644 --- a/tests/src/main/java/com/cryptape/cita/tests/SystemContractExample.java +++ b/tests/src/main/java/com/cryptape/cita/tests/SystemContractExample.java @@ -69,9 +69,5 @@ public static void main(String[] args) throws Exception { //if (setStake) { // System.out.println("success"); //} - - //test query groups - List allGroups = sysContract.queryGroups("0xe2066149012e6c1505e3549d103068bd0f2f0577"); - System.out.println("addresses of all groups: " + allGroups); } } From 3b32c96d7d2c82a5593c26611d39dc8615950422 Mon Sep 17 00:00:00 2001 From: yangzhenlong Date: Tue, 27 Aug 2019 15:25:07 +0800 Subject: [PATCH 5/6] add unit testing of newGroup interface --- .../protocol/system/CITAjSystemContract.java | 44 +++++++++++++++++++ .../cita/tests/GroupManagerExample.java | 18 +++++++- 2 files changed, 61 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/com/cryptape/cita/protocol/system/CITAjSystemContract.java b/core/src/main/java/com/cryptape/cita/protocol/system/CITAjSystemContract.java index 6b4f2613..1da4586b 100644 --- a/core/src/main/java/com/cryptape/cita/protocol/system/CITAjSystemContract.java +++ b/core/src/main/java/com/cryptape/cita/protocol/system/CITAjSystemContract.java @@ -601,6 +601,50 @@ public List queryGroups(String senderAddress) throws IOException { return list; } + /** + * new group + * @see newGroup + * @param superAdminAddress the address of super_admin + * @param groupName the name of group to be created + * @param accounts accounts added to the group + * @param adminPrivateKey the private key of super_admin + * @param version + * @param chainId + * @return the transaction hash for creating group + * @throws IOException + */ + public String newGroup(String superAdminAddress, + String groupName, + List accounts, + String adminPrivateKey, + int version, + BigInteger chainId) throws IOException { + // account addresses convert to Address object list + List
addresses = new ArrayList<>(accounts.size()); + for(String acc : accounts){ + addresses.add(new Address(acc)); + } + + // groupName string convert to bytes32 + String nameHex = Util.addUpTo64Hex(ConvertStrByte.stringToHexString(groupName)); + byte[] nameBytes = ConvertStrByte.hexStringToBytes(Numeric.cleanHexPrefix(nameHex)); + + // build input parameters + List inputParameters = Arrays.asList( + new Address(superAdminAddress),//origin + new Bytes32(nameBytes),//name + new DynamicArray
(addresses)//account + ); + + // encode input parameters + String funcData = CITASystemContract.encodeFunction(USER_MANAGER_NEW_GROUP, inputParameters); + + // send request to create group and return transaction hash + String txHash = CITASystemContract.sendTxAndGetHash( + USER_MANAGER_ADDR, service, adminPrivateKey, funcData, version, chainId); + return txHash; + } + public Transaction constructStoreTransaction(String data, int version, BigInteger chainId) { return new Transaction( STORE_ADDR, Util.getNonce(), DEFAULT_QUOTA, diff --git a/tests/src/main/java/com/cryptape/cita/tests/GroupManagerExample.java b/tests/src/main/java/com/cryptape/cita/tests/GroupManagerExample.java index 026c3c6a..08dac5f4 100644 --- a/tests/src/main/java/com/cryptape/cita/tests/GroupManagerExample.java +++ b/tests/src/main/java/com/cryptape/cita/tests/GroupManagerExample.java @@ -1,7 +1,11 @@ package com.cryptape.cita.tests; +import com.cryptape.cita.protocol.core.methods.response.Log; +import com.cryptape.cita.protocol.system.CITASystemContract; + import java.io.IOException; +import java.util.Arrays; import java.util.List; /** @@ -10,9 +14,21 @@ * https://docs.citahub.com/zh-CN/cita/account-permission/account */ public class GroupManagerExample extends SystemContractExample { - public static void main(String[] args) throws IOException { + public static void main(String[] args) throws IOException, InterruptedException { // query groups List groupAddress = sysContract.queryGroups("0xfFFfFFFFFffFFfffFFFFfffffFffffFFfF020009"); System.out.println("groupAddress: " + groupAddress); + + // create a group + String transcationHash = sysContract.newGroup("0xfFFfFFFFFffFFfffFFFFfffffFffffFFfF020009", + "newGroup", + Arrays.asList("e1c4021742730ded647590a1686d5c4bfcbae0b0", "45a50f45cb81c8aedeab917ea0cd3c9178ebdcae"), + adminPriavteKey, + version, + chainId); + System.out.println("transcationHash: " + transcationHash); + // get receipt by hash + Log log = CITASystemContract.getReceiptLog(service, transcationHash, 0); + System.out.println("groupAddress: " + (log == null ? "null" : log.getAddress())); } } From 517d1b37eaba0edfa788bc262449e00eddedc2db Mon Sep 17 00:00:00 2001 From: chenhao Date: Wed, 16 Oct 2019 15:31:09 +0800 Subject: [PATCH 6/6] update version and changelog and readme --- 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 3b1212d7..aadabd51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ All notable changes to this project will be documented in this file. +# [v0.25.0](https://github.com/cryptape/cita-sdk-java/compare/v0.24.1...v0.25.0) (2019-08-27) + +### Feature + +* add queryGroups RPC request +* add newGroup RPC request + # [v0.24.1](https://github.com/cryptape/cita-sdk-java/compare/v0.24.0...v0.24.1) (2019-08-16) ### Feature diff --git a/README.md b/README.md index 200ecc56..a51a0620 100644 --- a/README.md +++ b/README.md @@ -29,12 +29,12 @@ maven com.cryptape.cita core - 0.24.1 + 0.25.0 ``` Gradle ``` -compile 'com.cryptape.cita:core:0.24.1' +compile 'com.cryptape.cita:core:0.25.0' ``` Install manually @@ -170,12 +170,12 @@ Gradle 5.0 com.cryptape.cita core - 0.24.1 + 0.25.0 ``` Gradle ``` -compile 'com.cryptape.cita:core:0.24.1' +compile 'com.cryptape.cita:core:0.25.0' ``` 手动安装 diff --git a/build.gradle b/build.gradle index 1b246717..89617197 100644 --- a/build.gradle +++ b/build.gradle @@ -49,7 +49,7 @@ allprojects { targetCompatibility = 1.8 group 'com.cryptape.cita' - version '0.24.1' + version '0.25.0' apply plugin: 'java' apply plugin: 'jacoco' @@ -145,7 +145,7 @@ configure(subprojects.findAll { it.name != 'integration-tests' }) { publications { mavenJava(MavenPublication) { groupId 'com.cryptape.cita' - version '0.24.1' + version '0.25.0' from components.java artifact sourcesJar {