use serde::{Deserialize as SerdeDeserialize, Serialize};
use serde_json::Value as JsonValue;
use std::path::PathBuf;
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct IcrcLedgerRequest {
pub source_endpoint: String,
pub now_unix_secs: u64,
pub ledger_canister_id: String,
}
impl IcrcLedgerRequest {
#[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, Debug, Eq, PartialEq)]
pub struct IcrcBalanceRequest {
pub source_endpoint: String,
pub now_unix_secs: u64,
pub ledger_canister_id: String,
pub account_owner: String,
pub subaccount_hex: Option<String>,
}
impl IcrcBalanceRequest {
#[must_use]
pub fn new(
source_endpoint: impl Into<String>,
now_unix_secs: u64,
ledger_canister_id: impl Into<String>,
account_owner: impl Into<String>,
) -> Self {
Self {
source_endpoint: source_endpoint.into(),
now_unix_secs,
ledger_canister_id: ledger_canister_id.into(),
account_owner: account_owner.into(),
subaccount_hex: None,
}
}
#[must_use]
pub fn with_subaccount_hex(mut self, subaccount_hex: impl Into<String>) -> Self {
self.subaccount_hex = Some(subaccount_hex.into());
self
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct IcrcAllowanceRequest {
pub source_endpoint: String,
pub now_unix_secs: u64,
pub ledger_canister_id: String,
pub account_owner: String,
pub account_subaccount_hex: Option<String>,
pub spender_owner: String,
pub spender_subaccount_hex: Option<String>,
}
impl IcrcAllowanceRequest {
#[must_use]
pub fn new(
source_endpoint: impl Into<String>,
now_unix_secs: u64,
ledger_canister_id: impl Into<String>,
account_owner: impl Into<String>,
spender_owner: impl Into<String>,
) -> Self {
Self {
source_endpoint: source_endpoint.into(),
now_unix_secs,
ledger_canister_id: ledger_canister_id.into(),
account_owner: account_owner.into(),
account_subaccount_hex: None,
spender_owner: spender_owner.into(),
spender_subaccount_hex: None,
}
}
#[must_use]
pub fn with_account_subaccount_hex(
mut self,
account_subaccount_hex: impl Into<String>,
) -> Self {
self.account_subaccount_hex = Some(account_subaccount_hex.into());
self
}
#[must_use]
pub fn with_spender_subaccount_hex(
mut self,
spender_subaccount_hex: impl Into<String>,
) -> Self {
self.spender_subaccount_hex = Some(spender_subaccount_hex.into());
self
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct IcrcAccountTransactionPageRequest {
pub source_endpoint: String,
pub now_unix_secs: u64,
pub ledger_canister_id: String,
pub index_canister_id: Option<String>,
pub account_owner: String,
pub subaccount_hex: Option<String>,
pub start: Option<String>,
pub limit: u32,
}
impl IcrcAccountTransactionPageRequest {
#[must_use]
pub fn new(
source_endpoint: impl Into<String>,
now_unix_secs: u64,
ledger_canister_id: impl Into<String>,
account_owner: impl Into<String>,
limit: u32,
) -> Self {
Self {
source_endpoint: source_endpoint.into(),
now_unix_secs,
ledger_canister_id: ledger_canister_id.into(),
index_canister_id: None,
account_owner: account_owner.into(),
subaccount_hex: None,
start: None,
limit,
}
}
#[must_use]
pub fn with_index_canister_id(mut self, index_canister_id: impl Into<String>) -> Self {
self.index_canister_id = Some(index_canister_id.into());
self
}
#[must_use]
pub fn with_subaccount_hex(mut self, subaccount_hex: impl Into<String>) -> Self {
self.subaccount_hex = Some(subaccount_hex.into());
self
}
#[must_use]
pub fn with_start(mut self, start: impl Into<String>) -> Self {
self.start = Some(start.into());
self
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct IcrcAccountTransactionCacheRequest {
pub cache_root: PathBuf,
pub source_endpoint: String,
pub ledger_canister_id: String,
pub account_owner: String,
pub subaccount_hex: Option<String>,
}
impl IcrcAccountTransactionCacheRequest {
#[must_use]
pub fn new(
cache_root: impl Into<PathBuf>,
source_endpoint: impl Into<String>,
ledger_canister_id: impl Into<String>,
account_owner: impl Into<String>,
) -> Self {
Self {
cache_root: cache_root.into(),
source_endpoint: source_endpoint.into(),
ledger_canister_id: ledger_canister_id.into(),
account_owner: account_owner.into(),
subaccount_hex: None,
}
}
#[must_use]
pub fn with_subaccount_hex(mut self, subaccount_hex: impl Into<String>) -> Self {
self.subaccount_hex = Some(subaccount_hex.into());
self
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct IcrcAccountTransactionRefreshRequest {
pub cache: IcrcAccountTransactionCacheRequest,
pub now_unix_secs: u64,
pub index_canister_id: Option<String>,
pub page_size: u32,
pub max_pages: Option<u32>,
pub lock_stale_after_seconds: u64,
}
impl IcrcAccountTransactionRefreshRequest {
#[must_use]
pub const fn new(
cache: IcrcAccountTransactionCacheRequest,
now_unix_secs: u64,
page_size: u32,
lock_stale_after_seconds: u64,
) -> Self {
Self {
cache,
now_unix_secs,
index_canister_id: None,
page_size,
max_pages: None,
lock_stale_after_seconds,
}
}
#[must_use]
pub fn with_index_canister_id(mut self, index_canister_id: impl Into<String>) -> Self {
self.index_canister_id = Some(index_canister_id.into());
self
}
#[must_use]
pub const fn with_max_pages(mut self, max_pages: Option<u32>) -> Self {
self.max_pages = max_pages;
self
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum IcrcAccountTransactionSort {
Newest,
Oldest,
}
impl IcrcAccountTransactionSort {
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
Self::Newest => "newest",
Self::Oldest => "oldest",
}
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct IcrcAccountTransactionListRequest {
pub cache: IcrcAccountTransactionCacheRequest,
pub limit: u32,
pub sort: IcrcAccountTransactionSort,
}
impl IcrcAccountTransactionListRequest {
#[must_use]
pub const fn new(cache: IcrcAccountTransactionCacheRequest, limit: u32) -> Self {
Self {
cache,
limit,
sort: IcrcAccountTransactionSort::Newest,
}
}
#[must_use]
pub const fn with_sort(mut self, sort: IcrcAccountTransactionSort) -> Self {
self.sort = sort;
self
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct IcrcTransactionsRequest {
pub source_endpoint: String,
pub now_unix_secs: u64,
pub ledger_canister_id: String,
pub start: u64,
pub limit: u32,
pub follow_archives: bool,
}
impl IcrcTransactionsRequest {
#[must_use]
pub fn new(
source_endpoint: impl Into<String>,
now_unix_secs: u64,
ledger_canister_id: impl Into<String>,
start: u64,
limit: u32,
) -> Self {
Self {
source_endpoint: source_endpoint.into(),
now_unix_secs,
ledger_canister_id: ledger_canister_id.into(),
start,
limit,
follow_archives: false,
}
}
#[must_use]
pub const fn with_follow_archives(mut self, follow_archives: bool) -> Self {
self.follow_archives = follow_archives;
self
}
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct IcrcArchivesRequest {
pub source_endpoint: String,
pub now_unix_secs: u64,
pub ledger_canister_id: String,
pub from_canister_id: Option<String>,
}
impl IcrcArchivesRequest {
#[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(),
from_canister_id: None,
}
}
#[must_use]
pub fn with_from_canister_id(mut self, from_canister_id: impl Into<String>) -> Self {
self.from_canister_id = Some(from_canister_id.into());
self
}
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct IcrcTokenReport {
pub schema_version: u32,
pub ledger_canister_id: String,
pub fetched_at: String,
pub source_endpoint: String,
pub fetched_by: String,
pub token_name: String,
pub token_symbol: String,
pub decimals: u8,
pub transfer_fee: String,
pub total_supply: String,
pub minting_account_owner: Option<String>,
pub minting_account_subaccount_hex: Option<String>,
pub supported_standards: Vec<IcrcTokenStandardRow>,
pub metadata: Vec<IcrcTokenMetadataRow>,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct IcrcBalanceReport {
pub schema_version: u32,
pub ledger_canister_id: String,
pub account_owner: String,
pub subaccount_hex: Option<String>,
pub fetched_at: String,
pub source_endpoint: String,
pub fetched_by: String,
pub token_symbol: String,
pub decimals: u8,
pub balance: String,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct IcrcAllowanceReport {
pub schema_version: u32,
pub ledger_canister_id: String,
pub account_owner: String,
pub account_subaccount_hex: Option<String>,
pub spender_owner: String,
pub spender_subaccount_hex: Option<String>,
pub fetched_at: String,
pub source_endpoint: String,
pub fetched_by: String,
pub token_symbol: String,
pub decimals: u8,
pub allowance: String,
pub expires_at_unix_nanos: Option<String>,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct IcrcAccountTransactionPageReport {
pub schema_version: u32,
pub ledger_canister_id: String,
pub index_canister_id: String,
pub account_owner: String,
pub subaccount_hex: Option<String>,
pub requested_start: Option<String>,
pub requested_limit: u32,
pub next_start: Option<String>,
pub oldest_transaction_id: Option<String>,
pub balance: String,
pub token_symbol: String,
pub decimals: u8,
pub fetched_at: String,
pub source_endpoint: String,
pub fetched_by: String,
pub transactions: Vec<IcrcAccountTransactionRow>,
}
#[derive(Clone, Debug, Eq, PartialEq, SerdeDeserialize, Serialize)]
pub struct IcrcAccountTransactionCompleteness {
pub status: String,
pub page_size: u32,
pub page_count: u32,
pub row_count: usize,
pub point_in_time_guaranteed: bool,
}
#[derive(Clone, Debug, Eq, PartialEq, SerdeDeserialize, Serialize)]
pub struct IcrcAccountTransactionSnapshot {
pub schema_version: u32,
pub source_endpoint: String,
pub collection_started_at: String,
pub collection_completed_at: String,
pub fetched_by: String,
pub ledger_canister_id: String,
pub index_canister_id: String,
pub account_owner: String,
pub subaccount_hex: Option<String>,
pub balance: String,
pub token_symbol: String,
pub decimals: u8,
pub newest_transaction_id: Option<String>,
pub oldest_transaction_id: Option<String>,
pub completeness: IcrcAccountTransactionCompleteness,
pub transactions: Vec<IcrcAccountTransactionRow>,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct IcrcAccountTransactionRefreshReport {
pub schema_version: u32,
pub ledger_canister_id: String,
pub index_canister_id: String,
pub account_owner: String,
pub subaccount_hex: Option<String>,
pub transaction_count: usize,
pub newest_transaction_id: Option<String>,
pub oldest_transaction_id: Option<String>,
pub page_size: u32,
pub page_count: u32,
pub point_in_time_guaranteed: bool,
pub replaced_existing_cache: bool,
pub attempt_finalization_error: Option<String>,
pub collection_started_at: String,
pub collection_completed_at: String,
pub source_endpoint: String,
pub fetched_by: String,
pub cache_path: String,
pub refresh_attempt_path: String,
pub refresh_lock_path: String,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct IcrcAccountTransactionListReport {
pub schema_version: u32,
pub ledger_canister_id: String,
pub index_canister_id: String,
pub account_owner: String,
pub subaccount_hex: Option<String>,
pub requested_limit: u32,
pub sort: String,
pub total_transaction_count: usize,
pub returned_transaction_count: usize,
pub newest_transaction_id: Option<String>,
pub oldest_transaction_id: Option<String>,
pub balance: String,
pub token_symbol: String,
pub decimals: u8,
pub collection_started_at: String,
pub collection_completed_at: String,
pub source_endpoint: String,
pub fetched_by: String,
pub complete: bool,
pub point_in_time_guaranteed: bool,
pub page_size: u32,
pub page_count: u32,
pub cache_path: String,
pub transactions: Vec<IcrcAccountTransactionRow>,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct IcrcAccountTransactionCacheStatusReport {
pub schema_version: u32,
pub ledger_canister_id: String,
pub account_owner: String,
pub subaccount_hex: Option<String>,
pub source_endpoint: String,
pub found: bool,
pub cache: Option<IcrcAccountTransactionCacheSummary>,
pub expected_cache_path: String,
pub refresh_attempt_path: String,
pub refresh_lock_path: String,
pub latest_attempt: Option<IcrcAccountTransactionRefreshAttemptStatus>,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct IcrcAccountTransactionCacheSummary {
pub cache_status: String,
pub cache_error: Option<String>,
pub index_canister_id: Option<String>,
pub transaction_count: usize,
pub newest_transaction_id: Option<String>,
pub oldest_transaction_id: Option<String>,
pub page_size: u32,
pub page_count: u32,
pub complete: bool,
pub point_in_time_guaranteed: bool,
pub collection_started_at: String,
pub collection_completed_at: String,
pub cache_path: String,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct IcrcAccountTransactionRefreshAttemptStatus {
pub status: String,
pub started_at: String,
pub updated_at: String,
pub index_canister_id: Option<String>,
pub page_size: u32,
pub pages_fetched: u32,
pub rows_fetched: usize,
pub last_cursor: Option<String>,
pub last_error: Option<String>,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct IcrcIndexReport {
pub schema_version: u32,
pub ledger_canister_id: String,
pub fetched_at: String,
pub source_endpoint: String,
pub fetched_by: String,
pub index_canister_id: Option<String>,
pub index_error: Option<String>,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct IcrcTransactionsReport {
pub schema_version: u32,
pub ledger_canister_id: String,
pub fetched_at: String,
pub source_endpoint: String,
pub fetched_by: String,
pub requested_start: String,
pub requested_limit: u32,
pub follow_archives: bool,
pub log_length: Option<String>,
pub blocks: Vec<IcrcTransactionBlockRow>,
pub archived_blocks: Vec<IcrcArchivedBlocksRow>,
pub followed_archive_blocks: Vec<IcrcFollowedArchiveBlockRow>,
pub archive_follow_errors: Vec<IcrcArchiveFollowErrorRow>,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct IcrcBlockTypesReport {
pub schema_version: u32,
pub ledger_canister_id: String,
pub fetched_at: String,
pub source_endpoint: String,
pub fetched_by: String,
pub block_types: Vec<IcrcBlockTypeRow>,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct IcrcArchivesReport {
pub schema_version: u32,
pub ledger_canister_id: String,
pub from_canister_id: Option<String>,
pub fetched_at: String,
pub source_endpoint: String,
pub fetched_by: String,
pub archives: Vec<IcrcArchiveRow>,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct IcrcTipCertificateReport {
pub schema_version: u32,
pub ledger_canister_id: String,
pub fetched_at: String,
pub source_endpoint: String,
pub fetched_by: String,
pub certificate_present: bool,
pub certificate_hex: Option<String>,
pub certificate_bytes: Option<usize>,
pub hash_tree_hex: Option<String>,
pub hash_tree_bytes: Option<usize>,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct IcrcCapabilitiesReport {
pub schema_version: u32,
pub ledger_canister_id: String,
pub fetched_at: String,
pub source_endpoint: String,
pub fetched_by: String,
pub supported_standards: Vec<IcrcTokenStandardRow>,
pub capabilities: Vec<IcrcCapabilityRow>,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct IcrcCapabilityRow {
pub capability: String,
pub method: String,
pub status: String,
pub details: Option<String>,
pub error: Option<String>,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct IcrcTokenStandardRow {
pub name: String,
pub url: String,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct IcrcTokenMetadataRow {
pub key: String,
pub value_type: String,
pub value: JsonValue,
}
#[derive(Clone, Debug, Eq, PartialEq, SerdeDeserialize, Serialize)]
pub struct IcrcAccountRow {
pub owner: Option<String>,
pub subaccount_hex: Option<String>,
pub account_identifier: Option<String>,
}
#[derive(Clone, Debug, Eq, PartialEq, SerdeDeserialize, Serialize)]
pub struct IcrcAccountTransactionRow {
pub id: String,
pub kind: String,
pub timestamp_unix_nanos: Option<String>,
pub amount_base_units: Option<String>,
pub fee_base_units: Option<String>,
pub from: Option<IcrcAccountRow>,
pub to: Option<IcrcAccountRow>,
pub spender: Option<IcrcAccountRow>,
pub memo_hex: Option<String>,
pub created_at_time_unix_nanos: Option<String>,
pub expires_at_unix_nanos: Option<String>,
pub expected_allowance_base_units: Option<String>,
pub raw_transaction: JsonValue,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct IcrcTransactionBlockRow {
pub index: String,
pub block_type: Option<String>,
pub transaction_kind: Option<String>,
pub timestamp_unix_nanos: Option<String>,
pub amount_base_units: Option<String>,
pub raw_block: JsonValue,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct IcrcArchivedBlocksRow {
pub callback_canister_id: String,
pub callback_method: String,
pub ranges: Vec<IcrcArchivedRangeRow>,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct IcrcArchivedRangeRow {
pub start: String,
pub length: String,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct IcrcFollowedArchiveBlockRow {
pub archive_canister_id: String,
pub callback_method: String,
pub index: String,
pub block_type: Option<String>,
pub transaction_kind: Option<String>,
pub timestamp_unix_nanos: Option<String>,
pub amount_base_units: Option<String>,
pub raw_block: JsonValue,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct IcrcArchiveFollowErrorRow {
pub callback_canister_id: String,
pub callback_method: String,
pub ranges: Vec<IcrcArchivedRangeRow>,
pub error: String,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct IcrcBlockTypeRow {
pub block_type: String,
pub url: String,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
pub struct IcrcArchiveRow {
pub canister_id: String,
pub start: String,
pub end: String,
}