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
use crate::element::Element;
use crate::zome_io::ExternIO;
use crate::CallbackResult;
use holo_hash::AnyDhtHash;
use holochain_serialized_bytes::prelude::*;
#[derive(
Clone, Copy, Hash, serde::Serialize, serde::Deserialize, PartialOrd, Ord, Debug, Eq, PartialEq,
)]
#[cfg_attr(feature = "full", derive(num_enum::TryFromPrimitive))]
#[cfg_attr(feature = "full", repr(i32))]
pub enum ValidationStatus {
Valid = 0,
Rejected = 1,
Abandoned = 2,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, SerializedBytes)]
pub struct ValidateData {
pub element: Element,
pub validation_package: Option<ValidationPackage>,
}
impl ValidateData {
pub fn new(element: Element, validation_package: Option<ValidationPackage>) -> Self {
Self {
element,
validation_package,
}
}
pub fn new_element_only(element: Element) -> Self {
Self {
element,
validation_package: None,
}
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, SerializedBytes)]
pub enum ValidateCallbackResult {
Valid,
Invalid(String),
UnresolvedDependencies(Vec<AnyDhtHash>),
}
impl CallbackResult for ValidateCallbackResult {
fn is_definitive(&self) -> bool {
matches!(self, ValidateCallbackResult::Invalid(_))
}
}
impl From<ExternIO> for ValidateCallbackResult {
fn from(guest_output: ExternIO) -> Self {
match guest_output.decode() {
Ok(v) => v,
Err(e) => Self::Invalid(format!("{:?}", e)),
}
}
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, SerializedBytes)]
pub struct ValidationPackage(pub Vec<Element>);
#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)]
pub enum RequiredValidationType {
Element,
SubChain,
Full,
Custom,
}
#[derive(Clone, PartialEq, Serialize, Deserialize, SerializedBytes, Debug)]
pub enum ValidationPackageCallbackResult {
Success(ValidationPackage),
Fail(String),
UnresolvedDependencies(Vec<AnyDhtHash>),
}
impl From<ExternIO> for ValidationPackageCallbackResult {
fn from(guest_output: ExternIO) -> Self {
match guest_output.decode() {
Ok(v) => v,
Err(e) => ValidationPackageCallbackResult::Fail(format!("{:?}", e)),
}
}
}
impl CallbackResult for ValidationPackageCallbackResult {
fn is_definitive(&self) -> bool {
matches!(self, ValidationPackageCallbackResult::Fail(_))
}
}
impl Default for RequiredValidationType {
fn default() -> Self {
Self::Element
}
}
impl ValidationPackage {
pub fn new(elements: Vec<Element>) -> Self {
Self(elements)
}
}
#[cfg(feature = "full")]
impl rusqlite::ToSql for ValidationStatus {
fn to_sql(&self) -> rusqlite::Result<rusqlite::types::ToSqlOutput> {
Ok(rusqlite::types::ToSqlOutput::Owned((*self as i32).into()))
}
}
#[cfg(feature = "full")]
impl rusqlite::types::FromSql for ValidationStatus {
fn column_result(value: rusqlite::types::ValueRef<'_>) -> rusqlite::types::FromSqlResult<Self> {
i32::column_result(value).and_then(|int| {
Self::try_from(int).map_err(|_| rusqlite::types::FromSqlError::InvalidType)
})
}
}