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