-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpost_install.sh
executable file
·333 lines (280 loc) · 7.57 KB
/
post_install.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
#!/bin/bash
export ENDPOINT=http://localhost:9082/api/v3
wallet=./data/godWallet.json
scoreAddressFileName=scoreAddr.env
###################Helpers##############
usage() {
echo "Usage: $0 []"
exit 1
}
if [ $# -eq 1 ]; then
CMD=$1
else
usage
fi
function printDebugTrace() {
local txHash=$1
goloop debug trace --uri http://localhost:9082/api/v3d $txHash | jq -r .
}
function wait_for_it() {
local txHash=$1
echo "Txn Hash: "$1
status=$(goloop rpc txresult --uri $ENDPOINT $txHash | jq -r .status)
if [ $status == "0x1" ]; then
echo "Successful"
else
echo $status
read -p "Print debug trace? [y/N]: " proceed
if [[ $proceed == "y" ]]; then
printDebugTrace $txHash
fi
exit 0
fi
}
i=0
function registerPRep() {
((i++))
wallet=$1
password=gochain
prep=$(cat $wallet | jq -r .address)
echo "Registering" $prep "as prep"
local txHash=$(goloop rpc sendtx call \
--uri $ENDPOINT \
--nid 3 \
--step_limit 1000000000\
--to cx0000000000000000000000000000000000000000 \
--value 0x6c6b935b8bbd400000 \
--method registerPRep \
--param name=Prep$i \
--param country=KOR \
--param city=Seoul \
--param [email protected] \
--param website="https://www.google.com" \
--param details="https://www.google$i.com"\
--param p2pEndpoint=192.168.0.0:2321\
--key_store $wallet \
--key_password $password | jq -r .)
sleep 2
wait_for_it $txHash
}
function setRevision() {
echo "Set revision"
local txHash=$(goloop rpc sendtx call \
--uri $ENDPOINT \
--nid 3 \
--step_limit 1000000000\
--to cx0000000000000000000000000000000000000001 \
--method setRevision \
--param code=0x15 \
--key_store $wallet \
--key_password $password | jq -r .)
sleep 2
wait_for_it $txHash
}
function setStake() {
echo "Set stake"
local bond=0x2a5a058fc295ed000000
local wallet=$1
local password=gochain
local txHash=$(goloop rpc sendtx call \
--uri $ENDPOINT \
--nid 3 \
--step_limit 1000000000\
--to cx0000000000000000000000000000000000000000 \
--method setStake \
--param value=$bond \
--key_store $wallet \
--key_password $password | jq -r .)
sleep 2
wait_for_it $txHash
}
function setDelegation() {
echo "Set delegation list"
local password=gochain
local prep=$(cat $wallet | jq -r .address)
local param="{\"params\":{\"delegations\":[{\"address\":\"${prep}\",\"value\":\"0x152d02c7e14af6800000\"}]}}"
local txHash=$(goloop rpc sendtx call \
--uri $ENDPOINT \
--nid 3 \
--step_limit 1000000000\
--to cx0000000000000000000000000000000000000000 \
--method setDelegation \
--raw $param \
--key_store $wallet \
--key_password $password | jq -r .)
sleep 2
wait_for_it $txHash
}
function setBonderList() {
echo "Set bonder list"
local password=gochain
local prep=$(cat $wallet | jq -r .address)
local param="{\"params\":{\"bonderList\":[\"${prep}\"]}}"
local txHash=$(goloop rpc sendtx call \
--uri $ENDPOINT \
--nid 3 \
--step_limit 1000000000\
--to cx0000000000000000000000000000000000000000 \
--method setBonderList \
--raw $param \
--key_store $wallet \
--key_password $password | jq -r .)
sleep 2
wait_for_it $txHash
}
function setBond() {
echo "Setting bond"
local prep=$(cat $wallet | jq -r .address)
local param="{\"params\":{\"bonds\":[{\"address\":\"${prep}\",\"value\":\"0x152d02c7e14af6800000\"}]}}"
local password=gochain
local txHash=$(goloop rpc sendtx call \
--uri $ENDPOINT \
--nid 3 \
--step_limit 1000000000\
--to cx0000000000000000000000000000000000000000 \
--method setBond \
--raw $param \
--key_store $wallet \
--key_password $password | jq -r .)
sleep 2
wait_for_it $txHash
}
function registerPublicKey() {
echo "Set node public key"
local wallet=$1
local pubKey=$2
local password=gochain
local txHash=$(goloop rpc sendtx call \
--uri $ENDPOINT \
--nid 3 \
--step_limit 1000000000\
--to cx0000000000000000000000000000000000000000 \
--method setPRepNodePublicKey \
--param pubKey=$pubKey \
--key_store $wallet \
--key_password $password | jq -r .)
sleep 2
wait_for_it $txHash
}
# contract that can send BTP Message
function deployBTPContract() {
echo "Deploying a contract that can send BTPMessage"
local wallet=$1
local password=gochain
local txHash=$(goloop rpc sendtx deploy btp-optimized.jar \
--content_type application/java \
--uri $ENDPOINT \
--nid 3 \
--step_limit 100000000000\
--to cx0000000000000000000000000000000000000000 \
--param name=BTP \
--key_store $wallet \
--key_password $password | jq -r .)
sleep 2
wait_for_it $txHash
scoreAddr=$(goloop rpc txresult --uri $ENDPOINT $txHash | jq -r .scoreAddress)
echo $scoreAddr > $scoreAddressFileName
}
function openBTPNetwork() {
echo "Opening BTP Network of type eth"
local wallet=$1
local name=$2
local owner=$3
local password=gochain
local txHash=$(goloop rpc sendtx call \
--uri $ENDPOINT \
--nid 3 \
--step_limit 1000000000\
--to cx0000000000000000000000000000000000000001 \
--method openBTPNetwork \
--param networkTypeName=eth \
--param name=$name \
--param owner=$owner \
--key_store $wallet \
--key_password $password | jq -r .)
sleep 2
wait_for_it $txHash
}
function setNetworkId() {
echo "Setting Network Id"
local wallet=$1
local toContract=$2
local password=gochain
local txHash=$(goloop rpc sendtx call \
--uri $ENDPOINT \
--nid 3 \
--step_limit 1000000000\
--to $toContract \
--method setNetworkId \
--param nid=0x1 \
--key_store $wallet \
--key_password $password | jq -r .)
sleep 2
wait_for_it $txHash
}
function sendBTPMessage() {
echo "Sending BTP Message---"
local wallet=$1
local toContract=$2
local password=gochain
local txHash=$(goloop rpc sendtx call \
--uri $ENDPOINT \
--nid 3 \
--step_limit 1000000000\
--to $toContract \
--method sendBTPMessageWithBytes \
--param message=0x04b3d972e61b4e8bf796c00e84030d22414a94d1830be528586e921584daadf934f74bd4a93146e5c3d34dc3af0e6dbcfe842318e939f8cc467707d6f4295d57e5\
--key_store $wallet \
--key_password $password | jq -r .)
# sleep 2
echo $txHash
# wait_for_it $txHash
}
function getPublicKey() {
goloop rpc call --uri http://localhost:9082/api/v3 \
--to cx0000000000000000000000000000000000000000 \
--method getPRepNodePublicKey \
--param address=$(cat $1| jq -r .address)
}
function setupBTP(){
echo "Run this after starting gochain-icon-image"
echo "Starting after 5 seconds...."
sleep 5
configure
deployBTPContract $wallet
openBTPNetwork $wallet icon-archway $scoreAddr
setNetworkId $wallet $scoreAddr
}
function configure(){
echo "Run this after starting gochain-icon-image"
echo "Starting after 5 seconds...."
sleep 5
registerPRep $wallet
setStake $wallet
setDelegation $wallet
setBonderList $wallet
setBond $wallet
registerPublicKey $wallet 0x04b3d972e61b4e8bf796c00e84030d22414a94d1830be528586e921584daadf934f74bd4a93146e5c3d34dc3af0e6dbcfe842318e939f8cc467707d6f4295d57e5 # public key of godwallet
}
function testMessage(){
echo $wallet
local scoreAddrFromF="$(cat $scoreAddressFileName)"
echo $scoreAddressFileName
echo $scoreAddrFromF
sendBTPMessage $wallet $scoreAddrFromF
}
##########Main switch case ###############
case "$CMD" in
setup )
setupBTP
;;
cfg )
configure
;;
sendBTPMessage )
testMessage
;;
* )
echo "Error: unknown command: $CMD"
usage
esac