SHOW:
|
|
- or go back to the newest paste.
| 1 | #!/bin/bash | |
| 2 | ||
| 3 | # Navigate to the Projects directory | |
| 4 | cd ~/Projects/ | |
| 5 | ||
| 6 | # Set up environment variables for Fabric binaries and configuration files | |
| 7 | export PATH=${PWD}/../bin:$PATH
| |
| 8 | export FABRIC_CFG_PATH=$PWD/../config/ | |
| 9 | ||
| 10 | # Check if Homebrew is installed | |
| 11 | if ! command -v brew &> /dev/null | |
| 12 | then | |
| 13 | echo "Homebrew could not be found. Please install Homebrew and rerun the script." | |
| 14 | exit 1 | |
| 15 | fi | |
| 16 | ||
| 17 | # Install Go | |
| 18 | brew install go | |
| 19 | if [ $? -ne 0 ]; then | |
| 20 | echo "Error installing Go. Exiting." | |
| 21 | exit 1 | |
| 22 | fi | |
| 23 | ||
| 24 | # Verify Go installation | |
| 25 | go version | |
| 26 | if [ $? -ne 0 ]; then | |
| 27 | echo "Go installation verification failed. Exiting." | |
| 28 | exit 1 | |
| 29 | fi | |
| 30 | ||
| 31 | # Clone Hyperledger Fabric samples | |
| 32 | git clone https://github.com/hyperledger/fabric-samples.git | |
| 33 | if [ $? -ne 0 ]; then | |
| 34 | - | cd fabric-samples |
| 34 | + | |
| 35 | exit 1 | |
| 36 | fi | |
| 37 | ||
| 38 | # Download Fabric binaries and Docker images | |
| 39 | curl -sSL https://bit.ly/2ysbOFE | bash -s | |
| 40 | if [ $? -ne 0 ]; then | |
| 41 | echo "Error downloading Fabric binaries and Docker images. Exiting." | |
| 42 | exit 1 | |
| 43 | fi | |
| 44 | - | cd fabric-samples/test-network |
| 44 | + | |
| 45 | # Navigate to the test network directory | |
| 46 | cd ./fabric-samples/test-network | |
| 47 | ||
| 48 | # Bring up the Fabric test network | |
| 49 | ./network.sh up createChannel | |
| 50 | if [ $? -ne 0 ]; then | |
| 51 | echo "Error bringing up Fabric network. Exiting." | |
| 52 | exit 1 | |
| 53 | fi | |
| 54 | ||
| 55 | # Set environment variables for Org1 | |
| 56 | export CORE_PEER_TLS_ENABLED=true | |
| 57 | export CORE_PEER_LOCALMSPID="Org1MSP" | |
| 58 | export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
| |
| 59 | export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/[email protected]/msp
| |
| 60 | export CORE_PEER_ADDRESS=localhost:7051 | |
| 61 | ||
| 62 | # Package and install chaincode on Org1 | |
| 63 | peer lifecycle chaincode package basic.tar.gz --path ../asset-transfer-basic/chaincode-go --lang golang --label basic_1.0 | |
| 64 | if [ $? -ne 0 ]; then | |
| 65 | echo "Error packaging chaincode. Exiting." | |
| 66 | exit 1 | |
| 67 | fi | |
| 68 | peer lifecycle chaincode install basic.tar.gz | |
| 69 | if [ $? -ne 0 ]; then | |
| 70 | echo "Error installing chaincode. Exiting." | |
| 71 | exit 1 | |
| 72 | fi | |
| 73 | ||
| 74 | # Query Org1, to verify that the correct sequence number is updated | |
| 75 | export CORE_PEER_LOCALMSPID="Org1MSP" | |
| 76 | export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
| |
| 77 | export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/[email protected]/msp
| |
| 78 | export CORE_PEER_ADDRESS=localhost:7051 | |
| 79 | ||
| 80 | | grep -q 'Version: 1.0, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc, Approvals: \[Org1MSP: true\]' | |
| 81 | if [ $? -ne 0 ]; then | |
| 82 | echo "Error: Chaincode is not committed with expected parameters for Org1. Exiting." | |
| 83 | exit 1 | |
| 84 | fi | |
| 85 | ||
| 86 | # Set environment variables for Org2 | |
| 87 | export CORE_PEER_LOCALMSPID="Org2MSP" | |
| 88 | export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
| |
| 89 | export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org2.example.com/users/[email protected]/msp
| |
| 90 | export CORE_PEER_ADDRESS=localhost:9051 | |
| 91 | ||
| 92 | # Install chaincode on Org2 | |
| 93 | peer lifecycle chaincode install basic.tar.gz | |
| 94 | ||
| 95 | # Query Org2, to verify that the correct sequence number is updated | |
| 96 | export CORE_PEER_LOCALMSPID="Org2MSP" | |
| 97 | export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
| |
| 98 | export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org2.example.com/users/[email protected]/msp
| |
| 99 | export CORE_PEER_ADDRESS=localhost:9051 | |
| 100 | ||
| 101 | | grep -q 'Version: 1.0, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc, Approvals: \[Org2MSP: true\]' | |
| 102 | if [ $? -ne 0 ]; then | |
| 103 | echo "Error: Chaincode is not committed with expected parameters for Org2. Exiting." | |
| 104 | exit 1 | |
| 105 | fi | |
| 106 | ||
| 107 | # Approve chaincode definition for Org1 | |
| 108 | export PACKAGE_ID=$(peer lifecycle chaincode queryinstalled | grep -o 'Package ID: \S*' | awk '{print $3}')
| |
| 109 | export CORE_PEER_LOCALMSPID="Org1MSP" | |
| 110 | export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
| |
| 111 | export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/[email protected]/msp
| |
| 112 | export CORE_PEER_ADDRESS=localhost:7051 | |
| 113 | ||
| 114 | peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name basic --version 1.0 --package-id $PACKAGE_ID --sequence 1 --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
| |
| 115 | if [ $? -ne 0 ]; then | |
| 116 | echo "Error approving chaincode definition. Exiting." | |
| 117 | exit 1 | |
| 118 | fi | |
| 119 | ||
| 120 | # Approve chaincode definition for Org2 | |
| 121 | export CORE_PEER_LOCALMSPID="Org2MSP" | |
| 122 | export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
| |
| 123 | export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org2.example.com/users/[email protected]/msp
| |
| 124 | export CORE_PEER_ADDRESS=localhost:9051 | |
| 125 | ||
| 126 | peer lifecycle chaincode approveformyorg -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name basic --version 1.0 --package-id $PACKAGE_ID --sequence 1 --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
| |
| 127 | ||
| 128 | # Commit chaincode definition | |
| 129 | peer lifecycle chaincode commit -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --channelID mychannel --name basic --version 1.0 --sequence 1 --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem --peerAddresses localhost:7051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
| |
| 130 | if [ $? -ne 0 ]; then | |
| 131 | echo "Error committing chaincode definition. Exiting." | |
| 132 | exit 1 | |
| 133 | fi | |
| 134 | ||
| 135 | # Invoke chaincode transaction | |
| 136 | peer chaincode invoke -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com --tls --cafile ${PWD}/organizations/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem -C mychannel -n basic -c '{"Args":["CreateAsset","asset1","blue","5","Tom","100"]}' --peerAddresses localhost:7051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt --peerAddresses localhost:9051 --tlsRootCertFiles ${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
| |
| 137 | if [ $? -ne 0 ]; then | |
| 138 | echo "Error invoking chaincode transaction. Exiting." | |
| 139 | exit 1 | |
| 140 | fi | |
| 141 |