1use crate::namespace::Namespace;
4use serde::{Deserialize, Serialize};
5use serde_json::Value;
6use std::{collections::HashSet, fmt::Display};
7
8#[cfg(feature = "openapi")]
9use utoipa::ToSchema;
10
11#[derive(Clone, Debug, Serialize, Deserialize)]
12#[cfg_attr(feature = "openapi", derive(ToSchema))]
13pub struct ProtocolsError {
14 pub evaluation: Option<String>,
15 pub validation: Option<String>,
16}
17
18#[derive(Clone, Debug, Serialize, Deserialize)]
19#[cfg_attr(feature = "openapi", derive(ToSchema))]
20pub struct PaginatorEvents {
21 pub paginator: Paginator,
22 pub events: Vec<EventInfo>,
23}
24
25#[derive(Clone, Debug, Serialize, Deserialize)]
26#[cfg_attr(feature = "openapi", derive(ToSchema))]
27pub struct CreateRequestInfo {
28 pub name: Option<String>,
29 pub description: Option<String>,
30 pub governance_id: String,
31 pub schema_id: String,
32 pub namespace: Namespace,
33}
34
35#[derive(Clone, Debug, Serialize, Deserialize)]
36#[cfg_attr(feature = "openapi", derive(ToSchema))]
37pub struct TransferRequestInfo {
38 pub subject_id: String,
39 pub new_owner: String,
40}
41
42#[derive(Clone, Debug, Serialize, Deserialize)]
43#[cfg_attr(feature = "openapi", derive(ToSchema))]
44pub struct ConfirmRequestInfo {
45 pub subject_id: String,
46 pub name_old_owner: Option<String>,
47}
48
49#[derive(Clone, Debug, Serialize, Deserialize)]
50#[cfg_attr(feature = "openapi", derive(ToSchema))]
51pub struct EOLRequestInfo {
52 pub subject_id: String,
53}
54
55#[derive(Clone, Debug, Serialize, Deserialize)]
56#[cfg_attr(feature = "openapi", derive(ToSchema))]
57pub struct FactRequestInfo {
58 pub subject_id: String,
59 pub payload: Value,
60}
61
62#[derive(Clone, Debug, Serialize, Deserialize)]
63#[cfg_attr(feature = "openapi", derive(ToSchema))]
64pub struct RejectRequestInfo {
65 pub subject_id: String,
66}
67
68#[derive(Clone, Debug, Serialize, Deserialize)]
69#[cfg_attr(feature = "openapi", derive(ToSchema))]
70pub enum EventRequestInfo {
71 Create(CreateRequestInfo),
72 Fact(FactRequestInfo),
73 Transfer(TransferRequestInfo),
74 Confirm(ConfirmRequestInfo),
75 EOL(EOLRequestInfo),
76 Reject(RejectRequestInfo),
77}
78
79#[derive(Clone, Debug, Serialize, Deserialize)]
80#[cfg_attr(feature = "openapi", derive(ToSchema))]
81pub struct EventInfo {
82 pub subject_id: String,
83 pub sn: u64,
84 pub patch: Option<Value>,
85 pub error: Option<ProtocolsError>,
86 pub event_req: EventRequestInfo,
87 pub succes: bool,
88}
89
90#[derive(Clone, Debug, Serialize, Deserialize)]
91#[cfg_attr(feature = "openapi", derive(ToSchema))]
92pub struct SignaturesDB {
93 pub subject_id: String,
94 pub sn: u64,
95 pub signatures_eval: Option<String>,
96 pub signatures_appr: Option<String>,
97 pub signatures_vali: String,
98}
99
100#[derive(Clone, Debug, Serialize, Deserialize)]
101#[cfg_attr(feature = "openapi", derive(ToSchema))]
102pub struct SignaturesInfo {
103 pub subject_id: String,
104 pub sn: u64,
105 pub signatures_eval: Option<HashSet<ProtocolsSignaturesInfo>>,
106 pub signatures_appr: Option<HashSet<ProtocolsSignaturesInfo>>,
107 pub signatures_vali: HashSet<ProtocolsSignaturesInfo>,
108}
109
110#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
111#[cfg_attr(feature = "openapi", derive(ToSchema))]
112pub enum ProtocolsSignaturesInfo {
113 Signature(SignatureInfo),
114 TimeOut(TimeOutResponseInfo),
115}
116
117#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
118#[cfg_attr(feature = "openapi", derive(ToSchema))]
119pub struct TimeOutResponseInfo {
120 pub who: String,
121 pub re_trys: u32,
122 pub timestamp: u64,
123}
124
125#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
126#[cfg_attr(feature = "openapi", derive(ToSchema))]
127pub struct SubjectDB {
128 pub name: Option<String>,
129 pub description: Option<String>,
130 pub subject_id: String,
131 pub governance_id: String,
132 pub genesis_gov_version: u64,
133 pub namespace: String,
134 pub schema_id: String,
135 pub owner: String,
136 pub creator: String,
137 pub active: String,
138 pub sn: u64,
139 pub properties: String,
140 pub new_owner: Option<String>,
141}
142
143#[derive(Clone, Debug, Serialize, Deserialize)]
144#[cfg_attr(feature = "openapi", derive(ToSchema))]
145pub struct SubjectInfo {
146 pub name: String,
147 pub description: String,
148 pub subject_id: String,
149 pub governance_id: String,
150 pub genesis_gov_version: u64,
151 pub namespace: String,
152 pub schema_id: String,
153 pub owner: String,
154 pub creator: String,
155 pub active: bool,
156 pub sn: u64,
157 pub properties: Value,
158 pub new_owner: Option<String>,
159}
160
161#[derive(Clone, Debug, Serialize, Deserialize)]
162#[cfg_attr(feature = "openapi", derive(ToSchema))]
163pub struct EventDB {
164 pub subject_id: String,
165 pub sn: u64,
166 pub patch: Option<String>,
167 pub error: Option<String>,
168 pub event_req: String,
169 pub succes: String,
170}
171
172#[derive(Clone, Debug, Serialize, Deserialize)]
173#[cfg_attr(feature = "openapi", derive(ToSchema))]
174pub struct Paginator {
175 pub pages: u64,
176 pub next: Option<u64>,
177 pub prev: Option<u64>,
178}
179
180#[derive(Clone, Debug, Serialize, Deserialize)]
181#[cfg_attr(feature = "openapi", derive(ToSchema))]
182pub struct RequestInfo {
183 pub state: RequestState,
184 pub version: u64,
185 pub error: Option<String>,
186}
187
188#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
189#[cfg_attr(feature = "openapi", derive(ToSchema))]
190pub enum RequestState {
191 Abort,
192 InQueue,
193 Invalid,
194 Finish,
195 Reboot,
196 Evaluation,
197 Approval,
198 Validation,
199 Distribution,
200}
201
202impl Display for RequestState {
203 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
204 match self {
205 RequestState::Abort => write!(f, "Abort"),
206 RequestState::InQueue => write!(f, "In Queue"),
207 RequestState::Invalid => write!(f, "Invalid"),
208 RequestState::Finish => write!(f, "Finish"),
209 RequestState::Reboot => write!(f, "Reboot"),
210 RequestState::Evaluation => write!(f, "Evaluation"),
211 RequestState::Approval => write!(f, "Approval"),
212 RequestState::Validation => write!(f, "Validation"),
213 RequestState::Distribution => write!(f, "Distribution"),
214 }
215 }
216}
217
218#[derive(Clone, Debug, Serialize, Deserialize)]
219#[cfg_attr(feature = "openapi", derive(ToSchema))]
220pub struct ApproveInfo {
221 pub state: String,
222 pub request: ApprovalReqInfo,
223}
224
225#[derive(Clone, Debug, Serialize, Deserialize)]
226#[cfg_attr(feature = "openapi", derive(ToSchema))]
227pub struct ApprovalReqInfo {
228 pub event_request: SignedInfo<FactInfo>,
230 pub sn: u64,
232 pub gov_version: u64,
234 pub patch: Value,
236 pub state_hash: String,
238 pub hash_prev_event: String,
240 pub subject_id: String,
242}
243
244#[derive(Clone, Debug, Serialize, Deserialize)]
245#[cfg_attr(feature = "openapi", derive(ToSchema))]
246pub struct FactInfo {
247 pub payload: Value,
248 pub subject_id: String,
249}
250
251#[derive(Clone, Debug, Serialize, Deserialize)]
252#[cfg_attr(feature = "openapi", derive(ToSchema))]
253pub struct SignedInfo<T: Serialize + Clone> {
254 pub content: T,
256 pub signature: SignatureInfo,
258}
259
260#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
261#[cfg_attr(feature = "openapi", derive(ToSchema))]
262pub struct SignatureInfo {
263 pub signer: String,
265 pub timestamp: u64,
267 pub content_hash: String,
269 pub value: String,
271}
272
273#[derive(Debug, Clone, Serialize, Deserialize)]
274#[cfg_attr(feature = "openapi", derive(ToSchema))]
275pub struct RequestData {
276 pub request_id: String,
277 pub subject_id: String,
278}
279
280#[derive(
281 Clone, Debug, Serialize, Deserialize, Ord, PartialEq, PartialOrd, Eq,
282)]
283#[cfg_attr(feature = "openapi", derive(ToSchema))]
284pub struct SubjsData {
285 pub subject_id: String,
286 pub schema_id: String,
287 pub active: bool,
288 pub name: Option<String>,
289 pub description: Option<String>,
290}
291
292#[derive(Clone, Debug, Serialize, Deserialize)]
293#[cfg_attr(feature = "openapi", derive(ToSchema))]
294pub struct GovsData {
295 pub governance_id: String,
296 pub active: bool,
297 pub name: Option<String>,
298 pub description: Option<String>,
299}
300
301#[derive(Clone, Debug, Serialize, Deserialize)]
302#[cfg_attr(feature = "openapi", derive(ToSchema))]
303pub struct TransferSubject {
304 pub name: String,
305 pub subject_id: String,
306 pub new_owner: String,
307 pub actual_owner: String,
308}