forked from opengsn/gsn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
restart-relay.sh
executable file
·97 lines (72 loc) · 1.91 KB
/
restart-relay.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
#!/bin/bash -e
if [ "$1" == "help" ]; then
echo Usage:
echo " $0 test - run all tests, and exit"
echo " $0 - (no args) start HttpRelayServer, and wait"
echo " $0 web - start HttpRelayServer and sample MetaCoin web app (downloaded into \"webpack-box\" subfolder"
exit 1
else
echo "use '$0 help' for usage."
fi
function onexit() {
echo onexit
pkill -f ganache
pkill -f RelayHttpServer
}
trap onexit EXIT
dir=`dirname $0`
root=`cd $dir;pwd`
cd $root
#todo: should compile the server elsewhere.
gobin=$root/build/server/bin/
export GOPATH=$root/server/:$root/build/server
echo "Using GOPATH=" $GOPATH
# cd $gobin
./scripts/extract_abi.js
make -C server
#todo: run if changed..
blocktime=${T=0}
pkill -f ganache-cli && echo killed old ganache.
pkill -f RelayHttpServer && echo kill old relayserver
GANACHE="npx ganache-cli -l 8000000 -b $blocktime -a 11 -h 0.0.0.0 "
if [ -n "$DEBUG" ]; then
$GANACHE -d --verbose &
else
#just display ganache version
sh -c "$GANACHE -d |grep ganache-core" &
fi
sleep 2
if ! pgrep -f ganache > /dev/null ; then
echo FATAL: failed to start ganache.
exit 1
fi
hubaddr=`npx truffle migrate | tee /dev/stderr | grep -A 4 "RelayHub" | grep "contract address" | grep "0x.*" -o`
if [ -z "$hubaddr" ]; then
echo "FATAL: failed to detect RelayHub address"
exit 1
fi
#fund relay:
relayurl=http://localhost:8090
( sleep 1 ; ./scripts/fundrelay.js $hubaddr $relayurl 0 ) &
if [ -n "$1" ]; then
$gobin/RelayHttpServer -RelayHubAddress $hubaddr -Workdir $root/build/server &
cd $root
sleep 1
case "$*" in
test) cmd="npx truffle test" ;;
test/*) cmd="npx truffle test $*" ;;
web) cmd="./init_metacoin.sh web" ;;
*) echo "Unknown command. do '$0 help'"; exit 1 ;;
esac
echo "Running: $cmd"
if eval $cmd
then
echo command completed successfully
else
exitcode=$?
echo command failed
fi
exit $exitcode
else
$gobin/RelayHttpServer -RelayHubAddress $hubaddr -Workdir $root/build/server
fi