#[cfg(feature = "host")]
use crate::runtime::RuntimeError;
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 IcrcAccountTransactionsError {
#[error("invalid ICRC account transaction limit {limit}; expected at least 1")]
InvalidLimit {
limit: u32,
},
#[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,
},
}