Skip to content

Commit

Permalink
Merge pull request #235 from yg3630536/feature/use-cns-for-configuration
Browse files Browse the repository at this point in the history
* add orgConfig CNS for configuration
  • Loading branch information
junqizhang-dev authored Jul 21, 2020
2 parents 9aa987f + f3cb091 commit c49046f
Show file tree
Hide file tree
Showing 46 changed files with 542 additions and 266 deletions.
52 changes: 30 additions & 22 deletions .ci/script/build-ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ app_xml_config_tpl=${java_source_code_dir}/src/main/resources/fisco.properties.t
app_xml_config=${java_source_code_dir}/src/main/resources/fisco.properties
weid_config_tpl=${java_source_code_dir}/src/main/resources/weidentity.properties.tpl
weid_config=${java_source_code_dir}/src/main/resources/weidentity.properties
font=${java_source_code_dir}/src/main/resources/NotoSansCJKtc-Regular.ttf

export MYSQL_ADDRESS=${1:-0.0.0.0:3306}
export MYSQL_DATABASE=${2:-database}
Expand All @@ -18,25 +17,23 @@ function modify_config()
{
echo "begin to modify sdk config..."

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}'
MYVARS='${FISCO_BCOS_VERSION}:${CNS_PROFILE_ACTIVE}'
envsubst ${MYVARS} < ${app_xml_config_tpl} >${app_xml_config}
cp ${app_xml_config} ${java_source_code_dir}/src/test/resources/
# cat $app_xml_config

export ORG_ID=${ORG_ID}
export AMOP_ID=${AMOP_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}'
NODEVAR='${ORG_ID}:${AMOP_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/

Expand All @@ -46,6 +43,8 @@ function modify_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
cp ${java_source_code_dir}/NotoSansCJKtc-Regular.ttf ${java_source_code_dir}/src/main/resources
cp ${java_source_code_dir}/NotoSansCJKtc-Regular.ttf ${java_source_code_dir}/src/test/resources
cp -r ${java_source_code_dir}/src/main/resources/WeDPR_dynamic_lib ${java_source_code_dir}/src/test/resources
echo "modify sdk config finished..."
}
Expand All @@ -57,27 +56,24 @@ 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
cp ${java_source_code_dir}/dist/lib/NotoSansCJKtc-Regular.ttf ${java_source_code_dir}/src/main/resources
cp ${java_source_code_dir}/dist/lib/NotoSansCJKtc-Regular.ttf ${java_source_code_dir}/src/test/resources


export FISCO_BCOS_VERSION="2"
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}'
MYVARS='${FISCO_BCOS_VERSION}:${CNS_PROFILE_ACTIVE}'
envsubst ${MYVARS} < ${app_xml_config_tpl} >${app_xml_config}


content="$NODE_IP"
#content="0.0.0.0:8900"
# content="0.0.0.0:8902"
export BLOCKCHIAN_NODE_INFO=${content}
export ORG_ID="webank_ci"
export AMOP_ID="amop_ci"
echo $MYSQL_ADDRESS
echo $MYSQL_DATABASE
echo $MYSQL_USERNAME
echo $MYSQL_PASSWORD
NODEVAR='${ORG_ID}:${MYSQL_ADDRESS}:${MYSQL_DATABASE}:${MYSQL_USERNAME}:${MYSQL_PASSWORD}:${BLOCKCHIAN_NODE_INFO}'
NODEVAR='${ORG_ID}:${AMOP_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 Expand Up @@ -109,20 +105,32 @@ function deploy_contract()
do
CLASSPATH=${CLASSPATH}:${jar_file}
done

chain_id=101
privateKey=18602059553666200379844734388296903882431291027699519961839765914892609749994

java ${JAVA_OPTS} -cp "$CLASSPATH" com.webank.weid.contract.deploy.DeployContract
java ${JAVA_OPTS} -cp "$CLASSPATH" com.webank.weid.contract.deploy.DeployContract ${chain_id} ${privateKey}
echo "contract deployment done."
}

