#[cfg(feature = "host")]
use crate::{HostCacheError, runtime::RuntimeError};
use std::path::PathBuf;
use thiserror::Error as ThisError;
#[derive(Debug, ThisError)]
pub enum IcrcError {
#[cfg(feature = "host")]
#[error("failed to create Tokio runtime for ICRC query: {0}")]
Runtime(#[from] RuntimeError),
#[error("failed to build IC agent for endpoint {endpoint}: {reason}")]
AgentBuild { endpoint: String, reason: String },
#[error("invalid {field}: {reason}")]
InvalidPrincipal { field: &'static str, reason: String },
#[error("invalid subaccount hex: {reason}")]
InvalidSubaccountHex { reason: String },
#[error("invalid subaccount length: expected 32 bytes, got {bytes}")]
InvalidSubaccountLength { bytes: usize },
#[error("failed to encode Candid request for {message}: {reason}")]
CandidEncode {
message: &'static str,
reason: String,
},
#[error("ICRC ledger method {method} failed: {reason}")]
AgentCall {
method: &'static str,
reason: String,
},
#[error("failed to decode Candid response {message}: {reason}")]
CandidDecode {
message: &'static str,
reason: String,
},
}
#[derive(Debug, ThisError)]
pub enum IcrcAccountTransactionError {
#[error("invalid ICRC account transaction source endpoint {value:?}: {reason}")]
InvalidSourceEndpoint {
value: String,
reason: String,
},
#[error(
"invalid ICRC account transaction page size {page_size}; expected between 1 and {max_page_size}"
)]
InvalidPageSize {
page_size: u32,
max_page_size: u32,
},
#[error("invalid ICRC account transaction page: {reason}")]
InvalidPage {
reason: String,
},
#[error("invalid ICRC account transaction list limit {limit}; expected at least 1")]
InvalidListLimit {
limit: u32,
},
#[error("invalid ICRC account transaction max pages {max_pages}; expected at least 1")]
InvalidMaxPages {
max_pages: u32,
},
#[error("invalid ICRC account transaction cursor {value:?}: {reason}")]
InvalidCursor {
value: String,
reason: String,
},
#[error(transparent)]
Query(#[from] IcrcError),
#[error(
"failed to discover an index for ledger {ledger_canister_id}; supply an explicit index canister: {source}"
)]
IndexDiscovery {
ledger_canister_id: String,
#[source]
source: IcrcError,
},
#[error("ledger {ledger_canister_id} has no usable ICRC index: {reason}")]
IndexUnavailable {
ledger_canister_id: String,
reason: String,
},
#[error(
"ICRC index {index_canister_id} reports ledger {actual_ledger_canister_id}, expected {expected_ledger_canister_id}"
)]
IndexLedgerMismatch {
index_canister_id: String,
expected_ledger_canister_id: String,
actual_ledger_canister_id: String,
},
#[error("ICRC index {index_canister_id} account transaction query failed: {message}")]
IndexQuery {
index_canister_id: String,
message: String,
},
#[error(
"incomplete ICRC account transaction collection after {pages_fetched} page(s) and {rows_fetched} row(s): {reason}"
)]
IncompleteCollection {
index_canister_id: Option<String>,
pages_fetched: u32,
rows_fetched: usize,
last_cursor: Option<String>,
reason: String,
},
#[error(
"ICRC account transaction collection failed after {pages_fetched} page(s) and {rows_fetched} row(s): {source}"
)]
CollectionPage {
index_canister_id: Option<String>,
pages_fetched: u32,
rows_fetched: usize,
last_cursor: Option<String>,
#[source]
source: Box<Self>,
},
#[error(
"ICRC account transaction source returned index {actual_index_canister_id}, expected explicitly requested index {expected_index_canister_id}"
)]
CollectionIndexMismatch {
expected_index_canister_id: String,
actual_index_canister_id: String,
},
#[error("invalid ICRC account transaction cache at {}: {reason}", path.display())]
InvalidCache {
path: PathBuf,
reason: String,
},
#[error(
"invalid ICRC account transaction refresh attempt at {}: {reason}",
path.display()
)]
InvalidRefreshAttempt {
path: PathBuf,
reason: String,
},
#[cfg(feature = "host")]
#[error(transparent)]
Cache(#[from] HostCacheError),
}