@@ -459,7 +459,7 @@ where
459
459
}
460
460
461
461
/// Reads sender and receiver addresses properly from an HTLC event.
462
- fn read_real_htlc_addresses ( transfer_details : & mut TransferDetails , msg_event : & & Event ) {
462
+ fn read_real_htlc_addresses ( transfer_details : & mut TransferDetails , msg_event : & Event ) {
463
463
match msg_event. kind . as_str ( ) {
464
464
CREATE_HTLC_EVENT => {
465
465
let from = some_or_return ! ( get_value_from_event_attributes(
@@ -492,10 +492,16 @@ where
492
492
}
493
493
}
494
494
495
- fn parse_transfer_values_from_events ( tx_events : Vec < & Event > ) -> Vec < TransferDetails > {
495
+ fn parse_transfer_values_from_events ( mut tx_events : Vec < & Event > ) -> Vec < TransferDetails > {
496
496
let mut transfer_details_list: Vec < TransferDetails > = vec ! [ ] ;
497
497
498
- for event in tx_events. iter ( ) {
498
+ for i in 0 ..tx_events. len ( ) {
499
+ if i >= tx_events. len ( ) {
500
+ continue ;
501
+ }
502
+
503
+ let event = tx_events[ i] ;
504
+
499
505
let amount_with_denoms = some_or_continue ! ( get_value_from_event_attributes(
500
506
& event. attributes,
501
507
AMOUNT_TAG_KEY ,
@@ -533,18 +539,20 @@ where
533
539
534
540
// For HTLC transactions, the sender and receiver addresses in the "transfer" event will be incorrect.
535
541
// Use `read_real_htlc_addresses` to handle them properly.
536
- if let Some ( htlc_event ) = tx_events
542
+ if let Some ( htlc_event_index ) = tx_events
537
543
. iter ( )
538
- . find ( |e| [ CREATE_HTLC_EVENT , CLAIM_HTLC_EVENT ] . contains ( & e. kind . as_str ( ) ) )
544
+ . position ( |e| [ CREATE_HTLC_EVENT , CLAIM_HTLC_EVENT ] . contains ( & e. kind . as_str ( ) ) )
539
545
{
540
- read_real_htlc_addresses ( & mut tx_details, htlc_event) ;
546
+ read_real_htlc_addresses ( & mut tx_details, tx_events[ htlc_event_index] ) ;
547
+ tx_events. remove ( htlc_event_index) ;
541
548
}
542
549
// For IBC transactions, the sender and receiver addresses in the "transfer" event will be incorrect.
543
550
// Use `read_real_ibc_addresses` to handle them properly.
544
- else if let Some ( ibc_event ) = tx_events. iter ( ) . find ( |e| {
551
+ else if let Some ( ibc_event_index ) = tx_events. iter ( ) . position ( |e| {
545
552
[ IBC_SEND_EVENT , IBC_RECEIVE_EVENT , IBC_NFT_RECEIVE_EVENT ] . contains ( & e. kind . as_str ( ) )
546
553
} ) {
547
- read_real_ibc_addresses ( & mut tx_details, ibc_event) ;
554
+ read_real_ibc_addresses ( & mut tx_details, tx_events[ ibc_event_index] ) ;
555
+ tx_events. remove ( ibc_event_index) ;
548
556
}
549
557
550
558
handle_new_transfer_event ( & mut transfer_details_list, tx_details) ;
@@ -643,7 +651,10 @@ where
643
651
}
644
652
}
645
653
646
- fn get_transfer_details ( tx_events : Vec < Event > , fee_amount_with_denom : String ) -> Vec < TransferDetails > {
654
+ fn get_transfer_details ( mut tx_events : Vec < Event > , fee_amount_with_denom : String ) -> Vec < TransferDetails > {
655
+ tx_events. sort_by ( |a, b| a. kind . cmp ( & b. kind ) ) ;
656
+ tx_events. dedup ( ) ;
657
+
647
658
// We are only interested `DELEGATE_EVENT` events for delegation transactions.
648
659
if let Some ( delegate_event) = tx_events. iter ( ) . find ( |e| e. kind == DELEGATE_EVENT ) {
649
660
return parse_transfer_values_from_events ( vec ! [ delegate_event] ) ;
0 commit comments