View difference between Paste ID: Q3ksCNR0 and eAWTiKQ0
SHOW: | | - or go back to the newest paste.
1
#!/bin/bash
2
3-
# Navigate to the Projects directory
3+
echo "Navigating to the Projects directory..."
4
cd ~/Projects/
5
6-
# Set up environment variables for Fabric binaries and configuration files
6+
echo "Setting 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
10+
echo "Checking 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
17+
echo "Installing Go language..."
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
24+
echo "Verifying 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
31+
echo "Cloning Hyperledger Fabric samples..."
32
git clone https://github.com/hyperledger/fabric-samples.git
33
if [ $? -ne 0 ]; then
34
    echo "Error cloning fabric-samples repository. Exiting."
35
    exit 1
36
fi
37
38-
# Download Fabric binaries and Docker images
38+
echo "Downloading 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
45-
# Navigate to the test network directory
45+
echo "Navigating to the test network directory..."
46-
cd ./fabric-samples/test-network
46+
cd fabric-samples/test-network
47
48-
# Bring up the Fabric test network
48+
echo "Bringing 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
55+
echo "Setting 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/Admin@org1.example.com/msp
60
export CORE_PEER_ADDRESS=localhost:7051
61
peer lifecycle chaincode querycommitted --channelID mychannel --name basic
62-
# Package and install chaincode on Org1
62+
63
echo "Package and install chaincode on Org1..."
64
peer lifecycle chaincode package basic.tar.gz --path ../asset-transfer-basic/chaincode-go --lang golang --label basic_1.0
65
if [ $? -ne 0 ]; then
66
    echo "Error packaging chaincode. Exiting."
67
    exit 1
68
fi
69
peer lifecycle chaincode install basic.tar.gz
70
if [ $? -ne 0 ]; then
71
    echo "Error installing chaincode. Exiting."
72
    exit 1
73
fi
74-
# Query Org1, to verify that the correct sequence number is updated
74+
75
echo "Querying chaincode committed status for Org1..."
76
echo "Verify that the correct sequence number is outputted."
77
export CORE_PEER_LOCALMSPID="Org1MSP"
78
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
79
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
80
export CORE_PEER_ADDRESS=localhost:7051
81
82
 | grep -q 'Version: 1.0, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc, Approvals: \[Org1MSP: true\]'
83
if [ $? -ne 0 ]; then
84
    echo "Error: Chaincode is not committed with expected parameters for Org1. Exiting."
85
    exit 1
86-
# Set environment variables for Org2
86+
87
88
echo "Setting environment variables for Org2..."
89
export CORE_PEER_LOCALMSPID="Org2MSP"
90
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
91
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
92-
# Install chaincode on Org2
92+
93
94
echo "Package and install chaincode on Org2..."
95-
# Query Org2, to verify that the correct sequence number is updated
95+
96
97
echo "Querying chaincode committed status for Org2..."
98
echo "Verify that the correct sequence number is outputted."
99
export CORE_PEER_LOCALMSPID="Org2MSP"
100
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
101
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
102
export CORE_PEER_ADDRESS=localhost:9051
103
104
 | grep -q 'Version: 1.0, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc, Approvals: \[Org2MSP: true\]'
105
if [ $? -ne 0 ]; then
106
    echo "Error: Chaincode is not committed with expected parameters for Org2. Exiting."
107-
# Approve chaincode definition for Org1
107+
108
fi
109
110
echo "Approve chaincode definition for Org1..."
111
export PACKAGE_ID=$(peer lifecycle chaincode queryinstalled | grep -o 'Package ID: \S*' | awk '{print $3}')
112
export CORE_PEER_LOCALMSPID="Org1MSP"
113
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
114
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp
115
export CORE_PEER_ADDRESS=localhost:7051
116
117
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
118
if [ $? -ne 0 ]; then
119
    echo "Error approving chaincode definition. Exiting."
120-
# Approve chaincode definition for Org2
120+
121
fi
122
123
Echo "Approve chaincode definition for Org2..."
124
export CORE_PEER_LOCALMSPID="Org2MSP"
125
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/organizations/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
126
export CORE_PEER_MSPCONFIGPATH=${PWD}/organizations/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp
127
export CORE_PEER_ADDRESS=localhost:9051
128-
# Commit chaincode definition
128+
129
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
130
131
echo "Commit chaincode definition to the channel..."
132
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
133
if [ $? -ne 0 ]; then
134
    echo "Error committing chaincode definition. Exiting."
135-
# Invoke chaincode transaction
135+
136
fi
137
138
echo "Invoking chaincode transaction..."
139
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
140
if [ $? -ne 0 ]; then
141
    echo "Error invoking chaincode transaction. Exiting."
142
    exit 1
143
fi
144