function install_font()
{
sudo mkdir -p /usr/share/fonts/custom&&
sudo cp ${font} /usr/share/fonts/custom/&&
sudo apt install xfonts-utils -y&&
sudo mkfontscale&&
sudo mkfontdir&&
sudo fc-cache -fv
echo "font install done."
# download NotoSansCJKtc-Regular.ttf
if [ ! -f NotoSansCJKtc-Regular.ttf ]; then
wget -c https://www.fisco.com.cn/cdn/weevent/weidentity/download/releases/NotoSansCJKtc-Regular.ttf
fi

if [ -f NotoSansCJKtc-Regular.ttf ]; then
sudo mkdir -p /usr/share/fonts/custom&&
sudo cp NotoSansCJKtc-Regular.ttf /usr/share/fonts/custom/&&
sudo apt install xfonts-utils -y&&
sudo mkfontscale&&
sudo mkfontdir&&
sudo fc-cache -fv
echo "font install done."
else
echo "font install fail."
fi
}

function main()
Expand Down
5 changes: 4 additions & 1 deletion build-tools/bin/run.config
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,14 @@ blockchain_address=
#FISCO BCOS 1.3, fill with "1", FISCO BCOS 2.0 fill with "2"
blockchain_fiscobcos_version=2

#amop_id
amop_id=

#org id
org_id=

#chain id
chain_id=
chain_id=101

#Configure your database information
mysql_address=
Expand Down
16 changes: 7 additions & 9 deletions build-tools/bin/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,21 +60,20 @@ function modify_config()
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}'
MYVARS='${FISCO_BCOS_VERSION}:${CNS_PROFILE_ACTIVE}'
envsubst ${MYVARS} < ${app_xml_config_tpl} >${app_xml_config}
cp ${app_xml_config} ${app_xml_config_dir}

export ORG_ID=${ORG_ID}
export AMOP_ID=${AMOP_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}'
NODEVAR='${ORG_ID}:${AMOP_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 Down Expand Up @@ -130,19 +129,18 @@ function gradle_build_sdk()

export BLOCKCHIAN_NODE_INFO=$(echo -e ${content})
export FISCO_BCOS_VERSION=${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}'
MYVARS='${FISCO_BCOS_VERSION}:${CNS_PROFILE_ACTIVE}:'
envsubst ${MYVARS} < ${app_xml_config_tpl} >${app_xml_config}

export ORG_ID=${org_id}
export AMOP_ID=${amop_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}'
NODEVAR='${ORG_ID}:${AMOP_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 All @@ -164,7 +162,7 @@ function deploy_contract()
CLASSPATH=${CLASSPATH}:${jar_file}
done

java ${JAVA_OPTS} -cp "$CLASSPATH" com.webank.weid.contract.deploy.DeployContract $1
java ${JAVA_OPTS} -cp "$CLASSPATH" com.webank.weid.contract.deploy.DeployContract ${chain_id} $1
echo "contract deployment done."
}

