Skip to content

Commit

Permalink
log cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
HardhatChad committed Aug 9, 2024
1 parent dda287c commit 573fd56
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 14 deletions.
12 changes: 6 additions & 6 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use clap::{arg, Parser};
pub struct BalanceArgs {
#[arg(
value_name = "ADDRESS",
help = "The account address to fetch the balance of"
help = "The account address to fetch the balance of."
)]
pub address: Option<String>,
}
Expand Down Expand Up @@ -56,7 +56,7 @@ pub struct MineArgs {
long,
short,
value_name = "CORES_COUNT",
help = "The number of CPU cores to allocate to mining",
help = "The number of CPU cores to allocate to mining.",
default_value = "1"
)]
pub cores: u64,
Expand All @@ -65,15 +65,15 @@ pub struct MineArgs {
long,
short,
value_name = "SECONDS",
help = "The number seconds before the deadline to stop mining and start submitting",
help = "The number seconds before the deadline to stop mining and start submitting.",
default_value = "5"
)]
pub buffer_time: u64,
}

#[derive(Parser, Debug)]
pub struct ProofArgs {
#[arg(value_name = "ADDRESS", help = "The address of the proof to fetch")]
#[arg(value_name = "ADDRESS", help = "The address of the proof to fetch.")]
pub address: Option<String>,
}

Expand Down Expand Up @@ -102,8 +102,8 @@ pub struct TransferArgs {
pub amount: f64,

#[arg(
value_name = "WALLET_ADDRESS",
help = "The wallet address of the receipient."
value_name = "RECIPIENT_ADDRESS",
help = "The account address of the receipient."
)]
pub to: String,
}
Expand Down
19 changes: 14 additions & 5 deletions src/mine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl Miner {
get_updated_proof_with_authority(&self.rpc_client, signer.pubkey(), last_hash_at)
.await;
println!(
"\nStake: {} ORE\n{} Multiplier: {:12}x",
"\n\nStake: {} ORE\n{} Multiplier: {:12}x",
amount_u64_to_string(proof.balance),
if last_hash_at.gt(&0) {
format!(
Expand Down Expand Up @@ -151,7 +151,7 @@ impl Miner {
if timer.elapsed().as_secs().ge(&cutoff_time) {
if i.id == 0 {
progress_bar.set_message(format!(
"Mining... ({} difficulty)",
"Mining... (difficulty {})",
global_best_difficulty,
));
}
Expand All @@ -161,9 +161,12 @@ impl Miner {
}
} else if i.id == 0 {
progress_bar.set_message(format!(
"Mining... ({} difficulty, {} sec remaining)",
"Mining... (difficulty {}, time {})",
global_best_difficulty,
cutoff_time.saturating_sub(timer.elapsed().as_secs()),
format_duration(
cutoff_time.saturating_sub(timer.elapsed().as_secs())
as u32
),
));
}
}
Expand Down Expand Up @@ -195,7 +198,7 @@ impl Miner {

// Update log
progress_bar.finish_with_message(format!(
"Best hash: {} (difficulty: {})",
"Best hash: {} (difficulty {})",
bs58::encode(best_hash.h).into_string(),
best_difficulty
));
Expand Down Expand Up @@ -260,3 +263,9 @@ impl Miner {
fn calculate_multiplier(balance: u64, top_balance: u64) -> f64 {
1.0 + (balance as f64 / top_balance as f64).min(1.0f64)
}

fn format_duration(seconds: u32) -> String {
let minutes = seconds / 60;
let remaining_seconds = seconds % 60;
format!("{:02}:{:02}", minutes, remaining_seconds)
}
8 changes: 8 additions & 0 deletions src/send_and_confirm.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::time::Duration;

use chrono::Local;
use colored::*;
use solana_client::{
client_error::{ClientError, ClientErrorKind, Result as ClientResult},
Expand Down Expand Up @@ -153,6 +154,13 @@ impl Miner {
TransactionConfirmationStatus::Processed => {}
TransactionConfirmationStatus::Confirmed
| TransactionConfirmationStatus::Finalized => {
let now = Local::now();
let formatted_time =
now.format("%Y-%m-%d %H:%M:%S").to_string();
progress_bar.println(format!(
" Timestamp: {}",
formatted_time
));
progress_bar.finish_with_message(format!(
"{} {}",
"OK".bold().green(),
Expand Down
6 changes: 3 additions & 3 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ pub async fn get_proof(client: &RpcClient, address: Pubkey) -> Proof {
let data = client
.get_account_data(&address)
.await
.expect("Failed to get miner account");
*Proof::try_from_bytes(&data).expect("Failed to parse miner account")
.expect("Failed to get proof account");
*Proof::try_from_bytes(&data).expect("Failed to parse proof account")
}

pub async fn get_clock(client: &RpcClient) -> Clock {
let data = client
.get_account_data(&sysvar::clock::ID)
.await
.expect("Failed to get miner account");
.expect("Failed to get clock account");
bincode::deserialize::<Clock>(&data).expect("Failed to deserialize clock")
}

Expand Down

0 comments on commit 573fd56

Please sign in to comment.