Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- echo "Navigating to the Projects directory..."
- cd ~/Projects/
- echo "Setting up environment variables for Fabric binaries and configuration files..."
- export PATH=${PWD}/../bin:$PATH
- export FABRIC_CFG_PATH=$PWD/../config/
- echo "Checking 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
- echo "Installing Go language..."
- brew install go
- if [ $? -ne 0 ]; then
- echo "Error installing Go. Exiting."
- exit 1
- fi
- echo "Verifying Go installation..."
- go version
- if [ $? -ne 0 ]; then
- echo "Go installation verification failed. Exiting."
- exit 1
- fi
- echo "Cloning 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
- echo "Downloading 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
- echo "Navigating to the test network directory..."
- cd fabric-samples/test-network
- echo "Bringing up the Fabric test network..."
- ./network.sh up createChannel
- if [ $? -ne 0 ]; then
- echo "Error bringing up Fabric network. Exiting."
- exit 1
- fi
- echo "Setting 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
- peer lifecycle chaincode querycommitted --channelID mychannel --name basic
- echo "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
- echo "Querying chaincode committed status for Org1..."
- echo "Verify that the correct sequence number is outputted."
- 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
- echo "Setting 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
- echo "Package and install chaincode on Org2..."
- peer lifecycle chaincode install basic.tar.gz
- echo "Querying chaincode committed status for Org2..."
- echo "Verify that the correct sequence number is outputted."
- 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
- echo "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
- Echo "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
- echo "Commit chaincode definition to the channel..."
- 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
- echo "Invoking 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