-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathresetwalletrescan
More file actions
executable file
·159 lines (133 loc) · 4.29 KB
/
resetwalletrescan
File metadata and controls
executable file
·159 lines (133 loc) · 4.29 KB
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/bin/bash
#
# Reset wallet using rescanblockchain method
#
# @author webworker01
#
scriptpath="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
source $scriptpath/main
if [[ -z $1 ]]; then
echo "Usage: ./resetwalletrescan <coin (LTC|CHIPS)>"
exit 0
fi
if (( $thirdpartycoins < 1 )); then
searchlist="coinsfirst[@]"
else
searchlist="coinsthird[@]"
fi
#search
for coins in "${!searchlist}"; do
searchcoin=($coins)
if [[ "${searchcoin[4]}" == "rescan" ]] && [[ "${1^^}" == "${searchcoin[0]}" ]]; then
eval $(echo coincli=${searchcoin[1]})
eval $(echo coinexec=${searchcoin[2]})
eval $(echo pidfile=${searchcoin[5]})
datadir="${HOME}/${searchcoin[3]}"
fi
done
if [[ -z $coincli ]]; then
log "resetwalletrescan" "${1} does not exist in paths!" "red" "echo"
exit 0
fi
coin=${1^^}
utxoamt=0.00010000
splitamount=10000
splitcoin=$coin
if [[ ! -z $ltc_address && $coin == "LTC" ]]; then
address=$ltc_address
splitqty=$ltcutxoqty
confcheck=".confirmations"
elif [[ ! -z $chips_address && $coin == "CHIPS" ]]; then
address=$chips_address
splitqty=$otherutxoqty
confcheck=".rawconfirmations"
elif [[ ! -z $aya_address && $coin == "AYA" ]]; then
address=$aya_address
splitqty=$otherutxoqty
splitamount=100000
utxoamt=0.00100000
confcheck=".confirmations"
elif [[ ! -z $sfusd_address && $coin == "SFUSD" ]]; then
address=$sfusd_address
splitqty=$otherutxoqty
confcheck=".confirmations"
elif [[ ! -z $mil_address && $coin == "MIL" ]]; then
address=$mil_address
splitamount=100000
utxoamt=0.00100000
confcheck=".confirmations"
else
echo "can't find address for $coin"
exit 0
fi
pidfile="$datadir/$pidfile"
privkey=$($coincli dumpprivkey $address)
#send balance to self
balance=$($coincli getbalance)
txid=$($coincli sendtoaddress $address $balance "" "" true)
log "resetwalletrescan" "${coin} balance sent $balance - txid : $txid"
#get block height of tx
i=0
confirmations=0
while [ "$confirmations" -eq "0" ]; do
sleep 10
confirmations=$(eval "${coincli} gettransaction ${txid} | jq ${confcheck}")
if [[ "$confirmations" == "null" ]]; then
confirmations=0
fi
i=$(($i+1))
${coincli} sendrawtransaction $(${coincli} getrawtransaction ${txid}) > /dev/null
log "resetwalletrescan" "${coin} sendbalance - waiting for confirmation $confirmations ($i) - ${txid}" "red" "echo"
done
blockhash=$($coincli gettransaction $txid | jq -r .blockhash)
scanfrom=$($coincli getblock $blockhash | jq .height)
#split funds
splitter=$(curl --url "http://127.0.0.1:$iguanaport" --data "{\"coin\":\"${splitcoin}\",\"agent\":\"iguana\",\"method\":\"splitfunds\",\"satoshis\":\"$splitamount\",\"sendflag\":1,\"duplicates\":$splitqty}")
log "resetwalletrescan" "${coin} - utxos: $splitqty - $splitter"
raw_tx=$(jq -r .result <<< $splitter)
if [[ ! -z $raw_tx ]]; then
usesignrawtxwallet=('AYA')
if [[ ${usesignrawtxwallet[*]} =~ ${coin} ]]; then
signed_tx=$(${coincli} signrawtransactionwithwallet ${raw_tx})
else
signed_tx=$(${coincli} signrawtransaction ${raw_tx})
fi
signed_tx=$(jq -r .hex <<< $signed_tx)
if [[ ! -z $signed_tx ]]; then
txid=$(${coincli} sendrawtransaction ${signed_tx})
if [[ ! -z $txid ]]; then
log "resetwalletrescan" "${coin} - utxos: ${splitqty} - ${txid}"
fi
fi
fi
sleep 10
#stop daemon
$coincli stop
i=0
while [ -f $pidfile ]; do
i=$((i+1))
log "resetwalletrescan" "Waiting for daemon ${coin} stop ($i)" "red" "echo"
sleep 1
done
sleep 15
#mv wallet
mv $datadir/wallet.dat $datadir/wallet.dat.old
#start daemon
log "resetwalletrescan" "Restart daemon ${coinexec}"
$coinexec -pubkey=$nn_pubkey &
#wait for start
i=0
while ! $coincli getnetworkinfo >/dev/null 2>&1; do
i=$((i+1))
log "resetwalletrescan" "${coin} - Waiting for daemon start ($i)" "red" "echo"
sleep 1
done
#import key without scan
importedaddress=$($coincli importprivkey $privkey "" false)
log "resetwalletrescan" "${coin} - Imported address -> $importedaddress"
#use rescanblockchain ("start_height")
$coincli rescanblockchain $scanfrom
log "resetwalletrescan" "${coin} - Start rescan from height $scanfrom"
sleep 15
newbalance=$($coincli getbalance)
log "resetwalletrescan" "${coin}- Done! Balance $newbalance"