diff --git a/src/lib.rs b/src/lib.rs index 3eab8e4..6e15aeb 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,7 @@ use chrono::prelude::*; use lazy_static::lazy_static; use std::convert::Into; +use std::sync::RwLock; // TODO review whether a genesis block has a block height of 1 or 0 @@ -21,35 +22,35 @@ pub struct BlockchainInfo { } lazy_static! { - static ref BSV_BI: BlockchainInfo = BlockchainInfo { + static ref BSV_BI: RwLock = RwLock::new(BlockchainInfo { block_period: 10 * 60, // 10 minutes, latest_block_height: 852792, latest_block_time: Utc.with_ymd_and_hms(2024, 7, 11, 19, 53, 7).unwrap(), - }; - static ref BTC_BI: BlockchainInfo = BlockchainInfo { + }); + static ref BTC_BI: RwLock = RwLock::new(BlockchainInfo { block_period: 10 * 60, // 10 minutes, latest_block_height: 851724, latest_block_time: Utc.with_ymd_and_hms(2024, 7, 11, 19, 38, 6).unwrap(), - }; - static ref XMR_BI: BlockchainInfo = BlockchainInfo { + }); + static ref XMR_BI: RwLock = RwLock::new(BlockchainInfo { block_period: 2 * 60, // 2 minutes, latest_block_height: 3190705, latest_block_time: Utc.with_ymd_and_hms(2024, 7, 11, 19, 54, 11).unwrap(), - }; - static ref ETH_BI: BlockchainInfo = BlockchainInfo { + }); + static ref ETH_BI: RwLock = RwLock::new(BlockchainInfo { block_period: 12, latest_block_height: 20285486, latest_block_time: Utc.with_ymd_and_hms(2024, 7, 11, 19, 53, 59).unwrap(), - }; + }); } impl From for BlockchainInfo { fn from(val: BlockchainSupported) -> Self { match val { - BlockchainSupported::BTC => *BTC_BI, - BlockchainSupported::BSV => *BSV_BI, - BlockchainSupported::XMR => *XMR_BI, - BlockchainSupported::ETH => *ETH_BI, + BlockchainSupported::BTC => *BTC_BI.read().unwrap(), + BlockchainSupported::BSV => *BSV_BI.read().unwrap(), + BlockchainSupported::XMR => *XMR_BI.read().unwrap(), + BlockchainSupported::ETH => *ETH_BI.read().unwrap(), } } }