bee_inx/milestone/
mod.rs

1// Copyright 2022 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4use bee_block as bee;
5
6mod info;
7
8use inx::proto;
9
10pub use self::info::MilestoneInfo;
11use crate::{maybe_missing, ProtocolParameters, Raw};
12
13/// The [`Milestone`] type.
14#[derive(Clone, Debug, PartialEq, Eq)]
15pub struct Milestone {
16    /// Information about the milestone.
17    pub milestone_info: MilestoneInfo,
18    /// The raw bytes of the milestone. Note that this is not a [`bee::payload::milestone::MilestonePayload`], but
19    /// rather a [`bee::payload::Payload`] and still needs to be unpacked.
20    pub milestone: Raw<bee::payload::Payload>,
21}
22
23impl TryFrom<proto::Milestone> for Milestone {
24    type Error = bee::InxError;
25
26    fn try_from(value: proto::Milestone) -> Result<Self, Self::Error> {
27        Ok(Self {
28            milestone_info: maybe_missing!(value.milestone_info).try_into()?,
29            milestone: maybe_missing!(value.milestone).data.into(),
30        })
31    }
32}
33
34impl From<Milestone> for proto::Milestone {
35    fn from(value: Milestone) -> Self {
36        Self {
37            milestone_info: Some(value.milestone_info.into()),
38            milestone: Some(value.milestone.into()),
39        }
40    }
41}
42
43/// The [`Milestone`] type.
44#[derive(Clone, Debug, PartialEq, Eq)]
45pub struct MilestoneAndProtocolParameters {
46    pub milestone: Milestone,
47    pub current_protocol_parameters: ProtocolParameters,
48}
49
50impl TryFrom<proto::MilestoneAndProtocolParameters> for MilestoneAndProtocolParameters {
51    type Error = bee::InxError;
52
53    fn try_from(value: proto::MilestoneAndProtocolParameters) -> Result<Self, Self::Error> {
54        Ok(Self {
55            milestone: maybe_missing!(value.milestone).try_into()?,
56            current_protocol_parameters: maybe_missing!(value.current_protocol_parameters).into(),
57        })
58    }
59}
60
61impl From<MilestoneAndProtocolParameters> for proto::MilestoneAndProtocolParameters {
62    fn from(value: MilestoneAndProtocolParameters) -> Self {
63        Self {
64            milestone: Some(value.milestone.into()),
65            current_protocol_parameters: Some(value.current_protocol_parameters.into()),
66        }
67    }
68}