Skip to content

Commit 24187ce

Browse files
author
Damien LACHAUME / PALO-IT
committed
Fetch missing certificate when downloading artifact & ctx proof using fake aggregator import script
1 parent 06b62b7 commit 24187ce

File tree

1 file changed

+20
-3
lines changed
  • mithril-test-lab/mithril-aggregator-fake/scripts

1 file changed

+20
-3
lines changed

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

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ download_artifacts() {
4646
local -r url=${1:?"No URL given to download_data function."};
4747
local -r artifact=${2:?"No artifact type given to download_data function."};
4848
local -r json_field=${3:?"No JSON field given to read from artifact list."};
49+
local -r download_missing_certificate=${4:-false};
4950
local -i nb=0
5051

5152
echo -n "Downloading ${artifact} data: "
@@ -55,12 +56,26 @@ download_artifacts() {
5556
do
5657
tput rc;
5758
wget -O $DATA_DIR/${artifact}-${field}.json --quiet "${url}/${field}"
59+
60+
if [ true = "$download_missing_certificate" ]; then
61+
download_missing_certificate $(jq -r .certificate_hash $DATA_DIR/${artifact}-${field}.json);
62+
fi
63+
5864
let "nb=nb+1"
5965
echo -n "$nb "
6066
done
6167
echo "";
6268
}
6369

70+
# Download certificate if a file with the hash does not already exist
71+
download_missing_certificate() {
72+
local -r certificate_hash=${@:?"No certificate hashesgiven to download_missing_certificate function."};
73+
74+
if [ ! -e "$DATA_DIR/certificate-${certificate_hash}.json" ]; then
75+
wget -O $DATA_DIR/certificate-${certificate_hash}.json --quiet "${BASE_URL}/certificate/${certificate_hash}";
76+
fi
77+
}
78+
6479
download_certificate_chain() {
6580
local parent_hash=$(jq -r .[0].hash $DATA_DIR/certificates.json);
6681
local certificate_hash;
@@ -92,6 +107,8 @@ download_ctx_proof() {
92107
do
93108
tput rc;
94109
wget -O $DATA_DIR/ctx-proof-${cardano_transaction_hash}.json --quiet "${BASE_URL}/proof/cardano-transaction?transaction_hashes=${cardano_transaction_hash}";
110+
download_missing_certificate $(jq -r .certificate_hash $DATA_DIR/ctx-proof-${cardano_transaction_hash}.json);
111+
95112
let "nb=nb+1"
96113
echo -n "$nb "
97114
done
@@ -102,7 +119,7 @@ write_ctx_proof_hashes_list() {
102119
local -r ctx_hashes=${@:?"No cardano transaction hashes given to write_ctx_proof_hashes_list function."};
103120
local -i nb=0
104121

105-
echo -n "Downloading cardano transaction proof: "
122+
echo -n "Writting cardano transaction proof ids to a file: "
106123
tput sc;
107124

108125
echo "[" > $DATA_DIR/ctx-proofs.json
@@ -158,10 +175,10 @@ download_artifacts "$BASE_URL/certificate" "certificate" "hash"
158175
download_certificate_chain
159176

160177
download_data "$BASE_URL/artifact/snapshots" "snapshots"
161-
download_artifacts "$BASE_URL/artifact/snapshot" "snapshot" "digest"
178+
download_artifacts "$BASE_URL/artifact/snapshot" "snapshot" "digest" true
162179

163180
download_data "$BASE_URL/artifact/mithril-stake-distributions" "mithril-stake-distributions"
164-
download_artifacts "$BASE_URL/artifact/mithril-stake-distribution" "mithril-stake-distribution" "hash"
181+
download_artifacts "$BASE_URL/artifact/mithril-stake-distribution" "mithril-stake-distribution" "hash" true
165182

166183
download_data "$BASE_URL/artifact/cardano-transactions" "ctx-commitments"
167184
download_artifacts "$BASE_URL/artifact/cardano-transaction" "ctx-commitment" "hash"

0 commit comments

Comments
 (0)