1use move_binary_format::{CompiledModule, file_format::SignatureToken};
5use move_bytecode_utils::resolve_struct;
6use move_core_types::{
7 account_address::AccountAddress, ident_str, identifier::IdentStr, language_storage::StructTag,
8};
9use serde::{Deserialize, Serialize};
10
11use crate::{SUI_FRAMEWORK_ADDRESS, id::UID};
12
13pub const CLOCK_MODULE_NAME: &IdentStr = ident_str!("clock");
14pub const CLOCK_STRUCT_NAME: &IdentStr = ident_str!("Clock");
15pub const RESOLVED_SUI_CLOCK: (&AccountAddress, &IdentStr, &IdentStr) =
16 (&SUI_FRAMEWORK_ADDRESS, CLOCK_MODULE_NAME, CLOCK_STRUCT_NAME);
17pub const CONSENSUS_COMMIT_PROLOGUE_FUNCTION_NAME: &IdentStr =
18 ident_str!("consensus_commit_prologue");
19
20#[derive(Debug, Serialize, Deserialize)]
21pub struct Clock {
22 pub id: UID,
23 pub timestamp_ms: u64,
24}
25
26impl Clock {
27 pub fn timestamp_ms(&self) -> u64 {
28 self.timestamp_ms
29 }
30
31 pub fn type_() -> StructTag {
32 StructTag {
33 address: SUI_FRAMEWORK_ADDRESS,
34 module: CLOCK_MODULE_NAME.to_owned(),
35 name: CLOCK_STRUCT_NAME.to_owned(),
36 type_params: vec![],
37 }
38 }
39
40 pub fn is_mutable(view: &CompiledModule, s: &SignatureToken) -> bool {
42 use SignatureToken as S;
43 match s {
44 S::MutableReference(inner) => Self::is_mutable(view, inner),
45 S::Datatype(idx) => resolve_struct(view, *idx) == RESOLVED_SUI_CLOCK,
46 _ => false,
47 }
48 }
49}