@@ -455,3 +455,68 @@ status_t ta_find_transactions_obj_by_tag(
455
455
ta_find_transactions_res_free (& hash_res );
456
456
return ret ;
457
457
}
458
+
459
+ static int idx_sort (void const * lhs , void const * rhs ) {
460
+ iota_transaction_t * _lhs = (iota_transaction_t * )lhs ;
461
+ iota_transaction_t * _rhs = (iota_transaction_t * )rhs ;
462
+
463
+ return (transaction_current_index (_lhs ) < transaction_current_index (_rhs ))
464
+ ? -1
465
+ : (transaction_current_index (_lhs ) >
466
+ transaction_current_index (_rhs ));
467
+ }
468
+
469
+ static void get_first_bundle_from_transactions (
470
+ transaction_array_t const transactions ,
471
+ bundle_transactions_t * const bundle ) {
472
+ iota_transaction_t * tail = NULL ;
473
+ iota_transaction_t * curr_tx = NULL ;
474
+ iota_transaction_t * prev = NULL ;
475
+
476
+ utarray_sort (transactions , idx_sort );
477
+ tail = (iota_transaction_t * )utarray_eltptr (transactions , 0 );
478
+ bundle_transactions_add (bundle , tail );
479
+
480
+ prev = tail ;
481
+ TX_OBJS_FOREACH (transactions , curr_tx ) {
482
+ if (transaction_current_index (curr_tx ) ==
483
+ (transaction_current_index (prev ) + 1 ) &&
484
+ (memcmp (transaction_hash (curr_tx ), transaction_trunk (prev ),
485
+ FLEX_TRIT_SIZE_243 ) == 0 )) {
486
+ bundle_transactions_add (bundle , curr_tx );
487
+ prev = curr_tx ;
488
+ }
489
+ }
490
+ }
491
+
492
+ status_t ta_get_bundle (const iota_client_service_t * const service ,
493
+ tryte_t const * const bundle_hash ,
494
+ bundle_transactions_t * const bundle ) {
495
+ status_t ret = SC_OK ;
496
+ iota_transaction_t * curr_tx = NULL ;
497
+ flex_trit_t bundle_hash_flex [FLEX_TRIT_SIZE_243 ];
498
+ transaction_array_t tx_objs = transaction_array_new ();
499
+ find_transactions_req_t * find_tx_req = find_transactions_req_new ();
500
+ if (find_tx_req == NULL ) {
501
+ ret = SC_CCLIENT_OOM ;
502
+ goto done ;
503
+ }
504
+
505
+ // find transactions by bundle hash
506
+ flex_trits_from_trytes (bundle_hash_flex , NUM_TRITS_BUNDLE , bundle_hash ,
507
+ NUM_TRITS_HASH , NUM_TRYTES_BUNDLE );
508
+ hash243_queue_push (& find_tx_req -> bundles , bundle_hash_flex );
509
+ ret = iota_client_find_transaction_objects (service , find_tx_req , tx_objs );
510
+ if (ret ) {
511
+ ret = SC_CCLIENT_FAILED_RESPONSE ;
512
+ goto done ;
513
+ }
514
+
515
+ // retreive only first bundle
516
+ get_first_bundle_from_transactions (tx_objs , bundle );
517
+
518
+ done :
519
+ transaction_array_free (tx_objs );
520
+ find_transactions_req_free (& find_tx_req );
521
+ return ret ;
522
+ }
0 commit comments