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

Commit

Permalink
fix(serializer): Add status code for empty result
Browse files Browse the repository at this point in the history
  • Loading branch information
jkrvivian committed Mar 11, 2019
1 parent 9367ff2 commit 7a15252
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
2 changes: 2 additions & 0 deletions accelerator/errors.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ typedef enum {
// CClient module
SC_CCLIENT_OOM = 0x01 | SC_MODULE_CCLIENT | SC_SEVERITY_FATAL,
/**< Fail to create cclient object */
SC_CCLIENT_NOT_FOUND = 0x02 | SC_MODULE_CCLIENT | SC_SEVERITY_FATAL,
/**< Empty result from cclient */
SC_CCLIENT_FAILED_RESPONSE = 0x03 | SC_MODULE_CCLIENT | SC_SEVERITY_FATAL,
/**< Error in cclient response */
SC_CCLIENT_INVALID_FLEX_TRITS = 0x04 | SC_MODULE_CCLIENT | SC_SEVERITY_MAJOR,
Expand Down
28 changes: 19 additions & 9 deletions serializer/serializer.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ void fill_tag(char* new_tag, char* old_tag, size_t tag_len) {
sprintf(new_tag, "%s%*.*s", old_tag, pad_len, pad_len, nines);
}

int ta_hash243_stack_to_json_array(hash243_stack_t stack,
cJSON* const json_root,
char const* const obj_name) {
status_t ta_hash243_stack_to_json_array(hash243_stack_t stack,
cJSON* const json_root,
char const* const obj_name) {
size_t array_count = 0;
cJSON* array_obj = NULL;
hash243_stack_entry_t* s_iter = NULL;
Expand All @@ -35,13 +35,15 @@ int ta_hash243_stack_to_json_array(hash243_stack_t stack,
return SC_CCLIENT_INVALID_FLEX_TRITS;
}
}
} else {
return SC_CCLIENT_NOT_FOUND;
}
return SC_OK;
}

int ta_hash243_queue_to_json_array(hash243_queue_t queue,
cJSON* const json_root,
char const* const obj_name) {
status_t ta_hash243_queue_to_json_array(hash243_queue_t queue,
cJSON* const json_root,
char const* const obj_name) {
size_t array_count;
cJSON* array_obj = NULL;
hash243_queue_entry_t* q_iter = NULL;
Expand All @@ -67,14 +69,16 @@ int ta_hash243_queue_to_json_array(hash243_queue_t queue,
return SC_CCLIENT_INVALID_FLEX_TRITS;
}
}
} else {
return SC_CCLIENT_NOT_FOUND;
}
return SC_OK;
}

status_t iota_transaction_to_json_object(iota_transaction_t const* const txn,
cJSON** txn_json) {
if (txn == NULL) {
return SC_SERIALIZER_NULL;
return SC_CCLIENT_NOT_FOUND;
}
char msg_trytes[NUM_TRYTES_SIGNATURE + 1], hash_trytes[NUM_TRYTES_HASH + 1],
tag_trytes[NUM_TRYTES_TAG + 1];
Expand Down Expand Up @@ -210,14 +214,17 @@ status_t ta_get_tips_res_serialize(char** obj,

status_t ta_send_transfer_req_deserialize(const char* const obj,
ta_send_transfer_req_t* req) {
if (obj == NULL) {
return SC_SERIALIZER_NULL;
}
cJSON* json_obj = cJSON_Parse(obj);
cJSON* json_result = NULL;
flex_trit_t tag_trits[NUM_TRITS_TAG], address_trits[NUM_TRITS_HASH];
int msg_len = 0, tag_len = 0;
status_t ret = SC_OK;

if (json_obj == NULL) {
ret = SC_SERIALIZER_JSON_CREATE;
ret = SC_SERIALIZER_JSON_PARSE;
goto done;
}

Expand Down Expand Up @@ -324,7 +331,10 @@ status_t ta_find_transactions_res_serialize(
goto done;
}

ta_hash243_queue_to_json_array(res->hashes, json_root, "hashes");
ret = ta_hash243_queue_to_json_array(res->hashes, json_root, "hashes");
if (ret) {
goto done;
}
*obj = cJSON_PrintUnformatted(json_root);
if (*obj == NULL) {
ret = SC_SERIALIZER_JSON_PARSE;
Expand Down

0 comments on commit 7a15252

Please sign in to comment.