Skip to content

Commit

Permalink
Merge pull request #210 from WeBankFinTech/feature/transcation-by-group
Browse files Browse the repository at this point in the history
Evidence supports multi-group transactions
  • Loading branch information
chaoxinhu committed May 22, 2020
2 parents 91e4cfd + e8b0db0 commit bde9f7b
Show file tree
Hide file tree
Showing 26 changed files with 868 additions and 288 deletions.
74 changes: 74 additions & 0 deletions src/main/java/com/webank/weid/constant/CnsType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright© (2018-2020) WeBank Co., Ltd.
*
* This file is part of weid-java-sdk.
*
* weid-java-sdk is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* weid-java-sdk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with weid-java-sdk. If not, see <https://www.gnu.org/licenses/>.
*/

package com.webank.weid.constant;

import org.apache.commons.lang3.StringUtils;

import com.webank.weid.util.PropertyUtils;

/**
* cns 类型定义.
*
* @author v_wbgyang
*
*/
public enum CnsType {

/**
* 默认的cns定义,此cns用于weid主合约存储.
*/
DEFAULT("allOrg", "v1.1"),

/**
* 共享cns定义,此cns可作为机构共享数据存储.
*/
SHARE("share", "v1.1");

private static final String SPLIT_CHAR = "/";

private String name;

private String version;

CnsType(String name, String version) {
this.name = getCnsName(name);
this.version = version;
}

private String getCnsName(String name) {
String profile = PropertyUtils.getProperty("cns.profile.active");
if (StringUtils.isNotBlank(profile)) {
return profile + SPLIT_CHAR + name;
}
return name;
}

public String toString() {
return name + SPLIT_CHAR + version;
}

public String getName() {
return name;
}

public String getVersion() {
return version;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,5 +108,5 @@ public final class ParamKeyConstant {
public static final String BIN_LOG_PATH = "binLogPath";
public static final String ENABLE_OFFLINE = "enableOffLine";
public static final String INTEVAL_PERIOD = "inteval_period";

public static final String SHARE_CNS = "cns.contract.share.follow.";
}
1 change: 1 addition & 0 deletions src/main/java/com/webank/weid/constant/WeIdConstant.java
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ public final class WeIdConstant {
public static final String CNS_SPECIFIC_ADDRESS = "SpecificIssuerController";
public static final String CNS_EVIDENCE_ADDRESS = "EvidenceFactory";
public static final String CNS_CPT_ADDRESS = "CptController";
public static final String CNS_GROUP_ID = "groupId";

public static final Integer ON_CHAIN_STRING_LENGTH = 2097152;

Expand Down
22 changes: 22 additions & 0 deletions src/main/java/com/webank/weid/contract/deploy/AddressProcess.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,22 @@ protected static String getAddress(String fileName) {
return address;
}

protected static ContractConfig getContractConfig() {
ContractConfig contractConfig = new ContractConfig();
String weIdAddress = getAddress("weIdContract.address");
String issuerAddress = getAddress("authorityIssuer.address");
String specificAddress = getAddress("specificIssuer.address");
String evidenceAddress = getAddress("evidenceController.address");
String cptAddress = getAddress("cptController.address");

contractConfig.setWeIdAddress(weIdAddress);
contractConfig.setIssuerAddress(issuerAddress);
contractConfig.setSpecificIssuerAddress(specificAddress);
contractConfig.setEvidenceAddress(evidenceAddress);
contractConfig.setCptAddress(cptAddress);
return contractConfig;
}

/**
* 根据合约地址获取hash数据.
* @param contractConfig 合约数据
Expand All @@ -118,4 +134,10 @@ public static String getHashByAddress(ContractConfig contractConfig) {
.append(evidenceAddress);
return DataToolUtils.getHash(address.toString());
}

public static String getHashForShare(Integer groupId, String evidenceAddress) {
StringBuffer address = new StringBuffer();
address.append("share").append(groupId).append(evidenceAddress);
return DataToolUtils.getHash(address.toString());
}
}
82 changes: 82 additions & 0 deletions src/main/java/com/webank/weid/contract/deploy/DeployEvidence.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright© (2018-2020) WeBank Co., Ltd.
*
* This file is part of weid-java-sdk.
*
* weid-java-sdk is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* weid-java-sdk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with weid-java-sdk. If not, see <https://www.gnu.org/licenses/>.
*/

package com.webank.weid.contract.deploy;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.webank.weid.config.FiscoConfig;
import com.webank.weid.contract.deploy.v2.DeployEvidenceV2;

/**
* The Class DeployContract.
*
* @author tonychen
*/
public abstract class DeployEvidence {

/**
* log4j.
*/
private static final Logger logger = LoggerFactory.getLogger(DeployEvidence.class);

/**
* The Fisco Config bundle.
*/
protected static final FiscoConfig fiscoConfig;

static {
fiscoConfig = new FiscoConfig();
if (!fiscoConfig.load()) {
logger.error("[BaseService] Failed to load Fisco-BCOS blockchain node information.");
System.exit(1);
}
}

/**
* The main method.
*
* @param args the arguments
*/
public static void main(String[] args) {

// args = new String[] {"2"};

if (args == null || args.length == 0) {
logger.error("input param illegal");
System.exit(1);
}

String groupStr = args[0];
Integer groupId = Integer.parseInt(groupStr);

String privateKey = null;
if (args != null && args.length > 1) {
privateKey = args[1];
}

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

public static void deployContract(String privateKey, Integer groupId) {
DeployEvidenceV2.deployContract(privateKey, groupId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.webank.weid.config.ContractConfig;
import com.webank.weid.constant.CnsType;
import com.webank.weid.constant.WeIdConstant;
import com.webank.weid.contract.deploy.AddressProcess;
import com.webank.weid.contract.v2.AuthorityIssuerController;
Expand Down Expand Up @@ -135,7 +137,7 @@ private static void registerToCns() {
String privateKey = AddressProcess.getAddressFromFile("ecdsa_key");
WeIdPrivateKey weIdPrivate = new WeIdPrivateKey();
weIdPrivate.setPrivateKey(privateKey);
RegisterAddressV2.registerAddress(weIdPrivate);
registerAddress(weIdPrivate);
}


Expand Down Expand Up @@ -384,4 +386,58 @@ private static String deployEvidenceContractsNew() {
}
return StringUtils.EMPTY;
}

/**
* 根据私钥将合约地址注册到cns中.
* @param privateKey 私钥信息
*/
public static void registerAddress(WeIdPrivateKey privateKey) {
CnsType cnsType = CnsType.DEFAULT;
//先進行cns注冊
RegisterAddressV2.registerBucketToCns(cnsType);
//获取地址hash
ContractConfig contractConfig = getContractConfig();
String hash = getHashByAddress(contractConfig);
logger.info("[registerAddress] contract hash = {}.", hash);
RegisterAddressV2.registerAddress(
cnsType,
hash,
contractConfig.getWeIdAddress(),
WeIdConstant.CNS_WEID_ADDRESS,
privateKey
);

RegisterAddressV2.registerAddress(
cnsType,
hash,
contractConfig.getIssuerAddress(),
WeIdConstant.CNS_AUTH_ADDRESS,
privateKey
);

RegisterAddressV2.registerAddress(
cnsType,
hash,
contractConfig.getSpecificIssuerAddress(),
WeIdConstant.CNS_SPECIFIC_ADDRESS,
privateKey
);

RegisterAddressV2.registerAddress(
cnsType,
hash,
contractConfig.getEvidenceAddress(),
WeIdConstant.CNS_EVIDENCE_ADDRESS,
privateKey
);

RegisterAddressV2.registerAddress(
cnsType,
hash,
contractConfig.getCptAddress(),
WeIdConstant.CNS_CPT_ADDRESS,
privateKey
);
writeAddressToFile(hash, "hash");
}
}

0 comments on commit bde9f7b

Please sign in to comment.