forked from algorand/indexer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate_accounts.sh
executable file
·117 lines (107 loc) · 2.63 KB
/
generate_accounts.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
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
#!/usr/bin/env bash
#
# Query an indexer postgres DB for accounts and dump them into stdout.
#
# This script is intended to be used with validate_accounting.sh
function help () {
echo "This script generates a stream of accounts and prints them to stdout."
echo "If the convert_addr tool is provided accounts will also be decoded"
echo "from base64 to the algorand standard address format."
echo ""
echo "Requires 'psql' command to be available."
echo ""
echo "options:"
echo " --convert_addr -> [optional] Path to the convert_addr utility."
echo " --pg_user -> Postgres username."
echo " --pg_pass -> Postgres password."
echo " --pg_url -> Postgres url (without http)."
echo " --pg_port -> Postgres port."
echo " --pg_db -> Postgres database."
echo " --query -> [optional] Query to use for selecting accounts."
}
#default selection queries
SELECTION_QUERY="select encode(addr,'base64') from account where deleted is false limit 1000"
SELECTION_QUERY_COPY="COPY (select encode(addr, 'base64') from account where deleted is false) TO stdout"
START_TIME=$SECONDS
PGUSER=
PGPASSWORD=
PGHOST=
PGPORT=
PGDB=
TEST=
while (( "$#" )); do
case "$1" in
--convert_addr)
shift
CONVERT_ADDR="$1"
;;
--pg_user)
shift
PGUSER="$1"
;;
--pg_pass)
shift
PGPASSWORD="$1"
;;
--pg_url)
shift
PGHOST="$1"
;;
--pg_port)
shift
PGPORT="$1"
;;
--pg_db)
shift
PGDB="$1"
;;
--test)
TEST=1
;;
--query)
shift
SELECTION_QUERY="$1"
SELECTION_QUERY_COPY="$1"
;;
-h|--help)
help
exit
;;
*)
echo "Unknown argument '$1'"
echo ""
help
exit
esac
shift
done
if [ -z $PGUSER ] || [ -z $PGPASSWORD ] || [ -z $PGPORT ] || [ -z $PGHOST ] || [ -z $PGDB ]; then
help
exit
fi
# Required for psql
export PGPASSWORD
# $1 - the query to execute
# $2 - if not empty prints the command before executing it
function psql_query {
if [ ! -z $2 ]; then
echo "psql -t -h $PGHOST -d $PGDB -XA -p $PGPORT -U $PGUSER -c \"$1\""
fi
psql -t -h $PGHOST -d $PGDB -XA -p $PGPORT -U $PGUSER -c "$1"
}
#####################
# Start the script! #
#####################
if [ ! -z $TEST ]; then
echo "psql configuration test:"
psql_query "select * from metastate" 1
fi
# If the converter tool is provided go ahead and convert everything
if [ ! -z $CONVERT_ADDR ]; then
while read -r line; do
ACCT=$($CONVERT_ADDR -addr $line)
echo $ACCT
done < <((psql_query "$SELECTION_QUERY"))
else
psql_query "$SELECTION_QUERY_COPY"
fi