@@ -12,7 +12,7 @@ check_requirements() {
12
12
display_help () {
13
13
if [ -n " ${1-" " } " ]; then echo " ERROR: ${1} " ; echo ; fi
14
14
echo " HELP"
15
- echo $0
15
+ echo " $0 "
16
16
echo
17
17
echo " Import and save data from a given Mithril Aggregator."
18
18
echo
@@ -31,7 +31,7 @@ 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
37
# $1=URL $2=artifact_name $3=target_dir (default to $DATA_DIR)
@@ -57,16 +57,16 @@ download_artifacts() {
57
57
echo -n " Downloading ${artifact} data: "
58
58
tput sc;
59
59
60
- for field in $( jq -r .[].${json_field} < $DATA_DIR /${artifact} s-list.json) ;
60
+ for field in $( jq -r " .[].${json_field} " < " $DATA_DIR /${artifact} s-list.json" ) ;
61
61
do
62
62
tput rc;
63
63
download_data " ${url} /${field} " " ${field} " " $artifact_dir "
64
64
65
65
if [ true = " $download_missing_certificate " ]; then
66
- 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" ) " ;
67
67
fi
68
68
69
- let " nb=nb+1"
69
+ (( nb= nb+ 1 ))
70
70
echo -n " $nb "
71
71
done
72
72
echo " ✅" ;
@@ -83,29 +83,31 @@ download_missing_certificate() {
83
83
}
84
84
85
85
download_certificate_chain () {
86
- local parent_hash=$( jq -r .[0].hash $DATA_DIR /certificates-list.json ) ;
86
+ local parent_hash=" " ;
87
87
local certificate_hash;
88
88
local -i nb=0
89
89
90
90
echo -n " Downloading certificate chain: "
91
91
tput sc;
92
92
93
+ parent_hash=$( jq -r " .[0].hash" " $DATA_DIR /certificates-list.json" ) ;
93
94
until [ -z " $parent_hash " ];
94
95
do
95
96
tput rc;
96
97
97
98
certificate_hash=$parent_hash ;
98
99
download_data " ${BASE_URL} /certificate/${certificate_hash} " " ${certificate_hash} " " $DATA_DIR /certificate"
99
100
parent_hash=$( jq -r .previous_hash " $DATA_DIR /certificate/${certificate_hash} .json" ) ;
100
- let " nb=nb+1"
101
+
102
+ (( nb= nb+ 1 ))
101
103
echo -n " $nb "
102
104
done
103
105
echo " ✅" ;
104
106
}
105
107
106
108
# $@=list of transactions_hashes
107
109
download_ctx_proof () {
108
- local -r ctx_hashes=${@ :?" No cardano transaction hashes given to download_ctx_proof function." } ;
110
+ local -r ctx_hashes=${* :?" No cardano transaction hashes given to download_ctx_proof function." } ;
109
111
local -i nb=0
110
112
local -r artifact_dir=" $DATA_DIR /ctx-proof"
111
113
@@ -118,38 +120,38 @@ download_ctx_proof() {
118
120
do
119
121
tput rc;
120
122
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" ) ;
123
+ download_missing_certificate " $( jq -r " .certificate_hash" " $DATA_DIR /ctx-proof/${cardano_transaction_hash} .json" ) " ;
122
124
123
- let " nb=nb+1"
125
+ (( nb= nb+ 1 ))
124
126
echo -n " $nb "
125
127
done
126
128
echo " ✅" ;
127
129
}
128
130
129
131
# $@=list of transactions_hashes
130
132
write_ctx_proof_hashes_list () {
131
- local -r ctx_hashes=${@ :?" No cardano transaction hashes given to write_ctx_proof_hashes_list function." } ;
133
+ local -r ctx_hashes=${* :?" No cardano transaction hashes given to write_ctx_proof_hashes_list function." } ;
132
134
local -i nb=0
133
135
134
- echo -n " Writting cardano transaction proof ids to a file: "
136
+ echo -n " Writing cardano transaction proof ids to a file: "
135
137
tput sc;
136
138
137
- echo " [" > $DATA_DIR /ctx-proofs-list.json
139
+ echo " [" > " $DATA_DIR /ctx-proofs-list.json"
138
140
139
141
local separator=" "
140
142
for cardano_transaction_hash in $ctx_hashes ;
141
143
do
142
144
tput rc;
143
- cat >> $DATA_DIR /ctx-proofs-list.json << EOF
145
+ cat >> " $DATA_DIR /ctx-proofs-list.json" << EOF
144
146
$separator { "transaction_hash": "$cardano_transaction_hash " }
145
147
EOF
146
148
147
149
separator=" ,"
148
150
149
- let " nb=nb+1"
151
+ (( nb= nb+ 1 ))
150
152
echo -n " $nb "
151
153
done
152
- echo " ]" >> $DATA_DIR /ctx-proofs-list.json
154
+ echo " ]" >> " $DATA_DIR /ctx-proofs-list.json"
153
155
154
156
echo " ✅" ;
155
157
}
@@ -165,10 +167,10 @@ join_artifacts_files() {
165
167
166
168
echo " Joining ${name} artifacts into ${dest} …"
167
169
170
+ local key=" "
168
171
buffer+=" {"
169
172
for filename in " $src /" * ; do
170
- local key=$( basename " ${filename% .* } " )
171
-
173
+ key=$( basename " ${filename% .* } " )
172
174
buffer+=$( echo " $separator \" $key \" : " | cat - " $filename " )
173
175
separator=" ,"
174
176
done
@@ -187,16 +189,16 @@ declare -r DATA_DIR=$1;
187
189
shift
188
190
declare -r BASE_URL=$1 ;
189
191
shift
190
- declare -r CARDANO_TRANSACTIONS_HASHES=$@ ;
192
+ declare -r CARDANO_TRANSACTIONS_HASHES=$* ;
191
193
192
194
echo " -- MITHRIL AGGREGATOR FAKE - DATA IMPORTER --"
193
- echo " data_dir:" $DATA_DIR
194
- echo " base_url:" $BASE_URL
195
- echo " tx_hashes:" $CARDANO_TRANSACTIONS_HASHES
195
+ echo " data_dir:" " $DATA_DIR "
196
+ echo " base_url:" " $BASE_URL "
197
+ echo " tx_hashes:" " $CARDANO_TRANSACTIONS_HASHES "
196
198
echo
197
199
198
200
if [ ! -d " $DATA_DIR " ]; then error " Specified directory '${DATA_DIR} ' is not a directory." ; fi
199
- wget --quiet --server-response --spider $BASE_URL 2> /dev/null || error " Could not reach URL '${BASE_URL} '." ;
201
+ wget --quiet --server-response --spider " $BASE_URL " 2> /dev/null || error " Could not reach URL '${BASE_URL} '." ;
200
202
201
203
export DATA_DIR URL;
202
204
@@ -220,8 +222,8 @@ download_data "$BASE_URL/artifact/cardano-transactions" "ctx-snapshots-list"
220
222
download_artifacts " $BASE_URL /artifact/cardano-transaction" " ctx-snapshot" " hash"
221
223
222
224
if [ -n " $CARDANO_TRANSACTIONS_HASHES " ]; then
223
- download_ctx_proof $CARDANO_TRANSACTIONS_HASHES
224
- write_ctx_proof_hashes_list $CARDANO_TRANSACTIONS_HASHES
225
+ download_ctx_proof " $CARDANO_TRANSACTIONS_HASHES "
226
+ write_ctx_proof_hashes_list " $CARDANO_TRANSACTIONS_HASHES "
225
227
join_artifacts_files " ctx-proof"
226
228
fi
227
229
0 commit comments