@@ -17,7 +17,6 @@ use chain::services::{
1717use chrono:: { NaiveDateTime , Utc } ;
1818use clap:: Parser ;
1919use deadpool_diesel:: postgres:: Object ;
20- use futures:: future:: FutureExt ;
2120use futures:: stream:: StreamExt ;
2221use namada_sdk:: time:: DateTimeUtc ;
2322use orm:: migrations:: CustomMigrationSource ;
@@ -287,13 +286,14 @@ async fn crawling_fn(
287286 native_token. clone ( ) ,
288287 ) ) ;
289288 let addresses = block. addresses_with_balance_change ( & native_token) ;
289+ let all_changed_tokens_supply = addresses
290+ . iter ( )
291+ . map ( |bc| bc. token . clone ( ) )
292+ . collect :: < HashSet < _ > > ( ) ;
290293
291- let token_supplies = first_block_in_epoch
292- . eq ( & block_height)
293- . then ( || query_token_supplies ( & client, & conn, & native_token, epoch) )
294- . future ( )
295- . await
296- . transpose ( ) ?;
294+ let token_supplies =
295+ query_token_supplies ( & client, & all_changed_tokens_supply, epoch)
296+ . await ?;
297297
298298 let validators_addresses = if first_block_in_epoch. eq ( & block_height) {
299299 let previous_epoch = epoch. saturating_sub ( 1 ) ;
@@ -492,7 +492,7 @@ async fn crawling_fn(
492492
493493 repository:: balance:: insert_token_supplies (
494494 transaction_conn,
495- token_supplies. into_iter ( ) . flatten ( ) ,
495+ token_supplies,
496496 ) ?;
497497
498498 repository:: balance:: insert_ibc_rate_limits (
@@ -641,10 +641,12 @@ async fn try_initial_query(
641641 . into_rpc_error ( )
642642 } ;
643643 let token_supplies_fut = async {
644- let native_token = namada_service:: get_native_token ( client)
645- . await
646- . into_rpc_error ( ) ?;
647- query_token_supplies ( client, conn, & native_token, epoch) . await
644+ query_token_supplies (
645+ client,
646+ & tokens. iter ( ) . cloned ( ) . collect :: < HashSet < _ > > ( ) ,
647+ epoch,
648+ )
649+ . await
648650 } ;
649651
650652 let ( rate_limits, token_supplies) =
@@ -874,22 +876,31 @@ async fn get_block(
874876 Ok ( ( block, tm_block_response, epoch) )
875877}
876878
877- async fn query_non_native_supplies (
879+ async fn query_token_supplies (
878880 client : & HttpClient ,
879- conn : & Object ,
881+ tokens : & HashSet < Token > ,
880882 epoch : u32 ,
881883) -> Result < Vec < TokenSupply > , MainError > {
882- let token_addresses = db_service:: get_non_native_tokens ( conn)
883- . await
884- . into_db_error ( ) ?;
885-
886- let mut buffer = Vec :: with_capacity ( 1 ) ;
887-
888- let mut stream = futures:: stream:: iter ( token_addresses)
889- . map ( |address| async move {
890- namada_service:: get_token_supply ( client, address, epoch)
884+ let mut buffer = Vec :: with_capacity ( tokens. len ( ) ) ;
885+
886+ let mut stream = futures:: stream:: iter ( tokens)
887+ . map ( |token| async move {
888+ match token {
889+ Token :: Ibc ( ibc_token) => namada_service:: get_token_supply (
890+ client,
891+ ibc_token. address . to_string ( ) ,
892+ epoch,
893+ )
891894 . await
892- . into_rpc_error ( )
895+ . into_rpc_error ( ) ,
896+ Token :: Native ( address) => {
897+ namada_service:: get_native_token_supply (
898+ client, address, epoch,
899+ )
900+ . await
901+ . into_rpc_error ( )
902+ }
903+ }
893904 } )
894905 . buffer_unordered ( 32 ) ;
895906
@@ -900,23 +911,3 @@ async fn query_non_native_supplies(
900911
901912 Ok ( buffer)
902913}
903-
904- async fn query_token_supplies (
905- client : & HttpClient ,
906- conn : & Object ,
907- native_token : & Id ,
908- epoch : u32 ,
909- ) -> Result < Vec < TokenSupply > , MainError > {
910- let native_fut =
911- namada_service:: get_native_token_supply ( client, native_token, epoch)
912- . map ( |result| result. into_rpc_error ( ) ) ;
913-
914- let non_native_fut = query_non_native_supplies ( client, conn, epoch) ;
915-
916- let ( native, non_native) = futures:: try_join!( native_fut, non_native_fut) ?;
917-
918- let mut supplies = non_native;
919- supplies. push ( native) ;
920-
921- Ok ( supplies)
922- }
0 commit comments