From 266f475b164d8e3645f5b844d14fe2863e6f9360 Mon Sep 17 00:00:00 2001 From: 223880 Date: Fri, 28 Jun 2024 08:15:47 -0300 Subject: [PATCH] Fix --- src/mining/lib.rs | 57 +++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 32 deletions(-) diff --git a/src/mining/lib.rs b/src/mining/lib.rs index 1994dbd..d15a617 100644 --- a/src/mining/lib.rs +++ b/src/mining/lib.rs @@ -1,44 +1,37 @@ use std::collections::HashMap; -use std::collections::HashMap; use std::sync::Arc; use std::sync::atomic::{AtomicUsize, Ordering}; - pub struct Miner { +pub struct Miner { pub id: usize, - pub struct Miner { - pub hash_power: usize, - pub hash_rate: AtomicUsize, - pub shares: Arc>, - pub difficulty: usize, - pub difficulty: u64, - } + pub hash_power: usize, + pub hash_rate: AtomicUsize, + pub shares: Arc>, + pub difficulty: u64, } - impl Miner { - +impl Miner { pub fn new(id: usize, hash_power: usize) -> Self { - impl Miner { - difficulty: 1, - } + Miner { + id, + hash_power, + hash_rate: AtomicUsize::new(0), + shares: Arc::new(HashMap::new()), + difficulty: 1, + } } -} - - pub fn hash_rate(&self) -> usize { -- self.hash_rate.load(Ordering::SeqCst) - self.hash_rate.load(Ordering::SeqCst) as u64 - } - - pub fn mine(&self, nonce: usize) -> bool { - let mut hash = nonce; - impl Miner { - self.hash_rate.store(hash_rate, Ordering::SeqCst); - true - - } else { - false - false - } + pub fn hash_rate(&self) -> usize { + self.hash_rate.load(Ordering::SeqCst) + } + pub fn mine(&self, nonce: usize) -> bool { + let hash = nonce; // Example: the actual hashing algorithm should replace this + if hash < self.difficulty as usize { + self.hash_rate.store(hash, Ordering::SeqCst); + true + } else { + false } - + } +}