#[cfg(feature = "host")]
use crate::runtime::RuntimeError;
use serde::Serialize;
#[cfg(feature = "host")]
use thiserror::Error as ThisError;
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct IcCanisterRequest {
pub source_endpoint: String,
pub now_unix_secs: u64,
pub canister_id: String,
}
impl IcCanisterRequest {
#[must_use]
pub fn new(
source_endpoint: impl Into<String>,
now_unix_secs: u64,
canister_id: impl Into<String>,
) -> Self {
Self {
source_endpoint: source_endpoint.into(),
now_unix_secs,
canister_id: canister_id.into(),
}
}
}
#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize)]
pub struct IcCanisterFilters {
pub has_name: Option<bool>,
pub subnet_id: Option<String>,
pub controller_id: Option<String>,
pub languages: Vec<String>,
pub canister_types: Vec<String>,
pub query: Option<String>,
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct IcCanisterCountRequest {
pub source_endpoint: String,
pub now_unix_secs: u64,
pub filters: IcCanisterFilters,
}
impl IcCanisterCountRequest {
#[must_use]
pub fn new(source_endpoint: impl Into<String>, now_unix_secs: u64) -> Self {
Self {
source_endpoint: source_endpoint.into(),
now_unix_secs,
filters: IcCanisterFilters::default(),
}
}
#[must_use]
pub fn with_filters(mut self, filters: IcCanisterFilters) -> Self {
self.filters = filters;
self
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct IcCanisterPageRequest {
pub source_endpoint: String,
pub now_unix_secs: u64,
pub filters: IcCanisterFilters,
pub limit: u16,
pub after: Option<String>,
pub before: Option<String>,
}
impl IcCanisterPageRequest {
#[must_use]
pub fn new(source_endpoint: impl Into<String>, now_unix_secs: u64) -> Self {
Self {
source_endpoint: source_endpoint.into(),
now_unix_secs,
filters: IcCanisterFilters::default(),
limit: super::DEFAULT_IC_CANISTER_PAGE_LIMIT,
after: None,
before: None,
}
}
#[must_use]
pub fn with_filters(mut self, filters: IcCanisterFilters) -> Self {
self.filters = filters;
self
}
#[must_use]
pub const fn with_limit(mut self, limit: u16) -> Self {
self.limit = limit;
self
}
#[must_use]
pub fn with_after(mut self, after: impl Into<String>) -> Self {
self.after = Some(after.into());
self
}
#[must_use]
pub fn with_before(mut self, before: impl Into<String>) -> Self {
self.before = Some(before.into());
self
}
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct IcCanisterUpgrade {
pub executed_timestamp_seconds: u64,
pub module_hash: String,
pub proposal_id: u64,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct IcCanisterReport {
pub schema_version: u32,
pub network: String,
pub authority: String,
pub source_endpoint: String,
pub fetched_at: String,
pub fetched_by: String,
pub certified: bool,
pub point_in_time_guaranteed: bool,
pub canister_id: String,
pub dashboard_id: u64,
pub canister_type: Option<String>,
pub name: String,
pub subnet_id: String,
pub controllers: Vec<String>,
pub language: String,
pub module_hash: String,
pub dashboard_updated_at: String,
pub upgrade_count: Option<usize>,
pub upgrades: Option<Vec<IcCanisterUpgrade>>,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct IcCanisterCountReport {
pub schema_version: u32,
pub network: String,
pub authority: String,
pub source_endpoint: String,
pub fetched_at: String,
pub fetched_by: String,
pub certified: bool,
pub point_in_time_guaranteed: bool,
pub filters: IcCanisterFilters,
pub total: u64,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct IcCanisterPageController {
pub principal_id: String,
pub raw_metadata: Option<String>,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct IcCanisterPageRow {
pub canister_id: String,
pub dashboard_id: u64,
pub canister_type: Option<String>,
pub name: String,
pub subnet_id: String,
pub controllers: Vec<IcCanisterPageController>,
pub language: String,
pub module_hash: String,
pub dashboard_updated_at: String,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct IcCanisterPageReport {
pub schema_version: u32,
pub network: String,
pub authority: String,
pub source_endpoint: String,
pub fetched_at: String,
pub fetched_by: String,
pub certified: bool,
pub point_in_time_guaranteed: bool,
pub filters: IcCanisterFilters,
pub requested_limit: u16,
pub returned_count: usize,
pub after: Option<String>,
pub before: Option<String>,
pub previous_cursor: Option<String>,
pub next_cursor: Option<String>,
pub rows: Vec<IcCanisterPageRow>,
}
#[cfg(feature = "host")]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct IcSourceRequest {
pub endpoint: String,
pub fetched_at: String,
pub fetched_by: String,
}
#[cfg(feature = "host")]
impl IcSourceRequest {
#[must_use]
pub fn new(
endpoint: impl Into<String>,
fetched_at: impl Into<String>,
fetched_by: impl Into<String>,
) -> Self {
Self {
endpoint: endpoint.into(),
fetched_at: fetched_at.into(),
fetched_by: fetched_by.into(),
}
}
}
#[cfg(feature = "host")]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct IcCanisterSourceData {
pub source_endpoint: String,
pub fetched_at: String,
pub fetched_by: String,
pub canister_id: String,
pub dashboard_id: u64,
pub canister_type: Option<String>,
pub name: String,
pub subnet_id: String,
pub controllers: Vec<String>,
pub language: String,
pub module_hash: String,
pub dashboard_updated_at: String,
pub upgrades: Option<Vec<IcCanisterUpgrade>>,
}
#[cfg(feature = "host")]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct IcCanisterCountSourceData {
pub source_endpoint: String,
pub fetched_at: String,
pub fetched_by: String,
pub filters: IcCanisterFilters,
pub total: u64,
}
#[cfg(feature = "host")]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct IcCanisterPageSourceData {
pub source_endpoint: String,
pub fetched_at: String,
pub fetched_by: String,
pub filters: IcCanisterFilters,
pub requested_limit: u16,
pub after: Option<String>,
pub before: Option<String>,
pub previous_cursor: Option<String>,
pub next_cursor: Option<String>,
pub rows: Vec<IcCanisterPageRow>,
}
#[cfg(feature = "host")]
#[derive(Debug, ThisError)]
pub enum IcHostError {
#[error("failed to run IC Dashboard query: {0}")]
Runtime(#[from] RuntimeError),
#[error("invalid {field}: {reason}")]
InvalidPrincipal {
field: &'static str,
reason: String,
},
#[error("invalid {field}: {reason}")]
InvalidRequest {
field: &'static str,
reason: String,
},
#[error("invalid IC Dashboard endpoint {endpoint}: {reason}")]
InvalidEndpoint {
endpoint: String,
reason: String,
},
#[error("failed to build IC Dashboard HTTP client: {reason}")]
HttpClientBuild {
reason: String,
},
#[error("IC Dashboard request to {url} failed: {reason}")]
HttpRequest {
url: String,
reason: String,
},
#[error("IC Dashboard request to {url} returned HTTP status {status}")]
HttpStatus {
url: String,
status: u16,
},
#[error("failed to decode IC Dashboard response from {url}: {reason}")]
JsonDecode {
url: String,
reason: String,
},
#[error("invalid IC Dashboard canister source data: {reason}")]
InvalidSourceData {
reason: String,
},
}