Added hash of last block to Ping/Pong messages.

This commit is contained in:
Revertron
2021-03-02 19:35:12 +01:00
parent 92ebefce91
commit 59df68d7c7
6 changed files with 35 additions and 24 deletions
+9 -3
View File
@@ -9,7 +9,7 @@ use std::cell::RefCell;
use chrono::Utc;
use crate::blockchain::transaction::hash_identity;
use crate::blockchain::blockchain::BlockQuality::*;
use crate::blockchain::BLOCK_DIFFICULTY;
use crate::blockchain::{BLOCK_DIFFICULTY, CHAIN_VERSION};
const DB_NAME: &str = "blockchain.db";
@@ -26,10 +26,9 @@ pub struct Blockchain {
impl Blockchain {
pub fn new(settings: &Settings) -> Self {
let origin = settings.get_origin();
let version = settings.version;
let db = sqlite::open(DB_NAME).expect("Unable to open blockchain DB");
let mut blockchain = Blockchain{ origin, version, blocks: Vec::new(), last_block: None, max_height: 0, db, zones: RefCell::new(HashSet::new()) };
let mut blockchain = Blockchain{ origin, version: CHAIN_VERSION, blocks: Vec::new(), last_block: None, max_height: 0, db, zones: RefCell::new(HashSet::new()) };
blockchain.init_db();
blockchain
}
@@ -231,6 +230,13 @@ impl Blockchain {
}
}
pub fn last_hash(&self) -> Bytes {
match &self.last_block {
None => { Bytes::default() }
Some(block) => { block.hash.clone() }
}
}
pub fn max_height(&self) -> u64 {
self.max_height
}