@@ -98,79 +98,68 @@ status_t api_generate_address(const iota_config_t* const tangle, const iota_clie
98
98
return ret ;
99
99
}
100
100
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 ) {
103
102
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 ) {
106
107
ret = SC_TA_OOM ;
107
108
goto done ;
108
109
}
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 ;
112
112
goto done ;
113
113
}
114
114
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 ;
128
117
goto done ;
129
118
}
130
119
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 ;
140
122
goto done ;
141
123
}
142
124
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 ) {
145
127
goto done ;
146
128
}
147
-
148
- ret = ta_find_transactions_res_serialize (json_result , res );
129
+ snprintf (* json_result , (res_buff -> length + 1 ), "%s" , res_buff -> data );
149
130
150
131
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 );
153
135
return ret ;
154
136
}
155
137
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 ) {
158
140
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 ) {
161
144
ret = SC_TA_OOM ;
162
145
goto done ;
163
146
}
164
147
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 );
166
154
if (ret ) {
167
155
goto done ;
168
156
}
169
157
170
- ret = ta_find_transactions_obj_res_serialize (json_result , res );
158
+ ret = ta_find_transaction_objects_res_serialize (json_result , res );
171
159
172
160
done :
173
- ta_find_transactions_obj_res_free (& res );
161
+ ta_find_transaction_objects_req_free (& req );
162
+ transaction_array_free (res );
174
163
return ret ;
175
164
}
176
165
@@ -318,12 +307,12 @@ status_t api_mam_send_message(const iota_config_t* const tangle, const iota_clie
318
307
status_t api_send_transfer (const iota_config_t * const tangle , const iota_client_service_t * const service ,
319
308
const char * const obj , char * * json_result ) {
320
309
status_t ret = SC_OK ;
321
- char hash_trytes [NUM_TRYTES_HASH + 1 ];
322
310
ta_send_transfer_req_t * req = ta_send_transfer_req_new ();
323
311
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 ();
325
314
326
- if (req == NULL || res == NULL || txn_obj_res == NULL ) {
315
+ if (req == NULL || res == NULL || txn_obj_req == NULL || res_txn_array == NULL ) {
327
316
ret = SC_TA_OOM ;
328
317
goto done ;
329
318
}
@@ -339,20 +328,20 @@ status_t api_send_transfer(const iota_config_t* const tangle, const iota_client_
339
328
}
340
329
341
330
// 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 );
346
334
if (ret ) {
347
335
goto done ;
348
336
}
349
337
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 );
351
339
352
340
done :
353
341
ta_send_transfer_req_free (& req );
354
342
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 );
356
345
return ret ;
357
346
}
358
347
0 commit comments