概述
buildCC.sh
#!/bin/bash
. env.sh
. optChannel.sh
usage="Usage: $(basename -c command)
-c
package - 打包链码
install - 安装链码
queryInstall - 查询已安装链码
approve - 审核链码
checkreadiness - 查看链码是否就绪
commit - 提交链码
querycommitted - 查询通道已提交的链码
initCC - 初始化链码
-p 链码程序包目录(默认'')
-b 安装的链码包(tar.gz文件)
-i 链码ID,approve必传参数(asset_1:dc86a23bd13a23292567b853ac87479702e670b70d33413bfe5f547df7726717)
-n 链码名称(asset)
-v 链码版本(1)
-s 链码序号(1)
-t 通道名称(mychannel)
-l 链码标签(asset_1)
"
command=$1
ccpath=''
ccid=''
name=''
version=1
sequence=1
channelID=''
label=''
while getopts ":c:p:b:i:n:v:s:t:l:" opt
do
case $opt in
c)
command=$OPTARG
;;
p)
ccpath=$OPTARG
;;
b)
package=$OPTARG
;;
i)
ccid=$OPTARG
;;
n)
name=$OPTARG
;;
v)
version=$OPTARG
;;
s)
sequence=$OPTARG
;;
t)
channelID=$OPTARG
;;
l)
label=$OPTARG
;;
?)
echo "未知参数"
exit 1;;
esac
done
echo "参数列表:$@"
# ./buildCC.sh -c package -b asset.tar.gz -p '' -l asset_1
package(){
echo '打包链码开始'
JAR_NAME=`ll chaincode/|grep .jar | awk '{print $9}'`
echo "链码名称->$JAR_NAME"
setO1P1
echo ${CLI} --- ${ORG_HOST}
ssh ${ORG_HOST} "rm -rf ${CRYPTO_ROOT_PATH_MACHINE}chaincode/*"
scp -r ./chaincode/${JAR_NAME} root@${ORG_HOST}:${CRYPTO_ROOT_PATH_MACHINE}
ssh ${ORG_HOST} "docker exec ${CLI} bash -c "cd /opt/gopath/src/github.com/hyperledger/fabric/chaincode && rm -rf *.tar.gz && peer lifecycle chaincode package ${package} --path /opt/gopath/src/github.com/hyperledger/fabric/chaincode/${ccpath} --lang java --label ${label}""
setO2P1
echo ${CLI} --- ${ORG_HOST}
ssh ${ORG_HOST} "rm -rf ${CRYPTO_ROOT_PATH_MACHINE}chaincode/*"
scp -r ./chaincode/${JAR_NAME} root@${ORG_HOST}:${CRYPTO_ROOT_PATH_MACHINE}
ssh ${ORG_HOST} "docker exec ${CLI} bash -c "cd /opt/gopath/src/github.com/hyperledger/fabric/chaincode && rm -rf *.tar.gz && peer lifecycle chaincode package ${package} --path /opt/gopath/src/github.com/hyperledger/fabric/chaincode/${ccpath} --lang java --label ${label}""
echo '打包链码结束'
}
#./buildCC.sh -c install -p '' -b asset.tar.gz
install(){
echo '安装链码开始'
setO1P1
ssh ${ORG_HOST} "docker exec ${CLI} bash -c "cd /opt/gopath/src/github.com/hyperledger/fabric/chaincode/${ccpath} && peer lifecycle chaincode install ${package}""
setO1P2
ssh ${ORG_HOST} "docker exec ${CLI} bash -c "cd /opt/gopath/src/github.com/hyperledger/fabric/chaincode/${ccpath} && peer lifecycle chaincode install ${package}""
setO2P1
ssh ${ORG_HOST} "docker exec ${CLI} bash -c "cd /opt/gopath/src/github.com/hyperledger/fabric/chaincode/${ccpath} && peer lifecycle chaincode install ${package}""
setO2P2
ssh ${ORG_HOST} "docker exec ${CLI} bash -c "cd /opt/gopath/src/github.com/hyperledger/fabric/chaincode/${ccpath} && peer lifecycle chaincode install ${package}""
echo '安装链码结束'
}
#./buildCC.sh -c queryInstall
queryInstall(){
echo '查询已安装链码开始'
setO1P1
ssh ${ORG_HOST} "docker exec ${CLI} bash -c 'peer lifecycle chaincode queryinstalled'"
setO1P2
ssh ${ORG_HOST} "docker exec ${CLI} bash -c 'peer lifecycle chaincode queryinstalled'"
setO2P1
ssh ${ORG_HOST} "docker exec ${CLI} bash -c 'peer lifecycle chaincode queryinstalled'"
setO2P2
ssh ${ORG_HOST} "docker exec ${CLI} bash -c 'peer lifecycle chaincode queryinstalled'"
echo '查询已安装链码结束'
}
#./buildCC.sh -c approve -i asset_1:7f3c911c109fedad19809578f9b9146756e4142821b3ff697b1979566b3e482f -n asset -v 1 -s 1 -t mychannel -n asset
approve(){
echo '批准链码开始'
echo "ccid=${ccid}"
setO1P1
ssh ${ORG_HOST} "docker exec ${CLI} peer lifecycle chaincode approveformyorg --channelID ${channelID} --name ${name} --version ${version} --init-required --package-id ${ccid} --sequence ${sequence} --tls true --cafile $ORDERER_TLS_CA_CERT"
#setO1P2
#ssh ${ORG_HOST} "docker exec ${CLI} peer lifecycle chaincode approveformyorg --channelID ${channelID} --name ${name} --version ${version} --init-required --package-id ${ccid} --sequence ${sequence} --tls true --cafile $ORDERER_TLS_CA_CERT"
setO2P1
ssh ${ORG_HOST} "docker exec ${CLI} peer lifecycle chaincode approveformyorg --channelID ${channelID} --name ${name} --version ${version} --init-required --package-id ${ccid} --sequence ${sequence} --tls true --cafile $ORDERER_TLS_CA_CERT"
#setO2P2
#ssh ${ORG_HOST} "docker exec ${CLI} peer lifecycle chaincode approveformyorg --channelID ${channelID} --name ${name} --version ${version} --init-required --package-id ${ccid} --sequence ${sequence} --tls true --cafile $ORDERER_TLS_CA_CERT"
echo '批准链码结束'
}
#./buildCC.sh -c checkreadiness -v 1 -s 1 -t mychannel -n asset
checkreadiness(){
echo '查看链码是否就绪开始'
echo "ccid=${ccid}"
setO1P1
ssh ${ORG_HOST} "docker exec ${CLI} bash -c "peer lifecycle chaincode checkcommitreadiness --channelID ${channelID} --name ${name} --version ${version} --sequence ${sequence} --tls true --cafile $ORDERER_TLS_CA_CERT --output json""
# setO1P2
# ssh ${ORG_HOST} "docker exec ${CLI} bash -c "peer lifecycle chaincode checkcommitreadiness --channelID ${channelID} --name ${name} --version ${version} --sequence ${sequence} --tls true --cafile $ORDERER_TLS_CA_CERT --output json""
setO2P1
ssh ${ORG_HOST} "docker exec ${CLI} bash -c "peer lifecycle chaincode checkcommitreadiness --channelID ${channelID} --name ${name} --version ${version} --sequence ${sequence} --tls true --cafile $ORDERER_TLS_CA_CERT --output json""
# setO2P2
# ssh ${ORG_HOST} "docker exec ${CLI} bash -c "peer lifecycle chaincode checkcommitreadiness --channelID ${channelID} --name ${name} --version ${version} --sequence ${sequence} --tls true --cafile $ORDERER_TLS_CA_CERT --output json""
echo '查看链码是否就绪结束'
}
#./buildCC.sh -c commit -v 1 -s 1 -t mychannel -n asset
commit(){
echo '提交链码开始'
setO1P1
shell_str="docker exec ${CLI} peer lifecycle chaincode commit -o ${ORDERER_ADDRESS} --channelID ${channelID} --name ${name} --version ${version} --sequence ${sequence} --init-required --tls --cafile ${ORDERER_TLS_CA_CERT} --waitForEvent --peerAddresses ${CORE_PEER_ADDRESS} --tlsRootCertFiles ${CORE_PEER_TLS_CERT_FILE}"
setO2P1
shell_str="$shell_str --peerAddresses ${CORE_PEER_ADDRESS} --tlsRootCertFiles ${CORE_PEER_TLS_CERT_FILE}"
#执行拼接好的脚本
setO1P1
echo "拼接好的提交链码脚本:ssh ${ORG_HOST} $shell_str"
ssh ${ORG_HOST} "$shell_str"
echo '提交链码结束'
}
#./buildCC.sh -c queryCommited -t mychannel -n asset
queryCommited(){
echo '查询通道已提交链码开始'
setO1P1
ssh ${ORG_HOST} "docker exec ${CLI} peer lifecycle chaincode querycommitted -o ${ORDERER_ADDRESS} --channelID ${channelID} --name ${name} --tls --cafile ${ORDERER_TLS_CA_CERT} --peerAddresses ${CORE_PEER_ADDRESS} --tlsRootCertFiles ${CORE_PEER_TLS_CERT_FILE}"
setO2P1
ssh ${ORG_HOST} "docker exec ${CLI} peer lifecycle chaincode querycommitted -o ${ORDERER_ADDRESS} --channelID ${channelID} --name ${name} --tls --cafile ${ORDERER_TLS_CA_CERT} --peerAddresses ${CORE_PEER_ADDRESS} --tlsRootCertFiles ${CORE_PEER_TLS_CERT_FILE}"
echo '查询通道已提交链码结束'
}
#./buildCC.sh -c initCC -t mychannel -n asset
initCC(){
echo '初始化链码开始'
setO1P1
shell_str="docker exec ${CLI} peer chaincode invoke -o ${ORDERER_ADDRESS} --isInit --ordererTLSHostnameOverride ${ORDERER1_DOMAIN} --tls true --cafile ${ORDERER_TLS_CA_CERT} -C ${channelID} -n ${name} --peerAddresses ${CORE_PEER_ADDRESS} --tlsRootCertFiles ${CORE_PEER_TLS_CERT_FILE}"
setO1P2
shell_str="$shell_str --peerAddresses ${CORE_PEER_ADDRESS} --tlsRootCertFiles ${CORE_PEER_TLS_CERT_FILE} "
setO2P1
shell_str="$shell_str --peerAddresses ${CORE_PEER_ADDRESS} --tlsRootCertFiles ${CORE_PEER_TLS_CERT_FILE} "
setO2P2
shell_str="$shell_str --peerAddresses ${CORE_PEER_ADDRESS} --tlsRootCertFiles ${CORE_PEER_TLS_CERT_FILE} "
setO1P1
echo "拼接好的初始化链码脚本: ${ORG_HOST} $shell_str -c '{"function":"createCat","Args":["cat-00000001","cat-init-test","15","blue","mianyin"]}'"
ssh ${ORG_HOST} "$shell_str -c '{"function":"createCat","Args":["cat-00000001","cat-init-test","15","blue","mianyin"]}'"
echo '初始化链码结束'
}
case $command in
package)
package
;;
install)
install
;;
queryInstall)
queryInstall
;;
approve)
approve
;;
checkreadiness)
checkreadiness
;;
commit)
commit
;;
queryCommited)
queryCommited
;;
initCC)
initCC
;;
*)
echo "Error command"
echo "$usage"
;;
esac
deployCC.sh
#!/bin/bash
usage="Usage: ./deployCC.sh [channel_id] [chaincode_id] [version];
eg: ./deployCC.sh yljk-channel yljk_code 10"
if [ $# != 3 ] ; then
echo $usage
exit 1
fi
export CHANNEL_ID=$1
export CHANNEL_CODE_NAME=$2
export VERTION=$3
export SEQUENCE=$3
export CHAINCODE_PREFIX=${CHANNEL_CODE_NAME}_${VERTION}
./buildCC.sh -c package -b ${CHANNEL_CODE_NAME}.tar.gz -p '' -l ${CHANNEL_CODE_NAME}_${VERTION} &&
./buildCC.sh -c install -p '' -b ${CHANNEL_CODE_NAME}.tar.gz &&
export CHAINCODE_ID=`./buildCC.sh -c queryInstall > queryInstallinfo && sed -n "/${CHAINCODE_PREFIX}/p" queryInstallinfo |sed -n '$p'|sed 's/^Package.*ID: //g'|sed 's/,.*//g'` &&
echo "将要安装的链码ID-------------$CHAINCODE_ID" &&
./buildCC.sh -c approve -i ${CHAINCODE_ID} -n ${CHANNEL_CODE_NAME} -v ${VERTION} -s ${SEQUENCE} -t ${CHANNEL_ID} &&
./buildCC.sh -c checkreadiness -v ${VERTION} -s ${SEQUENCE} -t ${CHANNEL_ID} -n ${CHANNEL_CODE_NAME} &&
./buildCC.sh -c commit -v ${VERTION} -s ${SEQUENCE} -t ${CHANNEL_ID} -n ${CHANNEL_CODE_NAME} &&
./buildCC.sh -c queryCommited -t ${CHANNEL_ID} -n ${CHANNEL_CODE_NAME} &&
./buildCC.sh -c initCC -t ${CHANNEL_ID} -n ${CHANNEL_CODE_NAME}
最后
以上就是听话航空为你收集整理的fabric-链码一键部署的全部内容,希望文章能够帮你解决fabric-链码一键部署所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复