ic_query/icrc/model/contracts/reports/
ledger.rs1use 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 #[serde(flatten)]
21 pub provenance: super::IcrcReportProvenance,
22 #[serde(flatten)]
24 pub token: IcrcTokenData,
25}
26
27#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
34pub struct IcrcIndexReport {
35 #[serde(flatten)]
37 pub provenance: super::IcrcReportProvenance,
38 pub index_canister_id: Option<String>,
39 pub index_error: Option<String>,
40}
41
42#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
49pub struct IcrcTransactionsData {
50 pub log_length: Option<String>,
53 pub blocks: Vec<IcrcTransactionBlockRow>,
55 pub archived_blocks: Vec<IcrcArchivedBlocksRow>,
57 pub followed_archive_blocks: Vec<IcrcFollowedArchiveBlockRow>,
59 pub archive_follow_errors: Vec<IcrcArchiveFollowErrorRow>,
61}
62
63#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
70pub struct IcrcTransactionsReport {
71 #[serde(flatten)]
73 pub provenance: super::IcrcReportProvenance,
74 pub requested_start: String,
75 pub requested_limit: u32,
76 pub follow_archives: bool,
77 #[serde(flatten)]
79 pub transactions: IcrcTransactionsData,
80}
81
82#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
89pub struct IcrcBlockTypesReport {
90 #[serde(flatten)]
92 pub provenance: super::IcrcReportProvenance,
93 pub block_types: Vec<IcrcBlockTypeRow>,
94}
95
96#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
103pub struct IcrcArchivesReport {
104 #[serde(flatten)]
106 pub provenance: super::IcrcReportProvenance,
107 pub from_canister_id: Option<String>,
108 pub archives: Vec<IcrcArchiveRow>,
109}
110
111#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
118pub struct IcrcTipCertificateReport {
119 #[serde(flatten)]
121 pub provenance: super::IcrcReportProvenance,
122 pub certificate_present: bool,
123 pub certificate_hex: Option<String>,
124 pub certificate_bytes: Option<usize>,
125 pub hash_tree_hex: Option<String>,
126 pub hash_tree_bytes: Option<usize>,
127}
128
129#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
136pub struct IcrcCapabilitiesReport {
137 #[serde(flatten)]
139 pub provenance: super::IcrcReportProvenance,
140 pub supported_standards: Vec<IcrcTokenStandardRow>,
141 pub capabilities: Vec<IcrcCapabilityRow>,
142}
143
144#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
151pub struct IcrcCapabilityRow {
152 pub capability: String,
153 pub method: String,
154 pub status: IcrcCapabilityStatus,
155 pub details: Option<String>,
156 pub error: Option<String>,
157}
158
159#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize)]
166#[serde(rename_all = "snake_case")]
167pub enum IcrcCapabilityStatus {
168 Available,
170 Unsupported,
172 Error,
174}
175
176impl IcrcCapabilityStatus {
177 #[must_use]
179 pub const fn as_str(self) -> &'static str {
180 match self {
181 Self::Available => "available",
182 Self::Unsupported => "unsupported",
183 Self::Error => "error",
184 }
185 }
186}
187
188#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
195pub struct IcrcTransactionBlockRow {
196 pub index: String,
197 pub block_type: Option<String>,
198 pub transaction_kind: Option<String>,
199 pub timestamp_unix_nanos: Option<String>,
200 pub amount_base_units: Option<String>,
201 pub raw_block: JsonValue,
202}
203
204#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
211pub struct IcrcArchivedBlocksRow {
212 pub callback_canister_id: String,
213 pub callback_method: String,
214 pub ranges: Vec<IcrcArchivedRangeRow>,
215}
216
217#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
224pub struct IcrcArchivedRangeRow {
225 pub start: String,
226 pub length: String,
227}
228
229#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
236pub struct IcrcFollowedArchiveBlockRow {
237 pub archive_canister_id: String,
238 pub callback_method: String,
239 #[serde(flatten)]
241 pub block: IcrcTransactionBlockRow,
242}
243
244#[cfg(test)]
245mod tests {
246 use super::*;
247
248 #[test]
249 fn capability_status_labels_are_stable() {
250 for (status, label) in [
251 (IcrcCapabilityStatus::Available, "available"),
252 (IcrcCapabilityStatus::Unsupported, "unsupported"),
253 (IcrcCapabilityStatus::Error, "error"),
254 ] {
255 assert_eq!(
256 serde_json::to_string(&status).unwrap(),
257 format!("\"{label}\"")
258 );
259 assert_eq!(status.as_str(), label);
260 }
261 }
262}
263
264#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
271pub struct IcrcArchiveFollowErrorRow {
272 pub callback_canister_id: String,
273 pub callback_method: String,
274 pub ranges: Vec<IcrcArchivedRangeRow>,
275 pub error: String,
276}
277
278#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
285pub struct IcrcBlockTypeRow {
286 pub block_type: String,
287 pub url: String,
288}
289
290#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
297pub struct IcrcArchiveRow {
298 pub canister_id: String,
299 pub start: String,
300 pub end: String,
301}