/
rebuild_wallet_macos
executable file
·126 lines (98 loc) · 3.71 KB
/
rebuild_wallet_macos
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
#!/bin/bash
TARBIN=`which tar`
USER=`whoami`
CREATEBACKUP=1
DIR=$PWD
CURLBIN=`which curl`
USER=PayDayrpc
PASS=2r29rQxgav7TzGKvyGEYVmQEETcUY6bMjimJVMhQGxzr
if [ "$CURLBIN" == "" ]; then
echo "For script working need a curl binary"
exit 0
fi
if [ "$TARBIN" == "" ]; then
echo "For script working need a tar binary"
exit 0
fi
wait_to_start() {
open -a $BINARY --args -daemon -listen -server -rpcuser=$USER -rpcpassword=$PASS -enableaccounts -staking=0 -createwalletbackups=100 -min -splash=0
while [ -z "$(netstat -lant | grep 7215)" ]
do
echo -n .
sleep 1
done
sleep 1
echo
}
wait_to_stop() {
while [ -n "$(ps -A | grep -m1 [P]ayDay | awk '{print $1}')" ]
do
echo -n .
sleep 1
done
echo
}
if [ -d "/Applications/PayDay-Qt.app/" ]; then
BINARY="/Applications/PayDay-Qt.app"
fi
if [ -d "$DIR/PayDayCoin-qt.app" ]; then
BINARY="$DIR/PayDayCoin-qt.app"
fi
wait_to_start
KEYS=`$CURLBIN -s --user $USER:$PASS http://127.0.0.1:7215 --data-binary "{\"jsonrpc\": \"1.0\", \"id\":\"curltest\", \"method\": \"listaccounts\", \"params\": [] }" -H "content-type: text/plain" | grep -o "\"[a-zA-Z0-9[:space:]]*\":[0-9\.]*" | tr -d \"`
var1=1
IFS=$'\n'
for pair in $KEYS
do
key=$(echo $pair | awk -F: '{print $1}')
[ "$key" == "error" ] || [ "$key" == "result" ] || [ "$key" == "id" ] || {
addr=`$CURLBIN -s --user $USER:$PASS http://127.0.0.1:7215 --data-binary "{\"jsonrpc\": \"1.0\", \"id\":\"curltest\", \"method\": \"getaddressesbyaccount\", \"params\": [\"$key\"] }" -H "content-type: text/plain" | grep -o "M[a-zA-Z0-9]*"`
if [ -n "$addr" ]; then
priv=`$CURLBIN -s --user $USER:$PASS http://127.0.0.1:7215 --data-binary "{\"jsonrpc\": \"1.0\", \"id\":\"curltest\", \"method\": \"dumpprivkey\", \"params\": [\"$addr\"] }" -H "content-type: text/plain" | grep -o "D[a-zA-Z0-9]*"`
privkeys[$var1]="\"$key\":\"$priv\""
var1=$(( $var1 + 1 ))
fi
}
done
$CURLBIN -s --user $USER:$PASS http://127.0.0.1:7215 --data-binary "{\"jsonrpc\": \"1.0\", \"id\":\"curltest\", \"method\": \"stop\", \"params\": [] }" -H "content-type: text/plain" > /dev/null
wait_to_stop
if [ "$CREATEBACKUP" == "1" ]; then
cd $HOME
tar -cf PayDay-wallet_backup-$(date +%s).tar "$HOME/Library/Application Support/PayDay"
echo "Create backup PayDay Profile in HOME folder"
fi
wallets=($(ls "$HOME/Library/Application Support/PayDay/backups"))
echo "Select backup wallet file and type his number:"
for index in ${!wallets[*]}
do
echo [$index]: ${wallets[$index]}
done
read -p "Enter number: " BPOS
if [[ $BPOS =~ ^[0-9]*$ ]]; then
if [ "$BPOS" -gt ${#wallets[*]} ]; then
echo "Out of range. Using first backup wallet."
WNAME=${wallets[0]}
else
WNAME=${wallets[$BPOS]}
fi
else
echo "Wrong value. Using first backup wallet"
WNAME=${wallets[0]}
fi
echo "Clear PayDay Profile"
find "$HOME/Library/Application Support/PayDay" -type f ! -name "PayDay.conf" ! -name "wallet.dat*" -delete
find "$HOME/Library/Application Support/PayDay" -type d ! -name "backups" -delete
cp "$HOME/Library/Application Support/PayDay/backups/$WNAME" "$HOME/Library/Application Support/PayDay/wallet.dat"
wait_to_start
sleep 10
for (( ind = 1; ind < var1; ind++ ))
do
data=${privkeys[$ind]}
key=$(echo $data | awk -F: '{print $2}' | tr -d \")
value=$(echo $data | awk -F: '{print $1}' | tr -d \")
$CURLBIN -s --user $USER:$PASS http://127.0.0.1:7215 --data-binary "{\"jsonrpc\": \"1.0\", \"id\":\"curltest\", \"method\": \"importprivkey\", \"params\": [\"$key\", \"$value\"] }" -H "content-type: text/plain" > /dev/null
done
$CURLBIN -s --user $USER:$PASS http://127.0.0.1:7215 --data-binary "{\"jsonrpc\": \"1.0\", \"id\":\"curltest\", \"method\": \"stop\", \"params\": [] }" -H "content-type: text/plain" > /dev/null
wait_to_stop
echo "Start wallet and check balanses and Received addresses"
exit 0