kabu_core_blockchain/
app_state.rs1use alloy::primitives::ChainId;
2use kabu_types_blockchain::ChainParameters;
3use kabu_types_blockchain::Mempool;
4use kabu_types_entities::AccountNonceAndBalanceState;
5use kabu_types_market::Market;
6use reth_ethereum_primitives::EthPrimitives;
7use reth_node_types::NodePrimitives;
8use std::sync::Arc;
9use tokio::sync::RwLock;
10
11#[derive(Clone)]
12pub struct AppState<N: NodePrimitives = EthPrimitives> {
13 pub chain_id: ChainId,
14 pub chain_parameters: ChainParameters,
15 pub market: Arc<RwLock<Market>>,
16 pub mempool: Arc<RwLock<Mempool<N>>>,
17 pub account_nonce_and_balance: Arc<RwLock<AccountNonceAndBalanceState>>,
18}
19
20impl<N: NodePrimitives> AppState<N> {
21 pub fn new(chain_id: ChainId) -> Self {
22 let chain_parameters = ChainParameters::ethereum();
23
24 Self {
25 chain_id,
26 chain_parameters,
27 market: Arc::new(RwLock::new(Market::default())),
28 mempool: Arc::new(RwLock::new(Default::default())),
29 account_nonce_and_balance: Arc::new(RwLock::new(AccountNonceAndBalanceState::new())),
30 }
31 }
32
33 pub fn with_chain_parameters(mut self, chain_parameters: ChainParameters) -> Self {
34 self.chain_parameters = chain_parameters;
35 self
36 }
37}