Expand Down
16 changes: 6 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,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.21") {
compile("com.webank:weid-contract-java:1.2.22-rc.2-SNAPSHOT") {
exclude group: "org.slf4j", module: "slf4j-log4j12"
// exclude group: "org.fisco-bcos", module: "web3sdk"
// exclude group: "org.fisco-bcos", module: "web3sdk-weevent"
Expand All @@ -170,7 +170,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.21") {
compile("com.webank:weid-contract-java:1.2.22-rc.2-SNAPSHOT") {
exclude group: "org.slf4j", module: "slf4j-log4j12"
// exclude group: "org.fisco-bcos", module: "web3sdk"
// exclude group: "org.fisco-bcos", module: "web3sdk-weevent"
Expand Down Expand Up @@ -213,6 +213,10 @@ processResources {
exclude '**/**'
}

clean {
delete "dist"
}

task sourcesJar(type: Jar) {
classifier = 'sources'
from sourceSets.main.allSource
Expand Down Expand Up @@ -253,14 +257,6 @@ jar {
from file('src/main/resources/')
into 'dist/conf'
}
copy {
from file('dist/lib/NotoSansCJKtc-Regular.ttf')
into 'src/main/resources/'
}
copy {
from file('dist/lib/NotoSansCJKtc-Regular.ttf')
into 'src/test/resources/'
}
if (!gradle.startParameter.isOffline()) {
copy {
from configurations.runtime
Expand Down
Binary file removed dist/lib/NotoSansCJKtc-Regular.ttf
Binary file not shown.
10 changes: 5 additions & 5 deletions src/main/java/com/webank/weid/config/FiscoConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ public class FiscoConfig {
private String issuerAddress;
private String evidenceAddress;
private String specificIssuerAddress;

@NotNull(message = "the chain.id is undefined")
@NotEmpty(message = "the value of chain.id is null")
@MatchPattern(pattern = "\\d+", message = "the value of chain.id is invalid")
private String chainId;

@NotNull(message = "the web3sdk.timeout is undefined")
Expand Down Expand Up @@ -141,7 +137,10 @@ public class FiscoConfig {
@NotEmpty(message = "the value of blockchain.orgid is null")
private String currentOrgId;

@NotNull(message = "the cns.contract.follow is undefined")
@NotNull(message = "the amop.id is undefined")
@NotEmpty(message = "the value of amop.id is null")
private String amopId;

private String cnsContractFollow;

/**
Expand Down Expand Up @@ -176,6 +175,7 @@ public boolean load() {
v2NodeCrtPath = PropertyUtils.getProperty("v2.node-crt-path");
v2NodeKeyPath = PropertyUtils.getProperty("v2.node-key-path");
currentOrgId = PropertyUtils.getProperty("blockchain.orgid");
amopId = PropertyUtils.getProperty("amop.id");
cnsContractFollow = PropertyUtils.getProperty("cns.contract.follow");
return true;
} catch (Exception e) {
Expand Down
9 changes: 7 additions & 2 deletions src/main/java/com/webank/weid/constant/CnsType.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,17 @@ public enum CnsType {
/**
* 默认的cns定义,此cns用于weid主合约存储.
*/
DEFAULT("allOrg", "v1.1"),
DEFAULT("allOrg", "v2.1"),

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

/**
* 机构配置CNS定义.
*/
ORG_CONFING("orgConfig", "v2.1");

private static final String SPLIT_CHAR = "/";

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/webank/weid/constant/WeIdConstant.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ public final class WeIdConstant {
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 String CNS_CHAIN_ID = "chainId";
public static final String CNS_GLOBAL_KEY = "globalKey";
public static final String CNS_MAIN_HASH = "mainHash";
public static final String CNS_EVIDENCE_HASH = "evidenceHash";

public static final Integer ON_CHAIN_STRING_LENGTH = 2097152;

Expand Down
27 changes: 22 additions & 5 deletions src/main/java/com/webank/weid/contract/deploy/DeployContract.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@

package com.webank.weid.contract.deploy;

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

import com.webank.weid.config.FiscoConfig;
import com.webank.weid.constant.ErrorCode;
import com.webank.weid.constant.WeIdConstant;
import com.webank.weid.contract.deploy.v1.DeployContractV1;
import com.webank.weid.contract.deploy.v2.DeployContractV2;
import com.webank.weid.exception.WeIdBaseException;

/**
* The Class DeployContract.
Expand Down Expand Up @@ -59,19 +62,33 @@ public abstract class DeployContract {
*/
public static void main(String[] args) {

String chainId = args[0];
String privateKey = null;
if (args != null && args.length > 0) {
privateKey = args[0];
if (args != null && args.length > 2) {
privateKey = args[1];
}
if (StringUtils.isBlank(privateKey)) {
privateKey = AddressProcess.getAddressFromFile("ecdsa_key");
}
fiscoConfig.setChainId(chainId);
try {
deployContract(privateKey, true);
} catch (WeIdBaseException e) {
if (e.getErrorCode().getCode() == ErrorCode.CNS_NO_PERMISSION.getCode()) {
System.out.println("deploy fail, Maybe your private key is incorrect. Please make "
+ "sure that the root directory of the private key file ecdsa_key that "
+ "you deployed for the first time exists in the root directory.");
}
throw e;
}
deployContract(privateKey);
System.exit(0);
}

public static void deployContract(String privateKey) {
public static void deployContract(String privateKey, boolean instantEnable) {
if (fiscoConfig.getVersion().startsWith(WeIdConstant.FISCO_BCOS_1_X_VERSION_PREFIX)) {
DeployContractV1.deployContract(privateKey);
} else {
DeployContractV2.deployContract(privateKey);
DeployContractV2.deployContract(privateKey, fiscoConfig, instantEnable);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,6 @@ public static void main(String[] args) {
* @return 返回部署的hash值
*/
public static String deployContract(String privateKey, Integer groupId, boolean instantEnable) {
return DeployEvidenceV2.deployContract(privateKey, groupId, instantEnable);
return DeployEvidenceV2.deployContract(fiscoConfig, privateKey, groupId, instantEnable);
}
}
Loading

0 comments on commit c49046f

Please sign in to comment.