-
Notifications
You must be signed in to change notification settings - Fork 29
/
validateaddress.sh
executable file
·37 lines (35 loc) · 1.06 KB
/
validateaddress.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
#!/bin/bash
cd "${BASH_SOURCE%/*}" || exit
Radd=$(./printkey.py Radd)
privkey=$(./printkey.py wif)
chain=${1}
cli=$(./listclis.sh ${chain})
# Wait for the deamon to actually start
started=0
timewaited=0
while (( started == 0 )); do
sleep 10
timewaited=$(( timewaited +10 ))
if (( ((timewaited % 30)) == 0 )); then
echo "[${chain}] : waited ... ${timewaited}s ... errcode: ${outcome}"
fi
validateaddress=$(${cli} validateaddress ${Radd} 2> /dev/null)
outcome=$(echo $?)
if (( outcome == 0 )); then
started=1
elif (( outcome == 1 )) && (( timewaited > 30 )); then
exit
fi
done
mine=$(jq -r .ismine <<<"${validateaddress}")
if [[ ${mine} == "false" ]]; then
echo "[${chain}] : Importing private key and rescanning last 10,000 blocks..."
height=$(${cli} getblockcount)
if (( height < 10000 )); then
echo "[${chain}] : $(${cli} importprivkey ${privkey})"
else
echo "[${chain}] : $(${cli} importprivkey ${privkey} "" true $(( height - 10000 )))"
fi
else
echo "[${chain}] : ${Radd}"
fi