Skip to content
This repository was archived by the owner on Dec 26, 2022. It is now read-only.

Commit 8a947e3

Browse files
committed
fix: Make use of ta_error_to_string
Closes #502. Applied ta_error_to_string in loggers.
1 parent 075f5fa commit 8a947e3

File tree

16 files changed

+350
-344
lines changed

16 files changed

+350
-344
lines changed

accelerator/config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ status_t ta_core_default_init(ta_core_t* const core) {
192192
status_t ret = SC_OK;
193193

194194
logger_id = logger_helper_enable(CONFIG_LOGGER, LOGGER_DEBUG, true);
195-
ta_log_info("enable logger %s.\n", CONFIG_LOGGER);
195+
ta_log_info("Enable logger %s.\n", CONFIG_LOGGER);
196196

197197
ta_config_t* const ta_conf = &core->ta_conf;
198198
iota_config_t* const iota_conf = &core->iota_conf;

accelerator/core/apis.c

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -54,23 +54,23 @@ status_t api_get_tips(const iota_client_service_t* const service, char** json_re
5454

5555
if (res == NULL) {
5656
ret = SC_CCLIENT_OOM;
57-
ta_log_error("%s\n", "SC_CCLIENT_OOM");
57+
ta_log_error("%s\n", ta_error_to_string(ret));
5858
goto done;
5959
}
6060

6161
lock_handle_lock(&cjson_lock);
6262
if (iota_client_get_tips(service, res) != RC_OK) {
6363
lock_handle_unlock(&cjson_lock);
6464
ret = SC_CCLIENT_FAILED_RESPONSE;
65-
ta_log_error("%s\n", "SC_CCLIENT_FAILED_RESPONSE");
65+
ta_log_error("%s\n", ta_error_to_string(ret));
6666
goto done;
6767
}
6868
lock_handle_unlock(&cjson_lock);
6969

7070
ret = ta_get_tips_res_serialize(res, json_result);
7171
if (ret != SC_OK) {
7272
ret = SC_CCLIENT_JSON_PARSE;
73-
ta_log_error("%s\n", "SC_CCLIENT_JSON_PARSE");
73+
ta_log_error("%s\n", ta_error_to_string(ret));
7474
goto done;
7575
}
7676

@@ -88,7 +88,7 @@ status_t api_get_tips_pair(const iota_config_t* const iconf, const iota_client_s
8888

8989
if (req == NULL || res == NULL || res_buff == NULL) {
9090
ret = SC_TA_OOM;
91-
ta_log_error("%s\n", "SC_TA_OOM");
91+
ta_log_error("%s\n", ta_error_to_string(ret));
9292
goto done;
9393
}
9494

@@ -97,21 +97,21 @@ status_t api_get_tips_pair(const iota_config_t* const iconf, const iota_client_s
9797
if (iota_client_get_transactions_to_approve(service, req, res) != RC_OK) {
9898
lock_handle_unlock(&cjson_lock);
9999
ret = SC_CCLIENT_FAILED_RESPONSE;
100-
ta_log_error("%s\n", "SC_CCLIENT_FAILED_RESPONSE");
100+
ta_log_error("%s\n", ta_error_to_string(ret));
101101
goto done;
102102
}
103103
lock_handle_unlock(&cjson_lock);
104104

105105
if (service->serializer.vtable.get_transactions_to_approve_serialize_response(res, res_buff) != RC_OK) {
106106
ret = SC_CCLIENT_JSON_PARSE;
107-
ta_log_error("%s\n", "SC_CCLIENT_JSON_PARSE");
107+
ta_log_error("%s\n", ta_error_to_string(ret));
108108
goto done;
109109
}
110110

111111
*json_result = (char*)malloc((res_buff->length + 1) * sizeof(char));
112112
if (*json_result == NULL) {
113113
ret = SC_CCLIENT_JSON_PARSE;
114-
ta_log_error("%s\n", "SC_CCLIENT_JSON_PARSE");
114+
ta_log_error("%s\n", ta_error_to_string(ret));
115115
goto done;
116116
}
117117
snprintf(*json_result, (res_buff->length + 1), "%s", res_buff->data);
@@ -129,7 +129,7 @@ status_t api_generate_address(const iota_config_t* const iconf, const iota_clien
129129
ta_generate_address_res_t* res = ta_generate_address_res_new();
130130
if (res == NULL) {
131131
ret = SC_TA_OOM;
132-
ta_log_error("%s\n", "SC_TA_OOM");
132+
ta_log_error("%s\n", ta_error_to_string(ret));
133133
goto done;
134134
}
135135

@@ -157,7 +157,7 @@ status_t api_find_transaction_object_single(const iota_client_service_t* const s
157157
transaction_array_t* res = transaction_array_new();
158158
if (req == NULL || res == NULL) {
159159
ret = SC_TA_OOM;
160-
ta_log_error("%s\n", "SC_TA_OOM");
160+
ta_log_error("%s\n", ta_error_to_string(ret));
161161
goto done;
162162
}
163163

@@ -188,7 +188,7 @@ status_t api_find_transaction_objects(const iota_client_service_t* const service
188188
transaction_array_t* res = transaction_array_new();
189189
if (req == NULL || res == NULL) {
190190
ret = SC_TA_OOM;
191-
ta_log_error("%s\n", "SC_TA_OOM");
191+
ta_log_error("%s\n", ta_error_to_string(ret));
192192
goto done;
193193
}
194194

@@ -226,11 +226,11 @@ status_t api_find_transactions_by_tag(const iota_client_service_t* const service
226226
find_transactions_res_t* res = find_transactions_res_new();
227227
if (req == NULL || res == NULL) {
228228
ret = SC_TA_OOM;
229-
ta_log_error("%s\n", "SC_TA_OOM");
229+
ta_log_error("%s\n", ta_error_to_string(ret));
230230
goto done;
231231
}
232232

233-
// If 'tag' is less than 27 trytes (NUM_TRYTES_TAG), expands it
233+
// If 'tag' is less than 27 trytes (NUM_TRYTES_TAG), expand it
234234
if (strnlen(obj, NUM_TRYTES_TAG) < NUM_TRYTES_TAG) {
235235
char new_tag[NUM_TRYTES_TAG + 1];
236236
// Fill in '9' to get valid tag (27 trytes)
@@ -244,15 +244,15 @@ status_t api_find_transactions_by_tag(const iota_client_service_t* const service
244244

245245
if (find_transactions_req_tag_add(req, tag_trits) != RC_OK) {
246246
ret = SC_CCLIENT_INVALID_FLEX_TRITS;
247-
ta_log_error("%s\n", "SC_CCLIENT_INVALID_FLEX_TRITS");
247+
ta_log_error("%s\n", ta_error_to_string(ret));
248248
goto done;
249249
}
250250

251251
lock_handle_lock(&cjson_lock);
252252
if (iota_client_find_transactions(service, req, res) != RC_OK) {
253253
lock_handle_unlock(&cjson_lock);
254254
ret = SC_CCLIENT_FAILED_RESPONSE;
255-
ta_log_error("%s\n", "SC_CCLIENT_FAILED_RESPONSE");
255+
ta_log_error("%s\n", ta_error_to_string(ret));
256256
goto done;
257257
}
258258
lock_handle_unlock(&cjson_lock);
@@ -273,7 +273,7 @@ status_t api_find_transactions_obj_by_tag(const iota_client_service_t* const ser
273273
transaction_array_t* res = transaction_array_new();
274274
if (req == NULL || res == NULL) {
275275
ret = SC_TA_OOM;
276-
ta_log_error("%s\n", "SC_TA_OOM");
276+
ta_log_error("%s\n", ta_error_to_string(ret));
277277
goto done;
278278
}
279279

@@ -291,7 +291,7 @@ status_t api_find_transactions_obj_by_tag(const iota_client_service_t* const ser
291291

292292
if (find_transactions_req_tag_add(req, tag_trits) != RC_OK) {
293293
ret = SC_CCLIENT_INVALID_FLEX_TRITS;
294-
ta_log_error("%s\n", "SC_CCLIENT_INVALID_FLEX_TRITS");
294+
ta_log_error("%s\n", ta_error_to_string(ret));
295295
goto done;
296296
}
297297

@@ -319,7 +319,7 @@ status_t api_recv_mam_message(const iota_config_t* const iconf, const iota_clien
319319
mam_api_t mam;
320320
ta_recv_mam_req_t* req = recv_mam_req_new();
321321
if (req == NULL) {
322-
ta_log_error("%s\n", "SC_TA_OOM");
322+
ta_log_error("%s\n", ta_error_to_string(ret));
323323
return SC_TA_OOM;
324324
}
325325
bundle_array_t* bundle_array = NULL;
@@ -336,7 +336,7 @@ status_t api_recv_mam_message(const iota_config_t* const iconf, const iota_clien
336336
recv_mam_data_id_mam_v1_t* data_id = (recv_mam_data_id_mam_v1_t*)req->data_id;
337337
if (mam_api_init(&mam, (tryte_t*)iconf->seed) != RC_OK) {
338338
ret = SC_MAM_FAILED_INIT;
339-
ta_log_error("%s\n", "SC_MAM_FAILED_INIT");
339+
ta_log_error("%s\n", ta_error_to_string(ret));
340340
goto done;
341341
}
342342

@@ -370,7 +370,7 @@ status_t api_recv_mam_message(const iota_config_t* const iconf, const iota_clien
370370
retcode_t rc = ta_mam_api_bundle_read(&mam, bundle, &payload);
371371
if (rc != RC_OK) {
372372
ret = SC_MAM_FAILED_RESPONSE;
373-
ta_log_error("%s\n", "SC_MAM_FAILED_RESPONSE");
373+
ta_log_error("%s\n", ta_error_to_string(ret));
374374
goto done;
375375
}
376376

@@ -387,11 +387,11 @@ status_t api_recv_mam_message(const iota_config_t* const iconf, const iota_clien
387387
// Destroying MAM API
388388
if (ret != SC_MAM_FAILED_INIT) {
389389
if (mam_api_save(&mam, iconf->mam_file_path, NULL, 0) != RC_OK) {
390-
ta_log_error("%s\n", "SC_MAM_FILE_SAVE");
390+
ta_log_error("%s\n", ta_error_to_string(ret));
391391
}
392392
if (mam_api_destroy(&mam) != RC_OK) {
393393
ret = SC_MAM_FAILED_DESTROYED;
394-
ta_log_error("%s\n", "SC_MAM_FAILED_DESTROYED");
394+
ta_log_error("%s\n", ta_error_to_string(ret));
395395
}
396396
}
397397
bundle_array_free(&bundle_array);
@@ -421,7 +421,7 @@ status_t api_send_mam_message(const ta_config_t* const info, const iota_config_t
421421
if (send_mam_req_deserialize(payload, req)) {
422422
lock_handle_unlock(&cjson_lock);
423423
ret = SC_MAM_FAILED_INIT;
424-
ta_log_error("%s\n", "SC_MAM_FAILED_INIT");
424+
ta_log_error("%s\n", ta_error_to_string(ret));
425425
goto done;
426426
}
427427
lock_handle_unlock(&cjson_lock);
@@ -456,7 +456,7 @@ status_t api_send_mam_message(const ta_config_t* const info, const iota_config_t
456456
if (ta_send_bundle(info, iconf, service, bundle) != SC_OK) {
457457
lock_handle_unlock(&cjson_lock);
458458
ret = SC_MAM_FAILED_RESPONSE;
459-
ta_log_error("%s\n", "SC_MAM_FAILED_RESPONSE");
459+
ta_log_error("%s\n", ta_error_to_string(ret));
460460
goto done;
461461
}
462462
lock_handle_unlock(&cjson_lock);
@@ -499,7 +499,7 @@ status_t api_send_mam_message(const ta_config_t* const info, const iota_config_t
499499
if (ta_send_bundle(info, iconf, service, bundle) != SC_OK) {
500500
lock_handle_unlock(&cjson_lock);
501501
ret = SC_MAM_FAILED_RESPONSE;
502-
ta_log_error("%s\n", "SC_MAM_FAILED_RESPONSE");
502+
ta_log_error("%s\n", ta_error_to_string(ret));
503503
goto done;
504504
}
505505
lock_handle_unlock(&cjson_lock);
@@ -529,11 +529,12 @@ status_t api_send_mam_message(const ta_config_t* const info, const iota_config_t
529529
if (ret != SC_MAM_FAILED_INIT) {
530530
// If `seed` is not assigned, then the local MAM file will be used. Therefore, we need to close the MAM file.
531531
if (!data->seed && mam_api_save(&mam, iconf->mam_file_path, NULL, 0) != RC_OK) {
532-
ta_log_error("%s\n", "SC_MAM_FILE_SAVE");
532+
ret = SC_MAM_FILE_SAVE;
533+
ta_log_error("%s\n", ta_error_to_string(ret));
533534
}
534535
if (mam_api_destroy(&mam)) {
535536
ret = SC_MAM_FAILED_DESTROYED;
536-
ta_log_error("%s\n", "SC_MAM_FAILED_DESTROYED");
537+
ta_log_error("%s\n", ta_error_to_string(ret));
537538
}
538539
}
539540
bundle_transactions_free(&bundle);
@@ -553,7 +554,7 @@ status_t api_send_transfer(const ta_core_t* const core, const char* const obj, c
553554

554555
if (req == NULL || res == NULL || txn_obj_req == NULL || res_txn_array == NULL) {
555556
ret = SC_TA_OOM;
556-
ta_log_error("%s\n", "SC_TA_OOM");
557+
ta_log_error("%s\n", ta_error_to_string(ret));
557558
goto done;
558559
}
559560

@@ -623,7 +624,7 @@ status_t api_send_trytes(const ta_config_t* const info, const iota_config_t* con
623624

624625
if (!trytes) {
625626
ret = SC_TA_OOM;
626-
ta_log_error("%s\n", "SC_TA_OOM");
627+
ta_log_error("%s\n", ta_error_to_string(ret));
627628
goto done;
628629
}
629630

0 commit comments

Comments
 (0)