tofuri_blockchain_sync/
lib.rs1use lazy_static::lazy_static;
2use serde::Deserialize;
3use serde::Serialize;
4use tofuri_core::*;
5lazy_static! {
6 static ref BPS: f32 = 0.5_f32 + (1_f32 / 2_f32.powf(BLOCK_TIME as f32));
7}
8#[derive(Default, Debug, Clone, Serialize, Deserialize)]
9pub struct Sync {
10 pub bps: f32,
11 pub new: f32,
12 pub completed: bool,
13}
14impl Sync {
15 pub fn handler(&mut self) {
16 self.bps += self.new;
17 self.bps /= 2.0;
18 self.new = 0.0;
19 self.completed = !self.downloading();
20 }
21 pub fn downloading(&self) -> bool {
22 self.bps > *BPS
23 }
24}