Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- # Navigate to the Projects directory
- cd ~/Projects/
- # Set up environment variables for Fabric binaries and configuration files
- export PATH=${PWD}/../bin:$PATH
- export FABRIC_CFG_PATH=$PWD/../config/
- # Check if Homebrew is installed
- if ! command -v brew &> /dev/null
- then
- echo "Homebrew could not be found. Please install Homebrew and rerun the script."
- exit 1
- fi
- # Install Go
- brew install go
- if [ $? -ne 0 ]; then
- echo "Error installing Go. Exiting."
- exit 1
- fi
- # Verify Go installation
- go version
- if [ $? -ne 0 ]; then
- echo "Go installation verification failed. Exiting."
- exit 1
- fi
- # Clone Hyperledger Fabric samples
- git clone https://github.com/hyperledger/fabric-samples.git
- if [ $? -ne 0 ]; then
- echo "Error cloning fabric-samples repository. Exiting."
- exit 1
- fi
- # Download Fabric binaries and Docker images
- curl -sSL https://bit.ly/2ysbOFE | bash -s
- if [ $? -ne 0 ]; then
- echo "Error downloading Fabric binaries and Docker images. Exiting."
- exit 1
- fi
- # Navigate to the test network directory
- cd ./fabric-samples/test-network
- # Bring up the Fabric test network
- ./network.sh up createChannel
- if [ $? -ne 0 ]; then
- echo "Error bringing up Fabric network. Exiting."
- exit 1
- fi
- # Set environment variables for Org1
- export CORE_PEER_TLS_ENABLED=true
- export CORE_PEER_LOCALMSPID="Org1MSP"
- export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
- export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
- export CORE_PEER_ADDRESS=localhost:7051
- # Package and install chaincode on Org1
- peer lifecycle chaincode package basic.tar.gz --path ../asset-transfer-basic/chaincode-go --lang golang --label basic_1.0
- if [ $? -ne 0 ]; then
- echo "Error packaging chaincode. Exiting."
- exit 1
- fi
- peer lifecycle chaincode install basic.tar.gz
- if [ $? -ne 0 ]; then
- echo "Error installing chaincode. Exiting."
- exit 1
- fi
- # Query Org1, to verify that the correct sequence number is updated
- export CORE_PEER_LOCALMSPID="Org1MSP"
- export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
- export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
- export CORE_PEER_ADDRESS=localhost:7051
- | grep -q 'Version: 1.0, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc, Approvals: \[Org1MSP: true\]'
- if [ $? -ne 0 ]; then
- echo "Error: Chaincode is not committed with expected parameters for Org1. Exiting."
- exit 1
- fi
- # Set environment variables for Org2
- export CORE_PEER_LOCALMSPID="Org2MSP"
- export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
- export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
- export CORE_PEER_ADDRESS=localhost:9051
- # Install chaincode on Org2
- peer lifecycle chaincode install basic.tar.gz
- # Query Org2, to verify that the correct sequence number is updated
- export CORE_PEER_LOCALMSPID="Org2MSP"
- export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
- export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
- export CORE_PEER_ADDRESS=localhost:9051
- | grep -q 'Version: 1.0, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc, Approvals: \[Org2MSP: true\]'
- if [ $? -ne 0 ]; then
- echo "Error: Chaincode is not committed with expected parameters for Org2. Exiting."
- exit 1
- fi
- # Approve chaincode definition for Org1
- export PACKAGE_ID=$(peer lifecycle chaincode queryinstalled | grep -o 'Package ID: \S*' | awk '{print $3}')
- export CORE_PEER_LOCALMSPID="Org1MSP"
- export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
- export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
- export CORE_PEER_ADDRESS=localhost:7051
- 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
- if [ $? -ne 0 ]; then
- echo "Error approving chaincode definition. Exiting."
- exit 1
- fi
- # Approve chaincode definition for Org2
- export CORE_PEER_LOCALMSPID="Org2MSP"
- export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
- export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
- export CORE_PEER_ADDRESS=localhost:9051
- 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
- # Commit chaincode definition
- 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
- if [ $? -ne 0 ]; then
- echo "Error committing chaincode definition. Exiting."
- exit 1
- fi
- # Invoke chaincode transaction
- 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
- if [ $? -ne 0 ]; then
- echo "Error invoking chaincode transaction. Exiting."
- exit 1
- fi
Add Comment
Please, Sign In to add comment