Advertisement
Guest User

Untitled

a guest
Sep 17th, 2019
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.81 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # Copyright IBM Corp All Rights Reserved
  4. #
  5. # SPDX-License-Identifier: Apache-2.0
  6. #
  7. # Exit on first error
  8. set -e
  9.  
  10. # don't rewrite paths for Windows Git Bash users
  11. export MSYS_NO_PATHCONV=1
  12. starttime=$(date +%s)
  13. CC_SRC_LANGUAGE=${1:-"go"}
  14. CC_SRC_LANGUAGE=`echo "$CC_SRC_LANGUAGE" | tr [:upper:] [:lower:]`
  15. if [ "$CC_SRC_LANGUAGE" = "go" -o "$CC_SRC_LANGUAGE" = "golang" ]; then
  16. CC_RUNTIME_LANGUAGE=golang
  17. CC_SRC_PATH=github.com/chaincode/fabcar/go
  18. elif [ "$CC_SRC_LANGUAGE" = "java" ]; then
  19. CC_RUNTIME_LANGUAGE=java
  20. CC_SRC_PATH=/opt/gopath/src/github.com/chaincode/fabcar/java
  21. elif [ "$CC_SRC_LANGUAGE" = "javascript" ]; then
  22. CC_RUNTIME_LANGUAGE=node # chaincode runtime language is node.js
  23. CC_SRC_PATH=/opt/gopath/src/github.com/chaincode/fabcar/javascript
  24. elif [ "$CC_SRC_LANGUAGE" = "typescript" ]; then
  25. CC_RUNTIME_LANGUAGE=node # chaincode runtime language is node.js
  26. CC_SRC_PATH=/opt/gopath/src/github.com/chaincode/fabcar/typescript
  27. echo Compiling TypeScript code into JavaScript ...
  28. pushd ../chaincode/fabcar/typescript
  29. npm install
  30. npm run build
  31. popd
  32. echo Finished compiling TypeScript code into JavaScript
  33. else
  34. echo The chaincode language ${CC_SRC_LANGUAGE} is not supported by this script
  35. echo Supported chaincode languages are: go, javascript, and typescript
  36. exit 1
  37. fi
  38.  
  39.  
  40. # clean the keystore
  41. rm -rf ./hfc-key-store
  42.  
  43. # launch network; create channel and join peer to channel
  44. cd ../first-network
  45. echo y | ./byfn.sh down
  46. echo y | ./byfn.sh up -a -n -s couchdb
  47.  
  48. CONFIG_ROOT=/opt/gopath/src/github.com/hyperledger/fabric/peer
  49. ORG1_MSPCONFIGPATH=${CONFIG_ROOT}/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
  50. ORG1_TLS_ROOTCERT_FILE=${CONFIG_ROOT}/crypto/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
  51. ORG2_MSPCONFIGPATH=${CONFIG_ROOT}/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
  52. ORG2_TLS_ROOTCERT_FILE=${CONFIG_ROOT}/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
  53. ORDERER_TLS_ROOTCERT_FILE=${CONFIG_ROOT}/crypto/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
  54. set -x
  55.  
  56. echo "Installing smart contract on peer0.org1.example.com"
  57. docker exec \
  58. -e CORE_PEER_LOCALMSPID=Org1MSP \
  59. -e CORE_PEER_ADDRESS=peer0.org1.example.com:7051 \
  60. -e CORE_PEER_MSPCONFIGPATH=${ORG1_MSPCONFIGPATH} \
  61. -e CORE_PEER_TLS_ROOTCERT_FILE=${ORG1_TLS_ROOTCERT_FILE} \
  62. cli \
  63. peer chaincode install \
  64. -n fabcar \
  65. -v 1.0 \
  66. -p "$CC_SRC_PATH" \
  67. -l "$CC_RUNTIME_LANGUAGE"
  68.  
  69. echo "Installing smart contract on peer1.org1.example.com"
  70. docker exec \
  71. -e CORE_PEER_LOCALMSPID=Org1MSP \
  72. -e CORE_PEER_ADDRESS=peer1.org1.example.com:8051 \
  73. -e CORE_PEER_MSPCONFIGPATH=${ORG1_MSPCONFIGPATH} \
  74. -e CORE_PEER_TLS_ROOTCERT_FILE=${ORG1_TLS_ROOTCERT_FILE} \
  75. cli \
  76. peer chaincode install \
  77. -n fabcar \
  78. -v 1.0 \
  79. -p "$CC_SRC_PATH" \
  80. -l "$CC_RUNTIME_LANGUAGE"
  81.  
  82. echo "Installing smart contract on peer0.org2.example.com"
  83. docker exec \
  84. -e CORE_PEER_LOCALMSPID=Org2MSP \
  85. -e CORE_PEER_ADDRESS=peer0.org2.example.com:9051 \
  86. -e CORE_PEER_MSPCONFIGPATH=${ORG2_MSPCONFIGPATH} \
  87. -e CORE_PEER_TLS_ROOTCERT_FILE=${ORG2_TLS_ROOTCERT_FILE} \
  88. cli \
  89. peer chaincode install \
  90. -n fabcar \
  91. -v 1.0 \
  92. -p "$CC_SRC_PATH" \
  93. -l "$CC_RUNTIME_LANGUAGE"
  94.  
  95. echo "Installing smart contract on peer1.org2.example.com"
  96. docker exec \
  97. -e CORE_PEER_LOCALMSPID=Org2MSP \
  98. -e CORE_PEER_ADDRESS=peer1.org2.example.com:10051 \
  99. -e CORE_PEER_MSPCONFIGPATH=${ORG2_MSPCONFIGPATH} \
  100. -e CORE_PEER_TLS_ROOTCERT_FILE=${ORG2_TLS_ROOTCERT_FILE} \
  101. cli \
  102. peer chaincode install \
  103. -n fabcar \
  104. -v 1.0 \
  105. -p "$CC_SRC_PATH" \
  106. -l "$CC_RUNTIME_LANGUAGE"
  107.  
  108. echo "Instantiating smart contract on mychannel"
  109. docker exec \
  110. -e CORE_PEER_LOCALMSPID=Org1MSP \
  111. -e CORE_PEER_MSPCONFIGPATH=${ORG1_MSPCONFIGPATH} \
  112. cli \
  113. peer chaincode instantiate \
  114. -o orderer.example.com:7050 \
  115. -C mychannel \
  116. -n fabcar \
  117. -l "$CC_RUNTIME_LANGUAGE" \
  118. -v 1.0 \
  119. -c '{"Args":[]}' \
  120. -P "AND('Org1MSP.member','Org2MSP.member')" \
  121. --tls \
  122. --cafile ${ORDERER_TLS_ROOTCERT_FILE} \
  123. --peerAddresses peer0.org1.example.com:7051 \
  124. --tlsRootCertFiles ${ORG1_TLS_ROOTCERT_FILE}
  125.  
  126. echo "Waiting for instantiation request to be committed ..."
  127. sleep 10
  128.  
  129. echo "Submitting initLedger transaction to smart contract on mychannel"
  130. echo "The transaction is sent to all of the peers so that chaincode is built before receiving the following requests"
  131. docker exec \
  132. -e CORE_PEER_LOCALMSPID=Org1MSP \
  133. -e CORE_PEER_MSPCONFIGPATH=${ORG1_MSPCONFIGPATH} \
  134. cli \
  135. peer chaincode invoke \
  136. -o orderer.example.com:7050 \
  137. -C mychannel \
  138. -n fabcar \
  139. -c '{"function":"initLedger","Args":[]}' \
  140. --waitForEvent \
  141. --tls \
  142. --cafile ${ORDERER_TLS_ROOTCERT_FILE} \
  143. --peerAddresses peer0.org1.example.com:7051 \
  144. --peerAddresses peer1.org1.example.com:8051 \
  145. --peerAddresses peer0.org2.example.com:9051 \
  146. --peerAddresses peer1.org2.example.com:10051 \
  147. --tlsRootCertFiles ${ORG1_TLS_ROOTCERT_FILE} \
  148. --tlsRootCertFiles ${ORG1_TLS_ROOTCERT_FILE} \
  149. --tlsRootCertFiles ${ORG2_TLS_ROOTCERT_FILE} \
  150. --tlsRootCertFiles ${ORG2_TLS_ROOTCERT_FILE}
  151. set +x
  152.  
  153. cat <<EOF
  154.  
  155. Total setup execution time : $(($(date +%s) - starttime)) secs ...
  156.  
  157. Next, use the FabCar applications to interact with the deployed FabCar contract.
  158. The FabCar applications are available in multiple programming languages.
  159. Follow the instructions for the programming language of your choice:
  160.  
  161. JavaScript:
  162.  
  163. Start by changing into the "javascript" directory:
  164. cd javascript
  165.  
  166. Next, install all required packages:
  167. npm install
  168.  
  169. Then run the following applications to enroll the admin user, and register a new user
  170. called user1 which will be used by the other applications to interact with the deployed
  171. FabCar contract:
  172. node enrollAdmin
  173. node registerUser
  174.  
  175. You can run the invoke application as follows. By default, the invoke application will
  176. create a new car, but you can update the application to submit other transactions:
  177. node invoke
  178.  
  179. You can run the query application as follows. By default, the query application will
  180. return all cars, but you can update the application to evaluate other transactions:
  181. node query
  182.  
  183. TypeScript:
  184.  
  185. Start by changing into the "typescript" directory:
  186. cd typescript
  187.  
  188. Next, install all required packages:
  189. npm install
  190.  
  191. Next, compile the TypeScript code into JavaScript:
  192. npm run build
  193.  
  194. Then run the following applications to enroll the admin user, and register a new user
  195. called user1 which will be used by the other applications to interact with the deployed
  196. FabCar contract:
  197. node dist/enrollAdmin
  198. node dist/registerUser
  199.  
  200. You can run the invoke application as follows. By default, the invoke application will
  201. create a new car, but you can update the application to submit other transactions:
  202. node dist/invoke
  203.  
  204. You can run the query application as follows. By default, the query application will
  205. return all cars, but you can update the application to evaluate other transactions:
  206. node dist/query
  207.  
  208. Java:
  209.  
  210. Start by changing into the "java" directory:
  211. cd java
  212.  
  213. Then, install dependencies and run the test using:
  214. mvn test
  215.  
  216. The test will invoke the sample client app which perform the following:
  217. - Enroll admin and user1 and import them into the wallet (if they don't already exist there)
  218. - Submit a transaction to create a new car
  219. - Evaluate a transaction (query) to return details of this car
  220. - Submit a transaction to change the owner of this car
  221. - Evaluate a transaction (query) to return the updated details of this car
  222.  
  223. EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement