Skip to main content

bee_ledger_types/
created_output.rs

1// Copyright 2020-2021 IOTA Stiftung
2// SPDX-License-Identifier: Apache-2.0
3
4use core::ops::Deref;
5
6use bee_block::{output::Output, payload::milestone::MilestoneIndex, protocol::ProtocolParameters, BlockId};
7
8use crate::error::Error;
9
10/// Represents a newly created output.
11#[derive(Clone, Debug, Eq, PartialEq, packable::Packable)]
12#[packable(unpack_error = Error)]
13#[packable(unpack_visitor = ProtocolParameters)]
14pub struct CreatedOutput {
15    block_id: BlockId,
16    milestone_index: MilestoneIndex,
17    milestone_timestamp: u32,
18    inner: Output,
19}
20
21impl CreatedOutput {
22    /// Creates a new [`CreatedOutput`].
23    pub fn new(block_id: BlockId, milestone_index: MilestoneIndex, milestone_timestamp: u32, inner: Output) -> Self {
24        Self {
25            block_id,
26            milestone_index,
27            milestone_timestamp,
28            inner,
29        }
30    }
31
32    /// Returns the block id of the [`CreatedOutput`].
33    pub fn block_id(&self) -> &BlockId {
34        &self.block_id
35    }
36
37    /// Returns the milestone index of the [`CreatedOutput`].
38    pub fn milestone_index(&self) -> MilestoneIndex {
39        self.milestone_index
40    }
41
42    /// Returns the milestone milestone timestamp of the [`CreatedOutput`].
43    pub fn milestone_timestamp(&self) -> u32 {
44        self.milestone_timestamp
45    }
46
47    /// Returns the inner output of the [`CreatedOutput`].
48    pub fn inner(&self) -> &Output {
49        &self.inner
50    }
51}
52
53impl Deref for CreatedOutput {
54    type Target = Output;
55
56    fn deref(&self) -> &Self::Target {
57        &self.inner
58    }
59}