Skip to content

Commit 7fe7cf4

Browse files
authored
Merge pull request #149 from cryptape/release/v0.25.0
Release/v0.25.0
2 parents 264bdf8 + 517d1b3 commit 7fe7cf4

File tree

7 files changed

+115
-8
lines changed

7 files changed

+115
-8
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
All notable changes to this project will be documented in this file.
22

3+
# [v0.25.0](https://github.com/cryptape/cita-sdk-java/compare/v0.24.1...v0.25.0) (2019-08-27)
4+
5+
### Feature
6+
7+
* add queryGroups RPC request
8+
* add newGroup RPC request
9+
310
# [v0.24.1](https://github.com/cryptape/cita-sdk-java/compare/v0.24.0...v0.24.1) (2019-08-16)
411

512
### Feature

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ maven
2929
<dependency>
3030
<groupId>com.cryptape.cita</groupId>
3131
<artifactId>core</artifactId>
32-
<version>0.24.1</version>
32+
<version>0.25.0</version>
3333
</dependency>
3434
```
3535
Gradle
3636
```
37-
compile 'com.cryptape.cita:core:0.24.1'
37+
compile 'com.cryptape.cita:core:0.25.0'
3838
```
3939

4040
Install manually
@@ -170,12 +170,12 @@ Gradle 5.0
170170
<dependency>
171171
<groupId>com.cryptape.cita</groupId>
172172
<artifactId>core</artifactId>
173-
<version>0.24.1</version>
173+
<version>0.25.0</version>
174174
</dependency>
175175
```
176176
Gradle
177177
```
178-
compile 'com.cryptape.cita:core:0.24.1'
178+
compile 'com.cryptape.cita:core:0.25.0'
179179
```
180180

