1use crate::entry_def::EntryVisibility;
2use crate::link::LinkTag;
3use crate::link::LinkType;
4use crate::timestamp::Timestamp;
5use crate::EntryRateWeight;
6use crate::MembraneProof;
7use crate::RateWeight;
8use holo_hash::impl_hashable_content;
9use holo_hash::ActionHash;
10use holo_hash::AgentPubKey;
11use holo_hash::AnyLinkableHash;
12use holo_hash::DnaHash;
13use holo_hash::EntryHash;
14use holo_hash::HashableContent;
15use holo_hash::HoloHashed;
16use holochain_serialized_bytes::prelude::*;
17use std::borrow::Borrow;
18use std::fmt::{Display, Formatter};
19use std::hash::Hash;
20
21pub mod builder;
22pub mod conversions;
23
24pub const POST_GENESIS_SEQ_THRESHOLD: u32 = 3;
28
29#[allow(missing_docs)]
36#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, SerializedBytes, Hash)]
37#[cfg_attr(
38 feature = "fuzzing",
39 derive(arbitrary::Arbitrary, proptest_derive::Arbitrary)
40)]
41#[serde(tag = "type")]
42pub enum Action {
43 Dna(Dna),
45 AgentValidationPkg(AgentValidationPkg),
46 InitZomesComplete(InitZomesComplete),
47 CreateLink(CreateLink),
48 DeleteLink(DeleteLink),
49 CloseChain(CloseChain),
50 OpenChain(OpenChain),
51 Create(Create),
52 Update(Update),
53 Delete(Delete),
54}
55
56impl Display for Action {
58 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
59 match self {
60 Action::Dna(dna) =>
61 write!(f, "dna={:?}", dna),
62
63 Action::AgentValidationPkg(avp) =>
64 write!(
65 f,
66 "agent_validation_pkg=[author={}, timestamp={:?}]",
67 avp.author, avp.timestamp
68 ),
69
70 Action::InitZomesComplete(izc) =>
71 write!(
72 f,
73 "init_zomes_complete=[author={}, timestamp={:?}]",
74 izc.author, izc.timestamp
75 ),
76 Action::CreateLink(link) => write!(f, "create_link=[author={}, timestamp={:?}, base_address={}, target_address={}, zome_index={}, link_type={:?}]", link.author, link.timestamp, link.base_address, link.target_address, link.zome_index, link.link_type),
77 Action::DeleteLink(link) => write!(f, "delete_link=[author={}, timestamp={:?}]", link.author, link.timestamp),
78 Action::OpenChain(oc) => write!(
79 f,
80 "open_chain=[author={}, timestamp={:?}]",
81 oc.author, oc.timestamp
82 ),
83 Action::CloseChain(cc) => write!(
84 f,
85 "close_chain=[author={}, timestamp={:?}]",
86 cc.author, cc.timestamp
87 ),
88 Action::Create(create) => write!(f, "create=[author={}, timestamp={:?}, entry_type={:?}, entry_hash={}]", create.author, create.timestamp, create.entry_type, create.entry_hash),
89 Action::Update(update) => write!(f, "create=[author={}, timestamp={:?}, original_action_address={}, original_entry_address={}, entry_type={:?}, entry_hash={}]", update.author, update.timestamp, update.original_action_address, update.original_entry_address, update.entry_type, update.entry_hash),
90 Action::Delete(delete) => write!(f, "create=[author={}, timestamp={:?}, deletes_address={}, deletes_entry_address={}]", delete.author, delete.timestamp, delete.deletes_address, delete.deletes_entry_address),
91 }
92 }
93}
94
95#[derive(Clone, Debug, Serialize, PartialEq, Eq, Hash)]
96#[serde(tag = "type")]
97pub(crate) enum ActionRef<'a> {
101 Dna(&'a Dna),
102 AgentValidationPkg(&'a AgentValidationPkg),
103 InitZomesComplete(&'a InitZomesComplete),
104 CreateLink(&'a CreateLink),
105 DeleteLink(&'a DeleteLink),
106 OpenChain(&'a OpenChain),
107 CloseChain(&'a CloseChain),
108 Create(&'a Create),
109 Update(&'a Update),
110 Delete(&'a Delete),
111}
112
113pub type ActionHashed = HoloHashed<Action>;
114
115impl ActionHashedContainer for ActionHashed {
116 fn action(&self) -> &Action {
117 self.as_content()
118 }
119
120 fn action_hash(&self) -> &ActionHash {
121 &self.hash
122 }
123}
124
125impl ActionSequenceAndHash for ActionHashed {
126 fn action_seq(&self) -> u32 {
127 self.content.action_seq()
128 }
129
130 fn address(&self) -> &ActionHash {
131 &self.hash
132 }
133}
134
135macro_rules! write_into_action {
137 ($($n:ident $(<$w : ty>)?),*,) => {
138
139 #[derive(serde::Serialize, serde::Deserialize, SerializedBytes, PartialEq, Eq, Clone, Debug)]
142 #[cfg_attr(feature = "fuzzing", derive(arbitrary::Arbitrary, proptest_derive::Arbitrary))]
143 pub enum ActionType {
144 $($n,)*
145 }
146
147 impl std::fmt::Display for ActionType {
148 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
149 write!(
150 f,
151 "{}",
152 match self {
153 $( ActionType::$n => stringify!($n), )*
154 }
155 )
156 }
157 }
158
159 impl From<&Action> for ActionType {
160 fn from(action: &Action) -> ActionType {
161 match action {
162 $(
163 Action::$n(_) => ActionType::$n,
164 )*
165 }
166 }
167 }
168 };
169}
170
171pub trait ActionWeighed {
179 type Unweighed: ActionUnweighed;
180 type Weight: Default;
181
182 fn into_action(self) -> Action;
184
185 fn unweighed(self) -> Self::Unweighed;
190}
191
192pub trait ActionUnweighed: Sized {
200 type Weighed: ActionWeighed;
201 type Weight: Default;
202
203 fn weighed(self, weight: Self::Weight) -> Self::Weighed;
207
208 #[cfg(feature = "test_utils")]
210 fn weightless(self) -> Self::Weighed {
211 self.weighed(Default::default())
212 }
213}
214
215impl<I: ActionWeighed> From<I> for Action {
216 fn from(i: I) -> Self {
217 i.into_action()
218 }
219}
220
221write_into_action! {
222 Dna,
223 AgentValidationPkg,
224 InitZomesComplete,
225 OpenChain,
226 CloseChain,
227
228 Create<EntryRateWeight>,
229 Update<EntryRateWeight>,
230 Delete<RateWeight>,
231
232 CreateLink<RateWeight>,
233 DeleteLink,
234}
235
236macro_rules! match_action {
238 ($h:ident => |$i:ident| { $($t:tt)* }) => {
239 match $h {
240 Action::Dna($i) => { $($t)* }
241 Action::AgentValidationPkg($i) => { $($t)* }
242 Action::InitZomesComplete($i) => { $($t)* }
243 Action::CreateLink($i) => { $($t)* }
244 Action::DeleteLink($i) => { $($t)* }
245 Action::OpenChain($i) => { $($t)* }
246 Action::CloseChain($i) => { $($t)* }
247 Action::Create($i) => { $($t)* }
248 Action::Update($i) => { $($t)* }
249 Action::Delete($i) => { $($t)* }
250 }
251 };
252}
253
254impl Action {
255 pub fn entry_data(&self) -> Option<(&EntryHash, &EntryType)> {
259 match self {
260 Self::Create(Create {
261 entry_hash,
262 entry_type,
263 ..
264 }) => Some((entry_hash, entry_type)),
265 Self::Update(Update {
266 entry_hash,
267 entry_type,
268 ..
269 }) => Some((entry_hash, entry_type)),
270 _ => None,
271 }
272 }
273
274 pub fn into_entry_data(self) -> Option<(EntryHash, EntryType)> {
276 match self {
277 Self::Create(Create {
278 entry_hash,
279 entry_type,
280 ..
281 }) => Some((entry_hash, entry_type)),
282 Self::Update(Update {
283 entry_hash,
284 entry_type,
285 ..
286 }) => Some((entry_hash, entry_type)),
287 _ => None,
288 }
289 }
290
291 pub fn entry_visibility(&self) -> Option<&EntryVisibility> {
292 self.entry_data()
293 .map(|(_, entry_type)| entry_type.visibility())
294 }
295
296 pub fn entry_hash(&self) -> Option<&EntryHash> {
297 self.entry_data().map(|d| d.0)
298 }
299
300 pub fn entry_type(&self) -> Option<&EntryType> {
301 self.entry_data().map(|d| d.1)
302 }
303
304 pub fn action_type(&self) -> ActionType {
305 self.into()
306 }
307
308 pub fn author(&self) -> &AgentPubKey {
311 match_action!(self => |i| { &i.author })
312 }
313
314 pub fn signer(&self) -> &AgentPubKey {
317 match self {
318 Action::CloseChain(CloseChain {
325 new_target: Some(MigrationTarget::Agent(agent)),
326 ..
327 }) => agent,
328
329 _ => self.author(),
331 }
332 }
333
334 pub fn timestamp(&self) -> Timestamp {
336 match_action!(self => |i| { i.timestamp })
337 }
338
339 pub fn action_seq(&self) -> u32 {
341 match self {
342 Self::Dna(Dna { .. }) => 0,
344 Self::AgentValidationPkg(AgentValidationPkg { action_seq, .. })
345 | Self::InitZomesComplete(InitZomesComplete { action_seq, .. })
346 | Self::CreateLink(CreateLink { action_seq, .. })
347 | Self::DeleteLink(DeleteLink { action_seq, .. })
348 | Self::Delete(Delete { action_seq, .. })
349 | Self::CloseChain(CloseChain { action_seq, .. })
350 | Self::OpenChain(OpenChain { action_seq, .. })
351 | Self::Create(Create { action_seq, .. })
352 | Self::Update(Update { action_seq, .. }) => *action_seq,
353 }
354 }
355
356 pub fn prev_action(&self) -> Option<&ActionHash> {
358 Some(match self {
359 Self::Dna(Dna { .. }) => return None,
360 Self::AgentValidationPkg(AgentValidationPkg { prev_action, .. }) => prev_action,
361 Self::InitZomesComplete(InitZomesComplete { prev_action, .. }) => prev_action,
362 Self::CreateLink(CreateLink { prev_action, .. }) => prev_action,
363 Self::DeleteLink(DeleteLink { prev_action, .. }) => prev_action,
364 Self::Delete(Delete { prev_action, .. }) => prev_action,
365 Self::CloseChain(CloseChain { prev_action, .. }) => prev_action,
366 Self::OpenChain(OpenChain { prev_action, .. }) => prev_action,
367 Self::Create(Create { prev_action, .. }) => prev_action,
368 Self::Update(Update { prev_action, .. }) => prev_action,
369 })
370 }
371
372 pub fn prev_action_mut(&mut self) -> Option<&mut ActionHash> {
374 Some(match self {
375 Self::Dna(Dna { .. }) => return None,
376 Self::AgentValidationPkg(AgentValidationPkg { prev_action, .. }) => prev_action,
377 Self::InitZomesComplete(InitZomesComplete { prev_action, .. }) => prev_action,
378 Self::CreateLink(CreateLink { prev_action, .. }) => prev_action,
379 Self::DeleteLink(DeleteLink { prev_action, .. }) => prev_action,
380 Self::Delete(Delete { prev_action, .. }) => prev_action,
381 Self::CloseChain(CloseChain { prev_action, .. }) => prev_action,
382 Self::OpenChain(OpenChain { prev_action, .. }) => prev_action,
383 Self::Create(Create { prev_action, .. }) => prev_action,
384 Self::Update(Update { prev_action, .. }) => prev_action,
385 })
386 }
387
388 pub fn is_genesis(&self) -> bool {
389 self.action_seq() < POST_GENESIS_SEQ_THRESHOLD
390 }
391
392 pub fn rate_data(&self) -> RateWeight {
393 match self {
394 Self::CreateLink(CreateLink { weight, .. }) => weight.clone(),
395 Self::Delete(Delete { weight, .. }) => weight.clone(),
396 Self::Create(Create { weight, .. }) => weight.clone().into(),
397 Self::Update(Update { weight, .. }) => weight.clone().into(),
398
399 Self::Dna(Dna { .. })
401 | Self::AgentValidationPkg(AgentValidationPkg { .. })
402 | Self::InitZomesComplete(InitZomesComplete { .. })
403 | Self::DeleteLink(DeleteLink { .. })
404 | Self::CloseChain(CloseChain { .. })
405 | Self::OpenChain(OpenChain { .. }) => RateWeight::default(),
406 }
407 }
408
409 pub fn entry_rate_data(&self) -> Option<EntryRateWeight> {
410 match self {
411 Self::Create(Create { weight, .. }) => Some(weight.clone()),
412 Self::Update(Update { weight, .. }) => Some(weight.clone()),
413
414 Self::CreateLink(CreateLink { .. }) => None,
417 Self::Delete(Delete { .. }) => None,
418
419 Self::Dna(Dna { .. })
421 | Self::AgentValidationPkg(AgentValidationPkg { .. })
422 | Self::InitZomesComplete(InitZomesComplete { .. })
423 | Self::DeleteLink(DeleteLink { .. })
424 | Self::CloseChain(CloseChain { .. })
425 | Self::OpenChain(OpenChain { .. }) => Some(EntryRateWeight::default()),
426 }
427 }
428}
429
430impl_hashable_content!(Action, Action);
431
432macro_rules! impl_hashable_content_for_ref {
435 ($n: ident) => {
436 impl HashableContent for $n {
437 type HashType = holo_hash::hash_type::Action;
438
439 fn hash_type(&self) -> Self::HashType {
440 use holo_hash::PrimitiveHashType;
441 holo_hash::hash_type::Action::new()
442 }
443
444 fn hashable_content(&self) -> holo_hash::HashableContentBytes {
445 let h = ActionRef::$n(self);
446 let sb = SerializedBytes::from(UnsafeBytes::from(
447 holochain_serialized_bytes::encode(&h)
448 .expect("Could not serialize HashableContent"),
449 ));
450 holo_hash::HashableContentBytes::Content(sb)
451 }
452 }
453 };
454}
455
456impl_hashable_content_for_ref!(Dna);
457impl_hashable_content_for_ref!(AgentValidationPkg);
458impl_hashable_content_for_ref!(InitZomesComplete);
459impl_hashable_content_for_ref!(CreateLink);
460impl_hashable_content_for_ref!(DeleteLink);
461impl_hashable_content_for_ref!(CloseChain);
462impl_hashable_content_for_ref!(OpenChain);
463impl_hashable_content_for_ref!(Create);
464impl_hashable_content_for_ref!(Update);
465impl_hashable_content_for_ref!(Delete);
466
467#[derive(
471 Debug,
472 Copy,
473 Clone,
474 Hash,
475 PartialEq,
476 Eq,
477 PartialOrd,
478 Ord,
479 Serialize,
480 Deserialize,
481 SerializedBytes,
482)]
483#[cfg_attr(
484 feature = "fuzzing",
485 derive(arbitrary::Arbitrary, proptest_derive::Arbitrary)
486)]
487pub struct ZomeIndex(pub u8);
488
489impl ZomeIndex {
490 pub fn new(u: u8) -> Self {
491 Self(u)
492 }
493}
494
495#[derive(
496 Debug,
497 Copy,
498 Clone,
499 Hash,
500 PartialEq,
501 Eq,
502 PartialOrd,
503 Ord,
504 Serialize,
505 Deserialize,
506 SerializedBytes,
507)]
508#[cfg_attr(
509 feature = "fuzzing",
510 derive(arbitrary::Arbitrary, proptest_derive::Arbitrary)
511)]
512pub struct EntryDefIndex(pub u8);
513
514#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, SerializedBytes, Hash)]
516#[cfg_attr(
517 feature = "fuzzing",
518 derive(arbitrary::Arbitrary, proptest_derive::Arbitrary)
519)]
520pub struct Dna {
521 pub author: AgentPubKey,
522 pub timestamp: Timestamp,
523 pub hash: DnaHash,
525}
526
527#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, SerializedBytes, Hash)]
530#[cfg_attr(
531 feature = "fuzzing",
532 derive(arbitrary::Arbitrary, proptest_derive::Arbitrary)
533)]
534pub struct AgentValidationPkg {
535 pub author: AgentPubKey,
536 pub timestamp: Timestamp,
537 pub action_seq: u32,
538 pub prev_action: ActionHash,
539
540 pub membrane_proof: Option<MembraneProof>,
541}
542
543#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, SerializedBytes, Hash)]
546#[cfg_attr(
547 feature = "fuzzing",
548 derive(arbitrary::Arbitrary, proptest_derive::Arbitrary)
549)]
550pub struct InitZomesComplete {
551 pub author: AgentPubKey,
552 pub timestamp: Timestamp,
553 pub action_seq: u32,
554 pub prev_action: ActionHash,
555}
556
557#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, SerializedBytes, Hash)]
559#[cfg_attr(
560 feature = "fuzzing",
561 derive(arbitrary::Arbitrary, proptest_derive::Arbitrary)
562)]
563pub struct CreateLink<W = RateWeight> {
564 pub author: AgentPubKey,
565 pub timestamp: Timestamp,
566 pub action_seq: u32,
567 pub prev_action: ActionHash,
568
569 pub base_address: AnyLinkableHash,
570 pub target_address: AnyLinkableHash,
571 pub zome_index: ZomeIndex,
572 pub link_type: LinkType,
573 pub tag: LinkTag,
574
575 pub weight: W,
576}
577
578#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, SerializedBytes, Hash)]
580#[cfg_attr(
581 feature = "fuzzing",
582 derive(arbitrary::Arbitrary, proptest_derive::Arbitrary)
583)]
584pub struct DeleteLink {
585 pub author: AgentPubKey,
586 pub timestamp: Timestamp,
587 pub action_seq: u32,
588 pub prev_action: ActionHash,
589
590 pub base_address: AnyLinkableHash,
594 pub link_add_address: ActionHash,
596}
597
598#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, SerializedBytes, Hash)]
606#[cfg_attr(
607 feature = "fuzzing",
608 derive(arbitrary::Arbitrary, proptest_derive::Arbitrary)
609)]
610pub enum MigrationTarget {
611 Dna(DnaHash),
613 Agent(AgentPubKey),
615}
616
617impl From<DnaHash> for MigrationTarget {
618 fn from(dna: DnaHash) -> Self {
619 MigrationTarget::Dna(dna)
620 }
621}
622
623impl From<AgentPubKey> for MigrationTarget {
624 fn from(agent: AgentPubKey) -> Self {
625 MigrationTarget::Agent(agent)
626 }
627}
628
629#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, SerializedBytes, Hash)]
637#[cfg_attr(
638 feature = "fuzzing",
639 derive(arbitrary::Arbitrary, proptest_derive::Arbitrary)
640)]
641pub struct CloseChain {
642 pub author: AgentPubKey,
643 pub timestamp: Timestamp,
644 pub action_seq: u32,
645 pub prev_action: ActionHash,
646
647 pub new_target: Option<MigrationTarget>,
648}
649
650#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, SerializedBytes, Hash)]
653#[cfg_attr(
654 feature = "fuzzing",
655 derive(arbitrary::Arbitrary, proptest_derive::Arbitrary)
656)]
657pub struct OpenChain {
658 pub author: AgentPubKey,
659 pub timestamp: Timestamp,
660 pub action_seq: u32,
661 pub prev_action: ActionHash,
662
663 pub prev_target: MigrationTarget,
664 pub close_hash: ActionHash,
667}
668
669#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, SerializedBytes, Hash)]
672#[cfg_attr(
673 feature = "fuzzing",
674 derive(arbitrary::Arbitrary, proptest_derive::Arbitrary)
675)]
676pub struct Create<W = EntryRateWeight> {
677 pub author: AgentPubKey,
678 pub timestamp: Timestamp,
679 pub action_seq: u32,
680 pub prev_action: ActionHash,
681
682 pub entry_type: EntryType,
683 pub entry_hash: EntryHash,
684
685 pub weight: W,
686}
687
688#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, SerializedBytes, Hash)]
703#[cfg_attr(
704 feature = "fuzzing",
705 derive(arbitrary::Arbitrary, proptest_derive::Arbitrary)
706)]
707pub struct Update<W = EntryRateWeight> {
708 pub author: AgentPubKey,
709 pub timestamp: Timestamp,
710 pub action_seq: u32,
711 pub prev_action: ActionHash,
712
713 pub original_action_address: ActionHash,
714 pub original_entry_address: EntryHash,
715
716 pub entry_type: EntryType,
717 pub entry_hash: EntryHash,
718
719 pub weight: W,
720}
721
722#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, SerializedBytes, Hash)]
729#[cfg_attr(
730 feature = "fuzzing",
731 derive(arbitrary::Arbitrary, proptest_derive::Arbitrary)
732)]
733pub struct Delete<W = RateWeight> {
734 pub author: AgentPubKey,
735 pub timestamp: Timestamp,
736 pub action_seq: u32,
737 pub prev_action: ActionHash,
738
739 pub deletes_address: ActionHash,
741 pub deletes_entry_address: EntryHash,
742
743 pub weight: W,
744}
745
746#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, SerializedBytes, Hash)]
749#[cfg_attr(
750 feature = "fuzzing",
751 derive(arbitrary::Arbitrary, proptest_derive::Arbitrary)
752)]
753pub struct UpdateAction {
754 pub author: AgentPubKey,
755 pub timestamp: Timestamp,
756 pub action_seq: u32,
757 pub prev_action: ActionHash,
758
759 pub original_action_address: ActionHash,
760}
761
762#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, SerializedBytes, Hash)]
765#[cfg_attr(
766 feature = "fuzzing",
767 derive(arbitrary::Arbitrary, proptest_derive::Arbitrary)
768)]
769pub struct DeleteAction {
770 pub author: AgentPubKey,
771 pub timestamp: Timestamp,
772 pub action_seq: u32,
773 pub prev_action: ActionHash,
774
775 pub deletes_address: ActionHash,
777}
778
779#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, SerializedBytes, Hash)]
783#[cfg_attr(
784 feature = "fuzzing",
785 derive(arbitrary::Arbitrary, proptest_derive::Arbitrary)
786)]
787pub enum EntryType {
788 AgentPubKey,
790 App(AppEntryDef),
792 CapClaim,
794 CapGrant,
796}
797
798impl EntryType {
799 pub fn visibility(&self) -> &EntryVisibility {
800 match self {
801 EntryType::AgentPubKey => &EntryVisibility::Public,
802 EntryType::App(app_entry_def) => app_entry_def.visibility(),
803 EntryType::CapClaim => &EntryVisibility::Private,
804 EntryType::CapGrant => &EntryVisibility::Private,
805 }
806 }
807}
808
809impl std::fmt::Display for EntryType {
810 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
811 match self {
812 EntryType::AgentPubKey => write!(f, "AgentPubKey"),
813 EntryType::App(app_entry_def) => write!(
814 f,
815 "App({:?}, {:?})",
816 app_entry_def.entry_index(),
817 app_entry_def.visibility()
818 ),
819 EntryType::CapClaim => write!(f, "CapClaim"),
820 EntryType::CapGrant => write!(f, "CapGrant"),
821 }
822 }
823}
824
825#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, SerializedBytes, Hash)]
827#[cfg_attr(
828 feature = "fuzzing",
829 derive(arbitrary::Arbitrary, proptest_derive::Arbitrary)
830)]
831pub struct AppEntryDef {
832 pub entry_index: EntryDefIndex,
835 pub zome_index: ZomeIndex,
837 pub visibility: EntryVisibility,
840}
841
842impl AppEntryDef {
843 pub fn new(
844 entry_index: EntryDefIndex,
845 zome_index: ZomeIndex,
846 visibility: EntryVisibility,
847 ) -> Self {
848 Self {
849 entry_index,
850 zome_index,
851 visibility,
852 }
853 }
854
855 pub fn entry_index(&self) -> EntryDefIndex {
856 self.entry_index
857 }
858 pub fn zome_index(&self) -> ZomeIndex {
859 self.zome_index
860 }
861 pub fn visibility(&self) -> &EntryVisibility {
862 &self.visibility
863 }
864}
865
866impl From<EntryDefIndex> for u8 {
867 fn from(ei: EntryDefIndex) -> Self {
868 ei.0
869 }
870}
871
872impl ZomeIndex {
873 pub fn index(&self) -> usize {
875 self.0 as usize
876 }
877}
878
879impl std::ops::Deref for ZomeIndex {
880 type Target = u8;
881
882 fn deref(&self) -> &Self::Target {
883 &self.0
884 }
885}
886
887impl Borrow<u8> for ZomeIndex {
888 fn borrow(&self) -> &u8 {
889 &self.0
890 }
891}
892
893pub trait ActionHashedContainer: ActionSequenceAndHash {
894 fn action(&self) -> &Action;
895
896 fn action_hash(&self) -> &ActionHash;
897}
898
899pub trait ActionSequenceAndHash {
900 fn action_seq(&self) -> u32;
901 fn address(&self) -> &ActionHash;
902}
903
904impl ActionSequenceAndHash for (u32, ActionHash) {
905 fn action_seq(&self) -> u32 {
906 self.0
907 }
908
909 fn address(&self) -> &ActionHash {
910 &self.1
911 }
912}