iuna

iuna - experimental devnet protocol
git clone https://iuna.jhx.app/git/iuna.git
Log | Files | Refs | README | LICENSE

state.rs (2251B)


      1 use std::{collections::BTreeMap, net::SocketAddr, path::PathBuf, sync::Arc};
      2 
      3 use tokio::sync::Mutex;
      4 
      5 use crate::{
      6     adapters::{
      7         chain_store::SqliteChainStore, config_store::UiConfig, p2p::GossipNetwork,
      8         ui_data_store::SqliteUiDataStore,
      9     },
     10     app::{SharedNode, SharedPeerBook, StratumStatus},
     11     domain::{BurnLeaderRank, OutPoint, RevealedBlindedTransaction, TxOutput},
     12 };
     13 
     14 #[derive(Clone)]
     15 pub(super) struct HttpState {
     16     pub(super) node: SharedNode,
     17     pub(super) peers: SharedPeerBook,
     18     pub(super) gossip: GossipNetwork,
     19     pub(super) ui_config: Arc<Mutex<UiConfig>>,
     20     pub(super) config_path: PathBuf,
     21     pub(super) chain_store: SqliteChainStore,
     22     pub(super) ui_data_store: SqliteUiDataStore,
     23     pub(super) wallet_path: PathBuf,
     24     pub(super) stratum: StratumStatus,
     25     pub(super) auth_sessions: Arc<Mutex<BTreeMap<String, AuthSession>>>,
     26     pub(super) auth_backoff: Arc<Mutex<BTreeMap<String, AuthBackoff>>>,
     27     pub(super) ui_cache: Arc<Mutex<UiChainCache>>,
     28     pub(super) ui_data_refresh: Arc<Mutex<()>>,
     29 }
     30 
     31 #[derive(Clone)]
     32 pub(super) struct AuthSession {
     33     pub(super) expires_at: u64,
     34     pub(super) wallet_password: String,
     35 }
     36 
     37 #[derive(Clone, Debug)]
     38 pub(super) struct AuthClientKey(pub(super) String);
     39 
     40 #[derive(Clone, Debug, Default)]
     41 pub(super) struct AuthBackoff {
     42     pub(super) failed_attempts: u32,
     43     pub(super) locked_until_ms: Option<u64>,
     44 }
     45 
     46 #[derive(Clone, Debug, Default)]
     47 pub(super) struct UiChainCache {
     48     pub(super) tip_hash: Option<String>,
     49     pub(super) outputs: BTreeMap<OutPoint, TxOutput>,
     50     pub(super) revealed_by_height: BTreeMap<u64, Vec<RevealedBlindedTransaction>>,
     51     pub(super) burn_leader_ranks_by_hash: BTreeMap<String, Vec<BurnLeaderRank>>,
     52 }
     53 
     54 #[derive(Clone, Debug, Default)]
     55 pub(super) struct UiChainView {
     56     pub(super) outputs: BTreeMap<OutPoint, TxOutput>,
     57     pub(super) revealed_by_height: BTreeMap<u64, Vec<RevealedBlindedTransaction>>,
     58     pub(super) burn_leader_ranks_by_hash: BTreeMap<String, Vec<BurnLeaderRank>>,
     59 }
     60 
     61 pub struct ServeOptions {
     62     pub config_path: PathBuf,
     63     pub chain_store: SqliteChainStore,
     64     pub ui_data_store: SqliteUiDataStore,
     65     pub wallet_path: PathBuf,
     66     pub stratum: StratumStatus,
     67     pub addr: SocketAddr,
     68 }