forked from hyperledger/fabric-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstartFabric.sh
executable file
·172 lines (130 loc) · 4.08 KB
/
startFabric.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
#!/bin/bash
#
# Copyright IBM Corp All Rights Reserved
#
# SPDX-License-Identifier: Apache-2.0
#
# Exit on first error
set -e pipefail
# don't rewrite paths for Windows Git Bash users
export MSYS_NO_PATHCONV=1
starttime=$(date +%s)
CC_SRC_LANGUAGE=golang
CC_RUNTIME_LANGUAGE=golang
CC_SRC_PATH=../chaincode/marbles02/go
echo Vendoring Go dependencies ...
pushd ../chaincode/marbles02/go
GO111MODULE=on go mod vendor
popd
echo Finished vendoring Go dependencies
# launch network; create channel and join peer to channel
pushd ../test-network
./network.sh down
./network.sh up createChannel -ca -s couchdb
export PATH=${PWD}/../bin:${PWD}:$PATH
export FABRIC_CFG_PATH=${PWD}/../config
# import environment variables
. scripts/envVar.sh
echo "Packaging the marbles smart contract"
setGlobals 1
peer lifecycle chaincode package marbles.tar.gz \
--path $CC_SRC_PATH \
--lang $CC_RUNTIME_LANGUAGE \
--label marblesv1
echo "Installing smart contract on peer0.org1.example.com"
peer lifecycle chaincode install marbles.tar.gz
echo "Installing smart contract on peer0.org2.example.com"
setGlobals 2
peer lifecycle chaincode install marbles.tar.gz
echo "Query the chaincode package id"
setGlobals 1
peer lifecycle chaincode queryinstalled >&log.txt
PACKAGE_ID=$(sed -n "/marblesv1/{s/^Package ID: //; s/, Label:.*$//; p;}" log.txt)
echo "Approving the chaincode definition for org1.example.com"
peer lifecycle chaincode approveformyorg \
-o localhost:7050 \
--ordererTLSHostnameOverride orderer.example.com \
--channelID mychannel \
--name marbles \
--version 1.0 \
--init-required \
--signature-policy AND"('Org1MSP.member','Org2MSP.member')" \
--sequence 1 \
--package-id $PACKAGE_ID \
--tls \
--cafile ${ORDERER_CA}
echo "Approving the chaincode definition for org2.example.com"
setGlobals 2
peer lifecycle chaincode approveformyorg \
-o localhost:7050 \
--ordererTLSHostnameOverride orderer.example.com \
--channelID mychannel \
--name marbles \
--version 1.0 \
--init-required \
--signature-policy AND"('Org1MSP.member','Org2MSP.member')" \
--sequence 1 \
--package-id $PACKAGE_ID \
--tls \
--cafile ${ORDERER_CA}
echo "Checking if the chaincode definition is ready to commit"
peer lifecycle chaincode checkcommitreadiness \
--channelID mychannel \
--name marbles \
--version 1.0 \
--sequence 1 \
--output json \
--init-required \
--signature-policy AND"('Org1MSP.member','Org2MSP.member')" >&log.txt
rc=0
for var in "\"Org1MSP\": true" "\"Org2MSP\": true"
do
grep "$var" log.txt &>/dev/null || let rc=1
done
if test $rc -eq 0; then
echo "Chaincode definition is ready to commit"
else
sleep 10
fi
parsePeerConnectionParameters 1 2
echo "Commit the chaincode definition to the channel"
peer lifecycle chaincode commit \
-o localhost:7050 \
--ordererTLSHostnameOverride orderer.example.com \
--channelID mychannel \
--name marbles \
--version 1.0 \
--init-required \
--signature-policy AND"('Org1MSP.member','Org2MSP.member')" \
--sequence 1 \
--tls \
--cafile ${ORDERER_CA} \
$PEER_CONN_PARMS
echo "Check if the chaincode has been committed to the channel ..."
peer lifecycle chaincode querycommitted \
--channelID mychannel \
--name marbles >&log.txt
EXPECTED_RESULT="Version: 1.0, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc"
VALUE=$(grep -o "Version: 1.0, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc" log.txt)
echo "$VALUE"
if [ "$VALUE" = "Version: 1.0, Sequence: 1, Endorsement Plugin: escc, Validation Plugin: vscc" ] ; then
echo "chaincode has been committed"
else
sleep 10
fi
echo "invoke the marbles chaincode init function ... "
peer chaincode invoke \
-o localhost:7050 \
--ordererTLSHostnameOverride orderer.example.com \
-C mychannel \
-n marbles \
--isInit \
-c '{"Args":["Init"]}' \
--tls \
--cafile ${ORDERER_CA} \
$PEER_CONN_PARMS
rm log.txt
popd
cat <<EOF
Total setup execution time : $(($(date +%s) - starttime)) secs ...
EOF