radix_clis/resim/
cmd_set_current_time.rs

1use clap::Parser;
2use radix_common::prelude::*;
3use radix_common::time::UtcDateTime;
4use radix_engine::blueprints::consensus_manager::{
5    ProposerMilliTimestampSubstate, ProposerMinuteTimestampSubstate,
6};
7
8use crate::resim::*;
9
10/// Set the current time
11#[derive(Parser, Debug)]
12pub struct SetCurrentTime {
13    /// UTC date time in ISO-8601 format, up to second precision, such as '2011-12-03T10:15:30Z'.
14    pub date_time: UtcDateTime,
15}
16
17impl SetCurrentTime {
18    pub fn run<O: std::io::Write>(&self, out: &mut O) -> Result<(), String> {
19        let instant = self.date_time.to_instant();
20        db_upsert_timestamps(
21            ProposerMilliTimestampSubstate {
22                epoch_milli: instant.seconds_since_unix_epoch * 1000,
23            },
24            ProposerMinuteTimestampSubstate {
25                epoch_minute: i32::try_from(instant.seconds_since_unix_epoch / 60).unwrap(),
26            },
27        )?;
28        writeln!(out, "Time set successfully").map_err(Error::IOError)?;
29        Ok(())
30    }
31}