181181
手动安装

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ allprojects {
4949
targetCompatibility = 1.8
5050

5151
group 'com.cryptape.cita'
52-
version '0.24.1'
52+
version '0.25.0'
5353

5454
apply plugin: 'java'
5555
apply plugin: 'jacoco'
@@ -145,7 +145,7 @@ configure(subprojects.findAll { it.name != 'integration-tests' }) {
145145
publications {
146146
mavenJava(MavenPublication) {
147147
groupId 'com.cryptape.cita'
148-
version '0.24.1'
148+
version '0.25.0'
149149
from components.java
150150

151151
artifact sourcesJar {

core/src/main/java/com/cryptape/cita/protocol/system/CITASystemContract.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public interface CITASystemContract {
8989
String Authorization_MANAGER_CHECK_RESOURCE = "checkResource";
9090

9191
//User manager
92-
String USER_MANAGER_ADDR = "0xffffffffffffffffffffffffffffffffff020010";
92+
String USER_MANAGER_ADDR = "0xffffffffffffffffffffffffffffffffff02000a";
9393
//User manager manipulation
9494
String USER_MANAGER_NEW_GROUP = "newGroup";
9595
String USER_MANAGER_DELETE_GROUP = "deleteGroup";

core/src/main/java/com/cryptape/cita/protocol/system/CITAjSystemContract.java

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,71 @@ public QueryResourceResult queryResource(String fromAddr, String permissionAddr)
580580
return new QueryResourceResult(contracts, functions);
581581
}
582582

583+
/**
584+
* query all groups
585+
* @param senderAddress sender address
586+
* @return list addresses of all groups
587+
* @throws IOException
588+
*/
589+
public List<String> queryGroups(String senderAddress) throws IOException {
590+
String callData = CITASystemContract.encodeCall(USER_MANAGER_QUERY_GROUPS);
591+
AppCall callResult = CITASystemContract.sendCall(
592+
senderAddress, USER_MANAGER_ADDR, callData, service);
593+
List<TypeReference<?>> outputParamters
594+
= Collections.singletonList(new TypeReference<DynamicArray<Address>>() {});
595+
List<Type> resultTypes = CITASystemContract.decodeCallResult(callResult, outputParamters);
596+
ArrayList<Address> results = (ArrayList<Address>) resultTypes.get(0).getValue();
597+
List<String> list = new ArrayList<>(results.size());
598+
for (Address address : results) {
599+
list.add(address.getValue());
600+
}
601+
return list;
602+
}
603+
604+
/**
605+
* new group
606+
* @see <a href="https://docs.citahub.com/zh-CN/cita/sys-contract-interface/interface#newgroup">newGroup</a>
607+
* @param superAdminAddress the address of super_admin
608+
* @param groupName the name of group to be created
609+
* @param accounts accounts added to the group
610+
* @param adminPrivateKey the private key of super_admin
611+
* @param version
612+
* @param chainId
613+
* @return the transaction hash for creating group
614+
* @throws IOException
615+
*/
616+
public String newGroup(String superAdminAddress,
617+
String groupName,
618+
List<String> accounts,
619+
String adminPrivateKey,
620+
int version,
621+
BigInteger chainId) throws IOException {
622+
// account addresses convert to Address object list
623+
List<Address> addresses = new ArrayList<>(accounts.size());
624+
for(String acc : accounts){
625+
addresses.add(new Address(acc));
626+
}
627+
628+
// groupName string convert to bytes32
629+
String nameHex = Util.addUpTo64Hex(ConvertStrByte.stringToHexString(groupName));
630+
byte[] nameBytes = ConvertStrByte.hexStringToBytes(Numeric.cleanHexPrefix(nameHex));
631+
632+
// build input parameters
633+
List<Type> inputParameters = Arrays.asList(
634+
new Address(superAdminAddress),//origin
635+
new Bytes32(nameBytes),//name
636+
new DynamicArray<Address>(addresses)//account
637+
);
638+
639+
// encode input parameters
640+
String funcData = CITASystemContract.encodeFunction(USER_MANAGER_NEW_GROUP, inputParameters);
641+
642+
// send request to create group and return transaction hash
643+
String txHash = CITASystemContract.sendTxAndGetHash(
644+
USER_MANAGER_ADDR, service, adminPrivateKey, funcData, version, chainId);
645+
return txHash;
646+
}
647+
583648
public Transaction constructStoreTransaction(String data, int version, BigInteger chainId) {
584649
return new Transaction(
585650
STORE_ADDR, Util.getNonce(), DEFAULT_QUOTA,
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package com.cryptape.cita.tests;
2+
3+
4+
import com.cryptape.cita.protocol.core.methods.response.Log;
5+
import com.cryptape.cita.protocol.system.CITASystemContract;
6+
7+
import java.io.IOException;
8+
import java.util.Arrays;
9+
import java.util.List;
10+
11+
/**
12+
* Group and Account Management
13+
* If you want to know more about the documentation, please click on the link below.
14+
* https://docs.citahub.com/zh-CN/cita/account-permission/account
15+
*/
16+
public class GroupManagerExample extends SystemContractExample {
17+
public static void main(String[] args) throws IOException, InterruptedException {
18+
// query groups
19+
List<String> groupAddress = sysContract.queryGroups("0xfFFfFFFFFffFFfffFFFFfffffFffffFFfF020009");
20+
System.out.println("groupAddress: " + groupAddress);
21+
22+
// create a group
23+
String transcationHash = sysContract.newGroup("0xfFFfFFFFFffFFfffFFFFfffffFffffFFfF020009",
24+
"newGroup",
25+
Arrays.asList("e1c4021742730ded647590a1686d5c4bfcbae0b0", "45a50f45cb81c8aedeab917ea0cd3c9178ebdcae"),
26+
adminPriavteKey,
27+
version,
28+
chainId);
29+
System.out.println("transcationHash: " + transcationHash);
30+
// get receipt by hash
31+
Log log = CITASystemContract.getReceiptLog(service, transcationHash, 0);
32+
System.out.println("groupAddress: " + (log == null ? "null" : log.getAddress()));
33+
}
34+
}

tests/src/main/java/com/cryptape/cita/tests/SystemContractExample.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public class SystemContractExample {
1313
static String adminPriavteKey;
1414
static int version;
1515
static BigInteger chainId;
16+
static CITAjSystemContract sysContract;
1617

1718
static {
1819
Config conf = new Config();
@@ -22,11 +23,11 @@ public class SystemContractExample {
2223
adminPriavteKey = conf.adminPrivateKey;
2324
version = TestUtil.getVersion(service);
2425
chainId = TestUtil.getChainId(service);
26+
sysContract = new CITAjSystemContract(service);
2527
}
2628

2729
public static void main(String[] args) throws Exception {
2830

29-
CITAjSystemContract sysContract = new CITAjSystemContract(service);
3031
long quotaPrice = sysContract.getQuotaPrice(senderAddr);
3132
System.out.println("Quota price is: " + quotaPrice);
3233

0 commit comments

Comments
 (0)