-
Notifications
You must be signed in to change notification settings - Fork 2
/
reseeder.sh
executable file
·65 lines (53 loc) · 1.14 KB
/
reseeder.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
#!/bin/bash
# begin
reseed_interval=$1
#use for reseeding module access
sender_node_id=$2
echo "reseed every $reseed_interval blocks"
function get_last_block_height() {
local hs=$(randappcli q block --trust-node | jq '.block_meta.header.height | tonumber')
echo $hs
}
function get_btc_hash() {
local hsh=$(curl https://blockchain.info/latestblock | jq .hash)
echo $hsh
if [ -z $hsh ]
then
return 1
else
return 0
fi
}
prevHeight=$(get_last_block_height)
echo last block height = $prevHeight
function is_time_to_reseed() {
local lb=$(get_last_block_height)
local pH=$prevHeight
local diff=$(($lb - $pH))
echo $lb
if [ $diff -ge $reseed_interval ]
then
return 0
else
return 1
fi
}
while [ 1 ]
do
r=$(is_time_to_reseed)
r2=$?
if [ $r2 -eq 0 ]
then
echo "time to reseed"
prevHeight=$r
seed=$(get_btc_hash)
s2=$?
if [ $s2 -eq 0 ]
then
docker exec -ti "randappdnode$sender_node_id" bash -c "./randappcli tx reseeding send $seed --keyring-backend=test --chain-id=rchain --from node$sender_node_id -y"
fi
fi
echo "Waiting for reseeding time..."
sleep 2
done
# end