Skip to content

Commit d310e78

Browse files
authored
Run cargo clippy fix (#284)
1 parent a23e8ac commit d310e78

File tree

17 files changed

+272
-436
lines changed

17 files changed

+272
-436
lines changed

fplus-database/src/database/allocation_amounts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub async fn create_allocation_amount(
6666
};
6767

6868
let insert_result = new_allocation_amount.insert(&conn).await;
69-
println!("Allocation amount inserted: {:?}", insert_result);
69+
println!("Allocation amount inserted: {insert_result:?}");
7070

7171
Ok(())
7272
}

fplus-database/src/database/allocators.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ pub async fn create_or_update_allocator(
212212
.await
213213
.expect("Failed to get DB connection");
214214
let insert_result = new_allocator.insert(&conn).await?;
215-
println!("Allocator inserted: {:?}", insert_result);
215+
println!("Allocator inserted: {insert_result:?}");
216216
Ok(insert_result)
217217
}
218218
}

fplus-database/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub async fn setup() -> Result<(), DbErr> {
4040
let db_conn = Database::connect(&database_url).await?;
4141
let mut db_conn_global = DB_CONN
4242
.lock()
43-
.map_err(|e| DbErr::Custom(format!("Failed to lock database connection: {}", e)))?;
43+
.map_err(|e| DbErr::Custom(format!("Failed to lock database connection: {e}")))?;
4444
*db_conn_global = Some(db_conn);
4545
Ok(())
4646
}
@@ -54,7 +54,7 @@ pub async fn setup() -> Result<(), DbErr> {
5454
pub async fn get_database_connection() -> Result<DatabaseConnection, DbErr> {
5555
let db_conn = DB_CONN
5656
.lock()
57-
.map_err(|e| DbErr::Custom(format!("Failed to lock database connection: {}", e)))?;
57+
.map_err(|e| DbErr::Custom(format!("Failed to lock database connection: {e}")))?;
5858
if let Some(ref conn) = *db_conn {
5959
Ok(conn.clone())
6060
} else {

fplus-http-server/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ async fn main() -> std::io::Result<()> {
4747
dotenv::dotenv().ok();
4848
env_logger::init();
4949
if let Err(e) = fplus_database::setup().await {
50-
panic!("Failed to setup database connection: {}", e);
50+
panic!("Failed to setup database connection: {e}");
5151
}
5252

5353
tokio::spawn(async {
5454
run_cron("0 0 0,4,8,12,16,20 * * * *", || {
5555
tokio::spawn(async {
5656
if let Err(e) = update_installation_ids_logic().await {
57-
eprintln!("Error: {:?}", e);
57+
eprintln!("Error: {e:?}");
5858
}
5959
})
6060
})

fplus-http-server/src/middleware/verifier_auth.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ where
6060
} = match query {
6161
Ok(q) => q.into_inner(),
6262
Err(e) => {
63-
println!("{}", e);
63+
println!("{e}");
6464
return Box::pin(async {
6565
Err(actix_web::error::ErrorBadRequest(
6666
"Wrong query string format",
@@ -85,7 +85,7 @@ where
8585
let client = Client::new();
8686
let user_info_result = client
8787
.get("https://api.github.com/user")
88-
.header("Authorization", format!("Bearer {}", token))
88+
.header("Authorization", format!("Bearer {token}"))
8989
.header("User-Agent", "Actix-web")
9090
.send()
9191
.await
@@ -130,7 +130,7 @@ where
130130
.map(|s| s.trim().to_lowercase())
131131
.collect();
132132
if verifier_handles.contains(&user_handle.to_lowercase()) {
133-
println!("{} is a verifier.", user_handle);
133+
println!("{user_handle} is a verifier.");
134134
} else {
135135
println!("The user is not a verifier.");
136136
return Err(actix_web::error::ErrorUnauthorized(
@@ -141,7 +141,7 @@ where
141141
}
142142
}
143143
Err(e) => {
144-
println!("Failed to get allocator: {:?}", e);
144+
println!("Failed to get allocator: {e:?}");
145145
}
146146
}
147147

fplus-lib/src/core/allocator/mod.rs

Lines changed: 28 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub async fn process_allocator_file(file_name: &str) -> Result<AllocatorModel, L
3232
let repo = get_env_var_or_default("ALLOCATOR_GOVERNANCE_REPO");
3333
let installation_id = get_env_var_or_default("GITHUB_INSTALLATION_ID")
3434
.parse::<i64>()
35-
.map_err(|e| LDNError::New(format!("Parse installation_id to i64 failed: {}", e)))?;
35+
.map_err(|e| LDNError::New(format!("Parse installation_id to i64 failed: {e}")))?;
3636
let branch = "main";
3737
let path = file_name.to_string();
3838

@@ -108,8 +108,7 @@ pub async fn is_allocator_repo_initialized(gh: &GithubWrapper) -> Result<bool, L
108108
let applications_directory = "applications";
109109
let all_files_result = gh.get_files(applications_directory).await.map_err(|e| {
110110
LDNError::Load(format!(
111-
"Failed to retrieve all files from GitHub. Reason: {}",
112-
e
111+
"Failed to retrieve all files from GitHub. Reason: {e}"
113112
))
114113
});
115114

@@ -151,11 +150,11 @@ pub async fn create_file_in_repo(
151150
)
152151
.send()
153152
.await
154-
.map_err(|e| LDNError::Load(format!("here {}", e)))?;
153+
.map_err(|e| LDNError::Load(format!("here {e}")))?;
155154
let file = file
156155
.text()
157156
.await
158-
.map_err(|e| LDNError::Load(format!("here1 {}", e)))?;
157+
.map_err(|e| LDNError::Load(format!("here1 {e}")))?;
159158

160159
//Get file from target repo. If file does not exist or fails to retrieve, create it
161160
let target_file = match gh.get_file(&file_path, "main").await {
@@ -243,8 +242,7 @@ pub async fn init_allocator_repo(gh: &GithubWrapper) -> Result<(), LDNError> {
243242
.await
244243
.map_err(|e| {
245244
LDNError::Load(format!(
246-
"Failed to retrieve all files from GitHub. Reason: {}",
247-
e
245+
"Failed to retrieve all files from GitHub. Reason: {e}"
248246
))
249247
})?;
250248

@@ -264,19 +262,14 @@ pub async fn init_allocator_repo(gh: &GithubWrapper) -> Result<(), LDNError> {
264262
pub async fn generate_github_app_jwt() -> Result<String, LDNError> {
265263
let app_id = get_env_var_or_default("GITHUB_APP_ID")
266264
.parse::<u64>()
267-
.map_err(|e| {
268-
LDNError::New(format!(
269-
"Parse days to next allocation to i64 failed: {}",
270-
e
271-
))
272-
})?;
265+
.map_err(|e| LDNError::New(format!("Parse days to next allocation to i64 failed: {e}")))?;
273266
let pem = get_env_var_or_default("GH_PRIVATE_KEY");
274267

275268
let key = EncodingKey::from_rsa_pem(pem.to_string().as_bytes())
276-
.map_err(|e| LDNError::Load(format!("Failed to load RSA PEM: {}", e)))?;
269+
.map_err(|e| LDNError::Load(format!("Failed to load RSA PEM: {e}")))?;
277270

278271
let token = create_jwt(octocrab::models::AppId(app_id), &key)
279-
.map_err(|e| LDNError::Load(format!("Failed to create JWT: {}", e)))?;
272+
.map_err(|e| LDNError::Load(format!("Failed to create JWT: {e}")))?;
280273

281274
Ok(token)
282275
}
@@ -285,13 +278,13 @@ pub async fn fetch_installation_ids(client: &Client, jwt: &str) -> Result<Vec<u6
285278
let req_url = "https://api.github.com/app/installations";
286279
let response = client
287280
.get(req_url)
288-
.header(header::AUTHORIZATION, format!("Bearer {}", jwt))
281+
.header(header::AUTHORIZATION, format!("Bearer {jwt}"))
289282
.header(header::ACCEPT, "application/vnd.github+json")
290283
.header("X-GitHub-Api-Version", "2022-11-28")
291284
.header(header::USER_AGENT, "YourApp")
292285
.send()
293286
.await
294-
.map_err(|e| LDNError::Load(format!("Failed to send request: {}", e)))?;
287+
.map_err(|e| LDNError::Load(format!("Failed to send request: {e}")))?;
295288

296289
if !response.status().is_success() {
297290
log::error!("Request failed with status: {}", response.status());
@@ -300,12 +293,12 @@ pub async fn fetch_installation_ids(client: &Client, jwt: &str) -> Result<Vec<u6
300293
let text = response
301294
.text()
302295
.await
303-
.map_err(|e| LDNError::Load(format!("Failed to decode response: {}", e)))?;
296+
.map_err(|e| LDNError::Load(format!("Failed to decode response: {e}")))?;
304297

305298
log::debug!("Response body: {}", text);
306299

307300
let installations: Vec<Installation> = serde_json::from_str(&text)
308-
.map_err(|e| LDNError::Load(format!("Failed to parse response as JSON: {}", e)))?;
301+
.map_err(|e| LDNError::Load(format!("Failed to parse response as JSON: {e}")))?;
309302

310303
Ok(installations.into_iter().map(|i| i.id).collect())
311304
}
@@ -315,13 +308,11 @@ pub async fn fetch_access_token(
315308
jwt: &str,
316309
installation_id: u64,
317310
) -> Result<String> {
318-
let req_url = format!(
319-
"https://api.github.com/app/installations/{}/access_tokens",
320-
installation_id
321-
);
311+
let req_url =
312+
format!("https://api.github.com/app/installations/{installation_id}/access_tokens");
322313
let res: AccessTokenResponse = client
323314
.post(req_url)
324-
.header(header::AUTHORIZATION, format!("Bearer {}", jwt))
315+
.header(header::AUTHORIZATION, format!("Bearer {jwt}"))
325316
.header(header::USER_AGENT, "YourApp")
326317
.send()
327318
.await?
@@ -334,7 +325,7 @@ pub async fn fetch_repositories(client: &Client, token: &str) -> Result<Vec<Repo
334325
let req_url = "https://api.github.com/installation/repositories";
335326
let res: RepositoriesResponse = client
336327
.get(req_url)
337-
.header(header::AUTHORIZATION, format!("Bearer {}", token))
328+
.header(header::AUTHORIZATION, format!("Bearer {token}"))
338329
.header(header::USER_AGENT, "YourApp")
339330
.send()
340331
.await?
@@ -366,7 +357,7 @@ pub async fn update_installation_ids_in_db(
366357
let installation_id: i64 = installation
367358
.installation_id
368359
.try_into()
369-
.map_err(|e| LDNError::Load(format!("Failed to pasre installation id to i64: {}", e)))?;
360+
.map_err(|e| LDNError::Load(format!("Failed to pasre installation id to i64: {e}")))?;
370361
for repo in installation.repositories.iter() {
371362
update_allocator_installation_ids(
372363
repo.owner.clone(),
@@ -390,7 +381,7 @@ pub async fn update_installation_ids_logic() -> Result<(), LDNError> {
390381
let client = Client::new();
391382
let jwt = generate_github_app_jwt()
392383
.await
393-
.map_err(|e| LDNError::Load(format!("Failed to generate GitHub App JWT: {}", e)))?;
384+
.map_err(|e| LDNError::Load(format!("Failed to generate GitHub App JWT: {e}")))?;
394385

395386
let installation_ids_result = fetch_installation_ids(&client, &jwt).await;
396387
let mut results: Vec<InstallationRepositories> = Vec::new();
@@ -401,8 +392,7 @@ pub async fn update_installation_ids_logic() -> Result<(), LDNError> {
401392
.await
402393
.map_err(|e| {
403394
LDNError::Load(format!(
404-
"Failed to fetch repositories for installation id: {}",
405-
e
395+
"Failed to fetch repositories for installation id: {e}"
406396
))
407397
})?;
408398
results.push(InstallationRepositories {
@@ -486,7 +476,7 @@ pub async fn force_update_allocators(
486476
Some(file),
487477
)
488478
.await
489-
.map_err(|e| LDNError::Load(format!("Failed to get files: {}", e)))?;
479+
.map_err(|e| LDNError::Load(format!("Failed to get files: {e}")))?;
490480
create_file_in_repo(&gh, &content.items[0], true).await?;
491481
}
492482
}
@@ -508,7 +498,7 @@ pub fn validate_amount_type_and_options(
508498
pub fn validate_fixed_amount_options(amount_options: &[String]) -> Result<(), String> {
509499
for option in amount_options {
510500
if !is_valid_fixed_option(option) {
511-
return Err(format!("Invalid fixed amount option: {}", option));
501+
return Err(format!("Invalid fixed amount option: {option}"));
512502
}
513503
}
514504
Ok(())
@@ -518,7 +508,7 @@ pub fn validate_percentage_amount_options(amount_options: &[String]) -> Result<(
518508
for option in amount_options {
519509
let no_percentage_option = option.replace('%', "");
520510
if no_percentage_option.parse::<i32>().is_err() {
521-
return Err(format!("Invalid percentage amount option: {}", option));
511+
return Err(format!("Invalid percentage amount option: {option}"));
522512
}
523513
}
524514
Ok(())
@@ -601,8 +591,7 @@ pub async fn create_allocator_from_file(files_changed: Vec<String>) -> Result<()
601591
})
602592
.map_err(|e| {
603593
LDNError::New(format!(
604-
"Installation Id not found for a repo: {} /// {}",
605-
repo, e
594+
"Installation Id not found for a repo: {repo} /// {e}"
606595
))
607596
})?;
608597

@@ -611,12 +600,11 @@ pub async fn create_allocator_from_file(files_changed: Vec<String>) -> Result<()
611600
match is_allocator_repo_initialized(&gh).await {
612601
Ok(true) => (),
613602
Ok(false) => init_allocator_repo(&gh).await.map_err(|e| {
614-
LDNError::New(format!("Initializing the allocator repo failed: {}", e))
603+
LDNError::New(format!("Initializing the allocator repo failed: {e}"))
615604
})?,
616605
Err(e) => {
617606
return Err(LDNError::New(format!(
618-
"Checking if the repo is initialized failed: {}",
619-
e
607+
"Checking if the repo is initialized failed: {e}"
620608
)));
621609
}
622610
}
@@ -642,7 +630,7 @@ pub async fn create_allocator_from_file(files_changed: Vec<String>) -> Result<()
642630
model.ma_address,
643631
)
644632
.await
645-
.map_err(|e| LDNError::New(format!("Create or update allocator failed: {}", e)))?;
633+
.map_err(|e| LDNError::New(format!("Create or update allocator failed: {e}")))?;
646634

647635
let allocator_id = allocator_creation_result.id;
648636

@@ -651,8 +639,7 @@ pub async fn create_allocator_from_file(files_changed: Vec<String>) -> Result<()
651639
.await
652640
.map_err(|e| {
653641
LDNError::New(format!(
654-
"Delete all old allocation amounts by allocator id failed: {}",
655-
e
642+
"Delete all old allocation amounts by allocator id failed: {e}"
656643
))
657644
})?;
658645

@@ -664,8 +651,7 @@ pub async fn create_allocator_from_file(files_changed: Vec<String>) -> Result<()
664651
.await
665652
.map_err(|e| {
666653
LDNError::New(format!(
667-
"Create allocation amount rows in the database failed: {}",
668-
e
654+
"Create allocation amount rows in the database failed: {e}"
669655
))
670656
})?;
671657
}

fplus-lib/src/core/application/file.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl FromStr for DatacapGroup {
2222
"da" => Ok(Self::DA),
2323
"ldn-v3" => Ok(Self::LDN),
2424
"e-fil" => Ok(Self::EFIL),
25-
_ => Err(format!("{} is not a valid datacap group", s)),
25+
_ => Err(format!("{s} is not a valid datacap group")),
2626
}
2727
}
2828
}
@@ -158,7 +158,7 @@ impl FromStr for DataType {
158158
"Public, Open Commercial/Enterprise" => Ok(Self::PublicOpenCommercialEnterprise),
159159
"Private Commercial/Enterprise" => Ok(Self::PrivateCommercialEnterprise),
160160
"Private Non-Profit / Social impact" => Ok(Self::PrivateNonProfitSocialImpact),
161-
_ => Err(format!("{} is not a valid data type", s)),
161+
_ => Err(format!("{s} is not a valid data type")),
162162
}
163163
}
164164
}

fplus-lib/src/core/application/gitcoin_interaction.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ pub async fn verify_on_gitcoin(address_from_signature: &Address) -> Result<f64,
7474

7575
if score <= minimum_score {
7676
return Err(LDNError::New(format!(
77-
"For address: {}, Gitcoin passport score is too low ({}). Minimum value is: {}",
78-
address_from_signature, score, minimum_score
77+
"For address: {address_from_signature}, Gitcoin passport score is too low ({score}). Minimum value is: {minimum_score}"
7978
)));
8079
}
8180
Ok(score)
@@ -103,7 +102,7 @@ async fn get_gitcoin_score_for_address(rpc_url: &str, address: Address) -> Resul
103102

104103
fn calculate_score(response: Bytes) -> Result<f64, LDNError> {
105104
let score = U256::from_str(&response.to_string())
106-
.map_err(|e| LDNError::Load(format!("Failed to parse response to U256: {}", e)))?
105+
.map_err(|e| LDNError::Load(format!("Failed to parse response to U256: {e}")))?
107106
.to::<u128>();
108107
Ok(score as f64 / 10000.0)
109108
}

0 commit comments

Comments
 (0)