-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.sh
executable file
·165 lines (144 loc) · 11.3 KB
/
run.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
#!/bin/bash
source .env
# ---------------------------------------------------------------------------
# Clear screen
# ---------------------------------------------------------------------------
clear
echo "# ---------------------------------------------------------------------------"
echo "# Create Channel : mychannel"
echo "# ---------------------------------------------------------------------------"
docker exec "$CLI_NAME" peer channel create -o "$ORDERER_NAME":7050 -c "$CHANNEL_NAME" -f "$CHANNEL_TX_LOCATION" --tls --cafile $ORDERER_CA_LOCATION
sleep 2
echo
echo "# ---------------------------------------------------------------------------"
echo "# Join channel : peer0.org1.example.com "
echo "# ---------------------------------------------------------------------------"
docker exec "$CLI_NAME" peer channel join -b "$CHANNEL_NAME".block --tls --cafile $ORDERER_CA_LOCATION
sleep 2
echo
echo "# ---------------------------------------------------------------------------"
echo "# Join channel : peer1.org1.example.com"
echo "# ---------------------------------------------------------------------------"
docker exec \
-e "CORE_PEER_LOCALMSPID=Org1MSP" \
-e "CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls/server.crt" \
-e "CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls/server.key" \
-e "CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/peers/peer1.org1.example.com/tls/ca.crt" \
-e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org1.example.com/users/Admin@org1.example.com/msp" \
-e "CORE_PEER_ADDRESS=peer1.org1.example.com:7051" \
"$CLI_NAME" peer channel join -b "$CHANNEL_NAME".block --tls --cafile $ORDERER_CA_LOCATION
sleep 2
echo
echo "# ---------------------------------------------------------------------------"
echo "# Join channel : peer0.org2.example.com"
echo "# ---------------------------------------------------------------------------"
docker exec \
-e "CORE_PEER_LOCALMSPID=Org2MSP" \
-e "CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.crt" \
-e "CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.key" \
-e "CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" \
-e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp" \
-e "CORE_PEER_ADDRESS=peer0.org2.example.com:7051" \
"$CLI_NAME" peer channel join -b "$CHANNEL_NAME".block --tls --cafile $ORDERER_CA_LOCATION
sleep 2
echo
echo "# ---------------------------------------------------------------------------"
echo "# Join channel : peer1.org2.example.com"
echo "# ---------------------------------------------------------------------------"
docker exec \
-e "CORE_PEER_LOCALMSPID=Org2MSP" \
-e "CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/tls/server.crt" \
-e "CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/tls/server.key" \
-e "CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer1.org2.example.com/tls/ca.crt" \
-e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp" \
-e "CORE_PEER_ADDRESS=peer1.org2.example.com:7051" \
"$CLI_NAME" peer channel join -b "$CHANNEL_NAME".block --tls --cafile $ORDERER_CA_LOCATION
sleep 2
echo
echo "# ---------------------------------------------------------------------------"
echo "# Update anchor peer : Org1"
echo "# ---------------------------------------------------------------------------"
docker exec "$CLI_NAME" peer channel update -o "$ORDERER_NAME":7050 -c "$CHANNEL_NAME" -f "$ORG1_ANCHOR_TX" --tls --cafile $ORDERER_CA_LOCATION
sleep 2
echo
echo "# ---------------------------------------------------------------------------"
echo "# Update anchor peer : Org2"
echo "# ---------------------------------------------------------------------------"
docker exec \
-e "CORE_PEER_LOCALMSPID=Org2MSP" \
-e "CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.crt" \
-e "CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.key" \
-e "CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" \
-e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp" \
-e "CORE_PEER_ADDRESS=peer0.org2.example.com:7051" \
"$CLI_NAME" peer channel update -o "$ORDERER_NAME":7050 -c "$CHANNEL_NAME" -f "$ORG2_ANCHOR_TX" --tls --cafile $ORDERER_CA_LOCATION
sleep 2
echo
echo "# ---------------------------------------------------------------------------"
echo "# Installing chaincode on org1"
echo "# ---------------------------------------------------------------------------"
docker exec "$CLI_NAME" peer chaincode install -n "$CHAINCODE_NAME" -p "$CHAINCODE_SRC" -v $CHAINCODE_VERSION
sleep 2
echo
echo "# ---------------------------------------------------------------------------"
echo "# Installing chaincode on org2"
echo "# ---------------------------------------------------------------------------"
docker exec \
-e "CORE_PEER_LOCALMSPID=Org2MSP" \
-e "CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.crt" \
-e "CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.key" \
-e "CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" \
-e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp" \
-e "CORE_PEER_ADDRESS=peer0.org2.example.com:7051" \
"$CLI_NAME" peer chaincode install -n "$CHAINCODE_NAME" -p "$CHAINCODE_SRC" -v $CHAINCODE_VERSION
sleep 2
echo
echo "# ---------------------------------------------------------------------------"
echo "# Instantiating chaincode"
echo "# ---------------------------------------------------------------------------"
docker exec "$CLI_NAME" peer chaincode instantiate -o "$ORDERER_NAME":7050 -C "$CHANNEL_NAME" -n "$CHAINCODE_NAME" "$CHAINCODE_SRC" -v $CHAINCODE_VERSION -c '{"Args":["init"]}' -P "OR('Org1MSP.member', 'Org2MSP.member')" --tls --cafile $ORDERER_CA_LOCATION --collections-config "$COLLECTIONS_CONFIG"
sleep 10
echo
echo "# ---------------------------------------------------------------------------"
echo "# Invoking chaincode : {'name':'marble1','color':'blue','size':35,'owner':'tom','price':99}"
echo "# ---------------------------------------------------------------------------"
docker exec "$CLI_NAME" peer chaincode invoke -o "$ORDERER_NAME":7050 --tls --cafile $ORDERER_CA_LOCATION -C $CHANNEL_NAME -n $CHAINCODE_NAME -c '{"Args":["initMarble"]}' --transient "{\"marble\":\"$MARBLE\"}"
sleep 5
echo
echo "# ---------------------------------------------------------------------------"
echo "# Query chaincode - readMarble : Query from Org1 peer (Authorized)"
echo "# ---------------------------------------------------------------------------"
docker exec "$CLI_NAME" peer chaincode query -o "$ORDERER_NAME":7050 --tls --cafile $ORDERER_CA_LOCATION -C $CHANNEL_NAME -n $CHAINCODE_NAME -c '{"Args":["readMarble","marble1"]}'
sleep 2
echo
echo "# ---------------------------------------------------------------------------"
echo "# Query chaincode - readMarble : Query from Org2 peer (Authorized)"
echo "# ---------------------------------------------------------------------------"
docker exec \
-e "CORE_PEER_LOCALMSPID=Org2MSP" \
-e "CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.crt" \
-e "CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.key" \
-e "CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" \
-e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp" \
-e "CORE_PEER_ADDRESS=peer0.org2.example.com:7051" \
"$CLI_NAME" peer chaincode query -o "$ORDERER_NAME":7050 --tls --cafile $ORDERER_CA_LOCATION -C $CHANNEL_NAME -n $CHAINCODE_NAME -c '{"Args":["readMarble","marble1"]}'
sleep 2
echo
echo "# ---------------------------------------------------------------------------"
echo "# Query chaincode - readMarblePrivateDetails : Query from Org1 peer (Authorized)"
echo "# ---------------------------------------------------------------------------"
docker exec "$CLI_NAME" peer chaincode query -o "$ORDERER_NAME":7050 --tls --cafile $ORDERER_CA_LOCATION -C $CHANNEL_NAME -n $CHAINCODE_NAME -c '{"Args":["readMarblePrivateDetails","marble1"]}'
sleep 2
echo
echo "# ---------------------------------------------------------------------------"
echo "# Query chaincode - readMarblePrivateDetails : Query from Org2 peer (Unauthorized)"
echo "# ---------------------------------------------------------------------------"
docker exec \
-e "CORE_PEER_LOCALMSPID=Org2MSP" \
-e "CORE_PEER_TLS_CERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.crt" \
-e "CORE_PEER_TLS_KEY_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/server.key" \
-e "CORE_PEER_TLS_ROOTCERT_FILE=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/peers/peer0.org2.example.com/tls/ca.crt" \
-e "CORE_PEER_MSPCONFIGPATH=/opt/gopath/src/github.com/hyperledger/fabric/peer/crypto/peerOrganizations/org2.example.com/users/Admin@org2.example.com/msp" \
-e "CORE_PEER_ADDRESS=peer0.org2.example.com:7051" \
"$CLI_NAME" peer chaincode query -o "$ORDERER_NAME":7050 --tls --cafile $ORDERER_CA_LOCATION -C $CHANNEL_NAME -n $CHAINCODE_NAME -c '{"Args":["readMarblePrivateDetails","marble1"]}'
sleep 2