@@ -31,16 +31,16 @@ error() {
31
31
32
32
clean_directory () {
33
33
echo " Cleaning data directory…"
34
- rm " $DATA_DIR /*.json" || true
34
+ rm " $DATA_DIR /" * .json || true
35
35
}
36
36
37
- # $1=URL $2=artifact_name
37
+ # $1=URL $2=artifact_name $3=target_dir (default to $DATA_DIR)
38
38
download_data () {
39
39
local -r url=${1:? " No URL given to download_data function." } ;
40
40
local -r artifact=${2:? " No artifact type given to download_data function." } ;
41
+ local -r target_dir=${3:- $DATA_DIR }
41
42
42
- echo " Downloading ${artifact} data."
43
- wget -O - --quiet " ${url} " | jq > " $DATA_DIR /${artifact} .json" ;
43
+ wget -O - --quiet " ${url} " | jq > " $target_dir /${artifact} .json" ;
44
44
}
45
45
46
46
# $1=URL $2=artifact_name $3=JSON field
@@ -50,17 +50,20 @@ download_artifacts() {
50
50
local -r json_field=${3:? " No JSON field given to read from artifact list." } ;
51
51
local -r download_missing_certificate=${4:- false} ;
52
52
local -i nb=0
53
+ local -r artifact_dir=" $DATA_DIR /${artifact} "
54
+
55
+ mkdir -p " $artifact_dir "
53
56
54
57
echo -n " Downloading ${artifact} data: "
55
58
tput sc;
56
59
57
- for field in $( jq -r .[].${json_field} < $DATA_DIR /${artifact} s.json) ;
60
+ for field in $( jq -r .[].${json_field} < $DATA_DIR /${artifact} s-list .json) ;
58
61
do
59
62
tput rc;
60
- download_data " ${url} /${field} " " ${artifact} - ${ field}"
63
+ download_data " ${url} /${field} " " ${field} " " $artifact_dir "
61
64
62
65
if [ true = " $download_missing_certificate " ]; then
63
- download_missing_certificate $( jq -r .certificate_hash $DATA_DIR /${artifact} - ${field} .json) ;
66
+ download_missing_certificate $( jq -r " .certificate_hash" " $DATA_DIR /${artifact} / ${field} .json" ) ;
64
67
fi
65
68
66
69
let " nb=nb+1"
@@ -74,13 +77,13 @@ download_artifacts() {
74
77
download_missing_certificate () {
75
78
local -r certificate_hash=${1:? " No certificate hashes given to download_missing_certificate function." } ;
76
79
77
- if [ ! -e " $DATA_DIR /certificate- ${certificate_hash} .json" ]; then
78
- download_data " ${BASE_URL} /certificate/${certificate_hash} " " certificate- ${certificate_hash} "
80
+ if [ ! -e " $DATA_DIR /certificate/ ${certificate_hash} .json" ]; then
81
+ download_data " ${BASE_URL} /certificate/${certificate_hash} " " ${certificate_hash} " " $DATA_DIR /certificate "
79
82
fi
80
83
}
81
84
82
85
download_certificate_chain () {
83
- local parent_hash=$( jq -r .[0].hash $DATA_DIR /certificates.json) ;
86
+ local parent_hash=$( jq -r .[0].hash $DATA_DIR /certificates-list .json) ;
84
87
local certificate_hash;
85
88
local -i nb=0
86
89
@@ -90,9 +93,10 @@ download_certificate_chain() {
90
93
until [ -z " $parent_hash " ];
91
94
do
92
95
tput rc;
96
+
93
97
certificate_hash=$parent_hash ;
94
- download_data " ${BASE_URL} /certificate/${certificate_hash} " " certificate- ${certificate_hash} "
95
- parent_hash=$( jq -r .previous_hash $DATA_DIR /certificate- ${certificate_hash} .json) ;
98
+ download_data " ${BASE_URL} /certificate/${certificate_hash} " " ${certificate_hash} " " $DATA_DIR /certificate "
99
+ parent_hash=$( jq -r .previous_hash " $DATA_DIR /certificate/ ${certificate_hash} .json" ) ;
96
100
let " nb=nb+1"
97
101
echo -n " $nb "
98
102
done
@@ -103,15 +107,18 @@ download_certificate_chain() {
103
107
download_ctx_proof () {
104
108
local -r ctx_hashes=${@:? " No cardano transaction hashes given to download_ctx_proof function." } ;
105
109
local -i nb=0
110
+ local -r artifact_dir=" $DATA_DIR /ctx-proof"
111
+
112
+ mkdir -p " $artifact_dir "
106
113
107
114
echo -n " Downloading cardano transaction proof: "
108
115
tput sc;
109
116
110
117
for cardano_transaction_hash in $ctx_hashes ;
111
118
do
112
119
tput rc;
113
- download_data " ${BASE_URL} /proof/cardano-transaction?transaction_hashes=${cardano_transaction_hash} " " ctx-proof- ${cardano_transaction_hash} "
114
- download_missing_certificate $( jq -r .certificate_hash $DATA_DIR /ctx-proof- ${cardano_transaction_hash} .json) ;
120
+ download_data " ${BASE_URL} /proof/cardano-transaction?transaction_hashes=${cardano_transaction_hash} " " ${cardano_transaction_hash} " " ${artifact_dir }"
121
+ download_missing_certificate $( jq -r " .certificate_hash" " $DATA_DIR /ctx-proof/ ${cardano_transaction_hash} .json" ) ;
115
122
116
123
let " nb=nb+1"
117
124
echo -n " $nb "
@@ -127,13 +134,13 @@ write_ctx_proof_hashes_list() {
127
134
echo -n " Writting cardano transaction proof ids to a file: "
128
135
tput sc;
129
136
130
- echo " [" > $DATA_DIR /ctx-proofs.json
137
+ echo " [" > $DATA_DIR /ctx-proofs-list .json
131
138
132
139
local separator=" "
133
140
for cardano_transaction_hash in $ctx_hashes ;
134
141
do
135
142
tput rc;
136
- cat >> $DATA_DIR /ctx-proofs.json << EOF
143
+ cat >> $DATA_DIR /ctx-proofs-list .json << EOF
137
144
$separator { "transaction_hash": "$cardano_transaction_hash " }
138
145
EOF
139
146
@@ -142,11 +149,35 @@ EOF
142
149
let " nb=nb+1"
143
150
echo -n " $nb "
144
151
done
145
- echo " ]" >> $DATA_DIR /ctx-proofs.json
152
+ echo " ]" >> $DATA_DIR /ctx-proofs-list .json
146
153
147
154
echo " ✅" ;
148
155
}
149
156
157
+ # Join downloaded artifacts files into a single files
158
+ # $1=name of the artifacts to join
159
+ join_artifacts_files () {
160
+ local -r name=${1:? " No artifact name given to join_artifacts_files function." } ;
161
+ local -r src=" ${DATA_DIR:? } /${name} "
162
+ local -r dest=" $DATA_DIR " /" $name " s.json
163
+ local buffer=" "
164
+ local separator=" "
165
+
166
+ echo " Joining ${name} artifacts into ${dest} …"
167
+
168
+ buffer+=" {"
169
+ for filename in " $src /" * ; do
170
+ local key=$( basename " ${filename% .* } " )
171
+
172
+ buffer+=$( echo " $separator \" $key \" : " | cat - " $filename " )
173
+ separator=" ,"
174
+ done
175
+ buffer+=" }"
176
+
177
+ echo ${buffer} | jq > " $dest "
178
+ rm -rf " $src "
179
+ }
180
+
150
181
# MAIN execution
151
182
152
183
if [ -z " ${1-" " } " ]; then display_help " No data directory given to download JSON files." ; fi ;
@@ -172,22 +203,28 @@ export DATA_DIR URL;
172
203
check_requirements;
173
204
clean_directory;
174
205
206
+ echo " Downloading epoch-settings"
175
207
download_data " $BASE_URL /epoch-settings" " epoch-settings"
176
208
177
- download_data " $BASE_URL /certificates" " certificates"
209
+ download_data " $BASE_URL /certificates" " certificates-list "
178
210
download_artifacts " $BASE_URL /certificate" " certificate" " hash"
179
211
download_certificate_chain
180
212
181
- download_data " $BASE_URL /artifact/snapshots" " snapshots"
213
+ download_data " $BASE_URL /artifact/snapshots" " snapshots-list "
182
214
download_artifacts " $BASE_URL /artifact/snapshot" " snapshot" " digest" true
183
215
184
- download_data " $BASE_URL /artifact/mithril-stake-distributions" " mithril-stake-distributions"
216
+ download_data " $BASE_URL /artifact/mithril-stake-distributions" " mithril-stake-distributions-list "
185
217
download_artifacts " $BASE_URL /artifact/mithril-stake-distribution" " mithril-stake-distribution" " hash" true
186
218
187
- download_data " $BASE_URL /artifact/cardano-transactions" " ctx-snapshots"
219
+ download_data " $BASE_URL /artifact/cardano-transactions" " ctx-snapshots-list "
188
220
download_artifacts " $BASE_URL /artifact/cardano-transaction" " ctx-snapshot" " hash"
189
221
190
222
if [ -n " $CARDANO_TRANSACTIONS_HASHES " ]; then
191
223
download_ctx_proof $CARDANO_TRANSACTIONS_HASHES
192
224
write_ctx_proof_hashes_list $CARDANO_TRANSACTIONS_HASHES
225
+ join_artifacts_files " ctx-proof"
193
226
fi
227
+
228
+ for artifact_type in " snapshot" " mithril-stake-distribution" " ctx-snapshot" " certificate" ; do
229
+ join_artifacts_files " $artifact_type "
230
+ done
0 commit comments