@@ -266,6 +266,10 @@ impl PostgresGateway {
266266 schema:: protocol_component_holds_token:: protocol_component_id
267267 . eq_any ( protocol_component_ids. clone ( ) ) ,
268268 )
269+ . order_by ( (
270+ schema:: protocol_component_holds_token:: protocol_component_id. asc ( ) ,
271+ schema:: protocol_component_holds_token:: token_index. asc ( ) ,
272+ ) )
269273 . load :: < ( i64 , Address ) > ( conn)
270274 . await
271275 . map_err ( PostgresError :: from) ?;
@@ -513,10 +517,11 @@ impl PostgresGateway {
513517 pc. tokens
514518 . clone ( )
515519 . into_iter ( )
516- . map ( move |add| ( * pc_id, add) )
517- . collect :: < Vec < ( i64 , Address ) > > ( )
520+ . enumerate ( )
521+ . map ( move |( idx, add) | ( * pc_id, add, idx as i16 ) )
522+ . collect :: < Vec < ( i64 , Address , i16 ) > > ( )
518523 } )
519- . collect :: < Vec < ( i64 , Address ) > > ( ) ;
524+ . collect :: < Vec < ( i64 , Address , i16 ) > > ( ) ;
520525
521526 let token_add_by_id: HashMap < Address , i64 > = token
522527 . inner_join ( account)
@@ -534,13 +539,14 @@ impl PostgresGateway {
534539 StorageError ,
535540 > = pc_tokens_map
536541 . iter ( )
537- . map ( |( pc_id, t_address) | {
542+ . map ( |( pc_id, t_address, token_idx ) | {
538543 let t_id = token_add_by_id
539544 . get ( t_address)
540545 . ok_or ( StorageError :: NotFound ( "Token" . to_string ( ) , t_address. to_string ( ) ) ) ?;
541546 Ok ( orm:: NewProtocolComponentHoldsToken {
542547 protocol_component_id : * pc_id,
543548 token_id : * t_id,
549+ token_index : * token_idx,
544550 } )
545551 } )
546552 . collect ( ) ;
0 commit comments