Skip to content

Commit 5c1d8eb

Browse files
committed
small cleanup
1 parent 6024c91 commit 5c1d8eb

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

src/mine.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::{
2424

2525
impl Miner {
2626
pub async fn mine(&self, args: MineArgs) {
27-
// Register, if needed.
27+
// Open account, if needed.
2828
let signer = self.signer();
2929
self.open().await;
3030

@@ -42,27 +42,31 @@ impl Miner {
4242
calculate_multiplier(proof.balance, config.top_balance)
4343
);
4444

45-
// Calc cutoff time
45+
// Calculate cutoff time
4646
let cutoff_time = self.get_cutoff(proof, args.buffer_time).await;
4747

4848
// Run drillx
4949
let solution =
5050
Self::find_hash_par(proof, cutoff_time, args.cores, config.min_difficulty as u32)
5151
.await;
5252

53-
// Submit most difficult hash
54-
let mut compute_budget = 500_000;
53+
// Build instruction set
5554
let mut ixs = vec![ore_api::instruction::auth(proof_pubkey(signer.pubkey()))];
55+
let mut compute_budget = 500_000;
5656
if self.should_reset(config).await && rand::thread_rng().gen_range(0..100).eq(&0) {
5757
compute_budget += 100_000;
5858
ixs.push(ore_api::instruction::reset(signer.pubkey()));
5959
}
60+
61+
// Build mine ix
6062
ixs.push(ore_api::instruction::mine(
6163
signer.pubkey(),
6264
signer.pubkey(),
6365
self.find_bus().await,
6466
solution,
6567
));
68+
69+
// Submit transaction
6670
self.send_and_confirm(&ixs, ComputeBudget::Fixed(compute_budget), false)
6771
.await
6872
.ok();

src/send_and_confirm.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,7 @@ impl Miner {
4747
let fee_payer = self.fee_payer();
4848

4949
// Return error, if balance is zero
50-
if let Ok(balance) = client.get_balance(&fee_payer.pubkey()).await {
51-
if balance <= sol_to_lamports(MIN_SOL_BALANCE) {
52-
panic!(
53-
"{} Insufficient balance: {} SOL\nPlease top up with at least {} SOL",
54-
"ERROR".bold().red(),
55-
lamports_to_sol(balance),
56-
MIN_SOL_BALANCE
57-
);
58-
}
59-
}
50+
self.check_balance().await;
6051

6152
// Set compute budget
6253
let mut final_ixs = vec![];
@@ -196,6 +187,24 @@ impl Miner {
196187
}
197188
}
198189

190+
pub async fn check_balance(&self) {
191+
// Throw error if balance is less than min
192+
if let Ok(balance) = self
193+
.rpc_client
194+
.get_balance(&self.fee_payer().pubkey())
195+
.await
196+
{
197+
if balance <= sol_to_lamports(MIN_SOL_BALANCE) {
198+
panic!(
199+
"{} Insufficient balance: {} SOL\nPlease top up with at least {} SOL",
200+
"ERROR".bold().red(),
201+
lamports_to_sol(balance),
202+
MIN_SOL_BALANCE
203+
);
204+
}
205+
}
206+
}
207+
199208
// TODO
200209
fn _simulate(&self) {
201210

0 commit comments

Comments
 (0)