iop_coeus_node/operations/
renew.rs

1use super::*;
2
3impl AuthorizedCommand for DoRenew {
4    fn validate_auth(&self, state: &State, pk: &MPublicKey) -> Result<()> {
5        state.validate_domain_owner(&self.name, pk)
6    }
7}
8
9impl Command for DoRenew {
10    // TODO check expiration policies
11    fn execute(self, state: &mut State) -> Result<UndoOperation> {
12        let domain = state.domain_mut(&self.name)?;
13
14        let undo_operation =
15            UndoRenew { name: self.name, expires_at_height: domain.expires_at_height() };
16        domain.set_expires_at_height(self.expires_at_height);
17        Ok(UndoOperation::Renew(undo_operation))
18    }
19}
20
21#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)]
22#[serde(rename_all = "camelCase")]
23pub struct UndoRenew {
24    #[serde(with = "serde_str")]
25    name: DomainName,
26    expires_at_height: BlockHeight,
27}
28
29impl UndoCommand for UndoRenew {
30    fn execute(self, state: &mut State) -> Result<()> {
31        let domain = state.domain_mut(&self.name)?;
32        domain.set_expires_at_height(self.expires_at_height);
33        Ok(())
34    }
35}