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

Commit 89b7385

Browse files
committed
feat(api): Implement find_transaction_objects
In order to take multiple query hashes, we use `iota_client_get_transaction_objects()` to replace the original get_transaction_object and rename API `get_transaction_objects()` as `find_transaction_objects()`. This new API receives transaction hases (in a JSON list), and returns a `transaction_array_t` object which is a list of transaction object can be easily applied. We use entangled original API `iota_client_find_transactions` to get transaction hashes with given informations. It uses POST request and request body is the same as IRI API `findTransactions`, but eliminating the `command` field. The tag related APIs are deprecated after both `find_trnasctions` and `find_transaction_objects` are implemeted, so the two deprecated APIs are removed in this commit.
1 parent fd30ba8 commit 89b7385

20 files changed

+387
-358
lines changed

accelerator/apis.c

Lines changed: 40 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -98,79 +98,68 @@ status_t api_generate_address(const iota_config_t* const tangle, const iota_clie
9898
return ret;
9999
}
100100

101-
status_t api_get_transaction_object(const iota_client_service_t* const service, const char* const obj,
102-
char** json_result) {
101+
status_t api_find_transactions(const iota_client_service_t* const service, const char* const obj, char** json_result) {
103102
status_t ret = SC_OK;
104-
ta_get_transaction_object_res_t* res = ta_get_transaction_object_res_new();
105-
if (res == NULL) {
103+
find_transactions_req_t* req = find_transactions_req_new();
104+
find_transactions_res_t* res = find_transactions_res_new();
105+
char_buffer_t* res_buff = char_buffer_new();
106+
if (req == NULL || res == NULL || res_buff == NULL) {
106107
ret = SC_TA_OOM;
107108
goto done;
108109
}
109-
110-
ret = ta_get_transaction_object(service, obj, res);
111-
if (ret) {
110+
if (service->serializer.vtable.find_transactions_deserialize_request(obj, req) != RC_OK) {
111+
ret = SC_CCLIENT_JSON_PARSE;
112112
goto done;
113113
}
114114

115-
ret = ta_get_transaction_object_res_serialize(json_result, res);
116-
117-
done:
118-
ta_get_transaction_object_res_free(&res);
119-
return ret;
120-
}
121-
122-
status_t api_find_transactions_by_tag(const iota_client_service_t* const service, const char* const obj,
123-
char** json_result) {
124-
status_t ret = SC_OK;
125-
ta_find_transactions_res_t* res = ta_find_transactions_res_new();
126-
if (res == NULL) {
127-
ret = SC_TA_OOM;
115+
if (iota_client_find_transactions(service, req, res) != RC_OK) {
116+
ret = SC_CCLIENT_FAILED_RESPONSE;
128117
goto done;
129118
}
130119

131-
char* req_tag = (char*)malloc((NUM_TRYTES_TAG + 1) * sizeof(char));
132-
int obj_len = strlen(obj);
133-
134-
if (obj_len == NUM_TRYTES_TAG) {
135-
strncpy(req_tag, obj, NUM_TRYTES_TAG);
136-
} else if (obj_len < NUM_TRYTES_TAG) {
137-
fill_nines(req_tag, obj, NUM_TRYTES_TAG);
138-
} else { // tag length > 27 trytes
139-
ret = SC_TA_WRONG_REQUEST_OBJ;
120+
if (service->serializer.vtable.find_transactions_serialize_response(res, res_buff) != RC_OK) {
121+
ret = SC_CCLIENT_JSON_PARSE;
140122
goto done;
141123
}
142124

143-
ret = ta_find_transactions_by_tag(service, req_tag, res);
144-
if (ret) {
125+
*json_result = (char*)malloc((res_buff->length + 1) * sizeof(char));
126+
if (*json_result == NULL) {
145127
goto done;
146128
}
147-
148-
ret = ta_find_transactions_res_serialize(json_result, res);
129+
snprintf(*json_result, (res_buff->length + 1), "%s", res_buff->data);
149130

150131
done:
151-
free(req_tag);
152-
ta_find_transactions_res_free(&res);
132+
find_transactions_req_free(&req);
133+
find_transactions_res_free(&res);
134+
char_buffer_free(res_buff);
153135
return ret;
154136
}
155137

156-
status_t api_find_transactions_obj_by_tag(const iota_client_service_t* const service, const char* const obj,
157-
char** json_result) {
138+
status_t api_find_transaction_objects(const iota_client_service_t* const service, const char* const obj,
139+
char** json_result) {
158140
status_t ret = SC_OK;
159-
ta_find_transactions_obj_res_t* res = ta_find_transactions_obj_res_new();
160-
if (res == NULL) {
141+
ta_find_transaction_objects_req_t* req = ta_find_transaction_objects_req_new();
142+
transaction_array_t* res = transaction_array_new();
143+
if (req == NULL || res == NULL) {
161144
ret = SC_TA_OOM;
162145
goto done;
163146
}
164147

165-
ret = ta_find_transactions_obj_by_tag(service, obj, res);
148+
ret = ta_find_transaction_objects_req_deserialize(obj, req);
149+
if (ret != SC_OK) {
150+
goto done;
151+
}
152+
153+
ret = ta_find_transaction_objects(service, req, res);
166154
if (ret) {
167155
goto done;
168156
}
169157

170-
ret = ta_find_transactions_obj_res_serialize(json_result, res);
158+
ret = ta_find_transaction_objects_res_serialize(json_result, res);
171159

172160
done:
173-
ta_find_transactions_obj_res_free(&res);
161+
ta_find_transaction_objects_req_free(&req);
162+
transaction_array_free(res);
174163
return ret;
175164
}
176165

@@ -318,12 +307,12 @@ status_t api_mam_send_message(const iota_config_t* const tangle, const iota_clie
318307
status_t api_send_transfer(const iota_config_t* const tangle, const iota_client_service_t* const service,
319308
const char* const obj, char** json_result) {
320309
status_t ret = SC_OK;
321-
char hash_trytes[NUM_TRYTES_HASH + 1];
322310
ta_send_transfer_req_t* req = ta_send_transfer_req_new();
323311
ta_send_transfer_res_t* res = ta_send_transfer_res_new();
324-
ta_get_transaction_object_res_t* txn_obj_res = ta_get_transaction_object_res_new();
312+
ta_find_transaction_objects_req_t* txn_obj_req = ta_find_transaction_objects_req_new();
313+
transaction_array_t* res_txn_array = transaction_array_new();
325314

326-
if (req == NULL || res == NULL || txn_obj_res == NULL) {
315+
if (req == NULL || res == NULL || txn_obj_req == NULL || res_txn_array == NULL) {
327316
ret = SC_TA_OOM;
328317
goto done;
329318
}
@@ -339,20 +328,20 @@ status_t api_send_transfer(const iota_config_t* const tangle, const iota_client_
339328
}
340329

341330
// return transaction object
342-
flex_trits_to_trytes((tryte_t*)hash_trytes, NUM_TRYTES_HASH, hash243_queue_peek(res->hash), NUM_TRITS_HASH,
343-
NUM_TRITS_HASH);
344-
hash_trytes[NUM_TRYTES_HASH] = '\0';
345-
ret = ta_get_transaction_object(service, hash_trytes, txn_obj_res);
331+
hash243_queue_push(&txn_obj_req->hashes, hash243_queue_peek(res->hash));
332+
333+
ret = ta_find_transaction_objects(service, txn_obj_req, res_txn_array);
346334
if (ret) {
347335
goto done;
348336
}
349337

350-
ret = ta_get_transaction_object_res_serialize(json_result, txn_obj_res);
338+
ret = ta_find_transaction_objects_res_serialize(json_result, res_txn_array);
351339

352340
done:
353341
ta_send_transfer_req_free(&req);
354342
ta_send_transfer_res_free(&res);
355-
ta_get_transaction_object_res_free(&txn_obj_res);
343+
ta_find_transaction_objects_req_free(&txn_obj_req);
344+
transaction_array_free(res_txn_array);
356345
return ret;
357346
}
358347

accelerator/apis.h

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -132,58 +132,38 @@ status_t api_send_transfer(const iota_config_t* const tangle, const iota_client_
132132
const char* const obj, char** json_result);
133133

134134
/**
135-
* @brief Return transaction object with given transaction hash.
135+
* @brief Return transaction hashes with given information such as bundle hashes, addresses, tags, or approvees.
136136
*
137-
* Explore transaction hash information with given transaction haash. This would
138-
* return whole transaction object details in json format instead of raw trytes.
137+
* Explore transaction hash with given transaction related information. This would
138+
* return a list of transaction hashes in json format.
139139
*
140140
* @param[in] service IRI node end point service
141-
* @param[in] obj transaction hash in trytes
141+
* @param[in] obj bundle hashes, addresses, tags, or approvees.
142142
* @param[out] json_result Result containing transaction objects in json format
143143
*
144144
* @return
145145
* - SC_OK on success
146146
* - non-zero on error
147147
*/
148-
status_t api_get_transaction_object(const iota_client_service_t* const service, const char* const obj,
149-
char** json_result);
148+
status_t api_find_transactions(const iota_client_service_t* const service, const char* const obj, char** json_result);
150149

151150
/**
152-
* @brief Return list of transaction hash with given tag hash.
151+
* @brief Return transaction object with given transaction hash.
153152
*
154-
* Retreive all transactions that have same given tag. The result is a list of
155-
* transaction hash in json format.
153+
* Explore transaction hash information with given transaction hash. This would
154+
* return whole transaction object details in json format instead of raw trytes.
156155
*
157156
* @param[in] service IRI node end point service
158-
* @param[in] obj tag in trytes
159-
* @param[out] json_result Result containing list of transaction hash in json
160-
* format
157+
* @param[in] obj transaction hash in trytes
158+
* @param[out] json_result Result containing transaction objects in json format
161159
*
162160
* @return
163161
* - SC_OK on success
164162
* - non-zero on error
165163
*/
166-
status_t api_find_transactions_by_tag(const iota_client_service_t* const service, const char* const obj,
164+
status_t api_find_transaction_objects(const iota_client_service_t* const service, const char* const obj,
167165
char** json_result);
168166

169-
/**
170-
* @brief Return list of transaction object with given tag hash.
171-
*
172-
* Retreive all transactions that have same given tag. The result is a list of
173-
* transaction objects in json format.
174-
*
175-
* @param[in] service IRI node end point service
176-
* @param[in] obj tag in trytes
177-
* @param[out] json_result Result containing list of transaction object in json
178-
* format
179-
*
180-
* @return
181-
* - SC_OK on success
182-
* - non-zero on error
183-
*/
184-
status_t api_find_transactions_obj_by_tag(const iota_client_service_t* const service, const char* const obj,
185-
char** json_result);
186-
187167
/**
188168
* @brief Attach trytes to Tangle and return transaction hashes
189169
*

0 commit comments

Comments
 (0)