iota_grpc_types/
lib.rs

1// Copyright (c) 2025 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4//! gRPC-specific versioned types for forward compatibility.
5//!
6//! These types provide versioning for gRPC streaming while positioning
7//! for future core type evolution. When core types themselves
8//! need versioning, these wrappers will evolve naturally.
9
10use serde::{Deserialize, Serialize};
11
12/// Forward-compatible versioned checkpoint data for gRPC streaming.
13#[derive(Serialize, Deserialize, Clone, Debug)]
14pub enum CheckpointData {
15    V1(iota_types::full_checkpoint_content::CheckpointData),
16}
17
18/// Forward-compatible versioned checkpoint summary for gRPC streaming.
19#[derive(Serialize, Deserialize, Clone, Debug)]
20pub enum CertifiedCheckpointSummary {
21    V1(iota_types::messages_checkpoint::CertifiedCheckpointSummary),
22}
23
24impl From<iota_types::full_checkpoint_content::CheckpointData> for CheckpointData {
25    fn from(data: iota_types::full_checkpoint_content::CheckpointData) -> Self {
26        Self::V1(data)
27    }
28}
29
30impl From<iota_types::messages_checkpoint::CertifiedCheckpointSummary>
31    for CertifiedCheckpointSummary
32{
33    fn from(summary: iota_types::messages_checkpoint::CertifiedCheckpointSummary) -> Self {
34        Self::V1(summary)
35    }
36}
37
38impl CheckpointData {
39    /// Extract the V1 checkpoint data, returning None for unknown versions
40    pub fn into_v1(self) -> Option<iota_types::full_checkpoint_content::CheckpointData> {
41        match self {
42            Self::V1(data) => Some(data),
43        }
44    }
45
46    /// Get a reference to the V1 checkpoint data, returning None for unknown
47    /// versions
48    pub fn as_v1(&self) -> Option<&iota_types::full_checkpoint_content::CheckpointData> {
49        match self {
50            Self::V1(data) => Some(data),
51        }
52    }
53
54    /// Get the sequence number regardless of version
55    pub fn sequence_number(&self) -> u64 {
56        match self {
57            Self::V1(data) => data.checkpoint_summary.sequence_number,
58        }
59    }
60}
61
62impl CertifiedCheckpointSummary {
63    /// Extract the V1 checkpoint summary, returning None for unknown versions
64    pub fn into_v1(self) -> Option<iota_types::messages_checkpoint::CertifiedCheckpointSummary> {
65        match self {
66            Self::V1(summary) => Some(summary),
67        }
68    }
69
70    /// Get a reference to the V1 checkpoint summary, returning None for unknown
71    /// versions
72    pub fn as_v1(&self) -> Option<&iota_types::messages_checkpoint::CertifiedCheckpointSummary> {
73        match self {
74            Self::V1(summary) => Some(summary),
75        }
76    }
77
78    /// Get the sequence number regardless of version
79    pub fn sequence_number(&self) -> u64 {
80        match self {
81            Self::V1(summary) => summary.data().sequence_number,
82        }
83    }
84}