-
Notifications
You must be signed in to change notification settings - Fork 0
/
deployChaincode-BankA.sh
executable file
·340 lines (271 loc) · 12.4 KB
/
deployChaincode-BankA.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
export CORE_PEER_TLS_ENABLED=true
export ORDERER_CA=${PWD}/artifacts/channel/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
export PEER0_ORG1_CA=${PWD}/artifacts/channel/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/tls/ca.crt
export PEER0_ORG2_CA=${PWD}/artifacts/channel/crypto-config/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt
export PEER0_ORG3_CA=${PWD}/artifacts/channel/crypto-config/peerOrganizations/org3.example.com/peers/peer0.org3.example.com/tls/ca.crt
export FABRIC_CFG_PATH=${PWD}/artifacts/channel/config/
export CHANNEL_NAME=bankachannel
setGlobalsForOrderer() {
export CORE_PEER_LOCALMSPID="OrdererMSP"
export CORE_PEER_TLS_ROOTCERT_FILE=${PWD}/artifacts/channel/crypto-config/ordererOrganizations/example.com/orderers/orderer.example.com/msp/tlscacerts/tlsca.example.com-cert.pem
export CORE_PEER_MSPCONFIGPATH=${PWD}/artifacts/channel/crypto-config/ordererOrganizations/example.com/users/[email protected]/msp
}
setGlobalsForPeer0Org1() {
export CORE_PEER_LOCALMSPID="Org1MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=$PEER0_ORG1_CA
export CORE_PEER_MSPCONFIGPATH=${PWD}/artifacts/channel/crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp
export CORE_PEER_ADDRESS=localhost:7051
}
setGlobalsForPeer0Org2() {
export CORE_PEER_LOCALMSPID="Org2MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=$PEER0_ORG2_CA
export CORE_PEER_MSPCONFIGPATH=${PWD}/artifacts/channel/crypto-config/peerOrganizations/org2.example.com/users/[email protected]/msp
export CORE_PEER_ADDRESS=localhost:9051
}
setGlobalsForPeer0Org3() {
export CORE_PEER_LOCALMSPID="Org3MSP"
export CORE_PEER_TLS_ROOTCERT_FILE=$PEER0_ORG3_CA
export CORE_PEER_MSPCONFIGPATH=${PWD}/artifacts/channel/crypto-config/peerOrganizations/org3.example.com/users/[email protected]/msp
export CORE_PEER_ADDRESS=localhost:11051
}
presetup() {
echo Vendoring Go dependencies ...
pushd ./artifacts/src/github.com/Bank/go
GO111MODULE=on go mod vendor
popd
echo Finished vendoring Go dependencies
}
# presetup
CHANNEL_NAME="bankachannel"
CC_RUNTIME_LANGUAGE="golang"
VERSION="1"
SEQUENCE="1"
CC_SRC_PATH="./artifacts/src/github.com/Bank/go"
CC_NAME="banka"
packageChaincode() {
rm -rf ${CC_NAME}.tar.gz
setGlobalsForPeer0Org1
peer lifecycle chaincode package ${CC_NAME}.tar.gz \
--path ${CC_SRC_PATH} --lang ${CC_RUNTIME_LANGUAGE} \
--label ${CC_NAME}_${VERSION}
echo "===================== Chaincode is packaged ===================== "
}
# packageChaincode
installChaincode() {
setGlobalsForPeer0Org1
peer lifecycle chaincode install ${CC_NAME}.tar.gz
echo "===================== Chaincode is installed on peer0.org1 ===================== "
setGlobalsForPeer0Org2
peer lifecycle chaincode install ${CC_NAME}.tar.gz
echo "===================== Chaincode is installed on peer0.org2 ===================== "
setGlobalsForPeer0Org3
peer lifecycle chaincode install ${CC_NAME}.tar.gz
echo "===================== Chaincode is installed on peer0.org3 ===================== "
}
# installChaincode
queryInstalled() {
setGlobalsForPeer0Org1
peer lifecycle chaincode queryinstalled >&log.txt
cat log.txt
PACKAGE_ID=$(sed -n "/${CC_NAME}_${VERSION}/{s/^Package ID: //; s/, Label:.*$//; p;}" log.txt)
echo PackageID is ${PACKAGE_ID}
echo "===================== Query installed successful on peer0.org1 on channel ===================== "
}
# queryInstalled
# --collections-config ./artifacts/private-data/collections_config.json \
# --signature-policy "OR('Org1MSP.member','Org2MSP.member')" \
approveForMyOrg1() {
setGlobalsForPeer0Org1
# set -x
peer lifecycle chaincode approveformyorg -o localhost:7050 \
--ordererTLSHostnameOverride orderer.example.com --tls \
--cafile $ORDERER_CA --channelID $CHANNEL_NAME --name ${CC_NAME} --version ${VERSION} \
--init-required --package-id ${PACKAGE_ID} \
--sequence ${SEQUENCE}
# set +x
echo "===================== chaincode approved from org 1 ===================== "
}
# queryInstalled
# approveForMyOrg1
# --signature-policy "OR ('Org1MSP.member')"
# --peerAddresses localhost:7051 --tlsRootCertFiles $PEER0_ORG1_CA --peerAddresses localhost:9051 --tlsRootCertFiles $PEER0_ORG2_CA
# --peerAddresses peer0.org1.example.com:7051 --tlsRootCertFiles $PEER0_ORG1_CA --peerAddresses peer0.org2.example.com:9051 --tlsRootCertFiles $PEER0_ORG2_CA
#--channel-config-policy Channel/Application/Admins
# --signature-policy "OR ('Org1MSP.peer','Org2MSP.peer')"
checkCommitReadyness() {
setGlobalsForPeer0Org1
peer lifecycle chaincode checkcommitreadiness \
--channelID $CHANNEL_NAME --name ${CC_NAME} --version ${VERSION} \
--sequence ${VERSION} --output json --init-required
echo "===================== checking commit readyness from org 1 ===================== "
}
# checkCommitReadyness
approveForMyOrg2() {
setGlobalsForPeer0Org2
peer lifecycle chaincode approveformyorg -o localhost:7050 \
--ordererTLSHostnameOverride orderer.example.com --tls $CORE_PEER_TLS_ENABLED \
--cafile $ORDERER_CA --channelID $CHANNEL_NAME --name ${CC_NAME} \
--version ${VERSION} --init-required --package-id ${PACKAGE_ID} \
--sequence ${SEQUENCE}
echo "===================== chaincode approved from org 2 ===================== "
}
# queryInstalled
# approveForMyOrg2
checkCommitReadyness() {
setGlobalsForPeer0Org2
peer lifecycle chaincode checkcommitreadiness --channelID $CHANNEL_NAME \
--peerAddresses localhost:9051 --tlsRootCertFiles $PEER0_ORG2_CA \
--name ${CC_NAME} --version ${VERSION} --sequence ${VERSION} --output json --init-required
echo "===================== checking commit readyness from org 1 ===================== "
}
# checkCommitReadyness
approveForMyOrg3() {
setGlobalsForPeer0Org3
peer lifecycle chaincode approveformyorg -o localhost:7050 \
--ordererTLSHostnameOverride orderer.example.com --tls $CORE_PEER_TLS_ENABLED \
--cafile $ORDERER_CA --channelID $CHANNEL_NAME --name ${CC_NAME} \
--version ${VERSION} --init-required --package-id ${PACKAGE_ID} \
--sequence ${SEQUENCE}
echo "===================== chaincode approved from org 2 ===================== "
}
# queryInstalled
# approveForMyOrg3
checkCommitReadyness() {
setGlobalsForPeer0Org3
peer lifecycle chaincode checkcommitreadiness --channelID $CHANNEL_NAME \
--peerAddresses localhost:11051 --tlsRootCertFiles $PEER0_ORG3_CA \
--name ${CC_NAME} --version ${VERSION} --sequence ${VERSION} --output json --init-required
echo "===================== checking commit readyness from org 1 ===================== "
}
# checkCommitReadyness
commitChaincodeDefination() {
setGlobalsForPeer0Org1
peer lifecycle chaincode commit -o localhost:7050 --ordererTLSHostnameOverride orderer.example.com \
--tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA \
--channelID $CHANNEL_NAME --name ${CC_NAME} \
--peerAddresses localhost:7051 --tlsRootCertFiles $PEER0_ORG1_CA \
--peerAddresses localhost:9051 --tlsRootCertFiles $PEER0_ORG2_CA \
--peerAddresses localhost:11051 --tlsRootCertFiles $PEER0_ORG3_CA \
--version ${VERSION} --sequence ${SEQUENCE} --init-required
}
# commitChaincodeDefination
queryCommitted() {
setGlobalsForPeer0Org1
peer lifecycle chaincode querycommitted --channelID $CHANNEL_NAME --name ${CC_NAME}
}
# queryCommitted
chaincodeInvokeInit() {
setGlobalsForPeer0Org1
peer chaincode invoke -o localhost:7050 \
--ordererTLSHostnameOverride orderer.example.com \
--tls $CORE_PEER_TLS_ENABLED --cafile $ORDERER_CA \
-C $CHANNEL_NAME -n ${CC_NAME} \
--peerAddresses localhost:7051 --tlsRootCertFiles $PEER0_ORG1_CA \
--peerAddresses localhost:9051 --tlsRootCertFiles $PEER0_ORG2_CA \
--peerAddresses localhost:11051 --tlsRootCertFiles $PEER0_ORG3_CA \
--isInit -c '{"Args":[]}'
}
# chaincodeInvokeInit
chaincodeInvoke() {
setGlobalsForPeer0Org1
# Create Car
peer chaincode invoke -o localhost:7050 \
--ordererTLSHostnameOverride orderer.example.com \
--tls $CORE_PEER_TLS_ENABLED \
--cafile $ORDERER_CA \
-C $CHANNEL_NAME -n ${CC_NAME} \
--peerAddresses localhost:7051 --tlsRootCertFiles $PEER0_ORG1_CA \
--peerAddresses localhost:9051 --tlsRootCertFiles $PEER0_ORG2_CA \
-c '{"function": "CreateAccount","Args":["{\"id\":\"2\",\"name\":\"hamid\",\"balance\":160019939}"]}'
# -c '{"function": "CreateDocument","Args":["{\"id\":\"1\",\"name\":\"amid\",\"addedAt\":1600138309939,\"url\":\"asdasdasdj\",\"contentHash\":\"asdj\"}"]}'
}
chaincodeInvokeGetBalance() {
setGlobalsForPeer0Org1
# Create Car
peer chaincode invoke -o localhost:7050 \
--ordererTLSHostnameOverride orderer.example.com \
--tls $CORE_PEER_TLS_ENABLED \
--cafile $ORDERER_CA \
-C $CHANNEL_NAME -n ${CC_NAME} \
--peerAddresses localhost:7051 --tlsRootCertFiles $PEER0_ORG1_CA \
--peerAddresses localhost:9051 --tlsRootCertFiles $PEER0_ORG2_CA \
-c '{"function": "GetBalance","Args":["B15352856648520921629"]}'
# -c '{"function": "CreateDocument","Args":["{\"id\":\"1\",\"name\":\"amid\",\"addedAt\":1600138309939,\"url\":\"asdasdasdj\",\"contentHash\":\"asdj\"}"]}'
}
chaincodeInvokePutBalance() {
setGlobalsForPeer0Org1
# Create Car
peer chaincode invoke -o localhost:7050 \
--ordererTLSHostnameOverride orderer.example.com \
--tls $CORE_PEER_TLS_ENABLED \
--cafile $ORDERER_CA \
-C $CHANNEL_NAME -n ${CC_NAME} \
--peerAddresses localhost:7051 --tlsRootCertFiles $PEER0_ORG1_CA \
--peerAddresses localhost:9051 --tlsRootCertFiles $PEER0_ORG2_CA \
-c '{"function": "PutBalance","Args":["A15352856648520921629"]}'
# -c '{"function": "CreateDocument","Args":["{\"id\":\"1\",\"name\":\"amid\",\"addedAt\":1600138309939,\"url\":\"asdasdasdj\",\"contentHash\":\"asdj\"}"]}'
}
LockSenderMoney() {
setGlobalsForPeer0Org1
# Create Car
peer chaincode invoke -o localhost:7050 \
--ordererTLSHostnameOverride orderer.example.com \
--tls $CORE_PEER_TLS_ENABLED \
--cafile $ORDERER_CA \
-C $CHANNEL_NAME -n ${CC_NAME} \
--peerAddresses localhost:7051 --tlsRootCertFiles $PEER0_ORG1_CA \
--peerAddresses localhost:9051 --tlsRootCertFiles $PEER0_ORG2_CA \
-c '{"function": "LockSenderMoney","Args":["{\"senderID\":\"A2\",\"RecipientID\":\"B2\",\"Amount\":160019939,\"TX\":\"\"}"]}'
}
FinializeTransfer() {
setGlobalsForPeer0Org1
# Create Car
peer chaincode invoke -o localhost:7050 \
--ordererTLSHostnameOverride orderer.example.com \
--tls $CORE_PEER_TLS_ENABLED \
--cafile $ORDERER_CA \
-C $CHANNEL_NAME -n ${CC_NAME} \
--peerAddresses localhost:7051 --tlsRootCertFiles $PEER0_ORG1_CA \
--peerAddresses localhost:9051 --tlsRootCertFiles $PEER0_ORG2_CA \
-c '{"function": "FinializeTransfer","Args":["{\"senderID\":\"A2\",\"RecipientID\":\"B2\",\"Amount\":160019939,\"TX\":\"43716174f403cfb50b250e211a7b131f9fa1d746d8d0ea37b997a9f7e0450812\"}"]}'
}
# chaincodeInvoke
chaincodeInvokeDeleteAsset() {
setGlobalsForPeer0Org1
# Create Car
peer chaincode invoke -o localhost:7050 \
--ordererTLSHostnameOverride orderer.example.com \
--tls $CORE_PEER_TLS_ENABLED \
--cafile $ORDERER_CA \
-C $CHANNEL_NAME -n ${CC_NAME} \
--peerAddresses localhost:7051 --tlsRootCertFiles $PEER0_ORG1_CA \
--peerAddresses localhost:9051 --tlsRootCertFiles $PEER0_ORG2_CA \
-c '{"function": "DeleteCarById","Args":["2"]}'
}
# chaincodeInvokeDeleteAsset
chaincodeQuery() {
setGlobalsForPeer0Org2
peer chaincode query -C $CHANNEL_NAME -n ${CC_NAME} -c '{"function": "GetCarById","Args":["1"]}'
}
# chaincodeQuery
# Run this function if you add any new dependency in chaincode
# presetup
packageChaincode
installChaincode
queryInstalled
approveForMyOrg1
checkCommitReadyness
approveForMyOrg2
checkCommitReadyness
approveForMyOrg3
commitChaincodeDefination
queryCommitted
chaincodeInvokeInit
sleep 5
chaincodeInvoke
# LockSenderMoney
# FinializeTransfer
# chaincodeInvokeGetBalance
# chaincodeInvokePutBalance
# sleep 3
# chaincodeQuery