From f8751a69b21922ff046e08ad6a95abd9d9a63f28 Mon Sep 17 00:00:00 2001 From: Josh Stevens Date: Tue, 6 Aug 2024 16:47:54 +0100 Subject: [PATCH] format --- cli/src/commands/new.rs | 9 ++++-- core/src/chat/clients.rs | 2 +- core/src/event/conditions.rs | 3 +- core/src/indexer/last_synced.rs | 50 ++++++++++++++++++++------------- core/src/manifest/stream.rs | 10 +++++-- 5 files changed, 47 insertions(+), 27 deletions(-) diff --git a/cli/src/commands/new.rs b/cli/src/commands/new.rs index a5737be9..87d0adf3 100644 --- a/cli/src/commands/new.rs +++ b/cli/src/commands/new.rs @@ -53,9 +53,12 @@ fn write_docker_compose(path: &Path) -> Result<(), WriteFileError> { } fn write_gitignore(path: &Path) -> Result<(), WriteFileError> { - write_file(&path.join(".gitignore"), r#".rindexer + write_file( + &path.join(".gitignore"), + r#".rindexer generated_csv/**/*.txt - "#) + "#, + ) } pub fn handle_new_command( @@ -218,7 +221,7 @@ POSTGRES_PASSWORD=rindexer"#; if is_rust_project { generate_rindexer_rust_project(&project_path); } - + write_gitignore(&project_path)?; print_success_message(&success_message); diff --git a/core/src/chat/clients.rs b/core/src/chat/clients.rs index 84cd13a8..d0502c1d 100644 --- a/core/src/chat/clients.rs +++ b/core/src/chat/clients.rs @@ -243,7 +243,7 @@ impl ChatClients { } } } - + if let Some(discord) = &self.discord { for instance in discord { if instance.config.networks.contains(&event_message.network) { diff --git a/core/src/event/conditions.rs b/core/src/event/conditions.rs index 158b34b2..1d385758 100644 --- a/core/src/event/conditions.rs +++ b/core/src/event/conditions.rs @@ -58,8 +58,7 @@ fn evaluate_condition(value: &Value, condition: &str) -> bool { U64::from_str_radix(comp, 10).unwrap_or_default() } "=" => value == &Value::String(comp.to_string()), - "" => value == &Value::String(subpart.to_string()), /* Exact match if no */ - // operator + "" => value == &Value::String(subpart.to_string()), _ => false, }; } diff --git a/core/src/indexer/last_synced.rs b/core/src/indexer/last_synced.rs index a2d9169c..da5ac8a6 100644 --- a/core/src/indexer/last_synced.rs +++ b/core/src/indexer/last_synced.rs @@ -22,13 +22,9 @@ async fn get_last_synced_block_number_file( network: &str, event_name: &str, ) -> Result, UpdateLastSyncedBlockNumberFile> { - let file_path = build_last_synced_block_number_file( - full_path, - contract_name, - network, - event_name, - ); - + let file_path = + build_last_synced_block_number_file(full_path, contract_name, network, event_name); + let path = Path::new(&file_path); if !path.exists() { @@ -86,8 +82,9 @@ pub async fn get_last_synced_block_number(config: SyncConfig<'_>) -> Option if config.database.is_none() && config.contract_csv_enabled { if let Some(csv_details) = config.csv_details { return if let Ok(result) = get_last_synced_block_number_file( - &get_full_path(config.project_path, &csv_details.path) - .unwrap_or_else(|_| panic!("failed to get full path {}", config.project_path.display())), + &get_full_path(config.project_path, &csv_details.path).unwrap_or_else(|_| { + panic!("failed to get full path {}", config.project_path.display()) + }), config.contract_name, config.network, config.event_name, @@ -114,10 +111,16 @@ pub async fn get_last_synced_block_number(config: SyncConfig<'_>) -> Option let stream_details = config.stream_details.as_ref().unwrap(); // create the path if it does not exist - stream_details.create_full_streams_last_synced_block_path(config.project_path, config.contract_name).await; + stream_details + .create_full_streams_last_synced_block_path(config.project_path, config.contract_name) + .await; return if let Ok(result) = get_last_synced_block_number_file( - &config.project_path.join(stream_details.get_streams_last_synced_block_path()).canonicalize().expect("Failed to canonicalize path"), + &config + .project_path + .join(stream_details.get_streams_last_synced_block_path()) + .canonicalize() + .expect("Failed to canonicalize path"), config.contract_name, config.network, config.event_name, @@ -187,7 +190,7 @@ async fn update_last_synced_block_number_for_file( &config.network_contract.network, &config.event_name, ); - + let last_block = get_last_synced_block_number_file( full_path, &config.contract_name, @@ -244,21 +247,30 @@ pub fn update_progress_and_last_synced(config: Arc, to_bl error!("Error updating last synced block: {:?}", e); } } else if let Some(csv_details) = &config.csv_details { - if let Err(e) = - update_last_synced_block_number_for_file(&config, - &get_full_path(&config.project_path, &csv_details.path) - .unwrap_or_else(|_| panic!("failed to get full path {}", config.project_path.display())), - to_block).await + if let Err(e) = update_last_synced_block_number_for_file( + &config, + &get_full_path(&config.project_path, &csv_details.path).unwrap_or_else(|_| { + panic!("failed to get full path {}", config.project_path.display()) + }), + to_block, + ) + .await { error!( "Error updating last synced block to CSV - path - {} error - {:?}", csv_details.path, e ); } - } else if let Some(stream_last_synced_block_file_path) = &config.stream_last_synced_block_file_path { + } else if let Some(stream_last_synced_block_file_path) = + &config.stream_last_synced_block_file_path + { if let Err(e) = update_last_synced_block_number_for_file( &config, - &config.project_path.join(stream_last_synced_block_file_path).canonicalize().expect("Failed to canonicalize path"), + &config + .project_path + .join(stream_last_synced_block_file_path) + .canonicalize() + .expect("Failed to canonicalize path"), to_block, ) .await diff --git a/core/src/manifest/stream.rs b/core/src/manifest/stream.rs index 5e92a74d..de6e8576 100644 --- a/core/src/manifest/stream.rs +++ b/core/src/manifest/stream.rs @@ -1,4 +1,5 @@ use std::path::Path; + use lapin::ExchangeKind; use serde::{Deserialize, Deserializer, Serialize}; use serde_json::{Map, Value}; @@ -171,8 +172,13 @@ impl StreamsConfig { path.trim_end_matches('_').to_string() } - pub async fn create_full_streams_last_synced_block_path(&self, project_path: &Path, contract_name: &str) { - let path = self.get_streams_last_synced_block_path() + "/" + contract_name + "/last-synced-blocks"; + pub async fn create_full_streams_last_synced_block_path( + &self, + project_path: &Path, + contract_name: &str, + ) { + let path = + self.get_streams_last_synced_block_path() + "/" + contract_name + "/last-synced-blocks"; let full_path = project_path.join(path);