saito_core/core/consensus/
context.rs1use std::io::Error;
2use std::sync::Arc;
3
4use tokio::sync::RwLock;
5
6use crate::core::consensus::blockchain::Blockchain;
7use crate::core::consensus::mempool::Mempool;
8use crate::core::consensus::wallet::Wallet;
9use crate::core::defs::{BlockId, Currency};
10use crate::core::process::run_task::RunTask;
11use crate::core::util::configuration::Configuration;
12
13#[derive(Clone)]
14pub struct Context {
15 pub blockchain_lock: Arc<RwLock<Blockchain>>,
16 pub mempool_lock: Arc<RwLock<Mempool>>,
17 pub wallet_lock: Arc<RwLock<Wallet>>,
18 pub config_lock: Arc<RwLock<dyn Configuration + Send + Sync>>,
19}
20
21impl Context {
22 pub fn new(
23 config_lock: Arc<RwLock<dyn Configuration + Send + Sync>>,
24 wallet_lock: Arc<RwLock<Wallet>>,
25 genesis_period: BlockId,
26 social_stake: Currency,
27 social_stake_period: BlockId,
28 ) -> Context {
29 Context {
30 blockchain_lock: Arc::new(RwLock::new(Blockchain::new(
31 wallet_lock.clone(),
32 genesis_period,
33 social_stake,
34 social_stake_period,
35 ))),
36 mempool_lock: Arc::new(RwLock::new(Mempool::new(wallet_lock.clone()))),
37 wallet_lock,
38 config_lock,
39 }
40 }
41 pub async fn init(&self, _task_runner: &dyn RunTask) -> Result<(), Error> {
42 Ok(())
43 }
44}