Skip to content

Commit

Permalink
Merge pull request #212 from yg3630536/feature/transcation-by-group
Browse files Browse the repository at this point in the history
* optimize deployment of evidence by groupId
  • Loading branch information
chaoxinhu committed May 25, 2020
2 parents bde9f7b + 96d3ed9 commit 0041adc
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 9 deletions.
14 changes: 11 additions & 3 deletions src/main/java/com/webank/weid/contract/deploy/DeployEvidence.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,19 @@ public static void main(String[] args) {
privateKey = args[1];
}

deployContract(privateKey, groupId);
deployContract(privateKey, groupId, true);
System.exit(0);
}

public static void deployContract(String privateKey, Integer groupId) {
DeployEvidenceV2.deployContract(privateKey, groupId);
/**
* 部署evidence合约.
*
* @param privateKey 私钥地址
* @param groupId 群组编号
* @param instantEnable 是否即时启用
* @return 返回部署的hash值
*/
public static String deployContract(String privateKey, Integer groupId, boolean instantEnable) {
return DeployEvidenceV2.deployContract(privateKey, groupId, instantEnable);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,11 @@ protected static void initWeb3j(Integer groupId) {
}
}

public static void deployContract(String inputPrivateKey, Integer groupId) {
public static String deployContract(
String inputPrivateKey,
Integer groupId,
boolean instantEnable
) {
initWeb3j(groupId);
String privateKey = initCredentials(inputPrivateKey);
String evidenceAddress = deployEvidenceContractsNew(groupId);
Expand Down Expand Up @@ -118,10 +122,16 @@ public static void deployContract(String inputPrivateKey, Integer groupId) {
WeIdConstant.CNS_GROUP_ID,
weIdPrivateKey
);
// 默认启用最新的配置: cns.contract.share.follow.<groupId>
Map<String, String> properties = new HashMap<>();
properties.put(ParamKeyConstant.SHARE_CNS + groupId.toString(), hash);
PropertiesService.getInstance().saveProperties(properties);

if (instantEnable) {
// 启用最新的配置: cns.contract.share.follow.<groupId>
Map<String, String> properties = new HashMap<>();
properties.put(ParamKeyConstant.SHARE_CNS + groupId.toString(), hash);
PropertiesService.getInstance().saveProperties(properties);
// 合约上也启用hash
RegisterAddressV2.enableHash(cnsType, hash, weIdPrivateKey);
}
return hash;
}

private static String deployEvidenceContractsNew(Integer groupId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,18 @@ private static String deployBucket() throws Exception {
new StaticGasProvider(WeIdConstant.GAS_PRICE, WeIdConstant.GAS_LIMIT)).send();
return dataBucket.getContractAddress();
}

/**
* 链上启用CNS.
* @param cnsType cns类型
* @param hash hash值
* @param weIdPrivateKey hash所属私钥
* @return 返回是否启用成功
*/
public static boolean enableHash(CnsType cnsType, String hash, WeIdPrivateKey weIdPrivateKey) {
logger.info("[enableHash] enable hash on chain.");
boolean result = getBucket(cnsType).enableHash(hash, weIdPrivateKey).getResult();
logger.info("[enableHash] the result of enable. result = {}", result);
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public String toJson() {
try {
String signature = this.getSignature();
Map<String, Object> credMap = DataToolUtils.objToMap(this);
credMap.remove(ParamKeyConstant.ISSUANCE_DATE);
//credMap.remove(ParamKeyConstant.ISSUANCE_DATE);
credMap.remove(ParamKeyConstant.CONTEXT);
credMap.remove(ParamKeyConstant.PROOF);
credMap.put(ParamKeyConstant.PROOF_TYPE, CredentialType.LITE1.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,54 @@

package com.webank.weid.protocol.base;

import java.io.IOException;
import java.util.ArrayList;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.github.fge.jackson.JsonLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.webank.weid.protocol.inf.JsonSerializer;

public class CredentialPojoList extends ArrayList<CredentialPojo> implements JsonSerializer {

private static final Logger logger = LoggerFactory.getLogger(CredentialPojoList.class);

/**
* the serial.
*/
private static final long serialVersionUID = -6164771401868673728L;

@Override
public String toJson() {
StringBuffer buffer = new StringBuffer();
buffer.append("[");
for (CredentialPojo credential : this) {
buffer.append(credential.toJson()).append(",");
}
buffer.deleteCharAt(buffer.length() - 1);
buffer.append("]");
return buffer.toString();
}

/**
* 将Json转换成CredentialPojoList.
*
* @param json json数据
* @return 返回CredentialPojoList
*/
public static CredentialPojoList fromJson(String json) {
try {
JsonNode jsonNode = JsonLoader.fromString(json);
ArrayNode arrayNode = (ArrayNode)jsonNode;
CredentialPojoList result = new CredentialPojoList();
arrayNode.forEach(node -> result.add(CredentialPojo.fromJson(node.toString())));
return result;
} catch (IOException e) {
logger.info("[fromJson] from JSON error for CredentialPojoList.", e);
return null;
}
}
}

0 comments on commit 0041adc

Please sign in to comment.