From 5c1d8ebf1be762d3c38a89abcab9aef96b9714dd Mon Sep 17 00:00:00 2001 From: Hardhat Chad Date: Thu, 8 Aug 2024 16:48:04 +0000 Subject: [PATCH] small cleanup --- src/mine.rs | 12 ++++++++---- src/send_and_confirm.rs | 29 +++++++++++++++++++---------- 2 files changed, 27 insertions(+), 14 deletions(-) diff --git a/src/mine.rs b/src/mine.rs index 0efc7ff2..60df59fa 100644 --- a/src/mine.rs +++ b/src/mine.rs @@ -24,7 +24,7 @@ use crate::{ impl Miner { pub async fn mine(&self, args: MineArgs) { - // Register, if needed. + // Open account, if needed. let signer = self.signer(); self.open().await; @@ -42,7 +42,7 @@ impl Miner { calculate_multiplier(proof.balance, config.top_balance) ); - // Calc cutoff time + // Calculate cutoff time let cutoff_time = self.get_cutoff(proof, args.buffer_time).await; // Run drillx @@ -50,19 +50,23 @@ impl Miner { Self::find_hash_par(proof, cutoff_time, args.cores, config.min_difficulty as u32) .await; - // Submit most difficult hash - let mut compute_budget = 500_000; + // Build instruction set let mut ixs = vec![ore_api::instruction::auth(proof_pubkey(signer.pubkey()))]; + let mut compute_budget = 500_000; if self.should_reset(config).await && rand::thread_rng().gen_range(0..100).eq(&0) { compute_budget += 100_000; ixs.push(ore_api::instruction::reset(signer.pubkey())); } + + // Build mine ix ixs.push(ore_api::instruction::mine( signer.pubkey(), signer.pubkey(), self.find_bus().await, solution, )); + + // Submit transaction self.send_and_confirm(&ixs, ComputeBudget::Fixed(compute_budget), false) .await .ok(); diff --git a/src/send_and_confirm.rs b/src/send_and_confirm.rs index 66b24902..41132793 100644 --- a/src/send_and_confirm.rs +++ b/src/send_and_confirm.rs @@ -47,16 +47,7 @@ impl Miner { let fee_payer = self.fee_payer(); // Return error, if balance is zero - if let Ok(balance) = client.get_balance(&fee_payer.pubkey()).await { - if balance <= sol_to_lamports(MIN_SOL_BALANCE) { - panic!( - "{} Insufficient balance: {} SOL\nPlease top up with at least {} SOL", - "ERROR".bold().red(), - lamports_to_sol(balance), - MIN_SOL_BALANCE - ); - } - } + self.check_balance().await; // Set compute budget let mut final_ixs = vec![]; @@ -196,6 +187,24 @@ impl Miner { } } + pub async fn check_balance(&self) { + // Throw error if balance is less than min + if let Ok(balance) = self + .rpc_client + .get_balance(&self.fee_payer().pubkey()) + .await + { + if balance <= sol_to_lamports(MIN_SOL_BALANCE) { + panic!( + "{} Insufficient balance: {} SOL\nPlease top up with at least {} SOL", + "ERROR".bold().red(), + lamports_to_sol(balance), + MIN_SOL_BALANCE + ); + } + } + } + // TODO fn _simulate(&self) {