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
use holo_hash::*;
use holochain_zome_types::prelude::*;
use crate::dht_op::error::DhtOpResult;
use crate::dht_op::DhtOpType;
use crate::dht_op::RenderedOp;
use crate::dht_op::RenderedOps;
use crate::header::WireDelete;
use crate::header::WireNewEntryHeader;
use crate::header::WireUpdateRelationship;
pub fn option_entry_hashed(entry: ElementEntry) -> Option<EntryHashed> {
match entry {
ElementEntry::Present(e) => Some(EntryHashed::from_content_sync(e)),
_ => None,
}
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, SerializedBytes, Default)]
pub struct WireEntryOps {
pub creates: Vec<Judged<WireNewEntryHeader>>,
pub deletes: Vec<Judged<WireDelete>>,
pub updates: Vec<Judged<WireUpdateRelationship>>,
pub entry: Option<EntryData>,
}
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize, SerializedBytes)]
pub struct EntryData {
pub entry: Entry,
pub entry_type: EntryType,
}
impl WireEntryOps {
pub fn new() -> Self {
Self::default()
}
pub fn render(self) -> DhtOpResult<RenderedOps> {
let Self {
creates,
deletes,
updates,
entry,
} = self;
match entry {
Some(EntryData { entry, entry_type }) => {
let mut ops = Vec::with_capacity(creates.len() + deletes.len() + updates.len());
let entry_hashed = EntryHashed::from_content_sync(entry);
for op in creates {
let status = op.validation_status();
let SignedHeader(header, signature) = op
.data
.into_signed_header(entry_type.clone(), entry_hashed.as_hash().clone());
ops.push(RenderedOp::new(
header,
signature,
status,
DhtOpType::StoreEntry,
)?);
}
for op in deletes {
let status = op.validation_status();
let op = op.data;
let signature = op.signature;
let header = Header::Delete(op.delete);
ops.push(RenderedOp::new(
header,
signature,
status,
DhtOpType::RegisterDeletedEntryHeader,
)?);
}
for op in updates {
let status = op.validation_status();
let SignedHeader(header, signature) =
op.data.into_signed_header(entry_hashed.as_hash().clone());
ops.push(RenderedOp::new(
header,
signature,
status,
DhtOpType::RegisterUpdatedContent,
)?);
}
Ok(RenderedOps {
entry: Some(entry_hashed),
ops,
})
}
None => Ok(Default::default()),
}
}
}