use serde::Serialize;
use std::fmt;
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct IcIcrcAnalyticsRequest {
pub source_endpoint: String,
pub now_unix_secs: u64,
pub ledger_canister_id: String,
}
impl IcIcrcAnalyticsRequest {
#[must_use]
pub fn new(
source_endpoint: impl Into<String>,
now_unix_secs: u64,
ledger_canister_id: impl Into<String>,
) -> Self {
Self {
source_endpoint: source_endpoint.into(),
now_unix_secs,
ledger_canister_id: ledger_canister_id.into(),
}
}
}
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize)]
#[serde(rename_all = "snake_case")]
pub enum IcIcrcIndexedCountKind {
Account,
Holder,
Transaction,
}
impl IcIcrcIndexedCountKind {
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::Account => "account",
Self::Holder => "holder",
Self::Transaction => "transaction",
}
}
#[cfg(feature = "host")]
pub(crate) const fn resource_path_segment(self) -> &'static str {
match self {
Self::Account => "accounts",
Self::Holder => "holders",
Self::Transaction => "transactions",
}
}
}
impl fmt::Display for IcIcrcIndexedCountKind {
fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> fmt::Result {
formatter.write_str(self.as_str())
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct IcIcrcIndexedCountRequest {
pub analytics: IcIcrcAnalyticsRequest,
pub kind: IcIcrcIndexedCountKind,
}
impl IcIcrcIndexedCountRequest {
#[must_use]
pub fn new(
source_endpoint: impl Into<String>,
now_unix_secs: u64,
ledger_canister_id: impl Into<String>,
kind: IcIcrcIndexedCountKind,
) -> Self {
Self {
analytics: IcIcrcAnalyticsRequest::new(
source_endpoint,
now_unix_secs,
ledger_canister_id,
),
kind,
}
}
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct IcIcrcTokenValueQuery {
pub start_unix_secs: u64,
pub end_unix_secs: u64,
pub limit: u16,
}
impl IcIcrcTokenValueQuery {
#[must_use]
pub const fn new(start_unix_secs: u64, end_unix_secs: u64, limit: u16) -> Self {
Self {
start_unix_secs,
end_unix_secs,
limit,
}
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct IcIcrcTokenValueRequest {
pub analytics: IcIcrcAnalyticsRequest,
pub query: IcIcrcTokenValueQuery,
}
impl IcIcrcTokenValueRequest {
#[must_use]
pub fn new(
source_endpoint: impl Into<String>,
now_unix_secs: u64,
ledger_canister_id: impl Into<String>,
query: IcIcrcTokenValueQuery,
) -> Self {
Self {
analytics: IcIcrcAnalyticsRequest::new(
source_endpoint,
now_unix_secs,
ledger_canister_id,
),
query,
}
}
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct IcIcrcTotalSupplyQuery {
pub start_unix_secs: u64,
pub end_unix_secs: u64,
pub step_secs: u32,
}
impl IcIcrcTotalSupplyQuery {
#[must_use]
pub const fn new(start_unix_secs: u64, end_unix_secs: u64, step_secs: u32) -> Self {
Self {
start_unix_secs,
end_unix_secs,
step_secs,
}
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct IcIcrcTotalSupplyRequest {
pub analytics: IcIcrcAnalyticsRequest,
pub query: IcIcrcTotalSupplyQuery,
}
impl IcIcrcTotalSupplyRequest {
#[must_use]
pub fn new(
source_endpoint: impl Into<String>,
now_unix_secs: u64,
ledger_canister_id: impl Into<String>,
query: IcIcrcTotalSupplyQuery,
) -> Self {
Self {
analytics: IcIcrcAnalyticsRequest::new(
source_endpoint,
now_unix_secs,
ledger_canister_id,
),
query,
}
}
}