-
Notifications
You must be signed in to change notification settings - Fork 0
/
simnet.sh
executable file
·131 lines (110 loc) · 2.85 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
#!/bin/sh
#
# A POSIX variable
OPTIND=1 # Reset in case getopts has been used previously in the shell.
# Initialize our own variables:
remove=0
daemon=1
wallet=1
first=0
loglevel=
while getopts "h?frdwl:" opt; do
case "$opt" in
h|\?)
echo "$(basename ""$0"") [-h] [-?] [-f|-r] [-d|-w] [-l loglevel] nodes_count"
exit 0
;;
r) remove=1
;;
f) first=1
remove=1
;;
d) wallet=0
;;
w) daemon=0
;;
l) loglevel=$OPTARG
;;
esac
done
shift $((OPTIND-1))
[ "${1:-}" = "--" ] && shift
# addresses and keys
MINING_ADDR=ame7CaXCbBV4YvpLUX3fNsGSd7y3ryBfKf
MINING_SKEY=Fw28Hpjon65S4XT8uyfh7w7UFxWVExTs8oDyQZXwB1fTgwwzxnVY
# command shortcuts
CTL="ndrctl --simnet --rpcuser=a --rpcpass=a --skipverify"
CTLW="$CTL --wallet"
BTCD="btcd --simnet --rpcuser=a --rpcpass=a --miningkey=$MINING_SKEY"
BTCW="btcwallet --simnet --connect=localhost --username=a --password=a --createtemp"
# 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 [[ $remove -ne 0 ]]; then
rm -rf "$LOCALAPPDATA/btcd/data/simnet"
rm -rf "$LOCALAPPDATA/btcd/logs/simnet"
rm -rf "$LOCALAPPDATA/btcwallet/simnet"
rm -rf "$LOCALAPPDATA/btcwallet/logs/simnet"
fi
rm -rf "$LOCALAPPDATA/btcwalletTMP/simnet"
rm -rf "$LOCALAPPDATA/btcwalletTMP/logs/simnet"
if [[ ! -z "$loglevel" ]]; then
BTCD="$BTCD --debuglevel=$loglevel"
BTCW="$BTCW --debuglevel=$loglevel"
fi
if [[ $daemon -ne 0 ]]; then
START $BTCD
if [[ $first -ne 0 ]]; then
START $BTCW --appdata="$LOCALAPPDATA/btcwallet"
sleep 5
WALLET_ADDR=`$CTLW getnewaddress`
$CTLW stop
START $BTCW --appdata="$LOCALAPPDATA/btcwalletTMP"
sleep 5
$CTLW walletpassphrase "password" 0
$CTLW importprivkey $MINING_SKEY
ACC=imported
$CTLW sendfrom $ACC $WALLET_ADDR 6 NDR
$CTLW sendfrom $ACC $WALLET_ADDR 13 STB
$CTL generate 1
$CTLW stop
fi
# restart the daemon for persistent test
$CTL stop && sleep 3s
START $BTCD
fi
if [[ $wallet -ne 0 ]]; then
sleep 2
START $BTCW --appdata="$LOCALAPPDATA/btcwallet"
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}} NDR
$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)
# 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