-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
223880
committed
Jun 28, 2024
1 parent
c08ba8c
commit 266f475
Showing
1 changed file
with
25 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
} | ||
} |