Skip to content

Commit

Permalink
Fix almost all Clippy warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Filippo Costa <[email protected]>
  • Loading branch information
neysofu committed Dec 16, 2024
1 parent d9588cb commit ac75e82
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 36 deletions.
2 changes: 1 addition & 1 deletion crates/graphix_lib/src/bisect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
24 changes: 9 additions & 15 deletions crates/graphix_lib/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -80,13 +78,12 @@ impl Default for Config {
}

impl Config {
pub fn read(path: &Path) -> anyhow::Result<Self> {
let file_contents = std::fs::read_to_string(path)?;
Self::from_str(&file_contents)
}
#[cfg(test)]
pub fn read(path: impl AsRef<std::path::Path>) -> anyhow::Result<Self> {
use anyhow::Context;

pub fn from_str(s: &str) -> anyhow::Result<Self> {
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<IndexerConfig> {
Expand Down Expand Up @@ -152,10 +149,7 @@ impl IndexerId for IndexerConfig {
}

fn name(&self) -> Option<Cow<str>> {
match &self.name {
Some(name) => Some(Cow::Borrowed(name)),
None => None,
}
self.name.as_ref().map(|s| Cow::Borrowed(s.as_str()))
}
}

Expand Down Expand Up @@ -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();
}
}
8 changes: 4 additions & 4 deletions crates/graphix_lib/src/graphql_api/api_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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<Network, String> {
Expand Down Expand Up @@ -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.
Expand All @@ -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<SubgraphDeployment, String> {
Expand Down
6 changes: 3 additions & 3 deletions crates/graphix_lib/src/graphql_api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<serde_json::Value>) {
Expand All @@ -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());
};

Expand Down
2 changes: 1 addition & 1 deletion crates/graphix_lib/src/graphql_api/mutations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl MutationRoot {
.await?;

let report = DivergenceInvestigationReport {
uuid: uuid.clone(),
uuid,
status: DivergenceInvestigationStatus::Pending,
bisection_runs: vec![],
error: None,
Expand Down
5 changes: 1 addition & 4 deletions crates/indexer_client/src/real_indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,7 @@ impl IndexerClient for RealIndexer {
}

fn name(&self) -> Option<Cow<str>> {
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<Self>) -> anyhow::Result<()> {
Expand Down
1 change: 0 additions & 1 deletion crates/store/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ impl async_graphql::dataloader::Loader<IntId> for StoreLoader<models::Network> {
.await
.map_err(|e| e.to_string())?
.into_iter()
.map(|(id, network)| (id, network))
.collect())
}
}
Expand Down
7 changes: 2 additions & 5 deletions crates/store/src/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,7 @@ impl IndexerId for Indexer {
}

fn name(&self) -> Option<Cow<str>> {
match &self.name {
Some(name) => Some(Cow::Borrowed(name)),
None => None,
}
self.name.as_ref().map(|s| Cow::Borrowed(s.as_str()))
}
}

Expand Down Expand Up @@ -310,7 +307,7 @@ pub struct DivergingBlock {
impl From<types::DivergingBlock> 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(),
Expand Down
4 changes: 2 additions & 2 deletions crates/store/src/store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl Store {
}

pub async fn conn_err_string(&self) -> Result<Object<AsyncPgConnection>, String> {
Ok(self.pool.get().await.map_err(|e| e.to_string())?)
self.pool.get().await.map_err(|e| e.to_string())
}
}

Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit ac75e82

Please sign in to comment.