Skip to content

Commit f67a635

Browse files
committed
fix some clippy warnings
1 parent 9f7c65b commit f67a635

17 files changed

+292
-215
lines changed

src/command/account.rs

+38-15
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,23 @@ use std::str::FromStr;
22

33
use colored::Colorize;
44
use ore_api::state::proof_pda;
5-
use solana_program::{pubkey::Pubkey, native_token::lamports_to_sol};
5+
use solana_program::{native_token::lamports_to_sol, pubkey::Pubkey};
66
use solana_sdk::signature::Signer;
77
use spl_token::amount_to_ui_amount;
8-
use tabled::{Table, settings::{Style, Remove, object::{Rows, Columns}, Alignment}};
8+
use tabled::{
9+
settings::{
10+
object::{Columns, Rows},
11+
Alignment, Remove, Style,
12+
},
13+
Table,
14+
};
915

1016
use crate::{
1117
args::{AccountArgs, AccountCloseArgs, AccountCommand, ClaimArgs},
12-
utils::{amount_u64_to_f64, ask_confirm, format_timestamp, get_proof, get_proof_with_authority, ComputeBudget, TableData, TableSectionTitle},
18+
utils::{
19+
amount_u64_to_f64, ask_confirm, format_timestamp, get_proof, get_proof_with_authority,
20+
ComputeBudget, TableData, TableSectionTitle,
21+
},
1322
Miner,
1423
};
1524

