Simplify setEnvs func
parent
5a069caac9
commit
6e702e77f3
|
@ -30,40 +30,17 @@ verifyResult () {
|
|||
}
|
||||
|
||||
# Set global env variables for fabric usage
|
||||
# Usage: setEnvs localmsp tls_root_cert msp_cfg core_peer_addr
|
||||
# Usage: setEnvs org peer
|
||||
setEnvs () {
|
||||
local localMspId=$1
|
||||
local tlsRootCertFile=$2
|
||||
local mspCfgFile=$3
|
||||
local corePeerAddr=$4
|
||||
|
||||
echo_b "Set env for peer..."
|
||||
CORE_PEER_LOCALMSPID="${localMspId}"
|
||||
CORE_PEER_TLS_ROOTCERT_FILE="${tlsRootCertFile}"
|
||||
CORE_PEER_MSPCONFIGPATH="${mspCfgFile}"
|
||||
CORE_PEER_ADDRESS="${corePeerAddr}"
|
||||
|
||||
if [ 1 -eq 0 ]; then # TODO: remove this
|
||||
if [ $1 -eq 0 -o $1 -eq 1 ] ; then
|
||||
CORE_PEER_LOCALMSPID="Org1MSP"
|
||||
CORE_PEER_TLS_ROOTCERT_FILE=${ORG1_PEER0_TLS_ROOTCERT}
|
||||
CORE_PEER_MSPCONFIGPATH=${ORG1_ADMIN_MSP}
|
||||
if [ $1 -eq 0 ]; then
|
||||
CORE_PEER_ADDRESS=${ORG1_PEER0_URL}
|
||||
else
|
||||
CORE_PEER_ADDRESS=${ORG1_PEER1_URL}
|
||||
fi
|
||||
else
|
||||
CORE_PEER_LOCALMSPID="Org2MSP"
|
||||
CORE_PEER_TLS_ROOTCERT_FILE=${ORG2_PEER0_TLS_ROOTCERT}
|
||||
CORE_PEER_MSPCONFIGPATH=${ORG2_ADMIN_MSP}
|
||||
if [ $1 -eq 2 ]; then
|
||||
CORE_PEER_ADDRESS=${ORG2_PEER0_URL}
|
||||
else
|
||||
CORE_PEER_ADDRESS=${ORG2_PEER1_URL}
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
set -x
|
||||
local org=$1 # 1 or 2
|
||||
local peer=$2 # 0 or 1
|
||||
local t=""
|
||||
CORE_PEER_LOCALMSPID="Org${org}MSP"
|
||||
#CORE_PEER_MSPCONFIGPATH=\$${ORG${org}_ADMIN_MSP}
|
||||
t="\${ORG${org}_ADMIN_MSP}" && CORE_PEER_MSPCONFIGPATH=`eval echo $t`
|
||||
t="\${ORG${org}_PEER${peer}_TLS_ROOTCERT}" && CORE_PEER_TLS_ROOTCERT_FILE=`eval echo $t`
|
||||
t="\${ORG${org}_PEER${peer}_URL}" && CORE_PEER_ADDRESS=`eval echo $t`
|
||||
|
||||
env |grep CORE
|
||||
}
|
||||
|
@ -353,7 +330,8 @@ chaincodeStartDev () {
|
|||
local peer=$1
|
||||
local version=$2
|
||||
#setEnvs $peer
|
||||
setEnvs "Org1MSP" ${ORG1_PEER0_TLS_ROOTCERT} ${ORG1_ADMIN_MSP} ${ORG1_PEER0_URL}
|
||||
#setEnvs 1 0
|
||||
setEnvs 1 0
|
||||
CORE_CHAINCODE_LOGLEVEL=debug \
|
||||
CORE_PEER_ADDRESS=peer${peer}.org1.example.com:7052 \
|
||||
CORE_CHAINCODE_ID_NAME=mycc:${version} \
|
||||
|
|
|
@ -9,22 +9,22 @@ fi
|
|||
|
||||
## Install chaincode on all peers
|
||||
echo_b "Installing chaincode on all 4 peers..."
|
||||
setEnvs "Org1MSP" ${ORG1_PEER0_TLS_ROOTCERT} ${ORG1_ADMIN_MSP} ${ORG1_PEER0_URL}
|
||||
chaincodeInstall 0 ${CC_NAME} ${CC_INIT_VERSION} ${CC_PATH}
|
||||
setEnvs "Org1MSP" ${ORG1_PEER1_TLS_ROOTCERT} ${ORG1_ADMIN_MSP} ${ORG1_PEER1_URL}
|
||||
chaincodeInstall 1 ${CC_NAME} ${CC_INIT_VERSION} ${CC_PATH}
|
||||
setEnvs "Org2MSP" ${ORG2_PEER0_TLS_ROOTCERT} ${ORG2_ADMIN_MSP} ${ORG2_PEER0_URL}
|
||||
chaincodeInstall 2 ${CC_NAME} ${CC_INIT_VERSION} ${CC_PATH}
|
||||
setEnvs "Org2MSP" ${ORG2_PEER1_TLS_ROOTCERT} ${ORG2_ADMIN_MSP} ${ORG2_PEER1_URL}
|
||||
chaincodeInstall 3 ${CC_NAME} ${CC_INIT_VERSION} ${CC_PATH}
|
||||
setEnvs 1 0
|
||||
chaincodeInstall "1-0" ${CC_NAME} ${CC_INIT_VERSION} ${CC_PATH}
|
||||
setEnvs 1 1
|
||||
chaincodeInstall "1-1" ${CC_NAME} ${CC_INIT_VERSION} ${CC_PATH}
|
||||
setEnvs 2 0
|
||||
chaincodeInstall "2-0" ${CC_NAME} ${CC_INIT_VERSION} ${CC_PATH}
|
||||
setEnvs 2 1
|
||||
chaincodeInstall "2-1" ${CC_NAME} ${CC_INIT_VERSION} ${CC_PATH}
|
||||
|
||||
# Instantiate chaincode on all peers
|
||||
# Instantiate can only be executed once on any node
|
||||
echo_b "Instantiating chaincode on all 2 orgs (once for each org)..."
|
||||
setEnvs "Org1MSP" ${ORG1_PEER0_TLS_ROOTCERT} ${ORG1_ADMIN_MSP} ${ORG1_PEER0_URL}
|
||||
chaincodeInstantiate ${CHANNEL_NAME} 0 ${CC_NAME} ${CC_INIT_VERSION} ${CC_INIT_ARGS}
|
||||
setEnvs "Org2MSP" ${ORG2_PEER0_TLS_ROOTCERT} ${ORG2_ADMIN_MSP} ${ORG2_PEER0_URL}
|
||||
chaincodeInstantiate ${CHANNEL_NAME} 2 ${CC_NAME} ${CC_INIT_VERSION} ${CC_INIT_ARGS}
|
||||
setEnvs 1 0
|
||||
chaincodeInstantiate ${CHANNEL_NAME} "1-0" ${CC_NAME} ${CC_INIT_VERSION} ${CC_INIT_ARGS}
|
||||
setEnvs 2 0
|
||||
chaincodeInstantiate ${CHANNEL_NAME} "2-0" ${CC_NAME} ${CC_INIT_VERSION} ${CC_INIT_ARGS}
|
||||
|
||||
echo
|
||||
echo_g "===================== Init chaincode done ===================== "
|
||||
|
|
|
@ -11,16 +11,16 @@ fi
|
|||
|
||||
## Create channel
|
||||
echo_b "Creating channel ${CHANNEL_NAME}..."
|
||||
setEnvs "Org1MSP" ${ORG1_PEER0_TLS_ROOTCERT} ${ORG1_ADMIN_MSP} ${ORG1_PEER0_URL}
|
||||
setEnvs 1 0
|
||||
channelCreate ${CHANNEL_NAME}
|
||||
|
||||
## Join all the peers to the channel
|
||||
echo_b "Having all peers join the channel ${CHANNEL_NAME}..."
|
||||
setEnvs "Org1MSP" ${ORG1_PEER0_TLS_ROOTCERT} ${ORG1_ADMIN_MSP} ${ORG1_PEER0_URL}
|
||||
setEnvs 1 0
|
||||
channelJoin ${CHANNEL_NAME} 0
|
||||
setEnvs "Org1MSP" ${ORG1_PEER1_TLS_ROOTCERT} ${ORG1_ADMIN_MSP} ${ORG1_PEER1_URL}
|
||||
setEnvs 1 1
|
||||
channelJoin ${CHANNEL_NAME} 1
|
||||
setEnvs "Org2MSP" ${ORG2_PEER0_TLS_ROOTCERT} ${ORG2_ADMIN_MSP} ${ORG2_PEER0_URL}
|
||||
setEnvs 2 0
|
||||
channelJoin ${CHANNEL_NAME} 2
|
||||
setEnvs "Org2MSP" ${ORG2_PEER1_TLS_ROOTCERT} ${ORG2_ADMIN_MSP} ${ORG2_PEER1_URL}
|
||||
setEnvs 2 1
|
||||
channelJoin ${CHANNEL_NAME} 3
|
|
@ -11,52 +11,52 @@ echo_b "Channel name: "${CHANNEL_NAME}
|
|||
|
||||
#Query on chaincode on Peer0/Org1
|
||||
echo_b "Querying chaincode on peer 3..."
|
||||
setEnvs "Org2MSP" ${ORG2_PEER1_TLS_ROOTCERT} ${ORG2_ADMIN_MSP} ${ORG2_PEER1_URL}
|
||||
setEnvs 2 1
|
||||
chaincodeQuery ${CHANNEL_NAME} 3 ${CC_NAME} ${CC_QUERY_ARGS} 100
|
||||
|
||||
#Invoke on chaincode on Peer0/Org1
|
||||
echo_b "Sending invoke transaction (transfer 10) on org1/peer0..."
|
||||
setEnvs "Org1MSP" ${ORG1_PEER0_TLS_ROOTCERT} ${ORG1_ADMIN_MSP} ${ORG1_PEER0_URL}
|
||||
setEnvs 1 0
|
||||
chaincodeInvoke ${CHANNEL_NAME} 0 ${CC_NAME} ${CC_INVOKE_ARGS}
|
||||
|
||||
#Query on chaincode on Peer1/Org2, check if the result is 90
|
||||
echo_b "Querying chaincode on peer 1 and 3..."
|
||||
setEnvs "Org1MSP" ${ORG1_PEER1_TLS_ROOTCERT} ${ORG1_ADMIN_MSP} ${ORG1_PEER1_URL}
|
||||
setEnvs 1 1
|
||||
chaincodeQuery ${CHANNEL_NAME} 1 ${CC_NAME} ${CC_QUERY_ARGS} 90
|
||||
setEnvs "Org2MSP" ${ORG2_PEER1_TLS_ROOTCERT} ${ORG2_ADMIN_MSP} ${ORG2_PEER1_URL}
|
||||
setEnvs 2 1
|
||||
chaincodeQuery ${CHANNEL_NAME} 3 ${CC_NAME} ${CC_QUERY_ARGS} 90
|
||||
|
||||
#Invoke on chaincode on Peer1/Org2
|
||||
echo_b "Sending invoke transaction on org2/peer3..."
|
||||
setEnvs "Org2MSP" ${ORG2_PEER1_TLS_ROOTCERT} ${ORG2_ADMIN_MSP} ${ORG2_PEER1_URL}
|
||||
setEnvs 2 1
|
||||
chaincodeInvoke ${CHANNEL_NAME} 3 ${CC_NAME} ${CC_INVOKE_ARGS}
|
||||
|
||||
#Query on chaincode on Peer1/Org2, check if the result is 80
|
||||
echo_b "Querying chaincode on all 4peers..."
|
||||
setEnvs "Org1MSP" ${ORG1_PEER0_TLS_ROOTCERT} ${ORG1_ADMIN_MSP} ${ORG1_PEER0_URL}
|
||||
setEnvs 1 0
|
||||
chaincodeQuery ${CHANNEL_NAME} 0 ${CC_NAME} ${CC_QUERY_ARGS} 80
|
||||
setEnvs "Org2MSP" ${ORG2_PEER0_TLS_ROOTCERT} ${ORG2_ADMIN_MSP} ${ORG2_PEER0_URL}
|
||||
setEnvs 2 0
|
||||
chaincodeQuery ${CHANNEL_NAME} 2 ${CC_NAME} ${CC_QUERY_ARGS} 80
|
||||
|
||||
#Upgrade to new version
|
||||
echo_b "Upgrade chaincode to new version..."
|
||||
setEnvs "Org1MSP" ${ORG1_PEER0_TLS_ROOTCERT} ${ORG1_ADMIN_MSP} ${ORG1_PEER0_URL}
|
||||
setEnvs 1 0
|
||||
chaincodeInstall 0 ${CC_NAME} ${CC_UPGRADE_VERSION} ${CC_PATH}
|
||||
setEnvs "Org1MSP" ${ORG1_PEER1_TLS_ROOTCERT} ${ORG1_ADMIN_MSP} ${ORG1_PEER1_URL}
|
||||
setEnvs 1 1
|
||||
chaincodeInstall 1 ${CC_NAME} ${CC_UPGRADE_VERSION} ${CC_PATH}
|
||||
setEnvs "Org2MSP" ${ORG2_PEER0_TLS_ROOTCERT} ${ORG2_ADMIN_MSP} ${ORG2_PEER0_URL}
|
||||
setEnvs 2 0
|
||||
chaincodeInstall 2 ${CC_NAME} ${CC_UPGRADE_VERSION} ${CC_PATH}
|
||||
setEnvs "Org2MSP" ${ORG2_PEER1_TLS_ROOTCERT} ${ORG2_ADMIN_MSP} ${ORG2_PEER1_URL}
|
||||
setEnvs 2 1
|
||||
chaincodeInstall 3 ${CC_NAME} ${CC_UPGRADE_VERSION} ${CC_PATH}
|
||||
|
||||
# Upgrade on one peer of the channel will update all
|
||||
setEnvs "Org1MSP" ${ORG1_PEER0_TLS_ROOTCERT} ${ORG1_ADMIN_MSP} ${ORG1_PEER0_URL}
|
||||
setEnvs 1 0
|
||||
chaincodeUpgrade ${CHANNEL_NAME} 0 ${CC_NAME} ${CC_UPGRADE_VERSION} ${CC_UPGRADE_ARGS}
|
||||
|
||||
# Query new value, should refresh through all peers in the channel
|
||||
setEnvs "Org1MSP" ${ORG1_PEER0_TLS_ROOTCERT} ${ORG1_ADMIN_MSP} ${ORG1_PEER0_URL}
|
||||
setEnvs 1 0
|
||||
chaincodeQuery ${CHANNEL_NAME} 0 ${CC_NAME} ${CC_QUERY_ARGS} 100
|
||||
setEnvs "Org2MSP" ${ORG2_PEER1_TLS_ROOTCERT} ${ORG2_ADMIN_MSP} ${ORG2_PEER1_URL}
|
||||
setEnvs 2 1
|
||||
chaincodeQuery ${CHANNEL_NAME} 3 ${CC_NAME} ${CC_QUERY_ARGS} 100
|
||||
|
||||
echo_g "=== All GOOD, chaincode test completed ==="
|
||||
|
|
|
@ -9,7 +9,7 @@ elif [ -f scripts/func.sh ]; then
|
|||
source scripts/func.sh
|
||||
fi
|
||||
|
||||
setEnvs "Org1MSP" ${ORG1_PEER0_TLS_ROOTCERT} ${ORG1_ADMIN_MSP} ${ORG1_PEER0_URL}
|
||||
setEnvs 1 0
|
||||
|
||||
echo_b "=== Fetching blocks ==="
|
||||
|
||||
|
|
|
@ -11,9 +11,9 @@ fi
|
|||
|
||||
## Set the anchor peers for each org in the channel
|
||||
echo_b "Updating anchor peers for org1..."
|
||||
setEnvs "Org1MSP" ${ORG1_PEER0_TLS_ROOTCERT} ${ORG1_ADMIN_MSP} ${ORG1_PEER0_URL}
|
||||
setEnvs 1 0
|
||||
updateAnchorPeers ${CHANNEL_NAME} 0
|
||||
|
||||
echo_b "Updating anchor peers for org2..."
|
||||
setEnvs "Org2MSP" ${ORG2_PEER0_TLS_ROOTCERT} ${ORG2_ADMIN_MSP} ${ORG2_PEER0_URL}
|
||||
setEnvs 2 0
|
||||
updateAnchorPeers ${CHANNEL_NAME} 2
|
||||
|
|
Loading…
Reference in New Issue