github.com/inklabsfoundation/inkchain@v0.17.1-0.20181025012015-c3cef8062f19/examples/creative/scripts/func_init.sh (about)

     1  #!/usr/bin/env bash
     2  #
     3  #Copyright Ziggurat Corp. 2017 All Rights Reserved.
     4  #
     5  #SPDX-License-Identifier: Apache-2.0
     6  #
     7  
     8  ## DO NOT MODIFY THE FOLLOWING PART, UNLESS YOU KNOW WHAT IT MEANS ##
     9  echo_r () {
    10      [ $# -ne 1 ] && return 0
    11      echo -e "\033[31m$1\033[0m"
    12  }
    13  echo_g () {
    14      [ $# -ne 1 ] && return 0
    15      echo -e "\033[32m$1\033[0m"
    16  }
    17  echo_y () {
    18      [ $# -ne 1 ] && return 0
    19      echo -e "\033[33m$1\033[0m"
    20  }
    21  echo_b () {
    22      [ $# -ne 1 ] && return 0
    23      echo -e "\033[34m$1\033[0m"
    24  }
    25  
    26  CHANNEL_NAME="$1"
    27  : ${CHANNEL_NAME:="mychannel"}
    28  : ${TIMEOUT:="60"}
    29  COUNTER=0
    30  MAX_RETRY=5
    31  
    32  CC_PATH=github.com/inklabsfoundation/inkchain/examples
    33  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
    34  ARTIFACTS_PWD=/opt/gopath/src/github.com/inklabsfoundation/inkchain/peer/channel-artifacts
    35  SERVICE_CHARGE="10"
    36  
    37  verifyResult () {
    38      if [ $1 -ne 0 ] ; then
    39          echo_b "!!!!!!!!!!!!!!! "$2" !!!!!!!!!!!!!!!!"
    40          echo_r "================== ERROR !!! FAILED to execute MVE =================="
    41          echo
    42          exit 1
    43      fi
    44  }
    45  
    46  USER_TOKEN_01="70698e364537a106b5aa5332d660e2234b37eebcb3768a2a97ffb8042dfe2fc4"
    47  USER_ADDRESS_01="07caf88941eafcaaa3370657fccc261acb75dfba"
    48  
    49  USER_TOKEN_02="bc4bcb06a0793961aec4ee377796e050561b6a84852deccea5ad4583bb31eebe"
    50  USER_ADDRESS_02="4230a12f5b0693dd88bb35c79d7e56a68614b199"
    51  
    52  USER_TOKEN_03="344c267e5acb2ac9107465fc85eba24cbb17509e918c3cc3f5098dddf42167e5"
    53  USER_ADDRESS_03="a5ff00eb44bf19d5dfbde501c90e286badb58df4"
    54  
    55  createChannel() {
    56      peer channel create -o orderer.example.com:7050 -c ${CHANNEL_NAME} -f ${ARTIFACTS_PWD}/mychannel.tx --tls $CORE_PEER_TLS_ENABLED --cafile ${ORDERER_CA} >&log.txt
    57      res=$?
    58      cat log.txt
    59  
    60      verifyResult $res "Channel creation failed"
    61      echo
    62      # verify file mychannel.block exist
    63      if [ -s mychannel.block ]; then
    64          res=$?
    65          verifyResult $res "Channel created failed"
    66      fi
    67          echo_g "================channel \"$CHANNEL_NAME\" is created successfully ==============="
    68  }
    69  
    70  joinChannel () {
    71      echo_b "===================== PEER0 joined on the channel \"$CHANNEL_NAME\" ===================== "
    72      peer channel join -b ${CHANNEL_NAME}.block -o orderer.example.com:7050 >&log.txt
    73      res=$?
    74      cat log.txt
    75      if [ $res -ne 0 -a $COUNTER -lt $MAX_RETRY ]; then
    76          COUNTER=` expr $COUNTER + 1`
    77          echo_r "PEER0 failed to join the channel, Retry after 2 seconds"
    78          sleep 2
    79          joinWithRetry
    80      else
    81          COUNTER=0
    82      fi
    83          verifyResult $res "After $MAX_RETRY attempts, PEER0 has failed to Join the Channel"
    84  }
    85  
    86  updateAnchorPeers() {
    87      peer channel create -o orderer.example.com:7050  --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C ${CHANNEL_NAME} -f ${ARTIFACTS_PWD}/Org1MSPanchors.tx >&log.txt
    88      res=$?
    89      cat log.txt
    90      verifyResult $res "Anchor peer update failed"
    91      echo_g "==== Anchor peers for org1 on mychannel is updated successfully======"
    92      echo
    93  }
    94  
    95  # installChaincode token 1.0
    96  # installChaincode creative 1.0
    97  installChaincode () {
    98      peer chaincode install -n $1 -v $2 -p ${CC_PATH}/$1 -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 token 1.0
   107  # instantiateChaincode creative 1.0
   108  instantiateChaincode () {
   109      local starttime=$(date +%s)
   110      peer chaincode instantiate -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C ${CHANNEL_NAME} -n $1 -v $2 -c '{"Args":["init"]}' -P "OR ('Org1MSP.member')" >&log.txt
   111      res=$?
   112      cat log.txt
   113      verifyResult $res "Chaincode instantiation on pee0.org1 on channel "$CHANNEL_NAME" failed"
   114      echo_g "=========== Chaincode token Instantiation on peer0.org1 on channel "$CHANNEL_NAME" is successful ========== "
   115      echo_b "Instantiate spent $(($(date +%s)-starttime)) secs"
   116      echo
   117  }
   118  
   119  # upgradeChaincode creative 2.0
   120  upgradeChaincode () {
   121      local starttime=$(date +%s)
   122      peer chaincode upgrade -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C ${CHANNEL_NAME} -n $1 -v $2 -c '{"Args":["init"]}' -P "OR ('Org1MSP.member')" >&log.txt
   123      res=$?
   124      cat log.txt
   125      verifyResult $res "Chaincode instantiation on pee0.org1 on channel "$CHANNEL_NAME" failed"
   126      echo_g "=========== Chaincode token Instantiation on peer0.org1 on channel "$CHANNEL_NAME" is successful ========== "
   127      echo_b "Instantiate spent $(($(date +%s)-starttime)) secs"
   128      echo
   129  }