//! A Bitcoin CPU miner written in rust to show how the mining process actually works at the low level. This should demonstrate that mining is actually quite a simple process as the mine function is only 20 lines of code with comments.
usebitcoin::{
blockdata::constants::genesis_block,
consensus::encode::serialize,
hashes::{sha256d::HashasH256,Hash},
network::constants::Network,
};
usestd::{
borrow::BorrowMut,
io::Write,
sync::{
atomic::{AtomicBool,AtomicU32,Ordering},
mpsc,Arc,
},
thread,
time::SystemTime,
};
// process in smaller intervals to allow threads to stop and send status updates
constINTERVAL:u32=0xffffffff/1500|0;
/// Mine the genesis block
pubfnmain(){
letgenesis_block=genesis_block(Network::Bitcoin);
// the raw header we'll be hashing
letblock_header=serialize(&genesis_block.header);
// channel to send status updates
let(tx,rx)=mpsc::channel();
// the hash of the block header must be below the target