iota_types/timelock/
timelocked_staked_iota.rs1use serde::{Deserialize, Serialize};
5
6use crate::{
7 base_types::ObjectID,
8 committee::EpochId,
9 error::IotaError,
10 governance::StakedIota,
11 id::UID,
12 object::{Data, Object},
13};
14
15#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq)]
18pub struct TimelockedStakedIota {
19 id: UID,
20 staked_iota: StakedIota,
22 expiration_timestamp_ms: u64,
24 label: Option<String>,
26}
27
28impl TimelockedStakedIota {
29 pub fn id(&self) -> ObjectID {
31 self.id.id.bytes
32 }
33
34 pub fn pool_id(&self) -> ObjectID {
36 self.staked_iota.pool_id()
37 }
38
39 pub fn activation_epoch(&self) -> EpochId {
41 self.staked_iota.activation_epoch()
42 }
43
44 pub fn request_epoch(&self) -> EpochId {
46 self.staked_iota.activation_epoch().saturating_sub(1)
48 }
49
50 pub fn principal(&self) -> u64 {
52 self.staked_iota.principal()
53 }
54
55 pub fn expiration_timestamp_ms(&self) -> u64 {
57 self.expiration_timestamp_ms
58 }
59
60 pub fn label(&self) -> &Option<String> {
62 &self.label
63 }
64}
65
66impl TryFrom<&Object> for TimelockedStakedIota {
67 type Error = IotaError;
68 fn try_from(object: &Object) -> Result<Self, Self::Error> {
69 match &object.data {
70 Data::Struct(o) => {
71 if o.struct_tag().is_timelocked_staked_iota() {
72 return bcs::from_bytes(o.contents()).map_err(|err| IotaError::Type {
73 error: format!(
74 "Unable to deserialize TimelockedStakedIota object: {err:?}"
75 ),
76 });
77 }
78 }
79 Data::Package(_) => {}
80 }
81
82 Err(IotaError::Type {
83 error: format!("Object type is not a TimelockedStakedIota: {object:?}"),
84 })
85 }
86}