1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright 2022 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

use bee_block as bee;
use inx::proto;

use crate::maybe_missing;

/// Represents a treasury output.
#[allow(missing_docs)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct TreasuryOutput {
    pub milestone_id: bee::payload::milestone::MilestoneId,
    pub amount: u64,
}

impl TryFrom<proto::TreasuryOutput> for TreasuryOutput {
    type Error = bee::InxError;

    fn try_from(value: proto::TreasuryOutput) -> Result<Self, Self::Error> {
        Ok(TreasuryOutput {
            milestone_id: maybe_missing!(value.milestone_id).try_into()?,
            amount: value.amount,
        })
    }
}

/// Represents an update to the treasury.
#[allow(missing_docs)]
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct TreasuryUpdate {
    pub milestone_index: u32,
    pub created: TreasuryOutput,
    pub consumed: TreasuryOutput,
}

impl TryFrom<proto::TreasuryUpdate> for TreasuryUpdate {
    type Error = bee::InxError;

    fn try_from(value: proto::TreasuryUpdate) -> Result<Self, Self::Error> {
        Ok(Self {
            milestone_index: value.milestone_index,
            created: maybe_missing!(value.created).try_into()?,
            consumed: maybe_missing!(value.consumed).try_into()?,
        })
    }
}