-
Notifications
You must be signed in to change notification settings - Fork 1
/
interact.sh
executable file
·188 lines (146 loc) · 5.29 KB
/
interact.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
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 FABRIC_CFG_PATH=${PWD}/artifacts/channel/config/
export PRIVATE_DATA_CONFIG=${PWD}/artifacts/private-data/collections_config.json
export CHANNEL_NAME=mychannel
CHANNEL_NAME="mychannel"
CC_RUNTIME_LANGUAGE="golang"
VERSION="1"
CC_SRC_PATH="./artifacts/src/github.com/fabcar/go"
CC_NAME="fabcar"
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/Admin@org1.example.com/msp
# export CORE_PEER_MSPCONFIGPATH=${PWD}/artifacts/channel/crypto-config/peerOrganizations/org1.example.com/peers/peer0.org1.example.com/msp
export CORE_PEER_ADDRESS=localhost:7051
}
addCar() {
setGlobalsForPeer0Org1
## Solicita dados para transacao
echo -e '\n Digite os dados para adicionar novo registro:'
echo -e '\nChave: '
read chave
echo -e '\nMake: '
read make
echo -e '\nModel: '
read model
echo -e '\nColor: '
read color
echo -e '\nOwner: '
read owner
echo -e '\n'
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 '{"Args":["createCar", "'$chave'", "'$make'", "'$model'", "'$color'", "'$owner'"]}'
}
changeCarOwner() {
setGlobalsForPeer0Org1
## Solicita dados para transacao
echo -e '\n Digite a chave do carro e novo proprietario:'
echo -e '\nChave: '
read chave
echo -e '\nOwner: '
read owner
echo -e '\n'
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 '{"Args":["changeCarOwner", "'$chave'", "'$owner'"]}'
}
getHistory() {
setGlobalsForPeer0Org1
## Solicita dados para transacao
echo -e '\n Digite a chave do carro e novo proprietario:'
echo -e '\nChave: '
read chave
# echo -e '\nOwner: '
# read owner
# echo -e '\n'
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 '{"Args":["getHistoryForAsset", "'$chave'"]}'
}
queryAllCars() {
setGlobalsForPeer0Org1
peer chaincode query -C $CHANNEL_NAME -n ${CC_NAME} -c '{"Args":["queryAllCars"]}'
}
# queryAllCars
queryCar() {
setGlobalsForPeer0Org1
echo -e '\nChave: '
read chave
peer chaincode query -C $CHANNEL_NAME -n ${CC_NAME} -c '{"Args":["queryCar", "'$chave'"]}'
}
# queryCar
menu(){
clear
echo -e '*** Hyperledger Fabric Interaction *** \n'
echo -e ' ** Escolha a opcao de consulta ** \n'
select i in addCar changeOwner getHistory queryCar queryAllCars sair
do
case "$i" in
addCar)
echo -e '\n'
addCar
echo -e '\n'
read -n 1 -s -r -p "Pressine qualquer tecla para continuar..."
menu
;;
changeOwner)
echo -e '\n'
changeCarOwner
echo -e '\n'
read -n 1 -s -r -p "Pressine qualquer tecla para continuar..."
menu
;;
getHistory)
echo -e '\n'
getHistory
echo -e '\n'
read -n 1 -s -r -p "Pressine qualquer tecla para continuar..."
menu
;;
queryCar)
echo -e '\n'
queryCar
echo -e '\n'
read -n 1 -s -r -p "Pressine qualquer tecla para continuar..."
menu
;;
queryAllCars)
echo -e '\n'
queryAllCars
echo -e '\n'
read -n 1 -s -r -p "Pressine qualquer tecla para continuar..."
menu
;;
sair)
echo -e '\n'
echo "saindo..."
break
;;
*)
echo "opcao invalida, tente novamente"
;;
esac
done
exit 0
}
menu