1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
//! The `OpActivity` for v2, see description in the [`crate::flat_op_v2`] parent module.
use super::*;
use holochain_integrity_types::MigrationTarget;
/// Data specific to the
/// [`Op::RegisterAgentActivity`](holochain_integrity_types::op::Op::RegisterAgentActivity)
/// operation.
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum OpActivity<UnitType, LT> {
/// This operation registers the Action for an
/// app defined entry type to the author's chain.
CreateEntry {
/// The unit version of the app defined entry type. If this is [`None`] then the entry type
/// is defined in a different zome.
app_entry_type: Option<UnitType>,
/// The Create action that creates the entry
action: Action,
},
/// This operation registers the Action for an
/// app defined private entry type to the author's chain.
CreatePrivateEntry {
/// The unit version of the app defined entry type. If this is [`None`] then the entry type
/// is defined in a different zome.
app_entry_type: Option<UnitType>,
/// The Create action that creates the entry
action: Action,
},
/// This operation registers the Action for an
/// [`AgentPubKey`] to the author's chain.
CreateAgent {
/// The agent that was created
agent: AgentPubKey,
/// The Create action that creates the entry
action: Action,
},
/// This operation registers the Action for a
/// Capability Claim to the author's chain.
CreateCapClaim {
/// The Create action that creates the
/// [`CapClaim`](holochain_integrity_types::action::EntryType::CapClaim)
action: Action,
},
/// This operation registers the Action for a
/// Capability Grant to the author's chain.
CreateCapGrant {
/// The Create action that creates the
/// [`CapGrant`](holochain_integrity_types::action::EntryType::CapGrant)
action: Action,
},
/// This operation registers the Action for an
/// updated app defined entry type to the author's chain.
UpdateEntry {
/// The hash of the Action that created the original entry
original_action_hash: ActionHash,
/// The hash of the original entry
original_entry_hash: EntryHash,
/// The unit version of the app defined entry type. If this is [`None`] then the entry type
/// is defined in a different zome.
app_entry_type: Option<UnitType>,
/// The Update action that updates the entry
action: Action,
},
/// This operation registers the Action for an
/// updated app defined private entry type to the author's chain.
UpdatePrivateEntry {
/// The hash of the Action that created the original entry
original_action_hash: ActionHash,
/// The hash of the original entry
original_entry_hash: EntryHash,
/// The unit version of the app defined entry type.
/// If this is [`None`] then the entry type is defined in a different zome.
app_entry_type: Option<UnitType>,
/// The Update action that updates the entry
action: Action,
},
/// This operation registers the Action for an
/// updated [`AgentPubKey`] to the author's chain.
UpdateAgent {
/// The new [`AgentPubKey`].
new_key: AgentPubKey,
/// The original [`AgentPubKey`].
original_key: AgentPubKey,
/// The hash of the Action that created the original entry
original_action_hash: ActionHash,
/// The Update action that updates the agent's key
action: Action,
},
/// This operation registers the Action for an
/// updated Capability Claim to the author's chain.
UpdateCapClaim {
/// The hash of the Action that created the original
/// [`CapClaim`](holochain_integrity_types::action::EntryType::CapClaim)
original_action_hash: ActionHash,
/// The hash of the original
/// [`CapClaim`](holochain_integrity_types::action::EntryType::CapClaim)
original_entry_hash: EntryHash,
/// The Update action that updates the
/// [`CapClaim`](holochain_integrity_types::action::EntryType::CapClaim)
action: Action,
},
/// This operation registers the Action for an
/// updated Capability Grant to the author's chain.
UpdateCapGrant {
/// The hash of the Action that created the original
/// [`CapGrant`](holochain_integrity_types::action::EntryType::CapGrant)
original_action_hash: ActionHash,
/// The hash of the original
/// [`CapGrant`](holochain_integrity_types::action::EntryType::CapGrant)
original_entry_hash: EntryHash,
/// The Update action that updates the
/// [`CapGrant`](holochain_integrity_types::action::EntryType::CapGrant)
action: Action,
},
/// This operation registers the Action for a
/// deleted app defined entry type to the author's chain.
DeleteEntry {
/// The hash of the Action that created the original entry
original_action_hash: ActionHash,
/// The hash of the original entry
original_entry_hash: EntryHash,
/// The action that deletes the original entry
action: Action,
},
/// This operation registers the Action for a
/// new link to the author's chain.
CreateLink {
/// The base address of the link.
base_address: AnyLinkableHash,
/// The target address of the link.
target_address: AnyLinkableHash,
/// The link's tag.
tag: LinkTag,
/// The app defined link type of this link.
/// If this is [`None`] then the link type is defined in a different zome.
link_type: Option<LT>,
/// The action that creates this link
action: Action,
},
/// This operation registers the Action for a
/// deleted link to the author's chain and contains the original link's
/// Action hash.
DeleteLink {
/// The deleted link's CreateLink Action.
original_action_hash: ActionHash,
/// The base address where this link is stored.
/// This is the base address of the link that is being deleted.
base_address: AnyLinkableHash,
/// The DeleteLink action that deletes the link
action: Action,
},
/// This operation registers the Action for an
/// [`Action::Dna`](holochain_integrity_types::action::Action::Dna) to the author's chain.
Dna {
/// The hash of the DNA
dna_hash: DnaHash,
/// The Dna action
action: Action,
},
/// This operation registers the Action for an
/// [`Action::OpenChain`](holochain_integrity_types::action::Action::OpenChain) to the author's
/// chain and contains the previous chain's [`MigrationTarget`].
OpenChain {
/// Target for the previous chain that we are migrating from
previous_target: MigrationTarget,
/// Hash of the corresponding CloseChain.
close_hash: ActionHash,
/// The OpenChain action
action: Action,
},
/// This operation registers the Action for an
/// [`Action::CloseChain`](holochain_integrity_types::action::Action::CloseChain) to the
/// author's chain and contains the new chain's [`MigrationTarget`] if applicable.
CloseChain {
/// Target for the new chain that we are migrating to
new_target: Option<MigrationTarget>,
/// The CloseChain action
action: Action,
},
/// This operation registers the Action for an
/// [`Action::AgentValidationPkg`](holochain_integrity_types::action::Action::AgentValidationPkg)
/// to the author's chain and contains the membrane proof if there is one.
AgentValidationPkg {
/// The membrane proof proving that the agent is allowed to participate in this DNA
membrane_proof: Option<MembraneProof>,
/// The AgentValidationPkg action
action: Action,
},
/// This operation registers the Action for an
/// [`Action::InitZomesComplete`](holochain_integrity_types::action::Action::InitZomesComplete)
/// to the author's chain.
InitZomesComplete {
/// The InitZomesComplete action
action: Action,
},
}
impl<UnitType, LT> OpActivity<UnitType, LT> {
/// DRY constructor. `action.data` must be
/// [`ActionData::OpenChain`](holochain_integrity_types::dht_v2::ActionData::OpenChain).
pub(crate) fn open_chain(action: Action) -> Self {
let (previous_target, close_hash) = match &action.data {
holochain_integrity_types::dht_v2::ActionData::OpenChain(d) => {
(d.prev_target.clone(), d.close_hash.clone())
}
other => unreachable!("OpActivity::open_chain requires OpenChain data, got {other:?}"),
};
Self::OpenChain {
previous_target,
close_hash,
action,
}
}
/// DRY constructor. `action.data` must be
/// [`ActionData::CloseChain`](holochain_integrity_types::dht_v2::ActionData::CloseChain).
pub(crate) fn close_chain(action: Action) -> Self {
let new_target = match &action.data {
holochain_integrity_types::dht_v2::ActionData::CloseChain(d) => d.new_target.clone(),
other => {
unreachable!("OpActivity::close_chain requires CloseChain data, got {other:?}")
}
};
Self::CloseChain { new_target, action }
}
}
#[cfg(test)]
mod tests {
use super::*;
use holo_hash::{ActionHash, AgentPubKey, DnaHash};
use holochain_integrity_types::dht_v2::{
ActionData, ActionHeader, CloseChainData, OpenChainData,
};
fn action_from_data(data: ActionData) -> Action {
Action {
header: ActionHeader {
author: AgentPubKey::from_raw_36(vec![1u8; 36]),
timestamp: holochain_integrity_types::timestamp::Timestamp::from_micros(0),
action_seq: 0,
prev_action: None,
},
data,
}
}
#[test]
fn open_chain_constructor_extracts_fields() {
let target = MigrationTarget::Dna(DnaHash::from_raw_36(vec![5u8; 36]));
let close = ActionHash::from_raw_36(vec![6u8; 36]);
let action = action_from_data(ActionData::OpenChain(OpenChainData {
prev_target: target.clone(),
close_hash: close.clone(),
}));
let op = OpActivity::<(), ()>::open_chain(action);
match op {
OpActivity::OpenChain {
previous_target,
close_hash,
..
} => {
assert_eq!(previous_target, target);
assert_eq!(close_hash, close);
}
_ => panic!("expected OpenChain"),
}
}
#[test]
fn close_chain_constructor_extracts_target() {
let action = action_from_data(ActionData::CloseChain(CloseChainData { new_target: None }));
let op = OpActivity::<(), ()>::close_chain(action);
match op {
OpActivity::CloseChain { new_target, .. } => assert_eq!(new_target, None),
_ => panic!("expected CloseChain"),
}
}
}