iop_coeus_node/operations/
update.rs1use super::*;
2
3impl AuthorizedCommand for DoUpdate {
4 fn validate_auth(&self, state: &State, pk: &MPublicKey) -> Result<()> {
5 state.validate_domain_owner(&self.name, pk)
6 }
7}
8
9impl Command for DoUpdate {
10 fn execute(self, state: &mut State) -> Result<UndoOperation> {
11 let last_block = state.last_seen_height();
12
13 let domain_mut = state.domain_mut(&self.name)?;
14 ensure!(!domain_mut.is_expired_at(last_block), "Domain {} expired", self.name);
15
16 let mut undo_operation = UndoUpdate { name: self.name, data: self.data };
17 std::mem::swap(&mut undo_operation.data, domain_mut.data_mut());
18
19 match state.validate_subtree_policies(&undo_operation.name) {
20 Ok(()) => Ok(UndoOperation::Update(undo_operation)),
21 Err(e) => {
22 undo_operation.execute(state)?;
23 Err(e)
24 }
25 }
26 }
27}
28
29#[derive(Debug, Clone, Serialize, Deserialize, Eq, PartialEq)]
30#[serde(rename_all = "camelCase")]
31pub struct UndoUpdate {
32 #[serde(with = "serde_str")]
33 name: DomainName,
34 data: DynamicContent,
35}
36
37impl UndoCommand for UndoUpdate {
38 fn execute(self, state: &mut State) -> Result<()> {
39 let domain = state.domain_mut(&self.name)?;
40 domain.set_data(self.data);
41 Ok(())
42 }
43}