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
}
}