Skip to content

Commit

Permalink
Merge pull request #135 from yg3630536/feature/support-contract-in-cns
Browse files Browse the repository at this point in the history
* support contract manager in CNS
  • Loading branch information
chaoxinhu committed Mar 9, 2020
2 parents 9636bfc + f302135 commit a920a9d
Show file tree
Hide file tree
Showing 50 changed files with 1,287 additions and 240 deletions.
60 changes: 37 additions & 23 deletions .ci/script/build-ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,33 @@ JAVA_OPTS='-Djdk.tls.namedGroups="secp256r1,secp256k1"'
function modify_config()
{
echo "begin to modify sdk config..."
weid_address=$(cat weIdContract.address)
cpt_address=$(cat cptController.address)
issuer_address=$(cat authorityIssuer.address)
evidence_address=$(cat evidenceController.address)
specificissuer_address=$(cat specificIssuer.address)
export WEID_ADDRESS=${weid_address}
export CPT_ADDRESS=${cpt_address}
export ISSUER_ADDRESS=${issuer_address}
export EVIDENCE_ADDRESS=${evidence_address}
export SPECIFICISSUER_ADDRESS=${specificissuer_address}
export FISCO_BCOS_VERSION="2"
MYVARS='${WEID_ADDRESS}:${CPT_ADDRESS}:${ISSUER_ADDRESS}:${EVIDENCE_ADDRESS}:${SPECIFICISSUER_ADDRESS}:${FISCO_BCOS_VERSION}'

hash=$(cat hash)
export FISCO_BCOS_VERSION=${FISCO_BCOS_VERSION}
export CNS_PROFILE_ACTIVE=${CNS_PROFILE_ACTIVE}
export CNS_CONTRACT_FOLLOW=${hash}
export CHAIN_ID=${CHAIN_ID}

MYVARS='${FISCO_BCOS_VERSION}:${CNS_PROFILE_ACTIVE}:${CNS_CONTRACT_FOLLOW}:${CHAIN_ID}'
envsubst ${MYVARS} < ${app_xml_config_tpl} >${app_xml_config}
cp ${app_xml_config} ${java_source_code_dir}/src/test/resources/
NODEVAR='${BLOCKCHIAN_NODE_INFO}'
# cat $app_xml_config

export ORG_ID=${ORG_ID}
export MYSQL_ADDRESS=${MYSQL_ADDRESS}
export MYSQL_DATABASE=${MYSQL_DATABASE}
export MYSQL_USERNAME=${MYSQL_USERNAME}
export MYSQL_PASSWORD=${MYSQL_PASSWORD}
export BLOCKCHIAN_NODE_INFO=${BLOCKCHIAN_NODE_INFO}

NODEVAR='${ORG_ID}:${MYSQL_ADDRESS}:${MYSQL_DATABASE}:${MYSQL_USERNAME}:${MYSQL_PASSWORD}:${BLOCKCHIAN_NODE_INFO}'
envsubst ${NODEVAR} < ${weid_config_tpl} >${weid_config}
cp ${weid_config} ${java_source_code_dir}/src/test/resources/
# cat ${weid_config}

if [ -e ${java_source_code_dir}/ecdsa_key ];then
cp ${java_source_code_dir}/ecdsa_key ${java_source_code_dir}/src/test/resources/
fi
#cat $app_xml_config
cp ${java_source_code_dir}/.ci/ca.crt ${java_source_code_dir}/src/test/resources
cp ${java_source_code_dir}/.ci/node.crt ${java_source_code_dir}/src/test/resources
cp ${java_source_code_dir}/.ci/node.key ${java_source_code_dir}/src/test/resources
Expand All @@ -46,17 +52,25 @@ function gradle_build_sdk()
cp ${java_source_code_dir}/.ci/ca.crt ${java_source_code_dir}/src/main/resources
cp ${java_source_code_dir}/.ci/node.crt ${java_source_code_dir}/src/main/resources
cp ${java_source_code_dir}/.ci/node.key ${java_source_code_dir}/src/main/resources
content="$NODE_IP"
export BLOCKCHIAN_NODE_INFO=${content}
export WEID_ADDRESS="0x0"
export CPT_ADDRESS="0x0"
export ISSUER_ADDRESS="0x0"
export EVIDENCE_ADDRESS="0x0"
export SPECIFICISSUER_ADDRESS="0x0"

export FISCO_BCOS_VERSION="2"
MYVARS='${WEID_ADDRESS}:${CPT_ADDRESS}:${ISSUER_ADDRESS}:${EVIDENCE_ADDRESS}:${SPECIFICISSUER_ADDRESS}:${FISCO_BCOS_VERSION}'
export CNS_CONTRACT_FOLLOW=
export CNS_PROFILE_ACTIVE="ci"
export CHAIN_ID=101

MYVARS='${FISCO_BCOS_VERSION}:${CNS_PROFILE_ACTIVE}:${CNS_CONTRACT_FOLLOW}:${CHAIN_ID}'
envsubst ${MYVARS} < ${app_xml_config_tpl} >${app_xml_config}
NODEVAR='${BLOCKCHIAN_NODE_INFO}'


content="$NODE_IP"
#content="0.0.0.0:8900"
export BLOCKCHIAN_NODE_INFO=${content}
export ORG_ID="webank-ci"
export MYSQL_ADDRESS=0.0.0.0:3306
export MYSQL_DATABASE=database
export MYSQL_USERNAME=username
export MYSQL_PASSWORD=password
NODEVAR='${ORG_ID}:${MYSQL_ADDRESS}:${MYSQL_DATABASE}:${MYSQL_USERNAME}:${MYSQL_PASSWORD}:${BLOCKCHIAN_NODE_INFO}'
envsubst ${NODEVAR} < ${weid_config_tpl} >${weid_config}

echo "Begin to compile java code......"
Expand Down
16 changes: 14 additions & 2 deletions build-tools/bin/run.config
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,19 @@ blockchain_address=
blockchain_fiscobcos_version=2

#org id
org_id=organizationA
org_id=

#chain id
chain_id=1
chain_id=

#Configure your database information
mysql_address=
mysql_database=
mysql_username=
mysql_password=

#This variable is used to distinguish the environment. You can use "dev" to set the development environment,
#"stg" to set the test environment, "prd" to set the production environment.
#If you do not set it, the system will use allOrg as the environment by default.
#It is not recommended. Production use default configuration
cns_profile_active=prd
66 changes: 34 additions & 32 deletions build-tools/bin/setup.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/bin/bash

source run.config

java_source_code_dir=$2
config_file=${java_source_code_dir}/dist/bin/run.config
app_xml_config_dir=${java_source_code_dir}/dist/conf/
Expand Down Expand Up @@ -55,21 +57,24 @@ function replace_java_contract()
function modify_config()
{
echo "begin to modify sdk config..."
weid_address=$(cat weIdContract.address)
cpt_address=$(cat cptController.address)
issuer_address=$(cat authorityIssuer.address)
evidence_address=$(cat evidenceController.address)
specificissuer_address=$(cat specificIssuer.address)
export WEID_ADDRESS=${weid_address}
export CPT_ADDRESS=${cpt_address}
export ISSUER_ADDRESS=${issuer_address}
export EVIDENCE_ADDRESS=${evidence_address}
export SPECIFICISSUER_ADDRESS=${specificissuer_address}
export FISCO_BCOS_VERSION=${bcos_version}
MYVARS='${WEID_ADDRESS}:${CPT_ADDRESS}:${ISSUER_ADDRESS}:${EVIDENCE_ADDRESS}:${SPECIFICISSUER_ADDRESS}:${FISCO_BCOS_VERSION}'
hash=$(cat hash)
export FISCO_BCOS_VERSION=${FISCO_BCOS_VERSION}
export CNS_PROFILE_ACTIVE=${CNS_PROFILE_ACTIVE}
export CNS_CONTRACT_FOLLOW=${hash}
export CHAIN_ID=${CHAIN_ID}

MYVARS='${FISCO_BCOS_VERSION}:${CNS_PROFILE_ACTIVE}:${CNS_CONTRACT_FOLLOW}:${CHAIN_ID}'
envsubst ${MYVARS} < ${app_xml_config_tpl} >${app_xml_config}
cp ${app_xml_config} ${app_xml_config_dir}
NODEVAR='${BLOCKCHIAN_NODE_INFO}'

export ORG_ID=${ORG_ID}
export MYSQL_ADDRESS=${MYSQL_ADDRESS}
export MYSQL_DATABASE=${MYSQL_DATABASE}
export MYSQL_USERNAME=${MYSQL_USERNAME}
export MYSQL_PASSWORD=${MYSQL_PASSWORD}
export BLOCKCHIAN_NODE_INFO=${BLOCKCHIAN_NODE_INFO}

NODEVAR='${ORG_ID}:${MYSQL_ADDRESS}:${MYSQL_DATABASE}:${MYSQL_USERNAME}:${MYSQL_PASSWORD}:${BLOCKCHIAN_NODE_INFO}'
envsubst ${NODEVAR} < ${weid_config_tpl} >${weid_config}
cp ${weid_config} ${app_xml_config_dir}
echo "modify sdk config finished..."
Expand All @@ -78,17 +83,6 @@ function modify_config()
function clean_config()
{
echo "begin to clean config..."
cd ${java_source_code_dir}/dist
if [ -d bin/ ];then
rm -rf bin/
fi
if [ -d contracts/ ];then
rm -rf contracts/
fi
if [ -d output/ ];then
rm -rf output/
fi

cd ${java_source_code_dir}
if [ -f weIdContract.address ];then
rm -f weIdContract.address
Expand All @@ -105,6 +99,9 @@ function clean_config()
if [ -f specificIssuer.address ];then
rm -f specificIssuer.address
fi
if [ -f hash ];then
rm -f hash
fi
echo "clean finished..."
}

Expand All @@ -130,17 +127,22 @@ function gradle_build_sdk()
fi

done

export BLOCKCHIAN_NODE_INFO=$(echo -e ${content})
export WEID_ADDRESS="0x0"
export CPT_ADDRESS="0x0"
export ISSUER_ADDRESS="0x0"
export EVIDENCE_ADDRESS="0x0"
export SPECIFICISSUER_ADDRESS="0x0"
export FISCO_BCOS_VERSION=${bcos_version}
MYVARS='${WEID_ADDRESS}:${CPT_ADDRESS}:${ISSUER_ADDRESS}:${EVIDENCE_ADDRESS}:${SPECIFICISSUER_ADDRESS}:${FISCO_BCOS_VERSION}'
export CNS_CONTRACT_FOLLOW=
export CNS_PROFILE_ACTIVE=${cns_profile_active}
export CHAIN_ID=${chain_id}

MYVARS='${FISCO_BCOS_VERSION}:${CNS_PROFILE_ACTIVE}:${CNS_CONTRACT_FOLLOW}:${CHAIN_ID}'
envsubst ${MYVARS} < ${app_xml_config_tpl} >${app_xml_config}
NODEVAR='${BLOCKCHIAN_NODE_INFO}'

export ORG_ID=${org_id}
export MYSQL_ADDRESS=${mysql_address}
export MYSQL_DATABASE=${mysql_database}
export MYSQL_USERNAME=${mysql_username}
export MYSQL_PASSWORD=${mysql_password}
NODEVAR='${ORG_ID}:${MYSQL_ADDRESS}:${MYSQL_DATABASE}:${MYSQL_USERNAME}:${MYSQL_PASSWORD}:${BLOCKCHIAN_NODE_INFO}'
envsubst ${NODEVAR} < ${weid_config_tpl} >${weid_config}

cd ${java_source_code_dir}/
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ dependencies {
if (gradleVer.startsWith("4")) {
if (!gradle.startParameter.isOffline()) {
compile logger, lombok, apache_commons, json, mysql_driver, zxing, rpc, pdfbox, protobuf, caffeine, oval
compile("com.webank:weid-contract-java:1.2.14") {
compile("com.webank:weid-contract-java:1.2.15") {
exclude group: "org.slf4j", module: "slf4j-log4j12"
}
compile files("lib/WeDPR-Java-SDK.jar")
Expand All @@ -148,7 +148,7 @@ dependencies {
testAnnotationProcessor 'org.projectlombok:lombok:1.18.10'
testCompileOnly 'org.projectlombok:lombok:1.18.10'
compile logger, apache_commons, json, mysql_driver, zxing, rpc, pdfbox, protobuf, caffeine, oval
compile("com.webank:weid-contract-java:1.2.14") {
compile("com.webank:weid-contract-java:1.2.15") {
exclude group: "org.slf4j", module: "slf4j-log4j12"
}
compile files("lib/WeDPR-Java-SDK.jar")
Expand Down
6 changes: 3 additions & 3 deletions check-info.sh
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ function check_user_config() {
echo "the ca.crt is exists and the MD5 is `md5sum $ca_crt | cut -d " " -f1`"
fi

bcos_version=$(grep "bcos.version" $fisco_properties |awk -F"=" '{print $2}')
bcos_version=$(grep "bcos\.version" $fisco_properties |awk -F"=" '{print $2}')
if [[ $bcos_version == 1* ]];
then
if [ ! -f "$client_keystore" ];
Expand All @@ -166,7 +166,7 @@ function check_user_config() {
echo "ERROR: the bcos.version value is invalid."
fi

blockchain_orgid=$(grep "blockchain.orgid=" $weidentity_properties |awk -F"=" '{print $2}')
blockchain_orgid=$(grep "blockchain\.orgid=" $weidentity_properties |awk -F"=" '{print $2}')
echo "the current orgid: $blockchain_orgid"
nodes=$(grep "nodes=" $weidentity_properties |awk -F"=" '{print $2}')
echo "the current nodes: $nodes"
Expand Down Expand Up @@ -195,7 +195,7 @@ function check_jar_version() {
echo "----------------------------"
echo "6. Dependencies Jar Version"
echo "----------------------------"
bcos_version=$(grep "bcos.version" $fisco_properties |awk -F"=" '{print $2}')
bcos_version=$(grep "bcos\.version" $fisco_properties |awk -F"=" '{print $2}')
echo "the bcos version: $bcos_version"
isSdk=1
for file in $libDir/*
Expand Down
32 changes: 18 additions & 14 deletions src/main/java/com/webank/weid/config/FiscoConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
import net.sf.oval.constraint.Min;
import net.sf.oval.constraint.NotEmpty;
import net.sf.oval.constraint.NotNull;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -57,24 +59,10 @@ public class FiscoConfig {
@NotEmpty(message = "the value of nodes is null")
private String nodes;

@NotNull(message = "the weId.contractaddress is undefined")
@NotEmpty(message = "the value of weId.contractaddress is null")
private String weIdAddress;

@NotNull(message = "the cpt.contractaddress is undefined")
@NotEmpty(message = "the value of cpt.contractaddress is null")
private String cptAddress;

@NotNull(message = "the issuer.contractaddress is undefined")
@NotEmpty(message = "the value of issuer.contractaddress is null")
private String issuerAddress;

@NotNull(message = "the evidence.contractaddress is undefined")
@NotEmpty(message = "the value of evidence.contractaddress is null")
private String evidenceAddress;

@NotNull(message = "the specificissuer.contractaddress is undefined")
@NotEmpty(message = "the value of specificissuer.contractaddress is null")
private String specificIssuerAddress;

@NotNull(message = "the chain.id is undefined")
Expand Down Expand Up @@ -149,6 +137,9 @@ public class FiscoConfig {
@NotNull(message = "the blockchain.orgid is undefined")
@NotEmpty(message = "the value of blockchain.orgid is null")
private String currentOrgId;

@NotNull(message = "the cns.contract.follow is undefined")
private String cnsContractFollow;

/**
* load configuration without Spring context required.
Expand Down Expand Up @@ -182,6 +173,7 @@ public boolean load() {
v2NodeCrtPath = PropertyUtils.getProperty("v2.node-crt-path");
v2NodeKeyPath = PropertyUtils.getProperty("v2.node-key-path");
currentOrgId = PropertyUtils.getProperty("blockchain.orgid");
cnsContractFollow = PropertyUtils.getProperty("cns.contract.follow");
return true;
} catch (Exception e) {
logger.error("Error occurred during loading Fisco-Bcos properties: " + e.getMessage());
Expand All @@ -203,4 +195,16 @@ public void check() {
throw new WeIdBaseException(messageList.get(0));
}
}

/**
* check the contract address.
* @return 返回地址是否存在
*/
public boolean checkAddress() {
return StringUtils.isNotBlank(this.getWeIdAddress())
&& StringUtils.isNotBlank(this.getIssuerAddress())
&& StringUtils.isNotBlank(this.getSpecificIssuerAddress())
&& StringUtils.isNotBlank(this.getEvidenceAddress())
&& StringUtils.isNotBlank(this.getCptAddress());
}
}
25 changes: 25 additions & 0 deletions src/main/java/com/webank/weid/constant/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,31 @@ public enum ErrorCode {
* the data is expire.
*/
SQL_DATA_EXPIRE(160015, "the data is expire."),

/**
* no premission.
*/
CNS_NO_PERMISSION(160016, "no premission for this cns."),

/**
* the cns does not exist.
*/
CNS_DOES_NOT_EXIST(160017, "the cns does not exist."),

/**
* the cns is used.
*/
CNS_IS_USED(160018, "the cns is used."),

/**
* the cns is not used.
*/
CNS_IS_NOT_USED(160019, "the cns is not used."),

/**
* the code is undefined.
*/
CNS_CODE_UNDEFINED(160020, "the code is undefined."),

/**
* other uncatched exceptions or error.
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/webank/weid/constant/WeIdConstant.java
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,13 @@ public final class WeIdConstant {
* Removed WeID authentication specified tag.
*/
public static final String REMOVED_AUTHENTICATION_TAG = "OBSOLETEAUTH";

/**
* the address key in bucket.
*/
public static final String CNS_WEID_ADDRESS = "WeIdContract";
public static final String CNS_AUTH_ADDRESS = "AuthorityIssuerController";
public static final String CNS_SPECIFIC_ADDRESS = "SpecificIssuerController";
public static final String CNS_EVIDENCE_ADDRESS = "EvidenceFactory";
public static final String CNS_CPT_ADDRESS = "CptController";
}

0 comments on commit a920a9d

Please sign in to comment.