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
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
use std::fmt;

use serde::{Deserialize, Serialize};
use serde_json;

/// Represents a transfer in IOTA
#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
pub struct Transfer {
    timestamp: Option<String>,
    address: String,
    hash: Option<String>,
    persistence: Option<bool>,
    value: i64,
    message: String,
    tag: Option<String>,
    obsolete_tag: Option<String>,
}

impl fmt::Display for Transfer {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(
            f,
            "{}",
            serde_json::to_string_pretty(self).unwrap_or_default()
        )
    }
}

impl Into<Vec<Transfer>> for Transfer {
    fn into(self) -> Vec<Transfer> {
        vec![self]
    }
}

impl Into<Vec<Transfer>> for &Transfer {
    fn into(self) -> Vec<Transfer> {
        vec![self.clone()]
    }
}

impl Transfer {
    /// Provides a view of the address
    pub fn address(&self) -> &str {
        &self.address
    }
    /// Provides a mutable view of the address
    pub fn address_mut(&mut self) -> &mut String {
        &mut self.address
    }
    /// Setter accepting anything that can be turned into the relevant type
    pub fn set_address<T>(&mut self, new_value: T)
    where
        T: Into<String>,
    {
        self.address = new_value.into();
    }

    /// Provides a view of the hash
    pub fn hash(&self) -> &Option<String> {
        &self.hash
    }
    /// Provides a mutable view of the hash
    pub fn hash_mut(&mut self) -> &mut Option<String> {
        &mut self.hash
    }
    /// Setter accepting anything that can be turned into the relevant type
    pub fn set_hash<T>(&mut self, new_value: T)
    where
        T: Into<String>,
    {
        self.hash = Some(new_value.into());
    }

    /// Provides a view of the persistence
    pub fn persistence(&self) -> &Option<bool> {
        &self.persistence
    }
    /// Provides a mutable view of the persistence
    pub fn persistence_mut(&mut self) -> &mut Option<bool> {
        &mut self.persistence
    }
    /// Setter accepting anything that can be turned into the relevant type
    pub fn set_persistence<T>(&mut self, new_value: T)
    where
        T: Into<bool>,
    {
        self.persistence = Some(new_value.into());
    }

    /// Provides a view of the timestamp
    pub fn timestamp(&self) -> &Option<String> {
        &self.timestamp
    }
    /// Provides a mutable view of the timestamp
    pub fn timestamp_mut(&mut self) -> &mut Option<String> {
        &mut self.timestamp
    }
    /// Setter accepting anything that can be turned into the relevant type
    pub fn set_timestamp<T>(&mut self, new_value: T)
    where
        T: Into<String>,
    {
        self.timestamp = Some(new_value.into());
    }

    /// Provides a view of the value
    pub fn value(&self) -> &i64 {
        &self.value
    }
    /// Provides a mutable view of the value
    pub fn value_mut(&mut self) -> &mut i64 {
        &mut self.value
    }
    /// Setter accepting anything that can be turned into the relevant type
    pub fn set_value<T>(&mut self, new_value: T)
    where
        T: Into<i64>,
    {
        self.value = new_value.into();
    }

    /// Provides a view of the message
    pub fn message(&self) -> &str {
        &self.message
    }
    /// Provides a mutable view of the message
    pub fn message_mut(&mut self) -> &mut String {
        &mut self.message
    }
    /// Setter accepting anything that can be turned into the relevant type
    pub fn set_message<T>(&mut self, new_value: T)
    where
        T: Into<String>,
    {
        self.message = new_value.into();
    }

    /// Provides a view of the tag
    pub fn tag(&self) -> Option<String> {
        self.tag.clone()
    }
    /// Provides a mutable view of the tag
    pub fn tag_mut(&mut self) -> &mut Option<String> {
        &mut self.tag
    }
    /// Setter accepting anything that can be turned into the relevant type
    pub fn set_tag<T>(&mut self, new_value: T)
    where
        T: Into<String>,
    {
        self.tag = Some(new_value.into());
    }

    /// Provides a view of the obsolete_tag
    pub fn obsolete_tag(&self) -> Option<String> {
        self.obsolete_tag.clone()
    }
    /// Provides a mutable view of the obsolete_tag
    pub fn obsolete_tag_mut(&mut self) -> &mut Option<String> {
        &mut self.obsolete_tag
    }
    /// Setter accepting anything that can be turned into the relevant type
    pub fn set_obsolete_tag<T>(&mut self, new_value: T)
    where
        T: Into<String>,
    {
        self.obsolete_tag = Some(new_value.into());
    }
}