forked from blockchain-etl/ethereum-etl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
export_all.sh
executable file
·169 lines (133 loc) · 7.02 KB
/
export_all.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#!/usr/bin/env bash
# MIT License
#
# Copyright (c) 2018 Evgeny Medvedev, [email protected]
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
output_dir=.
current_time() { echo `date '+%Y-%m-%d %H:%M:%S'`; }
log() { echo "$(current_time) ${1}"; }
quit_if_returned_error() {
ret_val=$?
if [ ${ret_val} -ne 0 ]; then
log "An error occurred. Quitting."
exit ${ret_val}
fi
}
usage() { echo "Usage: $0 -s <start_block> -e <end_block> -b <batch_size> -p <provider_uri> [-o <output_dir>]" 1>&2; exit 1; }
while getopts ":s:e:b:p:o:" opt; do
case "${opt}" in
s)
start_block=${OPTARG}
;;
e)
end_block=${OPTARG}
;;
b)
batch_size=${OPTARG}
;;
p)
provider_uri=${OPTARG}
;;
o)
output_dir=${OPTARG}
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
if [ -z "${start_block}" ] || [ -z "${end_block}" ] || [ -z "${batch_size}" ] || [ -z "${provider_uri}" ]; then
usage
fi
for (( batch_start_block=$start_block; batch_start_block <= $end_block; batch_start_block+=$batch_size )); do
start_time=$(date +%s)
batch_end_block=$((batch_start_block + batch_size - 1))
batch_end_block=$((batch_end_block > end_block ? end_block : batch_end_block))
padded_batch_start_block=`printf "%08d" ${batch_start_block}`
padded_batch_end_block=`printf "%08d" ${batch_end_block}`
block_range=${padded_batch_start_block}-${padded_batch_end_block}
file_name_suffix=${padded_batch_start_block}_${padded_batch_end_block}
# Hive style partitioning
partition_dir=/start_block=${padded_batch_start_block}/end_block=${padded_batch_end_block}
### blocks_and_transactions
blocks_output_dir=${output_dir}/blocks${partition_dir}
mkdir -p ${blocks_output_dir};
transactions_output_dir=${output_dir}/transactions${partition_dir}
mkdir -p ${transactions_output_dir};
blocks_file=${blocks_output_dir}/blocks_${file_name_suffix}.csv
transactions_file=${transactions_output_dir}/transactions_${file_name_suffix}.csv
log "Exporting blocks ${block_range} to ${blocks_file}"
log "Exporting transactions from blocks ${block_range} to ${transactions_file}"
python3 ethereumetl export_blocks_and_transactions --start-block=${batch_start_block} --end-block=${batch_end_block} --provider-uri="${provider_uri}" --blocks-output=${blocks_file} --transactions-output=${transactions_file}
quit_if_returned_error
### token_transfers
token_transfers_output_dir=${output_dir}/token_transfers${partition_dir}
mkdir -p ${token_transfers_output_dir};
token_transfers_file=${token_transfers_output_dir}/token_transfers_${file_name_suffix}.csv
log "Exporting ERC20 transfers from blocks ${block_range} to ${token_transfers_file}"
python3 ethereumetl export_token_transfers --start-block=${batch_start_block} --end-block=${batch_end_block} --provider-uri="${provider_uri}" --output=${token_transfers_file}
quit_if_returned_error
### receipts_and_logs
transaction_hashes_output_dir=${output_dir}/transaction_hashes${partition_dir}
mkdir -p ${transaction_hashes_output_dir};
transaction_hashes_file=${transaction_hashes_output_dir}/transaction_hashes_${file_name_suffix}.csv
log "Extracting hash column from transaction file ${transactions_file}"
python3 ethereumetl extract_csv_column --input ${transactions_file} --output ${transaction_hashes_file} --column "hash"
quit_if_returned_error
receipts_output_dir=${output_dir}/receipts${partition_dir}
mkdir -p ${receipts_output_dir};
logs_output_dir=${output_dir}/logs${partition_dir}
mkdir -p ${logs_output_dir};
receipts_file=${receipts_output_dir}/receipts_${file_name_suffix}.csv
logs_file=${logs_output_dir}/logs_${file_name_suffix}.csv
log "Exporting receipts and logs from blocks ${block_range} to ${receipts_file} and ${logs_file}"
python3 ethereumetl export_receipts_and_logs --transaction-hashes ${transaction_hashes_file} --provider-uri="${provider_uri}" --receipts-output=${receipts_file} --logs-output=${logs_file}
quit_if_returned_error
### contracts
contract_addresses_output_dir=${output_dir}/contract_addresses${partition_dir}
mkdir -p ${contract_addresses_output_dir}
contract_addresses_file=${contract_addresses_output_dir}/contract_addresses_${file_name_suffix}.csv
log "Extracting contract_address from receipt file ${receipts_file}"
python3 ethereumetl extract_csv_column --input ${receipts_file} --column contract_address --output ${contract_addresses_file}
quit_if_returned_error
contracts_output_dir=${output_dir}/contracts${partition_dir}
mkdir -p ${contracts_output_dir};
contracts_file=${contracts_output_dir}/contracts_${file_name_suffix}.csv
log "Exporting contracts from blocks ${block_range} to ${contracts_file}"
python3 ethereumetl export_contracts --contract-addresses ${contract_addresses_file} --provider-uri="${provider_uri}" --output=${contracts_file}
quit_if_returned_error
### tokens
token_addresses_output_dir=${output_dir}/token_addresses${partition_dir}
mkdir -p ${token_addresses_output_dir}
token_addresses_file=${token_addresses_output_dir}/token_addresses_${file_name_suffix}
log "Extracting token_address from token_transfers file ${token_transfers_file}"
python3 ethereumetl extract_csv_column -i ${token_transfers_file} -c token_address -o - | sort | uniq > ${token_addresses_file}
quit_if_returned_error
tokens_output_dir=${output_dir}/tokens${partition_dir}
mkdir -p ${tokens_output_dir}
tokens_file=${tokens_output_dir}/tokens_${file_name_suffix}.csv
log "Exporting tokens from blocks ${block_range} to ${tokens_file}"
python3 ethereumetl export_tokens --token-addresses ${token_addresses_file} --provider-uri="${provider_uri}" --output ${tokens_file}
quit_if_returned_error
end_time=$(date +%s)
time_diff=$((end_time-start_time))
log "Exporting blocks ${block_range} took ${time_diff} seconds"
done