Skip to content

Commit bc1ad9c

Browse files
author
Damien LACHAUME / PALO-IT
committed
Enhance import.sh script of mithril-aggregator-fake with jq
1 parent 0759f89 commit bc1ad9c

File tree

1 file changed

+14
-10
lines changed
  • mithril-test-lab/mithril-aggregator-fake/scripts

1 file changed

+14
-10
lines changed

mithril-test-lab/mithril-aggregator-fake/scripts/import.sh

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ set +a -eu -o pipefail
55
check_requirements() {
66
which wget >/dev/null ||
77
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.";
810
}
911

1012
display_help() {
@@ -29,7 +31,7 @@ error() {
2931

3032
clean_directory() {
3133
echo "Cleaning data directory…"
32-
rm $DATA_DIR/*.json || true
34+
rm "$DATA_DIR/*.json" || true
3335
}
3436

3537
# $1=URL $2=artifact_name
@@ -38,13 +40,13 @@ download_data() {
3840
local -r artifact=${2:?"No artifact type given to download_data function."};
3941

4042
echo "Downloading ${artifact} data."
41-
wget -O $DATA_DIR/${artifact}.json --quiet "${url}"
43+
wget -O - --quiet "${url}" | jq > "$DATA_DIR/${artifact}.json";
4244
}
4345

4446
# $1=URL $2=artifact_name $3=JSON field
4547
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."};
4850
local -r json_field=${3:?"No JSON field given to read from artifact list."};
4951
local -r download_missing_certificate=${4:-false};
5052
local -i nb=0
@@ -55,7 +57,7 @@ download_artifacts() {
5557
for field in $(jq -r .[].${json_field} < $DATA_DIR/${artifact}s.json);
5658
do
5759
tput rc;
58-
wget -O $DATA_DIR/${artifact}-${field}.json --quiet "${url}/${field}"
60+
download_data "${url}/${field}" "${artifact}-${field}"
5961

6062
if [ true = "$download_missing_certificate" ]; then
6163
download_missing_certificate $(jq -r .certificate_hash $DATA_DIR/${artifact}-${field}.json);
@@ -68,11 +70,12 @@ download_artifacts() {
6870
}
6971

7072
# Download certificate if a file with the hash does not already exist
73+
# $1=certificate_hash
7174
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."};
7376

7477
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}"
7679
fi
7780
}
7881

@@ -88,14 +91,15 @@ download_certificate_chain() {
8891
do
8992
tput rc;
9093
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}"
9295
parent_hash=$(jq -r .previous_hash $DATA_DIR/certificate-${certificate_hash}.json);
9396
let "nb=nb+1"
9497
echo -n "$nb "
9598
done
9699
echo "";
97100
}
98101

102+
# $@=list of transactions_hashes
99103
download_ctx_proof() {
100104
local -r ctx_hashes=${@:?"No cardano transaction hashes given to download_ctx_proof function."};
101105
local -i nb=0
@@ -106,7 +110,7 @@ download_ctx_proof() {
106110
for cardano_transaction_hash in $ctx_hashes;
107111
do
108112
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}"
110114
download_missing_certificate $(jq -r .certificate_hash $DATA_DIR/ctx-proof-${cardano_transaction_hash}.json);
111115

112116
let "nb=nb+1"
@@ -115,6 +119,7 @@ download_ctx_proof() {
115119
echo "";
116120
}
117121

122+
# $@=list of transactions_hashes
118123
write_ctx_proof_hashes_list() {
119124
local -r ctx_hashes=${@:?"No cardano transaction hashes given to write_ctx_proof_hashes_list function."};
120125
local -i nb=0
@@ -140,7 +145,6 @@ EOF
140145
echo "]" >> $DATA_DIR/ctx-proofs.json
141146

142147
echo "";
143-
144148
}
145149

146150
# MAIN execution

0 commit comments

Comments
 (0)