Skip to main content

iota_types/
clock.rs

1// Copyright (c) Mysten Labs, Inc.
2// Modifications Copyright (c) 2024 IOTA Stiftung
3// SPDX-License-Identifier: Apache-2.0
4
5use iota_sdk_types::Identifier;
6use move_binary_format::{CompiledModule, file_format::SignatureToken};
7use move_bytecode_utils::resolve_struct;
8use move_core_types::{account_address::AccountAddress, ident_str, identifier::IdentStr};
9
10use crate::IOTA_FRAMEWORK_ADDRESS;
11
12pub const RESOLVED_IOTA_CLOCK: (&AccountAddress, &IdentStr, &IdentStr) = (
13    &IOTA_FRAMEWORK_ADDRESS,
14    ident_str!("clock"),
15    ident_str!("Clock"),
16);
17pub const CONSENSUS_COMMIT_PROLOGUE_FUNCTION_NAME: Identifier =
18    Identifier::from_static("consensus_commit_prologue");
19
20/// Detects a `&mut iota::clock::Clock` or `iota::clock::Clock` in the
21/// signature.
22pub fn is_mutable_clock(view: &CompiledModule, s: &SignatureToken) -> bool {
23    use SignatureToken as S;
24    match s {
25        S::MutableReference(inner) => is_mutable_clock(view, inner),
26        S::Datatype(idx) => resolve_struct(view, *idx) == RESOLVED_IOTA_CLOCK,
27        _ => false,
28    }
29}