-
Notifications
You must be signed in to change notification settings - Fork 5
/
client-run.sh
77 lines (64 loc) · 2.48 KB
/
client-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
#!/bin/bash
# (C) 2019 Keir Finlow-Bates
# See LICENSE for the licensing details of this software
if [ -z $BASH_VERSION ] ; then
echo "You must run this script using bash" 1>&2
exit 1
fi
# uncomment for debug info
set -x
# This script uses python3.
# Activate the virtual python3 environment
source venv/bin/activate
# Proof of concept - so minimal error checking!
# check if game blockchain has already been connected to
# if it is not running, start it
# if it does not exist, create it
# the asset bank is run in the default directory .multichain.
# game nodes are run in a .multichain-player
# ports are configured to allow two blockchain instances to work on one machine
# check if the blockchain node is already configured
if [ -e ~/.multichain-player/game/params.dat ]
then
echo -e "Game blockchain already exists."
multichain-cli -datadir=~/.multichain-player -port=19255 -rpcport=19254 game getinfo
if [ $? -eq 0 ]
then
echo -e "Game player blockchain is running."
else
echo -e "Starting game player blockchain daemon."
# run with reindex in case there was a broken shutdown
multichaind -datadir=~/.multichain-player -port=19255 -rpcport=19254 -reindex=1 game -daemon
fi
# otherwise sign up, get address activated, and start node
else
if [ -z "$1" ]
then
echo -e "No blockchain address supplied"
exit 0
else
if [ -z "$2" ]
then
echo -e "No signup address supplied"
exit 0
else
# create multichain player instance by connecting to asset bank, extract your local address
# and send it to the asset bank webserver for automatic connection
mkdir ~/.multichain-player
gameblockchain=$1
myaddress=$(multichaind -datadir=~/.multichain-player -port=19255 -rpcport=19254 $1 | grep -P -i -o -m 1 '(?<=grant )\S+' | sed -r 's/^\W|\W$//g')
echo -e "My address: $myaddress"
# POST section to sign up
curl --header "Content-Type: application/json" --request POST --data '{"address":"'"$myaddress"'"}' $2
# wait a few seconds for signup transaction to register
echo -e "Starting game player blockchain daemon."
multichaind -datadir=~/.multichain-player -port=19255 -rpcport=19254 game -daemon
fi
fi
fi
# this runs the application
echo -e "Starting client interface"
# start local webserver and browser
# in same shell, so quitting browser kills webserver (except it doesn't)
google-chrome --app=http://localhost:5002 &>/dev/null &
FLASK_APP=client-app.py flask run --host=0.0.0.0 --port 5002