mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-22 17:45:10 +00:00
FAB-10801 format and styling for shell artifacts
formatting for existing shell scripts Change-Id: I7e067730558bc55edc74b73e59195af7c825d8b2 Signed-off-by: Naga Pemmara <naga.pemmaraju@ibm.com>
This commit is contained in:
parent
e95210e9bc
commit
20ad472356
2 changed files with 277 additions and 268 deletions
|
|
@ -33,7 +33,7 @@ export FABRIC_CFG_PATH=${PWD}
|
||||||
export VERBOSE=false
|
export VERBOSE=false
|
||||||
|
|
||||||
# Print the usage message
|
# Print the usage message
|
||||||
function printHelp () {
|
function printHelp() {
|
||||||
echo "Usage: "
|
echo "Usage: "
|
||||||
echo " byfn.sh <mode> [-c <channel name>] [-t <timeout>] [-d <delay>] [-f <docker-compose-file>] [-s <dbtype>] [-l <language>] [-i <imagetag>] [-v]"
|
echo " byfn.sh <mode> [-c <channel name>] [-t <timeout>] [-d <delay>] [-f <docker-compose-file>] [-s <dbtype>] [-l <language>] [-i <imagetag>] [-v]"
|
||||||
echo " <mode> - one of 'up', 'down', 'restart', 'generate' or 'upgrade'"
|
echo " <mode> - one of 'up', 'down', 'restart', 'generate' or 'upgrade'"
|
||||||
|
|
@ -69,17 +69,17 @@ function printHelp () {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Ask user for confirmation to proceed
|
# Ask user for confirmation to proceed
|
||||||
function askProceed () {
|
function askProceed() {
|
||||||
read -p "Continue? [Y/n] " ans
|
read -p "Continue? [Y/n] " ans
|
||||||
case "$ans" in
|
case "$ans" in
|
||||||
y|Y|"" )
|
y | Y | "")
|
||||||
echo "proceeding ..."
|
echo "proceeding ..."
|
||||||
;;
|
;;
|
||||||
n|N )
|
n | N)
|
||||||
echo "exiting..."
|
echo "exiting..."
|
||||||
exit 1
|
exit 1
|
||||||
;;
|
;;
|
||||||
* )
|
*)
|
||||||
echo "invalid response"
|
echo "invalid response"
|
||||||
askProceed
|
askProceed
|
||||||
;;
|
;;
|
||||||
|
|
@ -88,8 +88,8 @@ function askProceed () {
|
||||||
|
|
||||||
# Obtain CONTAINER_IDS and remove them
|
# Obtain CONTAINER_IDS and remove them
|
||||||
# TODO Might want to make this optional - could clear other containers
|
# TODO Might want to make this optional - could clear other containers
|
||||||
function clearContainers () {
|
function clearContainers() {
|
||||||
CONTAINER_IDS=$(docker ps -a |awk '($2 ~ /dev-peer.*.mycc.*/) {print $1}')
|
CONTAINER_IDS=$(docker ps -a | awk '($2 ~ /dev-peer.*.mycc.*/) {print $1}')
|
||||||
if [ -z "$CONTAINER_IDS" -o "$CONTAINER_IDS" == " " ]; then
|
if [ -z "$CONTAINER_IDS" -o "$CONTAINER_IDS" == " " ]; then
|
||||||
echo "---- No containers available for deletion ----"
|
echo "---- No containers available for deletion ----"
|
||||||
else
|
else
|
||||||
|
|
@ -101,7 +101,7 @@ function clearContainers () {
|
||||||
# specifically the following images are often left behind:
|
# specifically the following images are often left behind:
|
||||||
# TODO list generated image naming patterns
|
# TODO list generated image naming patterns
|
||||||
function removeUnwantedImages() {
|
function removeUnwantedImages() {
|
||||||
DOCKER_IMAGE_IDS=$(docker images|awk '($1 ~ /dev-peer.*.mycc.*/) {print $3}')
|
DOCKER_IMAGE_IDS=$(docker images | awk '($1 ~ /dev-peer.*.mycc.*/) {print $3}')
|
||||||
if [ -z "$DOCKER_IMAGE_IDS" -o "$DOCKER_IMAGE_IDS" == " " ]; then
|
if [ -z "$DOCKER_IMAGE_IDS" -o "$DOCKER_IMAGE_IDS" == " " ]; then
|
||||||
echo "---- No images available for deletion ----"
|
echo "---- No images available for deletion ----"
|
||||||
else
|
else
|
||||||
|
|
@ -119,27 +119,27 @@ function checkPrereqs() {
|
||||||
# Note, we check configtxlator externally because it does not require a config file, and peer in the
|
# Note, we check configtxlator externally because it does not require a config file, and peer in the
|
||||||
# docker image because of FAB-8551 that makes configtxlator return 'development version' in docker
|
# docker image because of FAB-8551 that makes configtxlator return 'development version' in docker
|
||||||
LOCAL_VERSION=$(configtxlator version | sed -ne 's/ Version: //p')
|
LOCAL_VERSION=$(configtxlator version | sed -ne 's/ Version: //p')
|
||||||
DOCKER_IMAGE_VERSION=$(docker run --rm hyperledger/fabric-tools:$IMAGETAG peer version | sed -ne 's/ Version: //p'|head -1)
|
DOCKER_IMAGE_VERSION=$(docker run --rm hyperledger/fabric-tools:$IMAGETAG peer version | sed -ne 's/ Version: //p' | head -1)
|
||||||
|
|
||||||
echo "LOCAL_VERSION=$LOCAL_VERSION"
|
echo "LOCAL_VERSION=$LOCAL_VERSION"
|
||||||
echo "DOCKER_IMAGE_VERSION=$DOCKER_IMAGE_VERSION"
|
echo "DOCKER_IMAGE_VERSION=$DOCKER_IMAGE_VERSION"
|
||||||
|
|
||||||
if [ "$LOCAL_VERSION" != "$DOCKER_IMAGE_VERSION" ] ; then
|
if [ "$LOCAL_VERSION" != "$DOCKER_IMAGE_VERSION" ]; then
|
||||||
echo "=================== WARNING ==================="
|
echo "=================== WARNING ==================="
|
||||||
echo " Local fabric binaries and docker images are "
|
echo " Local fabric binaries and docker images are "
|
||||||
echo " out of sync. This may cause problems. "
|
echo " out of sync. This may cause problems. "
|
||||||
echo "==============================================="
|
echo "==============================================="
|
||||||
fi
|
fi
|
||||||
|
|
||||||
for UNSUPPORTED_VERSION in $BLACKLISTED_VERSIONS ; do
|
for UNSUPPORTED_VERSION in $BLACKLISTED_VERSIONS; do
|
||||||
echo "$LOCAL_VERSION" | grep -q $UNSUPPORTED_VERSION
|
echo "$LOCAL_VERSION" | grep -q $UNSUPPORTED_VERSION
|
||||||
if [ $? -eq 0 ] ; then
|
if [ $? -eq 0 ]; then
|
||||||
echo "ERROR! Local Fabric binary version of $LOCAL_VERSION does not match this newer version of BYFN and is unsupported. Either move to a later version of Fabric or checkout an earlier version of fabric-samples."
|
echo "ERROR! Local Fabric binary version of $LOCAL_VERSION does not match this newer version of BYFN and is unsupported. Either move to a later version of Fabric or checkout an earlier version of fabric-samples."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "$DOCKER_IMAGE_VERSION" | grep -q $UNSUPPORTED_VERSION
|
echo "$DOCKER_IMAGE_VERSION" | grep -q $UNSUPPORTED_VERSION
|
||||||
if [ $? -eq 0 ] ; then
|
if [ $? -eq 0 ]; then
|
||||||
echo "ERROR! Fabric Docker image version of $DOCKER_IMAGE_VERSION does not match this newer version of BYFN and is unsupported. Either move to a later version of Fabric or checkout an earlier version of fabric-samples."
|
echo "ERROR! Fabric Docker image version of $DOCKER_IMAGE_VERSION does not match this newer version of BYFN and is unsupported. Either move to a later version of Fabric or checkout an earlier version of fabric-samples."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
@ -147,7 +147,7 @@ function checkPrereqs() {
|
||||||
}
|
}
|
||||||
|
|
||||||
# Generate the needed certificates, the genesis block and start the network.
|
# Generate the needed certificates, the genesis block and start the network.
|
||||||
function networkUp () {
|
function networkUp() {
|
||||||
checkPrereqs
|
checkPrereqs
|
||||||
# generate artifacts if they don't exist
|
# generate artifacts if they don't exist
|
||||||
if [ ! -d "crypto-config" ]; then
|
if [ ! -d "crypto-config" ]; then
|
||||||
|
|
@ -175,8 +175,8 @@ function networkUp () {
|
||||||
# Upgrade the network from v1.0.x to v1.1
|
# Upgrade the network from v1.0.x to v1.1
|
||||||
# Stop the orderer and peers, backup the ledger from orderer and peers, cleanup chaincode containers and images
|
# Stop the orderer and peers, backup the ledger from orderer and peers, cleanup chaincode containers and images
|
||||||
# and relaunch the orderer and peers with latest tag
|
# and relaunch the orderer and peers with latest tag
|
||||||
function upgradeNetwork () {
|
function upgradeNetwork() {
|
||||||
docker inspect -f '{{.Config.Volumes}}' orderer.example.com |grep -q '/var/hyperledger/production/orderer'
|
docker inspect -f '{{.Config.Volumes}}' orderer.example.com | grep -q '/var/hyperledger/production/orderer'
|
||||||
if [ $? -ne 0 ]; then
|
if [ $? -ne 0 ]; then
|
||||||
echo "ERROR !!!! This network does not appear to be using volumes for its ledgers, did you start from fabric-samples >= v1.0.6?"
|
echo "ERROR !!!! This network does not appear to be using volumes for its ledgers, did you start from fabric-samples >= v1.0.6?"
|
||||||
exit 1
|
exit 1
|
||||||
|
|
@ -212,11 +212,11 @@ function upgradeNetwork () {
|
||||||
|
|
||||||
# Remove any old containers and images for this peer
|
# Remove any old containers and images for this peer
|
||||||
CC_CONTAINERS=$(docker ps | grep dev-$PEER | awk '{print $1}')
|
CC_CONTAINERS=$(docker ps | grep dev-$PEER | awk '{print $1}')
|
||||||
if [ -n "$CC_CONTAINERS" ] ; then
|
if [ -n "$CC_CONTAINERS" ]; then
|
||||||
docker rm -f $CC_CONTAINERS
|
docker rm -f $CC_CONTAINERS
|
||||||
fi
|
fi
|
||||||
CC_IMAGES=$(docker images | grep dev-$PEER | awk '{print $1}')
|
CC_IMAGES=$(docker images | grep dev-$PEER | awk '{print $1}')
|
||||||
if [ -n "$CC_IMAGES" ] ; then
|
if [ -n "$CC_IMAGES" ]; then
|
||||||
docker rmi -f $CC_IMAGES
|
docker rmi -f $CC_IMAGES
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
@ -231,9 +231,8 @@ function upgradeNetwork () {
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Tear down running network
|
# Tear down running network
|
||||||
function networkDown () {
|
function networkDown() {
|
||||||
# stop org3 containers also in addition to org1 and org2, in case we were running sample to add org3
|
# stop org3 containers also in addition to org1 and org2, in case we were running sample to add org3
|
||||||
docker-compose -f $COMPOSE_FILE -f $COMPOSE_FILE_COUCH -f $COMPOSE_FILE_ORG3 down --volumes --remove-orphans
|
docker-compose -f $COMPOSE_FILE -f $COMPOSE_FILE_COUCH -f $COMPOSE_FILE_ORG3 down --volumes --remove-orphans
|
||||||
|
|
||||||
|
|
@ -256,10 +255,10 @@ function networkDown () {
|
||||||
# Using docker-compose-e2e-template.yaml, replace constants with private key file names
|
# Using docker-compose-e2e-template.yaml, replace constants with private key file names
|
||||||
# generated by the cryptogen tool and output a docker-compose.yaml specific to this
|
# generated by the cryptogen tool and output a docker-compose.yaml specific to this
|
||||||
# configuration
|
# configuration
|
||||||
function replacePrivateKey () {
|
function replacePrivateKey() {
|
||||||
# sed on MacOSX does not support -i flag with a null extension. We will use
|
# sed on MacOSX does not support -i flag with a null extension. We will use
|
||||||
# 't' for our back-up's extension and delete it at the end of the function
|
# 't' for our back-up's extension and delete it at the end of the function
|
||||||
ARCH=`uname -s | grep Darwin`
|
ARCH=$(uname -s | grep Darwin)
|
||||||
if [ "$ARCH" == "Darwin" ]; then
|
if [ "$ARCH" == "Darwin" ]; then
|
||||||
OPTS="-it"
|
OPTS="-it"
|
||||||
else
|
else
|
||||||
|
|
@ -304,7 +303,7 @@ function replacePrivateKey () {
|
||||||
# After we run the tool, the certs will be parked in a folder titled ``crypto-config``.
|
# After we run the tool, the certs will be parked in a folder titled ``crypto-config``.
|
||||||
|
|
||||||
# Generates Org certs using cryptogen tool
|
# Generates Org certs using cryptogen tool
|
||||||
function generateCerts (){
|
function generateCerts() {
|
||||||
which cryptogen
|
which cryptogen
|
||||||
if [ "$?" -ne 0 ]; then
|
if [ "$?" -ne 0 ]; then
|
||||||
echo "cryptogen tool not found. exiting"
|
echo "cryptogen tool not found. exiting"
|
||||||
|
|
@ -431,7 +430,7 @@ function generateChannelArtifacts() {
|
||||||
|
|
||||||
# Obtain the OS and Architecture string that will be used to select the correct
|
# Obtain the OS and Architecture string that will be used to select the correct
|
||||||
# native binaries for your platform
|
# native binaries for your platform
|
||||||
OS_ARCH=$(echo "$(uname -s|tr '[:upper:]' '[:lower:]'|sed 's/mingw64_nt.*/windows/')-$(uname -m | sed 's/x86_64/amd64/g')" | awk '{print tolower($0)}')
|
OS_ARCH=$(echo "$(uname -s | tr '[:upper:]' '[:lower:]' | sed 's/mingw64_nt.*/windows/')-$(uname -m | sed 's/x86_64/amd64/g')" | awk '{print tolower($0)}')
|
||||||
# timeout duration - the duration the CLI should wait for a response from
|
# timeout duration - the duration the CLI should wait for a response from
|
||||||
# another container before giving up
|
# another container before giving up
|
||||||
CLI_TIMEOUT=10
|
CLI_TIMEOUT=10
|
||||||
|
|
@ -451,10 +450,11 @@ LANGUAGE=golang
|
||||||
# default image tag
|
# default image tag
|
||||||
IMAGETAG="latest"
|
IMAGETAG="latest"
|
||||||
# Parse commandline args
|
# Parse commandline args
|
||||||
if [ "$1" = "-m" ];then # supports old usage, muscle memory is powerful!
|
if [ "$1" = "-m" ]; then # supports old usage, muscle memory is powerful!
|
||||||
shift
|
shift
|
||||||
fi
|
fi
|
||||||
MODE=$1;shift
|
MODE=$1
|
||||||
|
shift
|
||||||
# Determine whether starting, stopping, restarting, generating or upgrading
|
# Determine whether starting, stopping, restarting, generating or upgrading
|
||||||
if [ "$MODE" == "up" ]; then
|
if [ "$MODE" == "up" ]; then
|
||||||
EXPMODE="Starting"
|
EXPMODE="Starting"
|
||||||
|
|
@ -473,37 +473,45 @@ fi
|
||||||
|
|
||||||
while getopts "h?c:t:d:f:s:l:i:v" opt; do
|
while getopts "h?c:t:d:f:s:l:i:v" opt; do
|
||||||
case "$opt" in
|
case "$opt" in
|
||||||
h|\?)
|
h | \?)
|
||||||
printHelp
|
printHelp
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
c) CHANNEL_NAME=$OPTARG
|
c)
|
||||||
|
CHANNEL_NAME=$OPTARG
|
||||||
;;
|
;;
|
||||||
t) CLI_TIMEOUT=$OPTARG
|
t)
|
||||||
|
CLI_TIMEOUT=$OPTARG
|
||||||
;;
|
;;
|
||||||
d) CLI_DELAY=$OPTARG
|
d)
|
||||||
|
CLI_DELAY=$OPTARG
|
||||||
;;
|
;;
|
||||||
f) COMPOSE_FILE=$OPTARG
|
f)
|
||||||
|
COMPOSE_FILE=$OPTARG
|
||||||
;;
|
;;
|
||||||
s) IF_COUCHDB=$OPTARG
|
s)
|
||||||
|
IF_COUCHDB=$OPTARG
|
||||||
;;
|
;;
|
||||||
l) LANGUAGE=$OPTARG
|
l)
|
||||||
|
LANGUAGE=$OPTARG
|
||||||
;;
|
;;
|
||||||
i) IMAGETAG=`uname -m`"-"$OPTARG
|
i)
|
||||||
|
IMAGETAG=$(uname -m)"-"$OPTARG
|
||||||
;;
|
;;
|
||||||
v) VERBOSE=true
|
v)
|
||||||
|
VERBOSE=true
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
# Announce what was requested
|
# Announce what was requested
|
||||||
|
|
||||||
if [ "${IF_COUCHDB}" == "couchdb" ]; then
|
if [ "${IF_COUCHDB}" == "couchdb" ]; then
|
||||||
echo
|
echo
|
||||||
echo "${EXPMODE} with channel '${CHANNEL_NAME}' and CLI timeout of '${CLI_TIMEOUT}' seconds and CLI delay of '${CLI_DELAY}' seconds and using database '${IF_COUCHDB}'"
|
echo "${EXPMODE} with channel '${CHANNEL_NAME}' and CLI timeout of '${CLI_TIMEOUT}' seconds and CLI delay of '${CLI_DELAY}' seconds and using database '${IF_COUCHDB}'"
|
||||||
else
|
else
|
||||||
echo "${EXPMODE} with channel '${CHANNEL_NAME}' and CLI timeout of '${CLI_TIMEOUT}' seconds and CLI delay of '${CLI_DELAY}' seconds"
|
echo "${EXPMODE} with channel '${CHANNEL_NAME}' and CLI timeout of '${CLI_TIMEOUT}' seconds and CLI delay of '${CLI_DELAY}' seconds"
|
||||||
fi
|
fi
|
||||||
# ask for confirmation to proceed
|
# ask for confirmation to proceed
|
||||||
askProceed
|
askProceed
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,8 @@ PEER0_ORG2_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrga
|
||||||
PEER0_ORG3_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt
|
PEER0_ORG3_CA=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt
|
||||||
|
|
||||||
# verify the result of the end-to-end test
|
# verify the result of the end-to-end test
|
||||||
verifyResult () {
|
verifyResult() {
|
||||||
if [ $1 -ne 0 ] ; then
|
if [ $1 -ne 0 ]; then
|
||||||
echo "!!!!!!!!!!!!!!! "$2" !!!!!!!!!!!!!!!!"
|
echo "!!!!!!!!!!!!!!! "$2" !!!!!!!!!!!!!!!!"
|
||||||
echo "========= ERROR !!! FAILED to execute End-2-End Scenario ==========="
|
echo "========= ERROR !!! FAILED to execute End-2-End Scenario ==========="
|
||||||
echo
|
echo
|
||||||
|
|
@ -28,10 +28,10 @@ setOrdererGlobals() {
|
||||||
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/users/Admin@example.com/msp
|
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/ordererOrganizations/example.com/users/Admin@example.com/msp
|
||||||
}
|
}
|
||||||
|
|
||||||
setGlobals () {
|
setGlobals() {
|
||||||
PEER=$1
|
PEER=$1
|
||||||
ORG=$2
|
ORG=$2
|
||||||
if [ $ORG -eq 1 ] ; then
|
if [ $ORG -eq 1 ]; then
|
||||||
CORE_PEER_LOCALMSPID="Org1MSP"
|
CORE_PEER_LOCALMSPID="Org1MSP"
|
||||||
CORE_PEER_TLS_ROOTCERT_FILE=$PEER0_ORG1_CA
|
CORE_PEER_TLS_ROOTCERT_FILE=$PEER0_ORG1_CA
|
||||||
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
|
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
|
||||||
|
|
@ -40,7 +40,7 @@ setGlobals () {
|
||||||
else
|
else
|
||||||
CORE_PEER_ADDRESS=peer1.org1.example.com:7051
|
CORE_PEER_ADDRESS=peer1.org1.example.com:7051
|
||||||
fi
|
fi
|
||||||
elif [ $ORG -eq 2 ] ; then
|
elif [ $ORG -eq 2 ]; then
|
||||||
CORE_PEER_LOCALMSPID="Org2MSP"
|
CORE_PEER_LOCALMSPID="Org2MSP"
|
||||||
CORE_PEER_TLS_ROOTCERT_FILE=$PEER0_ORG2_CA
|
CORE_PEER_TLS_ROOTCERT_FILE=$PEER0_ORG2_CA
|
||||||
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
|
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
|
||||||
|
|
@ -50,7 +50,7 @@ setGlobals () {
|
||||||
CORE_PEER_ADDRESS=peer1.org2.example.com:7051
|
CORE_PEER_ADDRESS=peer1.org2.example.com:7051
|
||||||
fi
|
fi
|
||||||
|
|
||||||
elif [ $ORG -eq 3 ] ; then
|
elif [ $ORG -eq 3 ]; then
|
||||||
CORE_PEER_LOCALMSPID="Org3MSP"
|
CORE_PEER_LOCALMSPID="Org3MSP"
|
||||||
CORE_PEER_TLS_ROOTCERT_FILE=$PEER0_ORG3_CA
|
CORE_PEER_TLS_ROOTCERT_FILE=$PEER0_ORG3_CA
|
||||||
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/users/Admin@org3.example.com/msp
|
CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org3.example.com/users/Admin@org3.example.com/msp
|
||||||
|
|
@ -64,11 +64,10 @@ setGlobals () {
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$VERBOSE" == "true" ]; then
|
if [ "$VERBOSE" == "true" ]; then
|
||||||
env |grep CORE
|
env | grep CORE
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
updateAnchorPeers() {
|
updateAnchorPeers() {
|
||||||
PEER=$1
|
PEER=$1
|
||||||
ORG=$2
|
ORG=$2
|
||||||
|
|
@ -93,7 +92,7 @@ updateAnchorPeers() {
|
||||||
}
|
}
|
||||||
|
|
||||||
## Sometimes Join takes time hence RETRY at least 5 times
|
## Sometimes Join takes time hence RETRY at least 5 times
|
||||||
joinChannelWithRetry () {
|
joinChannelWithRetry() {
|
||||||
PEER=$1
|
PEER=$1
|
||||||
ORG=$2
|
ORG=$2
|
||||||
setGlobals $PEER $ORG
|
setGlobals $PEER $ORG
|
||||||
|
|
@ -104,7 +103,7 @@ joinChannelWithRetry () {
|
||||||
set +x
|
set +x
|
||||||
cat log.txt
|
cat log.txt
|
||||||
if [ $res -ne 0 -a $COUNTER -lt $MAX_RETRY ]; then
|
if [ $res -ne 0 -a $COUNTER -lt $MAX_RETRY ]; then
|
||||||
COUNTER=` expr $COUNTER + 1`
|
COUNTER=$(expr $COUNTER + 1)
|
||||||
echo "peer${PEER}.org${ORG} failed to join the channel, Retry after $DELAY seconds"
|
echo "peer${PEER}.org${ORG} failed to join the channel, Retry after $DELAY seconds"
|
||||||
sleep $DELAY
|
sleep $DELAY
|
||||||
joinChannelWithRetry $PEER $ORG
|
joinChannelWithRetry $PEER $ORG
|
||||||
|
|
@ -114,7 +113,7 @@ joinChannelWithRetry () {
|
||||||
verifyResult $res "After $MAX_RETRY attempts, peer${PEER}.org${ORG} has failed to join channel '$CHANNEL_NAME' "
|
verifyResult $res "After $MAX_RETRY attempts, peer${PEER}.org${ORG} has failed to join channel '$CHANNEL_NAME' "
|
||||||
}
|
}
|
||||||
|
|
||||||
installChaincode () {
|
installChaincode() {
|
||||||
PEER=$1
|
PEER=$1
|
||||||
ORG=$2
|
ORG=$2
|
||||||
setGlobals $PEER $ORG
|
setGlobals $PEER $ORG
|
||||||
|
|
@ -129,7 +128,7 @@ installChaincode () {
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
instantiateChaincode () {
|
instantiateChaincode() {
|
||||||
PEER=$1
|
PEER=$1
|
||||||
ORG=$2
|
ORG=$2
|
||||||
setGlobals $PEER $ORG
|
setGlobals $PEER $ORG
|
||||||
|
|
@ -155,7 +154,7 @@ instantiateChaincode () {
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
upgradeChaincode () {
|
upgradeChaincode() {
|
||||||
PEER=$1
|
PEER=$1
|
||||||
ORG=$2
|
ORG=$2
|
||||||
setGlobals $PEER $ORG
|
setGlobals $PEER $ORG
|
||||||
|
|
@ -170,7 +169,7 @@ upgradeChaincode () {
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
chaincodeQuery () {
|
chaincodeQuery() {
|
||||||
PEER=$1
|
PEER=$1
|
||||||
ORG=$2
|
ORG=$2
|
||||||
setGlobals $PEER $ORG
|
setGlobals $PEER $ORG
|
||||||
|
|
@ -181,10 +180,11 @@ chaincodeQuery () {
|
||||||
|
|
||||||
# continue to poll
|
# continue to poll
|
||||||
# we either get a successful response, or reach TIMEOUT
|
# we either get a successful response, or reach TIMEOUT
|
||||||
while test "$(($(date +%s)-starttime))" -lt "$TIMEOUT" -a $rc -ne 0
|
while
|
||||||
|
test "$(($(date +%s) - starttime))" -lt "$TIMEOUT" -a $rc -ne 0
|
||||||
do
|
do
|
||||||
sleep $DELAY
|
sleep $DELAY
|
||||||
echo "Attempting to Query peer${PEER}.org${ORG} ...$(($(date +%s)-starttime)) secs"
|
echo "Attempting to Query peer${PEER}.org${ORG} ...$(($(date +%s) - starttime)) secs"
|
||||||
set -x
|
set -x
|
||||||
peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}' >&log.txt
|
peer chaincode query -C $CHANNEL_NAME -n mycc -c '{"Args":["query","a"]}' >&log.txt
|
||||||
res=$?
|
res=$?
|
||||||
|
|
@ -199,7 +199,7 @@ chaincodeQuery () {
|
||||||
done
|
done
|
||||||
echo
|
echo
|
||||||
cat log.txt
|
cat log.txt
|
||||||
if test $rc -eq 0 ; then
|
if test $rc -eq 0; then
|
||||||
echo "===================== Query successful on peer${PEER}.org${ORG} on channel '$CHANNEL_NAME' ===================== "
|
echo "===================== Query successful on peer${PEER}.org${ORG} on channel '$CHANNEL_NAME' ===================== "
|
||||||
else
|
else
|
||||||
echo "!!!!!!!!!!!!!!! Query result on peer${PEER}.org${ORG} is INVALID !!!!!!!!!!!!!!!!"
|
echo "!!!!!!!!!!!!!!! Query result on peer${PEER}.org${ORG} is INVALID !!!!!!!!!!!!!!!!"
|
||||||
|
|
@ -230,7 +230,7 @@ fetchChannelConfig() {
|
||||||
|
|
||||||
echo "Decoding config block to JSON and isolating config to ${OUTPUT}"
|
echo "Decoding config block to JSON and isolating config to ${OUTPUT}"
|
||||||
set -x
|
set -x
|
||||||
configtxlator proto_decode --input config_block.pb --type common.Block | jq .data.data[0].payload.data.config > "${OUTPUT}"
|
configtxlator proto_decode --input config_block.pb --type common.Block | jq .data.data[0].payload.data.config >"${OUTPUT}"
|
||||||
set +x
|
set +x
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -255,12 +255,12 @@ createConfigUpdate() {
|
||||||
OUTPUT=$4
|
OUTPUT=$4
|
||||||
|
|
||||||
set -x
|
set -x
|
||||||
configtxlator proto_encode --input "${ORIGINAL}" --type common.Config > original_config.pb
|
configtxlator proto_encode --input "${ORIGINAL}" --type common.Config >original_config.pb
|
||||||
configtxlator proto_encode --input "${MODIFIED}" --type common.Config > modified_config.pb
|
configtxlator proto_encode --input "${MODIFIED}" --type common.Config >modified_config.pb
|
||||||
configtxlator compute_update --channel_id "${CHANNEL}" --original original_config.pb --updated modified_config.pb > config_update.pb
|
configtxlator compute_update --channel_id "${CHANNEL}" --original original_config.pb --updated modified_config.pb >config_update.pb
|
||||||
configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate > config_update.json
|
configtxlator proto_decode --input config_update.pb --type common.ConfigUpdate >config_update.json
|
||||||
echo '{"payload":{"header":{"channel_header":{"channel_id":"'$CHANNEL'", "type":2}},"data":{"config_update":'$(cat config_update.json)'}}}' | jq . > config_update_in_envelope.json
|
echo '{"payload":{"header":{"channel_header":{"channel_id":"'$CHANNEL'", "type":2}},"data":{"config_update":'$(cat config_update.json)'}}}' | jq . >config_update_in_envelope.json
|
||||||
configtxlator proto_encode --input config_update_in_envelope.json --type common.Envelope > "${OUTPUT}"
|
configtxlator proto_encode --input config_update_in_envelope.json --type common.Envelope >"${OUTPUT}"
|
||||||
set +x
|
set +x
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -270,7 +270,7 @@ createConfigUpdate() {
|
||||||
# peers and associated org, then sets $PEER_CONN_PARMS and $PEERS
|
# peers and associated org, then sets $PEER_CONN_PARMS and $PEERS
|
||||||
parsePeerConnectionParameters() {
|
parsePeerConnectionParameters() {
|
||||||
# check for uneven number of peer and org parameters
|
# check for uneven number of peer and org parameters
|
||||||
if [ $(( $# % 2 )) -ne 0 ]; then
|
if [ $(($# % 2)) -ne 0 ]; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
@ -285,7 +285,8 @@ parsePeerConnectionParameters() {
|
||||||
PEER_CONN_PARMS="$PEER_CONN_PARMS $TLSINFO"
|
PEER_CONN_PARMS="$PEER_CONN_PARMS $TLSINFO"
|
||||||
fi
|
fi
|
||||||
# shift by two to get the next pair of peer/org parameters
|
# shift by two to get the next pair of peer/org parameters
|
||||||
shift; shift
|
shift
|
||||||
|
shift
|
||||||
done
|
done
|
||||||
# remove leading space for output
|
# remove leading space for output
|
||||||
PEERS="$(echo -e "$PEERS" | sed -e 's/^[[:space:]]*//')"
|
PEERS="$(echo -e "$PEERS" | sed -e 's/^[[:space:]]*//')"
|
||||||
|
|
@ -293,7 +294,7 @@ parsePeerConnectionParameters() {
|
||||||
|
|
||||||
# chaincodeInvoke <peer> <org> ...
|
# chaincodeInvoke <peer> <org> ...
|
||||||
# Accepts as many peer/org pairs as desired and requests endorsement from each
|
# Accepts as many peer/org pairs as desired and requests endorsement from each
|
||||||
chaincodeInvoke () {
|
chaincodeInvoke() {
|
||||||
parsePeerConnectionParameters $@
|
parsePeerConnectionParameters $@
|
||||||
res=$?
|
res=$?
|
||||||
verifyResult $res "Invoke transaction failed on channel '$CHANNEL_NAME' due to uneven number of peer and org parameters "
|
verifyResult $res "Invoke transaction failed on channel '$CHANNEL_NAME' due to uneven number of peer and org parameters "
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue