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
use crate::hash_type;
use crate::HoloHash;
pub type AgentPubKey = HoloHash<hash_type::Agent>;
pub type DnaHash = HoloHash<hash_type::Dna>;
pub type DhtOpHash = HoloHash<hash_type::DhtOp>;
pub type EntryHash = HoloHash<hash_type::Entry>;
pub type ActionHash = HoloHash<hash_type::Action>;
pub type NetIdHash = HoloHash<hash_type::NetId>;
pub type WasmHash = HoloHash<hash_type::Wasm>;
pub type ExternalHash = HoloHash<hash_type::External>;
pub type AnyDhtHash = HoloHash<hash_type::AnyDht>;
pub type AnyLinkableHash = HoloHash<hash_type::AnyLinkable>;
pub enum AnyDhtHashPrimitive {
Entry(EntryHash),
Action(ActionHash),
}
pub enum AnyLinkableHashPrimitive {
Entry(EntryHash),
Action(ActionHash),
External(ExternalHash),
}
impl AnyLinkableHash {
pub fn into_primitive(self) -> AnyLinkableHashPrimitive {
match self.hash_type() {
hash_type::AnyLinkable::Entry => {
AnyLinkableHashPrimitive::Entry(self.retype(hash_type::Entry))
}
hash_type::AnyLinkable::Action => {
AnyLinkableHashPrimitive::Action(self.retype(hash_type::Action))
}
hash_type::AnyLinkable::External => {
AnyLinkableHashPrimitive::External(self.retype(hash_type::External))
}
}
}
pub fn into_entry_hash(self) -> Option<EntryHash> {
if *self.hash_type() == hash_type::AnyLinkable::Entry {
Some(self.retype(hash_type::Entry))
} else {
None
}
}
pub fn into_action_hash(self) -> Option<ActionHash> {
if *self.hash_type() == hash_type::AnyLinkable::Action {
Some(self.retype(hash_type::Action))
} else {
None
}
}
pub fn into_external_hash(self) -> Option<ExternalHash> {
if *self.hash_type() == hash_type::AnyLinkable::External {
Some(self.retype(hash_type::External))
} else {
None
}
}
}
impl AnyDhtHash {
pub fn into_primitive(self) -> AnyDhtHashPrimitive {
match self.hash_type() {
hash_type::AnyDht::Entry => AnyDhtHashPrimitive::Entry(self.retype(hash_type::Entry)),
hash_type::AnyDht::Action => {
AnyDhtHashPrimitive::Action(self.retype(hash_type::Action))
}
}
}
pub fn into_entry_hash(self) -> Option<EntryHash> {
if *self.hash_type() == hash_type::AnyDht::Entry {
Some(self.retype(hash_type::Entry))
} else {
None
}
}
pub fn into_action_hash(self) -> Option<ActionHash> {
if *self.hash_type() == hash_type::AnyDht::Action {
Some(self.retype(hash_type::Action))
} else {
None
}
}
}
impl From<AnyLinkableHash> for AnyDhtHash {
fn from(hash: AnyLinkableHash) -> Self {
hash.retype(hash_type::AnyDht::Entry)
}
}
impl From<ActionHash> for AnyDhtHash {
fn from(hash: ActionHash) -> Self {
hash.retype(hash_type::AnyDht::Action)
}
}
impl From<EntryHash> for AnyDhtHash {
fn from(hash: EntryHash) -> Self {
hash.retype(hash_type::AnyDht::Entry)
}
}
impl From<AgentPubKey> for AnyDhtHash {
fn from(hash: AgentPubKey) -> Self {
hash.retype(hash_type::AnyDht::Entry)
}
}
impl From<AnyDhtHash> for ActionHash {
fn from(hash: AnyDhtHash) -> Self {
hash.retype(hash_type::Action)
}
}
impl From<AnyDhtHash> for EntryHash {
fn from(hash: AnyDhtHash) -> Self {
hash.retype(hash_type::Entry)
}
}
impl From<ActionHash> for AnyLinkableHash {
fn from(hash: ActionHash) -> Self {
hash.retype(hash_type::AnyLinkable::Action)
}
}
impl From<EntryHash> for AnyLinkableHash {
fn from(hash: EntryHash) -> Self {
hash.retype(hash_type::AnyLinkable::Entry)
}
}
impl From<AgentPubKey> for AnyLinkableHash {
fn from(hash: AgentPubKey) -> Self {
hash.retype(hash_type::AnyLinkable::Entry)
}
}
impl From<ExternalHash> for AnyLinkableHash {
fn from(hash: ExternalHash) -> Self {
hash.retype(hash_type::AnyLinkable::External)
}
}
impl From<AnyLinkableHash> for ActionHash {
fn from(hash: AnyLinkableHash) -> Self {
hash.retype(hash_type::Action)
}
}
impl From<AnyLinkableHash> for EntryHash {
fn from(hash: AnyLinkableHash) -> Self {
hash.retype(hash_type::Entry)
}
}
impl From<AnyLinkableHash> for ExternalHash {
fn from(hash: AnyLinkableHash) -> Self {
hash.retype(hash_type::External)
}
}
#[cfg(feature = "serialization")]
use holochain_serialized_bytes::prelude::*;
#[cfg(feature = "serialization")]
#[derive(Debug, PartialEq, serde::Serialize, serde::Deserialize, SerializedBytes)]
#[repr(transparent)]
#[serde(transparent)]
pub struct EntryHashes(pub Vec<EntryHash>);