1use crate::icrc::{IcrcTokenData, 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 #[serde(flatten)]
26 pub token: IcrcTokenData,
27}
28
29#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
36pub struct IcrcIndexReport {
37 pub schema_version: u32,
38 pub ledger_canister_id: String,
39 pub fetched_at: String,
40 pub source_endpoint: String,
41 pub fetched_by: String,
42 pub index_canister_id: Option<String>,
43 pub index_error: Option<String>,
44}
45
46#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
53pub struct IcrcTransactionsReport {
54 pub schema_version: u32,
55 pub ledger_canister_id: String,
56 pub fetched_at: String,
57 pub source_endpoint: String,
58 pub fetched_by: String,
59 pub requested_start: String,
60 pub requested_limit: u32,
61 pub follow_archives: bool,
62 pub log_length: Option<String>,
63 pub blocks: Vec<IcrcTransactionBlockRow>,
64 pub archived_blocks: Vec<IcrcArchivedBlocksRow>,
65 pub followed_archive_blocks: Vec<IcrcFollowedArchiveBlockRow>,
66 pub archive_follow_errors: Vec<IcrcArchiveFollowErrorRow>,
67}
68
69#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
76pub struct IcrcBlockTypesReport {
77 pub schema_version: u32,
78 pub ledger_canister_id: String,
79 pub fetched_at: String,
80 pub source_endpoint: String,
81 pub fetched_by: String,
82 pub block_types: Vec<IcrcBlockTypeRow>,
83}
84
85#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
92pub struct IcrcArchivesReport {
93 pub schema_version: u32,
94 pub ledger_canister_id: String,
95 pub from_canister_id: Option<String>,
96 pub fetched_at: String,
97 pub source_endpoint: String,
98 pub fetched_by: String,
99 pub archives: Vec<IcrcArchiveRow>,
100}
101
102#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
109pub struct IcrcTipCertificateReport {
110 pub schema_version: u32,
111 pub ledger_canister_id: String,
112 pub fetched_at: String,
113 pub source_endpoint: String,
114 pub fetched_by: String,
115 pub certificate_present: bool,
116 pub certificate_hex: Option<String>,
117 pub certificate_bytes: Option<usize>,
118 pub hash_tree_hex: Option<String>,
119 pub hash_tree_bytes: Option<usize>,
120}
121
122#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
129pub struct IcrcCapabilitiesReport {
130 pub schema_version: u32,
131 pub ledger_canister_id: String,
132 pub fetched_at: String,
133 pub source_endpoint: String,
134 pub fetched_by: String,
135 pub supported_standards: Vec<IcrcTokenStandardRow>,
136 pub capabilities: Vec<IcrcCapabilityRow>,
137}
138
139#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
146pub struct IcrcCapabilityRow {
147 pub capability: String,
148 pub method: String,
149 pub status: IcrcCapabilityStatus,
150 pub details: Option<String>,
151 pub error: Option<String>,
152}
153
154#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize)]
161#[serde(rename_all = "snake_case")]
162pub enum IcrcCapabilityStatus {
163 Available,
165 Unsupported,
167 Error,
169}
170
171impl IcrcCapabilityStatus {
172 #[must_use]
174 pub const fn as_str(self) -> &'static str {
175 match self {
176 Self::Available => "available",
177 Self::Unsupported => "unsupported",
178 Self::Error => "error",
179 }
180 }
181}
182
183#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
190pub struct IcrcTransactionBlockRow {
191 pub index: String,
192 pub block_type: Option<String>,
193 pub transaction_kind: Option<String>,
194 pub timestamp_unix_nanos: Option<String>,
195 pub amount_base_units: Option<String>,
196 pub raw_block: JsonValue,
197}
198
199#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
206pub struct IcrcArchivedBlocksRow {
207 pub callback_canister_id: String,
208 pub callback_method: String,
209 pub ranges: Vec<IcrcArchivedRangeRow>,
210}
211
212#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
219pub struct IcrcArchivedRangeRow {
220 pub start: String,
221 pub length: String,
222}
223
224#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
231pub struct IcrcFollowedArchiveBlockRow {
232 pub archive_canister_id: String,
233 pub callback_method: String,
234 pub index: String,
235 pub block_type: Option<String>,
236 pub transaction_kind: Option<String>,
237 pub timestamp_unix_nanos: Option<String>,
238 pub amount_base_units: Option<String>,
239 pub raw_block: JsonValue,
240}
241
242#[cfg(test)]
243mod tests {
244 use super::*;
245
246 #[test]
247 fn capability_status_labels_are_stable() {
248 for (status, label) in [
249 (IcrcCapabilityStatus::Available, "available"),
250 (IcrcCapabilityStatus::Unsupported, "unsupported"),
251 (IcrcCapabilityStatus::Error, "error"),
252 ] {
253 assert_eq!(
254 serde_json::to_string(&status).unwrap(),
255 format!("\"{label}\"")
256 );
257 assert_eq!(status.as_str(), label);
258 }
259 }
260}
261
262#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
269pub struct IcrcArchiveFollowErrorRow {
270 pub callback_canister_id: String,
271 pub callback_method: String,
272 pub ranges: Vec<IcrcArchivedRangeRow>,
273 pub error: String,
274}
275
276#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
283pub struct IcrcBlockTypeRow {
284 pub block_type: String,
285 pub url: String,
286}
287
288#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
295pub struct IcrcArchiveRow {
296 pub canister_id: String,
297 pub start: String,
298 pub end: String,
299}