-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtransactions
More file actions
executable file
·137 lines (123 loc) · 3.21 KB
/
transactions
File metadata and controls
executable file
·137 lines (123 loc) · 3.21 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
#!/bin/bash
# set -e
rpc_ip=${1:-"127.0.0.1:5015"}
ssh_host=${2:-localhost}
rpc_private=${3:-5015}
shift 3
unset file
if [[ $# -gt 0 ]]
then
if [[ -f "${1}" ]]
then
file="${1}"
echo "Tracking last ledger using ${1}"
shift
else
echo "File not found: ${1}"
exit 1
fi
fi
accounts=( rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh )
for accountfile in "$( dirname $0 )/ripple-account.txt" "$( dirname $0 )/ripple-accounts.txt"
do
echo Looking for account file ${accountfile}
if [ -r ${accountfile} ]
then
accounts=( $( cat ${accountfile} ) )
echo "Found accounts ${accounts[@]}"
break
fi
done
can_delete()
{
set -o pipefail
if [[ -n "${file}" ]]
then
if [[ $# -eq 0 ]]
then
cat "${file}"
else
echo "${@}" > "${file}"
fi
elif [[ ${ssh_host} == $( hostname ) ]] || [[ ${ssh_host} == "localhost" ]]
then
~/bin/rippled -q --rpc_ip=127.0.0.1:${rpc_private} can_delete $* | \
jq '.result.can_delete'
else
ssh ${ssh_host} ~/bin/rippled -q --rpc_port=127.0.0.1:${rpc_private} can_delete $1 | \
jq '.result.can_delete'
fi
}
until last=$( can_delete ) && [[ ${last} != "null" ]]
do
echo "Can not determine starting point (${last}). Will retry."
sleep 60
done
echo Last checked ledger: $last
next=$(( ${last} + 1 ))
while true
do
echo
date
echo Checking starting with ${next}
unset nextdelete
for account in "${accounts[@]}"
do
echo Looking for transactions for ${account} starting from ledger ${next}
time txs=$( ~/bin/rippled -q --rpc_ip=${rpc_ip} account_tx \
-- ${account} ${next} ${nextdelete:--1} descending )
error=$(echo ${txs} | jq '.error' )
status=$(echo ${txs} | jq '.result.status' )
if [[ ${error} != "null" ]]
then
echo Error: $error
echo ${txs} | jq '[ .error_message, .error_what ]'
sleep 60
break
elif [[ ${status} != '"success"' ]]
then
echo account_tx status: ${status}
echo ${txs} | jq '[ .result.error, .result.error_message ]'
sleep 60
break
fi
min=$( echo ${txs} | jq '.result.ledger_index_min' )
max=$( echo ${txs} | jq '.result.ledger_index_max' )
if [[ ${min} > ${next} ]]
then
backfill=$(( ${min} - ${next} ))
echo rippled only has ${min}-${max}. Wait for backfill ${backfill} ledgers.
wait=$(( $backfill > 300 ? $backfill / 10 : 30 ))
echo "Wait ${wait} seconds"
sleep ${wait}
unset nextdelete
break
fi
if [[ -z "${nextdelete}" ]]
then
nextdelete=${max}
echo Pending can_delete to ${nextdelete}
fi
count=$( echo ${txs} | jq '.result.transactions | length' )
echo Found ${count} txs in ${min}-${max}
if [[ ${count} > 0 ]]
then
echo "${txs}" >> transactions.${min}-${max}.txt
fi
done
if [[ -n "${nextdelete}" ]]
then
if last=$( can_delete ) && [[ ${last} != "null" && \
"${last}" != "$[ ${next} - 1 ]" ]]
then
next="${last}"
echo can_delete was updated externally to ${last}. Check now.
else
can_delete ${nextdelete}
next=$(( ${nextdelete} + 1 ))
echo Updated can_delete to $( can_delete ). Wait 30 seconds.
# Delay enough time for a new ledger to close.
sleep 30
fi
fi
done