-
Notifications
You must be signed in to change notification settings - Fork 0
/
simnet.sh
executable file
·144 lines (120 loc) · 3.03 KB
/
simnet.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
#
# A POSIX variable
OPTIND=1 # Reset in case getopts has been used previously in the shell.
# Initialize our own variables:
clear=0
daemon=1
wallet=1
first=0
loglevel=
while getopts "h?frdwl:" opt; do
case "$opt" in
h|\?)
echo "$(basename ""$0"") [-h] [-?] [-f|-c] [-d|-w] [-l loglevel] nodes_count"
exit 0
;;
c) clear=1
;;
f) first=1
clear=1
;;
d) wallet=0
;;
w) daemon=0
;;
l) loglevel=$OPTARG
;;
esac
done
shift $((OPTIND-1))
[ "${1:-}" = "--" ] && shift
# CONFIGS
: ${NDRD_DIR:=/tmp/ndrd}
: ${NDRW_DIR:=/tmp/ndrw}
: ${NDRW_TMP_DIR:=/tmp/ndrw_tmp}
# addresses and keys
MINING_ADDR=SsjBm7VwPmzG9LF1NJp8NjgHuHp8RqnVNCa
MINING_SKEY=PsURc5Lzk5GZhPeTkjzXsGpWS7yEkR6y8VuEaxB5PDpA8Lmrz2JPU
# command shortcuts
#NDRD="ndrd --simnet -ua -Pa --miningkey=$MINING_SKEY"
NDRD="ndrd --simnet -ua -Pa -A$NDRD_DIR --miningaddr=$MINING_ADDR --notls"
NDRW="ndrw --simnet -ua -Pa -A$NDRW_DIR --createtemp --noservertls --noclienttls"
NDRW_TMP="ndrw --simnet -ua -Pa -A$NDRW_TMP_DIR --createtemp --noservertls --noclienttls"
CTL="ndrctl --simnet -ua -Pa --notls --skipverify"
CTLW="ndrctl --simnet -ua -Pa --notls --skipverify --wallet"
# function
function START {
"$@" >/dev/null &
#start "$@"
}
# stop running daemon
if [[ $wallet -ne 0 ]]; then
$CTLW stop 2>/dev/null | grep stopping && sleep 3s
fi
$CTL stop 2>/dev/null | grep stopping && sleep 3s
# process OPTs
if [[ $clear -ne 0 ]]; then
rm -rf "$NDRD_DIR/data/simnet"
rm -rf "$NDRD_DIR/logs/simnet"
rm -rf "$NDRW_DIR/simnet"
rm -rf "$NDRW_DIR/logs/simnet"
fi
rm -rf "$NDRW_TMP_DIR"
if [[ ! -z "$loglevel" ]]; then
NDRD="$NDRD --debuglevel=$loglevel"
NDRW="$NDRW --debuglevel=$loglevel"
fi
if [[ $daemon -ne 0 ]]; then
START $NDRD
sleep 1
$CTL generate 18
if [[ $first -ne 0 ]]; then
START $NDRW
sleep 5
WALLET_ADDR=`$CTLW getnewaddress`
$CTLW stop
START $NDRW_TMP
sleep 5
$CTLW walletpassphrase password 0
$CTLW importprivkey $MINING_SKEY
$CTLW getbalance
$CTLW listunspent
ACC=imported
$CTLW sendfrom $ACC $WALLET_ADDR 13
$CTL generate 1
$CTLW stop
fi
# restart the daemon for persistent test
$CTL stop && sleep 3s
START $NDRD
fi
if [[ $wallet -ne 0 ]]; then
sleep 2
START $NDRW
sleep 5
$CTLW walletpassphrase "password" 0
aa=""
#bb=""
for i in {0..10}; do
aa="$aa\"`$CTLW getnewaddress`\":0.$((RANDOM%3+3)),"
#bb="$bb\"`$CTLW getnewaddress`\":0.$((RANDOM%3+3)),"
done
$CTLW sendmany default {${aa::-1}}
#$CTLW sendmany default {${bb::-1}} STB
$CTL generate 1
# for i in {0..9}; do
# $CTLW ask 0.$((RANDOM%5))$((RANDOM%9+1)) 2.$((RANDOM%2))$((RANDOM%10))
# $CTLW bid 0.$((RANDOM%5))$((RANDOM%9+1)) 1.$((RANDOM%2+8))$((RANDOM%10))
# done
fi
# idle waiting for Ctrl-D from user
echo "Ctrl-D to finish and stop all daemons.."
$(</dev/stdin)
# tail the log
#grc -c grc.conf tail -F {$NDRD_DIR,$NDRW_DIR,$NDRW_TMP_DIR}/logs/simnet/ndr*.log
# stop running daemons
if [[ $wallet -ne 0 ]]; then
$CTLW stop 2>/dev/null | grep stopping && sleep 3s
fi
$CTL stop 2>/dev/null | grep stopping && sleep 3s