@@ -113,13 +113,29 @@ joinChannelWithRetry() {
113
113
verifyResult $res " After $MAX_RETRY attempts, peer${PEER} .org${ORG} has failed to join channel '$CHANNEL_NAME ' "
114
114
}
115
115
116
+ # packageChaincode VERSION PEER ORG
117
+ packageChaincode () {
118
+ VERSION=$1
119
+ PEER=$2
120
+ ORG=$3
121
+ setGlobals $PEER $ORG
122
+ set -x
123
+ peer lifecycle chaincode package mycc.tar.gz --path ${CC_SRC_PATH} --lang ${LANGUAGE} --label mycc_${VERSION} >& log.txt
124
+ res=$?
125
+ set +x
126
+ cat log.txt
127
+ verifyResult $res " Chaincode packaging on peer${PEER} .org${ORG} has failed"
128
+ echo " ===================== Chaincode is packaged on peer${PEER} .org${ORG} ===================== "
129
+ echo
130
+ }
131
+
132
+ # installChaincode PEER ORG
116
133
installChaincode () {
117
134
PEER=$1
118
135
ORG=$2
119
136
setGlobals $PEER $ORG
120
- VERSION=${3:- 1.0}
121
137
set -x
122
- peer chaincode install -n mycc -v ${VERSION} -l ${LANGUAGE} -p ${CC_SRC_PATH} >& log.txt
138
+ peer lifecycle chaincode install mycc.tar.gz >& log.txt
123
139
res=$?
124
140
set +x
125
141
cat log.txt
@@ -128,45 +144,108 @@ installChaincode() {
128
144
echo
129
145
}
130
146
131
- instantiateChaincode () {
147
+ # queryInstalled PEER ORG
148
+ queryInstalled () {
132
149
PEER=$1
133
150
ORG=$2
134
151
setGlobals $PEER $ORG
135
- VERSION=${3:- 1.0}
152
+ set -x
153
+ peer lifecycle chaincode queryinstalled >& log.txt
154
+ res=$?
155
+ set +x
156
+ cat log.txt
157
+ PACKAGE_ID=` sed -n ' /Package/{s/^Package ID: //; s/, Label:.*$//; p;}' log.txt`
158
+ verifyResult $res " Query installed on peer${PEER} .org${ORG} has failed"
159
+ echo PackageID is ${PACKAGE_ID}
160
+ echo " ===================== Query installed successful on peer${PEER} .org${ORG} on channel ===================== "
161
+ echo
162
+ }
163
+
164
+ # approveForMyOrg VERSION PEER ORG
165
+ approveForMyOrg () {
166
+ VERSION=$1
167
+ PEER=$2
168
+ ORG=$3
169
+ setGlobals $PEER $ORG
136
170
137
- # while 'peer chaincode' command can get the orderer endpoint from the peer
138
- # (if join was successful), let's supply it directly as we know it using
139
- # the "-o" option
140
171
if [ -z " $CORE_PEER_TLS_ENABLED " -o " $CORE_PEER_TLS_ENABLED " = " false" ]; then
141
172
set -x
142
- peer chaincode instantiate -o orderer.example.com:7050 -C $CHANNEL_NAME -n mycc -l ${LANGUAGE} -v ${VERSION} -c ' {"Args":["init","a","100","b","200"]}' -P " AND ('Org1MSP.peer','Org2MSP.peer')" >& log.txt
173
+ peer lifecycle chaincode approveformyorg --channelID $CHANNEL_NAME --name mycc --version ${VERSION} --init-required --package-id ${PACKAGE_ID} --sequence 1 --waitForEvent >& log.txt
174
+ set +x
175
+ else
176
+ set -x
177
+ peer lifecycle chaincode approveformyorg --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA --channelID $CHANNEL_NAME --name mycc --version ${VERSION} --init-required --package-id ${PACKAGE_ID} --sequence 1 --waitForEvent >& log.txt
178
+ set +x
179
+ fi
180
+ cat log.txt
181
+ verifyResult $res " Chaincode definition approved on peer${PEER} .org${ORG} on channel '$CHANNEL_NAME ' failed"
182
+ echo " ===================== Chaincode definition approved on peer${PEER} .org${ORG} on channel '$CHANNEL_NAME ' ===================== "
183
+ echo
184
+ }
185
+
186
+ # commitChaincodeDefinition VERSION PEER ORG (PEER ORG)...
187
+ commitChaincodeDefinition () {
188
+ VERSION=$1
189
+ shift
190
+ parsePeerConnectionParameters $@
191
+ res=$?
192
+ verifyResult $res " Invoke transaction failed on channel '$CHANNEL_NAME ' due to uneven number of peer and org parameters "
193
+
194
+ # while 'peer chaincode' command can get the orderer endpoint from the
195
+ # peer (if join was successful), let's supply it directly as we know
196
+ # it using the "-o" option
197
+ if [ -z " $CORE_PEER_TLS_ENABLED " -o " $CORE_PEER_TLS_ENABLED " = " false" ]; then
198
+ set -x
199
+ peer lifecycle chaincode commit -o orderer.example.com:7050 --channelID $CHANNEL_NAME --name mycc $PEER_CONN_PARMS --version ${VERSION} --sequence 1 --init-required >& log.txt
143
200
res=$?
144
201
set +x
145
202
else
146
203
set -x
147
- peer chaincode instantiate -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C $CHANNEL_NAME -n mycc -l ${LANGUAGE } -v 1.0 -c ' {"Args":[" init","a","100","b","200"]} ' -P " AND ('Org1MSP.peer','Org2MSP.peer') " >& log.txt
204
+ peer lifecycle chaincode commit -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA --channelID $CHANNEL_NAME --name mycc $PEER_CONN_PARMS --version ${VERSION } --sequence 1 -- init-required >& log.txt
148
205
res=$?
149
206
set +x
150
207
fi
151
208
cat log.txt
152
- verifyResult $res " Chaincode instantiation on peer${PEER} .org${ORG} on channel '$CHANNEL_NAME ' failed"
153
- echo " ===================== Chaincode is instantiated on peer ${PEER} .org ${ORG} on channel '$CHANNEL_NAME ' ===================== "
209
+ verifyResult $res " Chaincode definition commit failed on peer${PEER} .org${ORG} on channel '$CHANNEL_NAME ' failed"
210
+ echo " ===================== Chaincode definition committed on channel '$CHANNEL_NAME ' ===================== "
154
211
echo
155
212
}
156
213
157
- upgradeChaincode () {
158
- PEER=$1
159
- ORG=$2
214
+ # queryCommitted VERSION PEER ORG
215
+ queryCommitted () {
216
+ VERSION=$1
217
+ PEER=$2
218
+ ORG=$3
160
219
setGlobals $PEER $ORG
220
+ EXPECTED_RESULT=" Version: ${VERSION} , Sequence: ${VERSION} , Endorsement Plugin: escc, Validation Plugin: vscc"
221
+ echo " ===================== Querying chaincode definition on peer${PEER} .org${ORG} on channel '$CHANNEL_NAME '... ===================== "
222
+ local rc=1
223
+ local starttime=$( date +%s)
161
224
162
- set -x
163
- peer chaincode upgrade -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C $CHANNEL_NAME -n mycc -v 2.0 -c ' {"Args":["init","a","90","b","210"]}' -P " AND ('Org1MSP.peer','Org2MSP.peer','Org3MSP.peer')"
164
- res=$?
165
- set +x
166
- cat log.txt
167
- verifyResult $res " Chaincode upgrade on peer${PEER} .org${ORG} has failed"
168
- echo " ===================== Chaincode is upgraded on peer${PEER} .org${ORG} on channel '$CHANNEL_NAME ' ===================== "
225
+ # continue to poll
226
+ # we either get a successful response, or reach TIMEOUT
227
+ while
228
+ test " $(( $(date +% s) - starttime)) " -lt " $TIMEOUT " -a $rc -ne 0
229
+ do
230
+ sleep $DELAY
231
+ echo " Attempting to Query peer${PEER} .org${ORG} ...$(( $(date +% s) - starttime)) secs"
232
+ set -x
233
+ peer lifecycle chaincode querycommitted --channelID $CHANNEL_NAME --name mycc >& log.txt
234
+ res=$?
235
+ set +x
236
+ test $res -eq 0 && VALUE=$( cat log.txt | grep -o ' ^Version: [0-9], Sequence: [0-9], Endorsement Plugin: escc, Validation Plugin: vscc' )
237
+ test " $VALUE " = " $EXPECTED_RESULT " && let rc=0
238
+ done
169
239
echo
240
+ cat log.txt
241
+ if test $rc -eq 0; then
242
+ echo " ===================== Query chaincode definition successful on peer${PEER} .org${ORG} on channel '$CHANNEL_NAME ' ===================== "
243
+ else
244
+ echo " !!!!!!!!!!!!!!! Query chaincode definition result on peer${PEER} .org${ORG} is INVALID !!!!!!!!!!!!!!!!"
245
+ echo " ================== ERROR !!! FAILED to execute End-2-End Scenario =================="
246
+ echo
247
+ exit 1
248
+ fi
170
249
}
171
250
172
251
chaincodeQuery () {
@@ -293,24 +372,34 @@ parsePeerConnectionParameters() {
293
372
PEERS=" $( echo -e " $PEERS " | sed -e ' s/^[[:space:]]*//' ) "
294
373
}
295
374
296
- # chaincodeInvoke <peer> <org> ...
375
+ # chaincodeInvoke IS_INIT PEER ORG (PEER ORG) ...
297
376
# Accepts as many peer/org pairs as desired and requests endorsement from each
298
377
chaincodeInvoke () {
378
+ IS_INIT=$1
379
+ shift
299
380
parsePeerConnectionParameters $@
300
381
res=$?
301
382
verifyResult $res " Invoke transaction failed on channel '$CHANNEL_NAME ' due to uneven number of peer and org parameters "
302
383
384
+ if [ " ${IS_INIT} " -eq " 1" ]; then
385
+ CCARGS=' {"Args":["Init","a","100","b","100"]}'
386
+ INIT_ARG=" --isInit"
387
+ else
388
+ CCARGS=' {"Args":["invoke","a","b","10"]}'
389
+ INIT_ARG=" "
390
+ fi
391
+
303
392
# while 'peer chaincode' command can get the orderer endpoint from the
304
393
# peer (if join was successful), let's supply it directly as we know
305
394
# it using the "-o" option
306
395
if [ -z " $CORE_PEER_TLS_ENABLED " -o " $CORE_PEER_TLS_ENABLED " = " false" ]; then
307
396
set -x
308
- peer chaincode invoke -o orderer.example.com:7050 -C $CHANNEL_NAME -n mycc $PEER_CONN_PARMS -c ' {"Args":["invoke","a","b","10"]} ' >& log.txt
397
+ peer chaincode invoke -o orderer.example.com:7050 -C $CHANNEL_NAME -n mycc $PEER_CONN_PARMS ${INIT_ARG} -c ${CCARGS} >& log.txt
309
398
res=$?
310
399
set +x
311
400
else
312
401
set -x
313
- peer chaincode invoke -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C $CHANNEL_NAME -n mycc $PEER_CONN_PARMS -c ' {"Args":["invoke","a","b","10"]} ' >& log.txt
402
+ peer chaincode invoke -o orderer.example.com:7050 --tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA -C $CHANNEL_NAME -n mycc $PEER_CONN_PARMS ${INIT_ARG} -c ${CCARGS} >& log.txt
314
403
res=$?
315
404
set +x
316
405
fi
0 commit comments