1use crate::icrc::{IcrcTokenMetadataRow, IcrcTokenStandardRow};
8use serde::Serialize;
9use serde_json::Value as JsonValue;
10
11#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
18pub struct IcrcTokenReport {
19 pub schema_version: u32,
20 pub ledger_canister_id: String,
21 pub fetched_at: String,
22 pub source_endpoint: String,
23 pub fetched_by: String,
24 pub token_name: String,
25 pub token_symbol: String,
26 pub decimals: u8,
27 pub transfer_fee: String,
28 pub total_supply: String,
29 pub minting_account_owner: Option<String>,
30 pub minting_account_subaccount_hex: Option<String>,
31 pub supported_standards: Vec<IcrcTokenStandardRow>,
32 pub metadata: Vec<IcrcTokenMetadataRow>,
33}
34
35#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
42pub struct IcrcIndexReport {
43 pub schema_version: u32,
44 pub ledger_canister_id: String,
45 pub fetched_at: String,
46 pub source_endpoint: String,
47 pub fetched_by: String,
48 pub index_canister_id: Option<String>,
49 pub index_error: Option<String>,
50}
51
52#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
59pub struct IcrcTransactionsReport {
60 pub schema_version: u32,
61 pub ledger_canister_id: String,
62 pub fetched_at: String,
63 pub source_endpoint: String,
64 pub fetched_by: String,
65 pub requested_start: String,
66 pub requested_limit: u32,
67 pub follow_archives: bool,
68 pub log_length: Option<String>,
69 pub blocks: Vec<IcrcTransactionBlockRow>,
70 pub archived_blocks: Vec<IcrcArchivedBlocksRow>,
71 pub followed_archive_blocks: Vec<IcrcFollowedArchiveBlockRow>,
72 pub archive_follow_errors: Vec<IcrcArchiveFollowErrorRow>,
73}
74
75#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
82pub struct IcrcBlockTypesReport {
83 pub schema_version: u32,
84 pub ledger_canister_id: String,
85 pub fetched_at: String,
86 pub source_endpoint: String,
87 pub fetched_by: String,
88 pub block_types: Vec<IcrcBlockTypeRow>,
89}
90
91#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
98pub struct IcrcArchivesReport {
99 pub schema_version: u32,
100 pub ledger_canister_id: String,
101 pub from_canister_id: Option<String>,
102 pub fetched_at: String,
103 pub source_endpoint: String,
104 pub fetched_by: String,
105 pub archives: Vec<IcrcArchiveRow>,
106}
107
108#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
115pub struct IcrcTipCertificateReport {
116 pub schema_version: u32,
117 pub ledger_canister_id: String,
118 pub fetched_at: String,
119 pub source_endpoint: String,
120 pub fetched_by: String,
121 pub certificate_present: bool,
122 pub certificate_hex: Option<String>,
123 pub certificate_bytes: Option<usize>,
124 pub hash_tree_hex: Option<String>,
125 pub hash_tree_bytes: Option<usize>,
126}
127
128#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
135pub struct IcrcCapabilitiesReport {
136 pub schema_version: u32,
137 pub ledger_canister_id: String,
138 pub fetched_at: String,
139 pub source_endpoint: String,
140 pub fetched_by: String,
141 pub supported_standards: Vec<IcrcTokenStandardRow>,
142 pub capabilities: Vec<IcrcCapabilityRow>,
143}
144
145#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
152pub struct IcrcCapabilityRow {
153 pub capability: String,
154 pub method: String,
155 pub status: IcrcCapabilityStatus,
156 pub details: Option<String>,
157 pub error: Option<String>,
158}
159
160#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize)]
167#[serde(rename_all = "snake_case")]
168pub enum IcrcCapabilityStatus {
169 Available,
171 Unsupported,
173 Error,
175}
176
177impl IcrcCapabilityStatus {
178 #[must_use]
180 pub const fn as_str(self) -> &'static str {
181 match self {
182 Self::Available => "available",
183 Self::Unsupported => "unsupported",
184 Self::Error => "error",
185 }
186 }
187}
188
189#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
196pub struct IcrcTransactionBlockRow {
197 pub index: String,
198 pub block_type: Option<String>,
199 pub transaction_kind: Option<String>,
200 pub timestamp_unix_nanos: Option<String>,
201 pub amount_base_units: Option<String>,
202 pub raw_block: JsonValue,
203}
204
205#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
212pub struct IcrcArchivedBlocksRow {
213 pub callback_canister_id: String,
214 pub callback_method: String,
215 pub ranges: Vec<IcrcArchivedRangeRow>,
216}
217
218#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
225pub struct IcrcArchivedRangeRow {
226 pub start: String,
227 pub length: String,
228}
229
230#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
237pub struct IcrcFollowedArchiveBlockRow {
238 pub archive_canister_id: String,
239 pub callback_method: String,
240 pub index: String,
241 pub block_type: Option<String>,
242 pub transaction_kind: Option<String>,
243 pub timestamp_unix_nanos: Option<String>,
244 pub amount_base_units: Option<String>,
245 pub raw_block: JsonValue,
246}
247
248#[cfg(test)]
249mod tests {
250 use super::*;
251
252 #[test]
253 fn capability_status_labels_are_stable() {
254 for (status, label) in [
255 (IcrcCapabilityStatus::Available, "available"),
256 (IcrcCapabilityStatus::Unsupported, "unsupported"),
257 (IcrcCapabilityStatus::Error, "error"),
258 ] {
259 assert_eq!(
260 serde_json::to_string(&status).unwrap(),
261 format!("\"{label}\"")
262 );
263 assert_eq!(status.as_str(), label);
264 }
265 }
266}
267
268#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
275pub struct IcrcArchiveFollowErrorRow {
276 pub callback_canister_id: String,
277 pub callback_method: String,
278 pub ranges: Vec<IcrcArchivedRangeRow>,
279 pub error: String,
280}
281
282#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
289pub struct IcrcBlockTypeRow {
290 pub block_type: String,
291 pub url: String,
292}
293
294#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
301pub struct IcrcArchiveRow {
302 pub canister_id: String,
303 pub start: String,
304 pub end: String,
305}