Skip to content
Snippets Groups Projects
Commit a308fff5 authored by qh11's avatar qh11
Browse files

Update worker.rs

parent aaa377e2
Branches main
No related tags found
No related merge requests found
......@@ -3,21 +3,26 @@ use log::{debug, info};
use crate::types::block::Block;
use crate::network::server::Handle as ServerHandle;
use std::thread;
use std::sync::{Arc, Mutex};
use crate::Blockchain;
#[derive(Clone)]
pub struct Worker {
server: ServerHandle,
finished_block_chan: Receiver<Block>,
blockchain:Arc<Mutex<Blockchain>>
}
impl Worker {
pub fn new(
server: &ServerHandle,
finished_block_chan: Receiver<Block>,
blockchain: &Arc<Mutex<Blockchain>>
) -> Self {
Self {
server: server.clone(),
finished_block_chan,
blockchain: Arc::clone(blockchain)
}
}
......@@ -35,6 +40,8 @@ impl Worker {
loop {
let _block = self.finished_block_chan.recv().expect("Receive finished block error");
// TODO for student: insert this finished block to blockchain, and broadcast this block hash
let mut new_blockchain = self.blockchain.lock().unwrap();
new_blockchain.insert(&_block);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment