diff --git a/crates/graphix_lib/src/bisect.rs b/crates/graphix_lib/src/bisect.rs index 9217358..36ee416 100644 --- a/crates/graphix_lib/src/bisect.rs +++ b/crates/graphix_lib/src/bisect.rs @@ -380,7 +380,7 @@ async fn handle_divergence_investigation_request( ctx: &GraphixState, ) -> DivergenceInvestigationReport { let mut report = DivergenceInvestigationReport { - uuid: req_uuid.clone(), + uuid: *req_uuid, status: DivergenceInvestigationStatus::Complete, bisection_runs: vec![], error: None, diff --git a/crates/graphix_lib/src/config.rs b/crates/graphix_lib/src/config.rs index 6490f33..6b3fdc8 100644 --- a/crates/graphix_lib/src/config.rs +++ b/crates/graphix_lib/src/config.rs @@ -2,10 +2,8 @@ use std::borrow::Cow; use std::collections::HashMap; -use std::path::Path; use std::sync::Arc; -use anyhow::Context; use graphix_common_types::IndexerAddress; use graphix_indexer_client::{IndexerClient, IndexerId, IndexerInterceptor, RealIndexer}; use graphix_network_sg_client::NetworkSubgraphClient; @@ -80,13 +78,12 @@ impl Default for Config { } impl Config { - pub fn read(path: &Path) -> anyhow::Result { - let file_contents = std::fs::read_to_string(path)?; - Self::from_str(&file_contents) - } + #[cfg(test)] + pub fn read(path: impl AsRef) -> anyhow::Result { + use anyhow::Context; - pub fn from_str(s: &str) -> anyhow::Result { - serde_yaml::from_str(s).context("invalid config file") + let file_contents = std::fs::read_to_string(path)?; + serde_yaml::from_str(&file_contents).context("invalid config file") } pub fn indexers(&self) -> Vec { @@ -152,10 +149,7 @@ impl IndexerId for IndexerConfig { } fn name(&self) -> Option> { - match &self.name { - Some(name) => Some(Cow::Borrowed(name)), - None => None, - } + self.name.as_ref().map(|s| Cow::Borrowed(s.as_str())) } } @@ -299,8 +293,8 @@ mod tests { #[test] fn parse_example_configs() { - Config::from_str(include_str!("../../../configs/testnet.graphix.yml")).unwrap(); - Config::from_str(include_str!("../../../configs/network.graphix.yml")).unwrap(); - Config::from_str(include_str!("../../../configs/readonly.graphix.yml")).unwrap(); + Config::read("../../configs/testnet.graphix.yml").unwrap(); + Config::read("../../configs/network.graphix.yml").unwrap(); + Config::read("../../configs/readonly.graphix.yml").unwrap(); } } diff --git a/crates/graphix_lib/src/graphql_api/api_types.rs b/crates/graphix_lib/src/graphql_api/api_types.rs index 0948449..a5137d1 100644 --- a/crates/graphix_lib/src/graphql_api/api_types.rs +++ b/crates/graphix_lib/src/graphql_api/api_types.rs @@ -69,7 +69,7 @@ impl ApiKey { #[graphql(name = "permissionLevel")] async fn graphql_permission_level(&self) -> ApiKeyPermissionLevel { - self.model.permission_level.clone() + self.model.permission_level } #[graphql(name = "notes")] @@ -246,7 +246,7 @@ impl Block { } pub fn hash(&self) -> common::BlockHash { - self.model.hash.clone().into() + self.model.hash.clone() } pub async fn network(&self, ctx: &GraphixState) -> Result { @@ -306,7 +306,7 @@ impl Block { /// The block hash, expressed as a hex string with a '0x' prefix. #[graphql(name = "hash")] async fn graphql_hash(&self) -> common::BlockHash { - self.model.hash.clone().into() + self.model.hash.clone() } /// The network that this block belongs to. @@ -325,7 +325,7 @@ pub struct ProofOfIndexing { impl ProofOfIndexing { pub fn hash(&self) -> common::PoiBytes { - self.model.poi.clone().into() + self.model.poi } pub async fn deployment(&self, ctx: &GraphixState) -> Result { diff --git a/crates/graphix_lib/src/graphql_api/mod.rs b/crates/graphix_lib/src/graphql_api/mod.rs index f0155d2..5a6b016 100644 --- a/crates/graphix_lib/src/graphql_api/mod.rs +++ b/crates/graphix_lib/src/graphql_api/mod.rs @@ -134,10 +134,10 @@ async fn graphql_handler( .finish(); let mut service = GraphQL::new(api_schema); - Ok(service + service .call(request) .await - .map_err(|_| api_key_error("Internal server error"))?) + .map_err(|_| api_key_error("Internal server error")) } fn api_key_error(err: impl ToString) -> (StatusCode, Json) { @@ -164,7 +164,7 @@ async fn require_permission_level( .as_ref() .ok_or_else(|| anyhow::anyhow!("No API key provided"))?; - let Some(actual_permission_level) = ctx_data.store.permission_level(&api_key).await? else { + let Some(actual_permission_level) = ctx_data.store.permission_level(api_key).await? else { return Err(anyhow::anyhow!("No permission level for API key").into()); }; diff --git a/crates/graphix_lib/src/graphql_api/mutations.rs b/crates/graphix_lib/src/graphql_api/mutations.rs index 034b28b..58120a1 100644 --- a/crates/graphix_lib/src/graphql_api/mutations.rs +++ b/crates/graphix_lib/src/graphql_api/mutations.rs @@ -50,7 +50,7 @@ impl MutationRoot { .await?; let report = DivergenceInvestigationReport { - uuid: uuid.clone(), + uuid, status: DivergenceInvestigationStatus::Pending, bisection_runs: vec![], error: None, diff --git a/crates/indexer_client/src/real_indexer.rs b/crates/indexer_client/src/real_indexer.rs index 7e21671..8fa4709 100644 --- a/crates/indexer_client/src/real_indexer.rs +++ b/crates/indexer_client/src/real_indexer.rs @@ -111,10 +111,7 @@ impl IndexerClient for RealIndexer { } fn name(&self) -> Option> { - match &self.name { - Some(name) => Some(Cow::Borrowed(name.as_str())), - None => None, - } + self.name.as_ref().map(|s| Cow::Borrowed(s.as_str())) } async fn ping(self: Arc) -> anyhow::Result<()> { diff --git a/crates/store/src/loader.rs b/crates/store/src/loader.rs index b62b9f2..fb8178a 100644 --- a/crates/store/src/loader.rs +++ b/crates/store/src/loader.rs @@ -100,7 +100,6 @@ impl async_graphql::dataloader::Loader for StoreLoader { .await .map_err(|e| e.to_string())? .into_iter() - .map(|(id, network)| (id, network)) .collect()) } } diff --git a/crates/store/src/models.rs b/crates/store/src/models.rs index 382d7cf..eb20978 100644 --- a/crates/store/src/models.rs +++ b/crates/store/src/models.rs @@ -122,10 +122,7 @@ impl IndexerId for Indexer { } fn name(&self) -> Option> { - match &self.name { - Some(name) => Some(Cow::Borrowed(name)), - None => None, - } + self.name.as_ref().map(|s| Cow::Borrowed(s.as_str())) } } @@ -310,7 +307,7 @@ pub struct DivergingBlock { impl From for DivergingBlock { fn from(block: types::DivergingBlock) -> Self { Self { - block_number: block.block.number as i64, + block_number: block.block.number, block_hash: block.block.hash.map(|hash| hash.to_string()), proof_of_indexing1: block.proof_of_indexing1.to_string(), proof_of_indexing2: block.proof_of_indexing2.to_string(), diff --git a/crates/store/src/store/mod.rs b/crates/store/src/store/mod.rs index 64ff066..62634cb 100644 --- a/crates/store/src/store/mod.rs +++ b/crates/store/src/store/mod.rs @@ -76,7 +76,7 @@ impl Store { } pub async fn conn_err_string(&self) -> Result, String> { - Ok(self.pool.get().await.map_err(|e| e.to_string())?) + self.pool.get().await.map_err(|e| e.to_string()) } } @@ -334,7 +334,7 @@ impl Store { .create_api_key(None, ApiKeyPermissionLevel::Admin) .await?; - let description = format!("Master API key created during database initialization. Use it to create a new private API key and then delete it for security reasons. `{}`", api_key.api_key.to_string()); + let description = format!("Master API key created during database initialization. Use it to create a new private API key and then delete it for security reasons. `{}`", api_key.api_key); self.modify_api_key( &api_key.api_key, Some(&description),