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

Commit bcfc578

Browse files
committed
feat(api): Return uuid and address of failed requests
Tangle-accelerator would return the uuid and the address of failed transaction request. The example response is as following: ``` {"uuid":"b76ad723-660a-44d7-bea5-26cc87ccbd05", "address":"POWEREDBYTANGLEACCELERATOR99999999999999999999999999999999 \ 99999999999999999999999"} ``` close #619
1 parent 3a4942f commit bcfc578

File tree

5 files changed

+30
-6
lines changed

5 files changed

+30
-6
lines changed

accelerator/core/core.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,11 @@ status_t ta_send_transfer(const ta_config_t* const info, const iota_config_t* co
229229
ta_log_error("Error in ta_send_trytes. Push transaction trytes to buffer.\n");
230230
res->uuid = (char*)malloc(sizeof(char) * UUID_STR_LEN);
231231
push_txn_to_buffer(cache, raw_tx, res->uuid);
232+
233+
txn = (iota_transaction_t*)utarray_front(out_bundle);
234+
res->address = (tryte_t*)malloc(sizeof(char) * NUM_TRYTES_ADDRESS);
235+
flex_trits_to_trytes(res->address, NUM_TRYTES_ADDRESS, transaction_address(txn), NUM_TRITS_ADDRESS,
236+
NUM_TRITS_ADDRESS);
232237
goto done;
233238
}
234239

accelerator/core/response/ta_send_transfer.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ ta_send_transfer_res_t* ta_send_transfer_res_new() {
1313
if (res) {
1414
res->hash = NULL;
1515
res->uuid = NULL;
16+
res->address = NULL;
1617
}
1718
return res;
1819
}
1920

2021
void ta_send_transfer_res_free(ta_send_transfer_res_t** res) {
2122
if ((*res)) {
2223
free((*res)->uuid);
24+
free((*res)->address);
2325
hash243_queue_free(&(*res)->hash);
2426
free((*res));
2527
*res = NULL;

accelerator/core/response/ta_send_transfer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ typedef struct {
3131
hash243_queue_t hash;
3232
transaction_array_t* txn_array;
3333
char* uuid;
34+
tryte_t* address;
3435
#ifdef DB_ENABLE
3536
char uuid_string[DB_UUID_STRING_LENGTH];
3637
#endif

accelerator/core/serializer/serializer.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -857,6 +857,7 @@ status_t ta_send_transfer_res_serialize(ta_send_transfer_res_t* res, char** obj)
857857

858858
if (res->uuid) {
859859
cJSON_AddStringToObject(json_root, "uuid", res->uuid);
860+
cJSON_AddStringToObject(json_root, "address", (char*)res->address);
860861
} else {
861862
ret = iota_transaction_to_json_object(transaction_array_at(res->txn_array, 0), &json_root);
862863
if (ret != SC_OK) {

tests/unit-test/test_serializer.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ void test_serialize_ta_generate_address(void) {
2929
free(json_result);
3030
}
3131

32-
void test_deserialize_ta_send_transfer(void) {
32+
void test_ta_send_transfer_req_deserialize(void) {
3333
const char* json_template =
3434
"{\"value\":100,"
3535
"\"message_format\":\"trytes\","
@@ -59,7 +59,7 @@ void test_deserialize_ta_send_transfer(void) {
5959
free(json);
6060
}
6161

62-
void test_deserialize_ta_send_transfer_raw_message(void) {
62+
void test_ta_send_transfer_raw_message_req_deserialize(void) {
6363
const char* json_template =
6464
"{\"value\":100,"
6565
"\"message\":\"%s\",\"tag\":\"" TEST_TAG
@@ -88,7 +88,7 @@ void test_deserialize_ta_send_transfer_raw_message(void) {
8888
free(json);
8989
}
9090

91-
void test_deserialize_ta_send_transfer_overrun(void) {
91+
void test_ta_send_transfer_overrun_req_deserialize(void) {
9292
const char* json_template =
9393
"{\"value\":100,"
9494
"\"message\":\"%s\",\"tag\":\"" TEST_TAG
@@ -107,6 +107,20 @@ void test_deserialize_ta_send_transfer_overrun(void) {
107107
free(json);
108108
}
109109

110+
void test_ta_send_transfer_buffered_res_serialize(void) {
111+
const char* json = "{\"uuid\":\"" TEST_UUID "\",\"address\":\"" TEST_ADDRESS "\"}";
112+
char* json_result;
113+
ta_send_transfer_res_t* res = ta_send_transfer_res_new();
114+
res->uuid = strdup(TEST_UUID);
115+
res->address = strdup(TEST_ADDRESS);
116+
117+
ta_send_transfer_res_serialize(res, &json_result);
118+
119+
TEST_ASSERT_EQUAL_STRING(json, json_result);
120+
ta_send_transfer_res_free(&res);
121+
free(json_result);
122+
}
123+
110124
void test_serialize_ta_find_transaction_objects(void) {
111125
const char* json =
112126
"[{\"hash\":\"" TRYTES_81_1 "\","
@@ -625,9 +639,10 @@ int main(void) {
625639

626640
serializer_logger_init();
627641
RUN_TEST(test_serialize_ta_generate_address);
628-
RUN_TEST(test_deserialize_ta_send_transfer);
629-
RUN_TEST(test_deserialize_ta_send_transfer_raw_message);
630-
RUN_TEST(test_deserialize_ta_send_transfer_overrun);
642+
RUN_TEST(test_ta_send_transfer_req_deserialize);
643+
RUN_TEST(test_ta_send_transfer_raw_message_req_deserialize);
644+
RUN_TEST(test_ta_send_transfer_overrun_req_deserialize);
645+
RUN_TEST(test_ta_send_transfer_buffered_res_serialize);
631646
RUN_TEST(test_serialize_ta_find_transaction_objects);
632647
RUN_TEST(test_serialize_ta_find_transactions_by_tag);
633648
RUN_TEST(test_serialize_ta_find_transactions_obj_by_tag);

0 commit comments

Comments
 (0)