-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathstartfabric.sh
executable file
·144 lines (110 loc) · 4.53 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
#!/bin/bash
# This script runs all the different Fabric commands needed to get the chaincode started,
# as well as running the chaincode jar and connecting to the proper address.
# It assumes the chaincode is stored in a file called 'chaincode.jar' under the folder
# '../build' (this file is produced by 'gradle build'.)
# The script color-codes the output of each process and prepends a tag so you can see
# the output of all Fabric processes without having to open several terminals.
# Note: Because this script is intended for internal development use, and not for
# use by people who are trying to actually operate blockchain things, it deletes the
# entire /var/hyperledger/production folder when re-run with the 'clean' option, since
# hyperledger doesn't really support removing channels or chaincodes. (for good reason!
# but when testing we want to be able to.) However, please be careful with this if you
# have other Hyperledger things going on on your machine!
# These set certain pause lengths so you can actually see what it is doing.
ENTER_PAUSE=0.4
BETWEEN_PAUSE=0.25
if [ -z "$1" ] ; then
echo "Usage: $0 <path to chaincode.jar> [ clean | restore ] [ <instantiation parameters> ]"
echo " for example: $0 build/chaincode.jar clean '\"a\",\"200\",\"b\",\"100\"'"
echo "!!!! Warning: the 'clean' option will delete everything in /var/hyperledger/production."
echo "!!!! Please be careful with it."
echo "(However, without it, this script probably won't work multiple times.)"
echo "Use the restore option to bring a chaincode back after shutting it down."
exit 1
fi
CCPATH=$1
CCDIR=$(dirname $CCPATH)
CCNAME="mycc"
CCVERSION=0
INIT_PARAMS=$2
RESTORE=""
if [ "$2" == "clean" ]; then
rm -f ch1.block
rm -rf /var/hyperledger/production
mkdir /var/hyperledger/production
INIT_PARAMS=$3
elif [ "$2" == "restore" ]; then
RESTORE="yes"
INIT_PARAMS=$3
fi
pkill orderer || true
pkill peer || true
# Color settings
CNORM=$(tput setaf 15)
CORDR=$(tput setaf 12)
CPEER=$(tput setaf 6)
CCHAN=$(tput setaf 11)
CINST=$(tput setaf 9)
CCODE=$(tput setaf 10)
echo $CNORM'======= START ORDERER ======='
sleep $ENTER_PAUSE
ORDERER_GENERAL_GENESISPROFILE=SampleDevModeSolo orderer 2>&1 | sed "s/^/$CORDR[-orderer-] /" &
sleep 0.5
echo $CNORM'====== ORDERER STARTED ======'
sleep $BETWEEN_PAUSE
echo $CNORM'======== START PEER ========='
sleep $ENTER_PAUSE
peer node start --peer-chaincodedev 2>&1 | tee peer_output.tmp | sed "s/^/$CPEER[peer-node] /" &
sleep 1
echo $CNORM'======= PEER STARTED ========'
sleep $BETWEEN_PAUSE
if [ -z "$RESTORE" ]; then
echo $CNORM'====== CREATE CHANNEL ======='
sleep $ENTER_PAUSE
peer channel create -c ch1 -o localhost:7050 2>&1 | sed "s/^/$CCHAN[make-chan] /"
sleep 0.5
echo $CNORM'====== CREATED CHANNEL ======'
sleep $BETWEEN_PAUSE
echo $CNORM'======= JOIN CHANNEL ========'
sleep $ENTER_PAUSE
peer channel join -b ch1.block -o localhost:7050 2>&1 | sed "s/^/$CCHAN[join-chan] /"
sleep 0.5
echo $CNORM'====== JOINED CHANNEL ======='
sleep $BETWEEN_PAUSE
echo $CNORM'===== INSTALL CHAINCODE ====='
sleep $ENTER_PAUSE
peer chaincode install -l java -p $CCDIR -n $CCNAME -v $CCVERSION 2>&1 | sed "s/^/$CINST[-install-] /"
sleep 0.5
echo $CNORM'==== CHAINCODE INSTALLED ===='
fi
sleep $BETWEEN_PAUSE
ip=$(cat peer_output.tmp | grep 'address=' | sed 's/.*address=//g' | sed 's/^\[//g' | sed 's/:.*$//' | head -1)
# echo -e "\e[96mIP address to connect to: " $ip
echo -e "\e[96m *** IP: $ip *** $CNORM"
sleep $BETWEEN_PAUSE
echo $CNORM'======= RUN CHAINCODE ======='
sleep $ENTER_PAUSE
java -jar $CCPATH -a $ip:7052 -i $CCNAME:$CCVERSION 2>&1 | sed "s/^/$CCODE[chaincode] /" &
sleep 5
echo $CNORM'===== CHAINCODE RUNNING ====='
sleep $BETWEEN_PAUSE
if [ -n "$INIT_PARAMS" ]; then
echo $CNORM'=== INSTANTIATE CHAINCODE ==='
echo -e "\e[96mInstantiation command: {\"Args\":[\"init\",$INIT_PARAMS]}"$CNORM
sleep $ENTER_PAUSE
peer chaincode instantiate -n $CCNAME -v $CCVERSION -l java -C ch1 -c "{\"Args\":[\"init\",$INIT_PARAMS]}" 2>&1 | sed "s/^/$CINST[-instant-] /"
sleep 1
echo -e "\e[96m(waiting for the blockchain!!)$CNORM"
sleep 2.5
echo $CNORM'=== CHAINCODE INSTANTIATED ==='
else
echo -e "\e[96m *** Note: No instantiation provided. ***$CNORM"
echo -e "\e[96m *** Please run 'peer chaincode instantiate' manually. ***$CNORM"
fi
sleep $BETWEEN_PAUSE
echo -e "\e[96m *** Great! We made it. *** $CNORM"
rm peer_output.tmp
sleep $BETWEEN_PAUSE
echo $CNORM'============ READY ==========='
sleep 1000000000