#[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, 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>>,
}
#[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(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 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,
},
}