-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfindcreationledger
More file actions
executable file
·125 lines (122 loc) · 4.04 KB
/
findcreationledger
File metadata and controls
executable file
·125 lines (122 loc) · 4.04 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
#!/bin/bash
# This is only useful if the account was created within the ledger range
# available. If you don't keep a lot of history, you're not going to have much
# success.
#
# Minimal input validation is performed.
#
if [[ $# -eq 0 ]]
then
echo "Usage: findcreationledger <account_id> [<minimum_ledger> [<rpc_ip:rpc_port>]]"
echo
echo "If minimum_ledger is not provided or is 0, the Mainnet ledger where"
echo "the DeleteableAccounts amendment was activated will be used."
# s1 and s2 listen to RPC on port 51234
exit 1
fi
# This is the ledger on mainnet where the deleteable accounts amendment was
# enabled. If an account ever had a sequence less than this, it must have
# been created before. May cause problems on altnets, but I'm not going to
# worry about that now.
deleteableaccounts=55313921
account=$1
shift
[[ $# -gt 0 && $1 -ne 0 ]] && minledger=$1 || minledger=${deleteableaccounts}
notfound="${minledger}"
shift
[[ $# -gt 0 ]] && rpcip="--rpc_ip=$1"
lastseq=0
found=$( rippled ${rpcip} -q ledger validated | jq '.result.ledger_index' )
tests=0
nexttest=0
if [[ -z "${notfound}" || "${notfound}" == "null" \
|| -z "${found}" || "${found}" == "null" ]]
then
echo "Error: Not found: $notfound. Found: $found."
exit 1
fi
while [[ $[ $notfound + 1 ] -lt $found ]]
do
if [[ ${nexttest} -ne 0 ]]
then
test=${nexttest}
else
test=$[ ($notfound + $found) / 2 ]
fi && \
nexttest=0 && \
echo -e "\nNot found: $notfound. Found: $found. Test $test." && \
tests=$[ ${tests} + 1 ]
result=$( rippled ${rpcip} -q account_info $account $test ) && \
seq=$( echo $result | jq '.result.account_data.Sequence' ) && \
if [[ -z "${seq}" || "${seq}" = "null" ]]
then
error=$( echo $result | jq '.result.error_message' )
echo "Not found ${error} at ledger $test"
notfound=$test
else
echo "Found seq $seq at ledger $test"
# It is unlikely and difficult, but not impossible, for an account
# to send more than 55 million transactions, which would make it
# look like a post-DeletableAccounts account when maybe it isn't.
# To speed things up, though, assume any account with a sequence
# that large was created at that ledger.
# Have any accounts sent more than 55 million transactions?
if [[ ${seq} -ge ${deleteableaccounts} && ${seq} -lt ${found} \
&& ${seq} -gt ${notfound} ]]
then
found=${seq}
nexttest=$[ ${seq} - 1 ]
else
found=${test}
fi
lastseq=${seq}
fi || break
done &&\
echo -e "\nNot found: $notfound. Found: $found. Tests: $tests" && \
if [[ $notfound -gt $found ]]
then
echo "Something went wrong"
fi && \
if [[ "${lastseq}" -eq 0 ]]
then
echo
echo "${account} not found"
exit 1
fi
if type jq > /dev/null && [[ $[ $notfound + 1 ] -eq $found && \
${lastseq} -ne ${found} && ${lastseq} -ne 1 ]]
then
echo "Look for transactions in ledger ${found} with seq before ${lastseq}"
createdseq=$(rippled -q ${rpcip} account_tx ${account} \
${found} ${found} | jq '.result.transactions |
map(.meta.AffectedNodes |
map(.CreatedNode |
select(.LedgerEntryType == "AccountRoot" and
.NewFields.Account == "'${account}'"))) |
.[] | .[] | .NewFields.Sequence')
if [[ "${createdseq}" != "" && "${createdseq}" -lt "${lastseq}" ]]
then
echo "Found transaction creating account with seq ${createdseq}"
lastseq="${createdseq}"
fi
fi
echo
if [[ $[ $notfound + 1 ] -eq $found && ( ${lastseq} -eq ${found} \
|| ${lastseq} -eq 1 ) ]]
then
echo "${account} was probably created"
echo "in ledger ${found} with sequence ${lastseq}"
else
echo "First found instance of account ${account}"
echo "has sequence ${lastseq}, which means either:"
echo "* it was created before ledger ${minledger}"
echo "* it was created in a ledger outside the range of available ledgers:"
if type jq > /dev/null
then
ledgers=$(rippled -q ${rpcip} server_info | jq -r \
'.result.info.complete_ledgers' )
echo " ${ledgers}"
fi
echo "* or it was created in ledger ${found} and had transactions"
echo " validated in that ledger, too."
fi