Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
223880 committed Jun 28, 2024
1 parent c08ba8c commit 266f475
Showing 1 changed file with 25 additions and 32 deletions.
57 changes: 25 additions & 32 deletions src/mining/lib.rs
Original file line number Diff line number Diff line change
@@ -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<HashMap<usize, usize>>,
pub difficulty: usize,
pub difficulty: u64,
}
pub hash_power: usize,
pub hash_rate: AtomicUsize,
pub shares: Arc<HashMap<usize, usize>>,
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
}

}
}

0 comments on commit 266f475

Please sign in to comment.