Skip to content

Commit

Permalink
Merge pull request #149 from cryptape/release/v0.25.0
Browse files Browse the repository at this point in the history
Release/v0.25.0
  • Loading branch information
rainchen authored Oct 16, 2019
2 parents 264bdf8 + 517d1b3 commit 7fe7cf4
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 8 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.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
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.24.1</version>
<version>0.25.0</version>
</dependency>
```
Gradle
```
compile 'com.cryptape.cita:core:0.24.1'
compile 'com.cryptape.cita:core:0.25.0'
```

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

手动安装
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,71 @@ 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<String> queryGroups(String senderAddress) throws IOException {
String callData = CITASystemContract.encodeCall(USER_MANAGER_QUERY_GROUPS);
AppCall callResult = CITASystemContract.sendCall(
senderAddress, USER_MANAGER_ADDR, callData, service);
List<TypeReference<?>> outputParamters
= Collections.singletonList(new TypeReference<DynamicArray<Address>>() {});
List<Type> resultTypes = CITASystemContract.decodeCallResult(callResult, outputParamters);
ArrayList<Address> results = (ArrayList<Address>) resultTypes.get(0).getValue();
List<String> list = new ArrayList<>(results.size());
for (Address address : results) {
list.add(address.getValue());
}
return list;
}

/**
* new group
* @see <a href="https://docs.citahub.com/zh-CN/cita/sys-contract-interface/interface#newgroup">newGroup</a>
* @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<String> accounts,
String adminPrivateKey,
int version,
BigInteger chainId) throws IOException {
// account addresses convert to Address object list
List<Address> 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<Type> inputParameters = Arrays.asList(
new Address(superAdminAddress),//origin
new Bytes32(nameBytes),//name
new DynamicArray<Address>(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,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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;

/**
* 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, InterruptedException {
// query groups
List<String> 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()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class SystemContractExample {
static String adminPriavteKey;
static int version;
static BigInteger chainId;
static CITAjSystemContract sysContract;

static {
Config conf = new Config();
Expand All @@ -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);

Expand Down

0 comments on commit 7fe7cf4

Please sign in to comment.