Made a full refactoring of synchronization primitives between settings, keystore, blockchain and miner.

This commit is contained in:
Revertron
2020-04-18 21:31:40 +02:00
parent 3eaf63ba79
commit 01f37cc238
13 changed files with 775 additions and 211 deletions
+6 -3
View File
@@ -10,9 +10,6 @@ pub struct Blockchain {
impl Blockchain {
pub fn new(chain_id: u32, version: u32) -> Self {
let mut blockchain = Blockchain{chain_id, version, blocks: Vec::new()};
let mut genesis = Self::genesis(chain_id, version);
genesis.mine();
blockchain.add_block(genesis);
blockchain
}
@@ -26,6 +23,12 @@ impl Blockchain {
Block::new(0, Utc::now().timestamp(), chain_id, version, Key::zero32(), None)
}
pub fn make_genesis(&mut self) {
let mut genesis = Self::genesis(self.chain_id, self.version);
genesis.mine();
self.add_block(genesis);
}
pub fn add_block(&mut self, block: Block) {
if self.check_block(&block, None) {
println!("Adding block:\n{:?}", &block);