diff --git a/gear-programs/historical-proxy/app/src/lib.rs b/gear-programs/historical-proxy/app/src/lib.rs index f44a677b..2c56b17e 100644 --- a/gear-programs/historical-proxy/app/src/lib.rs +++ b/gear-programs/historical-proxy/app/src/lib.rs @@ -18,7 +18,6 @@ pub struct HistoricalProxyProgram(RefCell); #[sails_rs::program] impl HistoricalProxyProgram { - // Program's constructor #[allow(clippy::new_without_default)] pub fn new() -> Self { let exec_context = GStdExecContext::new(); @@ -28,7 +27,6 @@ impl HistoricalProxyProgram { })) } - // Exposed service pub fn historical_proxy(&self) -> service::HistoricalProxyService { service::HistoricalProxyService::new(&self.0, GStdExecContext::new()) } diff --git a/gear-programs/historical-proxy/app/src/state.rs b/gear-programs/historical-proxy/app/src/state.rs index 7deb1d28..d4cbf6cf 100644 --- a/gear-programs/historical-proxy/app/src/state.rs +++ b/gear-programs/historical-proxy/app/src/state.rs @@ -1,25 +1,30 @@ use super::error::ProxyError; use super::{ActorId, Vec}; + pub type Slot = u64; +/// State of the Historical Proxy service. pub struct ProxyState { pub admin: ActorId, pub endpoints: EndpointList, } +/// Mapping between endpoints and Ethereum slots they're active from. +/// +/// ### Invariant +/// +/// Endpoints are stored in ascending order, sorted by slot number. +#[derive(Default)] pub struct EndpointList(Vec<(Slot, ActorId)>); -impl Default for EndpointList { - fn default() -> Self { - Self::new() - } -} - impl EndpointList { pub fn new() -> Self { Self(Vec::with_capacity(2)) } + /// Add new endpoint that will be active starting from `slot`(inclusive). + /// + /// Panics if provided `slot` <= greatest already existing slot. pub fn push(&mut self, slot: Slot, actor_id: ActorId) { assert!( self.0.is_empty() || self.0[self.0.len() - 1].0 < slot, @@ -28,10 +33,14 @@ impl EndpointList { self.0.push((slot, actor_id)); } + /// Get list of currently active endpoints. Returns `Vec<(Slot, ActorId)>` + /// where `ActorId` means endpoint address and `Slot` means Ethereum slot + /// this endpoint is active from(inclusive). pub fn endpoints(&self) -> Vec<(Slot, ActorId)> { self.0.clone() } + /// Get endpoint for the specified slot. Will return error if endpoint is not found. pub fn endpoint_for(&self, slot: Slot) -> Result { match self.0.binary_search_by(|(s, _)| s.cmp(&slot)) { Ok(i) => Ok(self.0[i].1),