iota_model/
inputs.rs

1use std::fmt;
2
3use serde::{Deserialize, Serialize};
4use serde_json;
5
6use super::Input;
7
8/// Represents a grouping of inputs and their cumulative balance
9#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
10pub struct Inputs {
11    inputs_list: Vec<Input>,
12    total_balance: i64,
13}
14
15impl fmt::Display for Inputs {
16    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
17        write!(
18            f,
19            "{}",
20            serde_json::to_string_pretty(self).unwrap_or_default()
21        )
22    }
23}
24
25impl Inputs {
26    /// Provides a view of the inputs_list
27    pub fn inputs_list(&self) -> &[Input] {
28        &self.inputs_list
29    }
30
31    /// Provides a mutable view of the inputs_list
32    pub fn inputs_list_mut(&mut self) -> &mut [Input] {
33        &mut self.inputs_list
34    }
35
36    /// Setter accepting anything that can be turned into the relevant type
37    pub fn set_inputs_list(&mut self, new_value: impl Into<Vec<Input>>) {
38        self.inputs_list = new_value.into();
39    }
40
41    /// Provides a view of the inputs address
42    pub fn add(&mut self, new_value: impl Into<Input>) {
43        self.inputs_list.push(new_value.into());
44    }
45
46    /// Provides a view of the total_balance
47    pub fn total_balance(&self) -> i64 {
48        self.total_balance
49    }
50
51    /// Provides a mutable view of the total_balance
52    pub fn total_balance_mut(&mut self) -> &mut i64 {
53        &mut self.total_balance
54    }
55
56    /// Setter accepting anything that can be turned into the relevant type
57    pub fn set_total_balance(&mut self, new_value: impl Into<i64>) {
58        self.total_balance = new_value.into();
59    }
60}