github.com/inklabsfoundation/inkchain@v0.17.1-0.20181025012015-c3cef8062f19/examples/cli_test/scripts/initialization.sh (about) 1 #!/bin/bash 2 # 3 #Copyright Ziggurat Corp. 2017 All Rights Reserved. 4 # 5 #SPDX-License-Identifier: Apache-2.0 6 # 7 8 # Detecting whether can import the header file to render colorful cli output 9 if [ -f ./header.sh ]; then 10 source ./header.sh 11 elif [ -f scripts/header.sh ]; then 12 source scripts/header.sh 13 else 14 alias echo_r="echo" 15 alias echo_g="echo" 16 alias echo_b="echo" 17 fi 18 19 CHANNEL_NAME="$1" 20 : ${CHANNEL_NAME:="mychannel"} 21 : ${TIMEOUT:="60"} 22 COUNTER=0 23 MAX_RETRY=5 24 TOKEN_CC_PATH=github.com/inklabsfoundation/inkchain/examples/chaincode/go/token 25 MARBLES_CC_PATH=github.com/inklabsfoundation/inkchain/examples/chaincode/go/marbles 26 ASSET_CC_PATH=github.com/inklabsfoundation/inkchain/examples/chaincode/go/asset 27 CAT_CC_PATH=github.com/inklabsfoundation/inkchain/examples/chaincode/go/cat 28 INKWORK_CC_PATH=github.com/inklabsfoundation/inkchain/examples/chaincode/go/inkwork 29 GUIDE_CC_PATH=github.com/inklabsfoundation/inkchain/examples/chaincode/go/guide_credit 30 STUDENT_CC_PATH=github.com/inklabsfoundation/inkchain/examples/chaincode/go/student 31 ORDERER_CA=/opt/gopath/src/github.com/inklabsfoundation/inkchain/peer/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem 32 33 echo_b "Chaincode Path : " $CC_PATH 34 echo_b "Channel name : " $CHANNEL_NAME 35 36 verifyResult () { 37 if [ $1 -ne 0 ] ; then 38 echo_b "!!!!!!!!!!!!!!! "$2" !!!!!!!!!!!!!!!!" 39 echo_r "================== ERROR !!! FAILED to execute MVE ==================" 40 echo 41 exit 1 42 fi 43 } 44 45 createChannel() { 46 peer channel create -o orderer.example.com:7050 -c ${CHANNEL_NAME} -f ./channel-artifacts/mychannel.tx --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA >&log.txt 47 res=$? 48 cat log.txt 49 50 verifyResult $res "Channel creation failed" 51 echo 52 # verify file mychannel.block exist 53 if [ -s mychannel.block ]; then 54 res=$? 55 verifyResult $res "Channel created failed" 56 fi 57 echo_g "================channel \"$CHANNEL_NAME\" is created successfully ===============" 58 } 59 60 ## Sometimes Join takes time hence RETRY atleast for 5 times 61 62 joinChannel () { 63 echo_b "===================== PEER0 joined on the channel \"$CHANNEL_NAME\" ===================== " 64 peer channel join -b ${CHANNEL_NAME}.block -o orderer.example.com:7050 >&log.txt 65 res=$? 66 cat log.txt 67 if [ $res -ne 0 -a $COUNTER -lt $MAX_RETRY ]; then 68 COUNTER=` expr $COUNTER + 1` 69 echo_r "PEER0 failed to join the channel, Retry after 2 seconds" 70 sleep 2 71 joinWithRetry 72 else 73 COUNTER=0 74 fi 75 verifyResult $res "After $MAX_RETRY attempts, PEER0 has failed to Join the Channel" 76 } 77 78 updateAnchorPeers() { 79 peer channel create -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C ${CHANNEL_NAME} -f ./channel-artifacts/Org1MSPanchors.tx >&log.txt 80 res=$? 81 cat log.txt 82 verifyResult $res "Anchor peer update failed" 83 echo_g "==== Anchor peers for org1 on mychannel is updated successfully======" 84 echo 85 } 86 87 installChaincode () { 88 peer chaincode install -n token -v 1.0 -p ${TOKEN_CC_PATH} -o orderer.example.com:7050 >&log.txt 89 90 #peer chaincode install -n marbles -v 1.0 -p ${MARBLES_CC_PATH} -o orderer.example.com:7050 >&log.txt 91 92 peer chaincode install -n asset -v 1.0 -p ${ASSET_CC_PATH} -o orderer.example.com:7050 >&log.txt 93 94 #peer chaincode install -n cat -v 1.0 -p ${CAT_CC_PATH} -o orderer.example.com:7050 >&log.txt 95 96 #peer chaincode install -n inkwork -v 1.0 -p ${INKWORK_CC_PATH} -o orderer.example.com:7050 >&log.txt 97 #peer chaincode install -n guide -v 1.0 -p ${GUIDE_CC_PATH} -o orderer.example.com:7050 >&log.txt 98 #peer chaincode install -n student -v 1.0 -p ${STUDENT_CC_PATH} -o orderer.example.com:7050 >&log.txt 99 res=$? 100 cat log.txt 101 verifyResult $res "Chaincode token installation on remote peer0 has Failed" 102 echo_g "===================== Chaincode is installed success on remote peer0===================== " 103 echo 104 } 105 106 instantiateChaincode () { 107 local starttime=$(date +%s) 108 peer chaincode instantiate -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C ${CHANNEL_NAME} -n token -v 1.0 -c '{"Args":["init"]}' -P "OR ('Org1MSP.member')" >&log.txt 109 #peer chaincode instantiate -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C ${CHANNEL_NAME} -n marbles -v 1.0 -c '{"Args":["initMarble","marble1","blue","35","tom"]}' -P "OR ('Org1MSP.member')" >&log.txt 110 #peer chaincode instantiate -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C ${CHANNEL_NAME} -n marbles -v 1.0 -c '{"Args":["init"]}' -P "OR ('Org1MSP.member')" >&log.txt 111 peer chaincode instantiate -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C ${CHANNEL_NAME} -n asset -v 1.0 -c '{"Args":["init"]}' -P "OR ('Org1MSP.member')" >&log.txt 112 #peer chaincode instantiate -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C ${CHANNEL_NAME} -n cat -v 1.0 -c '{"Args":["init","5","5","6","60","INK","i07caf88941eafcaaa3370657fccc261acb75dfba"]}' -P "OR ('Org1MSP.member')" >&log.txt 113 #peer chaincode instantiate -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C ${CHANNEL_NAME} -n inkwork -v 1.0 -c '{"Args":["init","i07caf88941eafcaaa3370657fccc261acb75dfba","INK"]}' -P "OR ('Org1MSP.member')" >&log.txt 114 #peer chaincode instantiate -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C ${CHANNEL_NAME} -n guide -v 1.0 -c '{"Args":["init"]}' -P "OR ('Org1MSP.member')" >&log.txt 115 #peer chaincode instantiate -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C ${CHANNEL_NAME} -n student -v 1.0 -c '{"Args":["init"]}' -P "OR ('Org1MSP.member')" >&log.txt 116 res=$? 117 cat log.txt 118 verifyResult $res "Chaincode instantiation on pee0.org1 on channel '$CHANNEL_NAME' failed" 119 echo_g "=========== Chaincode token Instantiation on peer0.org1 on channel '$CHANNEL_NAME' is successful ========== " 120 echo_b "Instantiate spent $(($(date +%s)-starttime)) secs" 121 echo 122 } 123 124 echo_b "====================1.Create channel(default newchannel) =============================" 125 createChannel 126 127 echo_b "====================2.Join pee0 to the channel ======================================" 128 joinChannel 129 130 echo_b "====================3.set anchor peers for org1 in the channel===========================" 131 #updateAnchorPeers 132 133 echo_b "=====================4.Install chaincode token on Peer0/Org0========================" 134 installChaincode 135 136 echo_b "=====================5.Instantiate chaincode token, this will take a while, pls waiting...===" 137 instantiateChaincode 138 139 echo 140 echo_g "=====================All GOOD, MVE initialization completed ===================== " 141 echo 142 exit 0