@@ -5,6 +5,8 @@ set +a -eu -o pipefail
5
5
check_requirements () {
6
6
which wget > /dev/null ||
7
7
error " It seems 'wget' is not installed or not in the path." ;
8
+ which jq > /dev/null ||
9
+ error " It seems 'jq' is not installed or not in the path." ;
8
10
}
9
11
10
12
display_help () {
@@ -29,7 +31,7 @@ error() {
29
31
30
32
clean_directory () {
31
33
echo " Cleaning data directory…"
32
- rm $DATA_DIR /* .json || true
34
+ rm " $DATA_DIR /*.json" || true
33
35
}
34
36
35
37
# $1=URL $2=artifact_name
@@ -38,13 +40,13 @@ download_data() {
38
40
local -r artifact=${2:? " No artifact type given to download_data function." } ;
39
41
40
42
echo " Downloading ${artifact} data."
41
- wget -O $DATA_DIR / ${artifact} .json --quiet " ${url} "
43
+ wget -O - --quiet " ${url} " | jq > " $DATA_DIR / ${artifact} .json " ;
42
44
}
43
45
44
46
# $1=URL $2=artifact_name $3=JSON field
45
47
download_artifacts () {
46
- local -r url=${1:? " No URL given to download_data function." } ;
47
- local -r artifact=${2:? " No artifact type given to download_data function." } ;
48
+ local -r url=${1:? " No URL given to download_artifacts function." } ;
49
+ local -r artifact=${2:? " No artifact type given to download_artifacts function." } ;
48
50
local -r json_field=${3:? " No JSON field given to read from artifact list." } ;
49
51
local -r download_missing_certificate=${4:- false} ;
50
52
local -i nb=0
@@ -55,7 +57,7 @@ download_artifacts() {
55
57
for field in $( jq -r .[].${json_field} < $DATA_DIR /${artifact} s.json) ;
56
58
do
57
59
tput rc;
58
- wget -O $DATA_DIR / ${artifact} - ${field} .json --quiet " ${url} / ${field} "
60
+ download_data " ${url} / ${field} " " ${artifact} - ${field} "
59
61
60
62
if [ true = " $download_missing_certificate " ]; then
61
63
download_missing_certificate $( jq -r .certificate_hash $DATA_DIR /${artifact} -${field} .json) ;
@@ -68,11 +70,12 @@ download_artifacts() {
68
70
}
69
71
70
72
# Download certificate if a file with the hash does not already exist
73
+ # $1=certificate_hash
71
74
download_missing_certificate () {
72
- local -r certificate_hash=${@ :?" No certificate hashesgiven to download_missing_certificate function." } ;
75
+ local -r certificate_hash=${1 :? " No certificate hashes given to download_missing_certificate function." } ;
73
76
74
77
if [ ! -e " $DATA_DIR /certificate-${certificate_hash} .json" ]; then
75
- wget -O $DATA_DIR /certificate- ${certificate_hash} .json --quiet " ${BASE_URL} / certificate/ ${certificate_hash} " ;
78
+ download_data " ${BASE_URL} /certificate/ ${certificate_hash} " " certificate- ${certificate_hash} "
76
79
fi
77
80
}
78
81
@@ -88,14 +91,15 @@ download_certificate_chain() {
88
91
do
89
92
tput rc;
90
93
certificate_hash=$parent_hash ;
91
- wget -O $DATA_DIR /certificate- ${certificate_hash} .json --quiet " ${BASE_URL} / certificate/ ${certificate_hash} " ;
94
+ download_data " ${BASE_URL} /certificate/ ${certificate_hash} " " certificate- ${certificate_hash} "
92
95
parent_hash=$( jq -r .previous_hash $DATA_DIR /certificate-${certificate_hash} .json) ;
93
96
let " nb=nb+1"
94
97
echo -n " $nb "
95
98
done
96
99
echo " ✅" ;
97
100
}
98
101
102
+ # $@=list of transactions_hashes
99
103
download_ctx_proof () {
100
104
local -r ctx_hashes=${@:? " No cardano transaction hashes given to download_ctx_proof function." } ;
101
105
local -i nb=0
@@ -106,7 +110,7 @@ download_ctx_proof() {
106
110
for cardano_transaction_hash in $ctx_hashes ;
107
111
do
108
112
tput rc;
109
- wget -O $DATA_DIR /ctx-proof- ${cardano_transaction_hash} .json --quiet " ${BASE_URL} /proof/cardano-transaction?transaction_hashes=${cardano_transaction_hash} " ;
113
+ download_data " ${BASE_URL} /proof/cardano-transaction?transaction_hashes=${cardano_transaction_hash} " " ctx-proof- ${cardano_transaction_hash} "
110
114
download_missing_certificate $( jq -r .certificate_hash $DATA_DIR /ctx-proof-${cardano_transaction_hash} .json) ;
111
115
112
116
let " nb=nb+1"
@@ -115,6 +119,7 @@ download_ctx_proof() {
115
119
echo " ✅" ;
116
120
}
117
121
122
+ # $@=list of transactions_hashes
118
123
write_ctx_proof_hashes_list () {
119
124
local -r ctx_hashes=${@:? " No cardano transaction hashes given to write_ctx_proof_hashes_list function." } ;
120
125
local -i nb=0
140
145
echo " ]" >> $DATA_DIR /ctx-proofs.json
141
146
142
147
echo " ✅" ;
143
-
144
148
}
145
149
146
150
# MAIN execution
0 commit comments