Added reading the data

Still need to do writing obviously
This commit is contained in:
2024-07-13 19:51:15 +01:00
parent 9620fdb116
commit c9a2fe6c71

View File

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