iop_coeus_node/operations/
start_block.rs

1use super::*;
2
3#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)]
4#[serde(rename_all = "camelCase")]
5pub struct DoStartBlock {
6    pub(super) height: BlockHeight,
7}
8
9impl Command for DoStartBlock {
10    fn execute(self, state: &mut State) -> Result<UndoOperation> {
11        ensure!(
12            state.last_seen_height() < self.height,
13            "Already seen height {}, cannot set it to {}",
14            state.last_seen_height(),
15            self.height
16        );
17        let undo_operation = UndoStartBlock { height: state.last_seen_height() };
18        state.set_last_seen_height(self.height);
19        Ok(UndoOperation::StartBlock(undo_operation))
20    }
21}
22
23#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)]
24#[serde(rename_all = "camelCase")]
25pub struct UndoStartBlock {
26    height: BlockHeight,
27}
28
29impl UndoCommand for UndoStartBlock {
30    fn execute(self, state: &mut State) -> Result<()> {
31        state.set_last_seen_height(self.height);
32        Ok(())
33    }
34}