1use bee_block as bee;
5use inx::proto;
6
7use crate::maybe_missing;
8
9#[allow(missing_docs)]
11#[derive(Clone, Debug, PartialEq, Eq)]
12pub struct TreasuryOutput {
13 pub milestone_id: bee::payload::milestone::MilestoneId,
14 pub amount: u64,
15}
16
17impl TryFrom<proto::TreasuryOutput> for TreasuryOutput {
18 type Error = bee::InxError;
19
20 fn try_from(value: proto::TreasuryOutput) -> Result<Self, Self::Error> {
21 Ok(TreasuryOutput {
22 milestone_id: maybe_missing!(value.milestone_id).try_into()?,
23 amount: value.amount,
24 })
25 }
26}
27
28impl From<TreasuryOutput> for proto::TreasuryOutput {
29 fn from(value: TreasuryOutput) -> Self {
30 Self {
31 milestone_id: Some(value.milestone_id.into()),
32 amount: value.amount,
33 }
34 }
35}
36
37#[allow(missing_docs)]
39#[derive(Clone, Debug, PartialEq, Eq)]
40pub struct TreasuryUpdate {
41 pub milestone_index: u32,
42 pub created: TreasuryOutput,
43 pub consumed: TreasuryOutput,
44}
45
46impl TryFrom<proto::TreasuryUpdate> for TreasuryUpdate {
47 type Error = bee::InxError;
48
49 fn try_from(value: proto::TreasuryUpdate) -> Result<Self, Self::Error> {
50 Ok(Self {
51 milestone_index: value.milestone_index,
52 created: maybe_missing!(value.created).try_into()?,
53 consumed: maybe_missing!(value.consumed).try_into()?,
54 })
55 }
56}
57
58impl From<TreasuryUpdate> for proto::TreasuryUpdate {
59 fn from(value: TreasuryUpdate) -> Self {
60 Self {
61 milestone_index: value.milestone_index,
62 created: Some(value.created.into()),
63 consumed: Some(value.consumed.into()),
64 }
65 }
66}