@@ -12,10 +12,10 @@ use cacher::CacherClient;
1212use primitives:: { Chain , NFTChain } ;
1313use settings:: Settings ;
1414use storage:: Database ;
15- use streamer:: { ChainAddressPayload , ConsumerStatusReporter , FetchAssetsPayload , FetchBlocksPayload , QueueName , ShutdownReceiver , run_consumer} ;
15+ use streamer:: { ChainAddressPayload , ConsumerStatusReporter , FetchAssetsPayload , FetchBlocksPayload , QueueName , ShutdownReceiver , StreamConnection , StreamReader , run_consumer} ;
1616
1717use crate :: consumers:: runner:: ChainConsumerRunner ;
18- use crate :: consumers:: { chain_providers, consumer_config, reader_for_queue } ;
18+ use crate :: consumers:: { chain_providers, consumer_config, reader_config } ;
1919
2020use fetch_address_transactions_consumer:: FetchAddressTransactionsConsumer ;
2121use fetch_assets_consumer:: FetchAssetsConsumer ;
@@ -25,23 +25,34 @@ use fetch_nft_assets_addresses_consumer::FetchNftAssetsAddressesConsumer;
2525use fetch_token_addresses_consumer:: FetchTokenAddressesConsumer ;
2626
2727pub async fn run_consumer_indexer ( settings : Settings , shutdown_rx : ShutdownReceiver , reporter : Arc < dyn ConsumerStatusReporter > ) -> Result < ( ) , Box < dyn Error + Send + Sync > > {
28+ let database = Database :: new ( & settings. postgres . url , settings. postgres . pool ) ;
2829 let settings = Arc :: new ( settings) ;
2930
3031 futures:: future:: try_join_all ( vec ! [
31- tokio:: spawn( run_fetch_blocks( settings. clone( ) , shutdown_rx. clone( ) , reporter. clone( ) ) ) ,
32- tokio:: spawn( run_fetch_assets( settings. clone( ) , shutdown_rx. clone( ) , reporter. clone( ) ) ) ,
33- tokio:: spawn( run_fetch_token_associations( settings. clone( ) , shutdown_rx. clone( ) , reporter. clone( ) ) ) ,
34- tokio:: spawn( run_fetch_coin_associations( settings. clone( ) , shutdown_rx. clone( ) , reporter. clone( ) ) ) ,
35- tokio:: spawn( run_fetch_nft_associations( settings. clone( ) , shutdown_rx. clone( ) , reporter. clone( ) ) ) ,
36- tokio:: spawn( run_fetch_transaction_associations( settings. clone( ) , shutdown_rx. clone( ) , reporter. clone( ) ) ) ,
32+ tokio:: spawn( run_fetch_blocks( settings. clone( ) , database. clone( ) , shutdown_rx. clone( ) , reporter. clone( ) ) ) ,
33+ tokio:: spawn( run_fetch_assets( settings. clone( ) , database. clone( ) , shutdown_rx. clone( ) , reporter. clone( ) ) ) ,
34+ tokio:: spawn( run_fetch_token_associations( settings. clone( ) , database. clone( ) , shutdown_rx. clone( ) , reporter. clone( ) ) ) ,
35+ tokio:: spawn( run_fetch_coin_associations( settings. clone( ) , database. clone( ) , shutdown_rx. clone( ) , reporter. clone( ) ) ) ,
36+ tokio:: spawn( run_fetch_nft_associations( settings. clone( ) , database. clone( ) , shutdown_rx. clone( ) , reporter. clone( ) ) ) ,
37+ tokio:: spawn( run_fetch_transaction_associations(
38+ settings. clone( ) ,
39+ database. clone( ) ,
40+ shutdown_rx. clone( ) ,
41+ reporter. clone( ) ,
42+ ) ) ,
3743 ] )
3844 . await ?;
3945
4046 Ok ( ( ) )
4147}
4248
43- async fn run_fetch_blocks ( settings : Arc < Settings > , shutdown_rx : ShutdownReceiver , reporter : Arc < dyn ConsumerStatusReporter > ) -> Result < ( ) , Box < dyn Error + Send + Sync > > {
44- ChainConsumerRunner :: new ( ( * settings) . clone ( ) , QueueName :: FetchBlocks , shutdown_rx, reporter)
49+ async fn run_fetch_blocks (
50+ settings : Arc < Settings > ,
51+ database : Database ,
52+ shutdown_rx : ShutdownReceiver ,
53+ reporter : Arc < dyn ConsumerStatusReporter > ,
54+ ) -> Result < ( ) , Box < dyn Error + Send + Sync > > {
55+ ChainConsumerRunner :: new ( ( * settings) . clone ( ) , database, QueueName :: FetchBlocks , shutdown_rx, reporter)
4556 . await ?
4657 . run ( |runner, chain| async move {
4758 let queue = QueueName :: FetchBlocks ;
@@ -64,10 +75,17 @@ async fn run_fetch_blocks(settings: Arc<Settings>, shutdown_rx: ShutdownReceiver
6475 . await
6576}
6677
67- async fn run_fetch_assets ( settings : Arc < Settings > , shutdown_rx : ShutdownReceiver , reporter : Arc < dyn ConsumerStatusReporter > ) -> Result < ( ) , Box < dyn Error + Send + Sync > > {
68- let database = Database :: new ( & settings. postgres . url , settings. postgres . pool ) ;
78+ async fn run_fetch_assets (
79+ settings : Arc < Settings > ,
80+ database : Database ,
81+ shutdown_rx : ShutdownReceiver ,
82+ reporter : Arc < dyn ConsumerStatusReporter > ,
83+ ) -> Result < ( ) , Box < dyn Error + Send + Sync > > {
6984 let queue = QueueName :: FetchAssets ;
70- let ( name, stream_reader) = reader_for_queue ( & settings, & queue) . await ?;
85+ let name = queue. to_string ( ) ;
86+ let connection = StreamConnection :: new ( & settings. rabbitmq . url , name. clone ( ) ) . await ?;
87+ let config = reader_config ( & settings. rabbitmq , name. clone ( ) ) ;
88+ let stream_reader = StreamReader :: from_connection ( & connection, config) . await ?;
7189 let cacher = CacherClient :: new ( & settings. redis . url ) . await ;
7290 let consumer = FetchAssetsConsumer {
7391 providers : chain_providers ( & settings, & name) ,
@@ -79,10 +97,11 @@ async fn run_fetch_assets(settings: Arc<Settings>, shutdown_rx: ShutdownReceiver
7997
8098async fn run_fetch_token_associations (
8199 settings : Arc < Settings > ,
100+ database : Database ,
82101 shutdown_rx : ShutdownReceiver ,
83102 reporter : Arc < dyn ConsumerStatusReporter > ,
84103) -> Result < ( ) , Box < dyn Error + Send + Sync > > {
85- ChainConsumerRunner :: new ( ( * settings) . clone ( ) , QueueName :: FetchTokenAssociations , shutdown_rx, reporter)
104+ ChainConsumerRunner :: new ( ( * settings) . clone ( ) , database , QueueName :: FetchTokenAssociations , shutdown_rx, reporter)
86105 . await ?
87106 . run ( |runner, chain| async move {
88107 let queue = QueueName :: FetchTokenAssociations ;
@@ -107,10 +126,11 @@ async fn run_fetch_token_associations(
107126
108127async fn run_fetch_coin_associations (
109128 settings : Arc < Settings > ,
129+ database : Database ,
110130 shutdown_rx : ShutdownReceiver ,
111131 reporter : Arc < dyn ConsumerStatusReporter > ,
112132) -> Result < ( ) , Box < dyn Error + Send + Sync > > {
113- ChainConsumerRunner :: new ( ( * settings) . clone ( ) , QueueName :: FetchCoinAssociations , shutdown_rx, reporter)
133+ ChainConsumerRunner :: new ( ( * settings) . clone ( ) , database , QueueName :: FetchCoinAssociations , shutdown_rx, reporter)
114134 . await ?
115135 . run ( |runner, chain| async move {
116136 let queue = QueueName :: FetchCoinAssociations ;
@@ -132,9 +152,14 @@ async fn run_fetch_coin_associations(
132152 . await
133153}
134154
135- async fn run_fetch_nft_associations ( settings : Arc < Settings > , shutdown_rx : ShutdownReceiver , reporter : Arc < dyn ConsumerStatusReporter > ) -> Result < ( ) , Box < dyn Error + Send + Sync > > {
155+ async fn run_fetch_nft_associations (
156+ settings : Arc < Settings > ,
157+ database : Database ,
158+ shutdown_rx : ShutdownReceiver ,
159+ reporter : Arc < dyn ConsumerStatusReporter > ,
160+ ) -> Result < ( ) , Box < dyn Error + Send + Sync > > {
136161 let chains: Vec < Chain > = NFTChain :: all ( ) . into_iter ( ) . map ( Into :: into) . collect ( ) ;
137- ChainConsumerRunner :: new ( ( * settings) . clone ( ) , QueueName :: FetchNftAssociations , shutdown_rx, reporter)
162+ ChainConsumerRunner :: new ( ( * settings) . clone ( ) , database , QueueName :: FetchNftAssociations , shutdown_rx, reporter)
138163 . await ?
139164 . run_for_chains ( chains, |runner, chain| async move {
140165 FetchNftAssetsAddressesConsumer :: run (
@@ -154,10 +179,11 @@ async fn run_fetch_nft_associations(settings: Arc<Settings>, shutdown_rx: Shutdo
154179
155180async fn run_fetch_transaction_associations (
156181 settings : Arc < Settings > ,
182+ database : Database ,
157183 shutdown_rx : ShutdownReceiver ,
158184 reporter : Arc < dyn ConsumerStatusReporter > ,
159185) -> Result < ( ) , Box < dyn Error + Send + Sync > > {
160- ChainConsumerRunner :: new ( ( * settings) . clone ( ) , QueueName :: FetchAddressTransactions , shutdown_rx, reporter)
186+ ChainConsumerRunner :: new ( ( * settings) . clone ( ) , database , QueueName :: FetchAddressTransactions , shutdown_rx, reporter)
161187 . await ?
162188 . run ( |runner, chain| async move {
163189 let queue = QueueName :: FetchAddressTransactions ;
0 commit comments