@@ -28,7 +37,7 @@ impl Miner {
2837
// Parse account address
2938
let signer = self.signer();
3039
let address = if let Some(address) = &args.address {
31-
if let Ok(address) = Pubkey::from_str(&address) {
40+
if let Ok(address) = Pubkey::from_str(address) {
3241
address
3342
} else {
3443
println!("Invalid address: {:?}", address);
@@ -40,7 +49,7 @@ impl Miner {
4049
signer.pubkey()
4150
};
4251

43-
// Aggregate data
52+
// Aggregate data
4453
let mut data = vec![];
4554
self.get_account_data(address, &mut data).await;
4655
self.get_proof_data(address, &mut data).await;
@@ -52,14 +61,14 @@ impl Miner {
5261
table.with(Style::blank());
5362
table.section_title(0, "Account");
5463
table.section_title(3, "Proof");
55-
64+
5665
println!("{table}\n");
5766
}
5867

5968
async fn get_proof_account(&self, args: AccountArgs) {
6069
// Parse account address
6170
let proof_address = if let Some(address) = &args.proof {
62-
if let Ok(address) = Pubkey::from_str(&address) {
71+
if let Ok(address) = Pubkey::from_str(address) {
6372
address
6473
} else {
6574
println!("Invalid address: {:?}", address);
@@ -69,8 +78,10 @@ impl Miner {
6978
return;
7079
};
7180

72-
// Aggregate data
73-
let proof = get_proof(&self.rpc_client, proof_address).await.expect("Failed to fetch proof account");
81+
// Aggregate data
82+
let proof = get_proof(&self.rpc_client, proof_address)
83+
.await
84+
.expect("Failed to fetch proof account");
7485
let mut data = vec![];
7586
self.get_account_data(proof.authority, &mut data).await;
7687
self.get_proof_data(proof.authority, &mut data).await;
@@ -82,7 +93,7 @@ impl Miner {
8293
table.with(Style::blank());
8394
table.section_title(0, "Account");
8495
table.section_title(3, "Proof");
85-
96+
8697
println!("{table}\n");
8798
}
8899

@@ -103,7 +114,11 @@ impl Miner {
103114
};
104115

105116
// Get SOL balance
106-
let sol_balance = self.rpc_client.get_balance(&authority).await.expect("Failed to fetch SOL balance");
117+
let sol_balance = self
118+
.rpc_client
119+
.get_balance(&authority)
120+
.await
121+
.expect("Failed to fetch SOL balance");
107122

108123
// Aggregate data
109124
data.push(TableData {
@@ -138,10 +153,13 @@ impl Miner {
138153
data.push(TableData {
139154
key: "Balance".to_string(),
140155
value: if proof.balance > 0 {
141-
format!("{} ORE", amount_u64_to_f64(proof.balance)).bold().yellow().to_string()
156+
format!("{} ORE", amount_u64_to_f64(proof.balance))
157+
.bold()
158+
.yellow()
159+
.to_string()
142160
} else {
143161
format!("{} ORE", amount_u64_to_f64(proof.balance))
144-
}
162+
},
145163
});
146164
data.push(TableData {
147165
key: "Last hash".to_string(),
@@ -157,7 +175,10 @@ impl Miner {
157175
});
158176
data.push(TableData {
159177
key: "Lifetime rewards".to_string(),
160-
value: format!("{} ORE", amount_to_ui_amount(proof.total_rewards, ore_api::consts::TOKEN_DECIMALS)),
178+
value: format!(
179+
"{} ORE",
180+
amount_to_ui_amount(proof.total_rewards, ore_api::consts::TOKEN_DECIMALS)
181+
),
161182
});
162183
data.push(TableData {
163184
key: "Miner".to_string(),
@@ -174,7 +195,9 @@ impl Miner {
174195
async fn close(&self, _args: AccountCloseArgs) {
175196
// Confirm proof exists
176197
let signer = self.signer();
177-
let proof = get_proof_with_authority(&self.rpc_client, signer.pubkey()).await.expect("Failed to fetch proof account");
198+
let proof = get_proof_with_authority(&self.rpc_client, signer.pubkey())
199+
.await
200+
.expect("Failed to fetch proof account");
178201

179202
// Confirm the user wants to close.
180203
if !ask_confirm(

src/command/benchmark.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ impl Miner {
2727
std::thread::spawn({
2828
move || {
2929
let timer = Instant::now();
30-
let first_nonce = u64::MAX
31-
.saturating_div(cores)
32-
.saturating_mul(i.id as u64);
30+
let first_nonce =
31+
u64::MAX.saturating_div(cores).saturating_mul(i.id as u64);
3332
let mut nonce = first_nonce;
3433
let mut memory = equix::SolverMemory::new();
3534
loop {

src/command/claim.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ impl Miner {
3535
pub async fn claim_from_proof(&self, args: ClaimArgs) {
3636
let signer = self.signer();
3737
let pubkey = signer.pubkey();
38-
let proof = get_proof_with_authority(&self.rpc_client, pubkey).await.expect("Failed to fetch proof account");
38+
let proof = get_proof_with_authority(&self.rpc_client, pubkey)
39+
.await
40+
.expect("Failed to fetch proof account");
3941
let mut ixs = vec![];
4042
let beneficiary = match args.to {
4143
None => self.initialize_ata(pubkey).await,

src/command/initialize.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use ore_api::consts::TREASURY_ADDRESS;
22
use solana_sdk::signature::Signer;
33

4-
use crate::{Miner, utils::ComputeBudget};
4+
use crate::{utils::ComputeBudget, Miner};
55

66
impl Miner {
77
pub async fn initialize(&self) {
@@ -12,6 +12,9 @@ impl Miner {
1212

1313
// Submit initialize tx
1414
let ix = ore_api::sdk::initialize(self.signer().pubkey());
15-
let _ = self.send_and_confirm(&[ix], ComputeBudget::Fixed(500_000), false).await.unwrap();
15+
let _ = self
16+
.send_and_confirm(&[ix], ComputeBudget::Fixed(500_000), false)
17+
.await
18+
.unwrap();
1619
}
1720
}

src/command/mine.rs

+18-22
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use std::{
33
sync::{Arc, RwLock},
44
thread::sleep,
55
time::{Duration, Instant},
6-
usize,
76
};
87

98
use b64::FromBase64;
@@ -144,11 +143,8 @@ impl Miner {
144143
} else {
145144
Some(boost_config.current)
146145
};
147-
let boost_keys = if let Some(boost_address) = boost_address {
148-
Some([boost_address, boost_config_address])
149-
} else {
150-
None
151-
};
146+
let boost_keys =
147+
boost_address.map(|boost_address| [boost_address, boost_config_address]);
152148
let mine_ix = ore_api::sdk::mine(
153149
signer.pubkey(),
154150
signer.pubkey(),
@@ -455,13 +451,12 @@ impl Miner {
455451
if let Ok(accounts) = self.rpc_client.get_multiple_accounts(&BUS_ADDRESSES).await {
456452
let mut top_bus_balance: u64 = 0;
457453
let mut top_bus = BUS_ADDRESSES[0];
458-
for account in accounts {
459-
if let Some(account) = account {
460-
if let Ok(bus) = Bus::try_from_bytes(&account.data) {
461-
if bus.rewards.gt(&top_bus_balance) {
462-
top_bus_balance = bus.rewards;
463-
top_bus = BUS_ADDRESSES[bus.id as usize];
464-
}
454+
for account in accounts.into_iter().flatten() {
455+
// Applied `.flatten()`
456+
if let Ok(bus) = Bus::try_from_bytes(&account.data) {
457+
if bus.rewards.gt(&top_bus_balance) {
458+
top_bus_balance = bus.rewards;
459+
top_bus = BUS_ADDRESSES[bus.id as usize];
465460
}
466461
}
467462
}
@@ -476,12 +471,13 @@ impl Miner {
476471
async fn fetch_solo_mine_event(&self, sig: Signature, verbose: bool) {
477472
// Add loading row
478473
let mining_data = SoloMiningData::fetching(sig);
479-
let mut data = self.solo_mining_data.write().unwrap();
480-
data.insert(0, mining_data);
481-
if data.len() >= 12 {
482-
data.pop();
483-
}
484-
drop(data);
474+
{
475+
let mut data = self.solo_mining_data.write().unwrap();
476+
data.insert(0, mining_data);
477+
if data.len() >= 12 {
478+
data.pop();
479+
}
480+
} // MutexGuard is dropped here
485481

486482
// Update table
487483
self.update_solo_mining_table(verbose);
@@ -522,7 +518,7 @@ impl Miner {
522518
signature: if verbose {
523519
sig.to_string()
524520
} else {
525-
format!("{}...", sig.to_string()[..8].to_string())
521+
format!("{}...", &sig.to_string()[..8])
526522
},
527523
block: tx.slot.to_string(),
528524
timestamp: format_timestamp(tx.block_time.unwrap_or_default()),
@@ -567,7 +563,7 @@ impl Miner {
567563
signature: if verbose {
568564
event.signature.to_string()
569565
} else {
570-
format!("{}...", event.signature.to_string()[..8].to_string())
566+
format!("{}...", &event.signature.to_string()[..8])
571567
},
572568
block: event.block.to_string(),
573569
timestamp: format_timestamp(event.timestamp as i64),
@@ -668,7 +664,7 @@ impl Miner {
668664
}
669665

670666
// Submit transaction
671-
if ixs.len() > 0 {
667+
if !ixs.is_empty() {
672668
self.send_and_confirm(&ixs, ComputeBudget::Fixed(400_000), false)
673669
.await
674670
.ok();

0 commit comments

Comments
 (0)