1use std::str::FromStr;
2
3use serde::{Deserialize, Serialize};
4
5#[derive(Serialize, Deserialize, Debug, Clone)]
6pub enum DatacapGroup {
7 #[serde(rename = "da")]
8 DA,
9 #[serde(rename = "ldn-v3")]
10 LDN,
11 #[serde(rename = "e-fil")]
12 EFIL,
13}
14
15impl FromStr for DatacapGroup {
16 type Err = String;
17
18 fn from_str(s: &str) -> Result<Self, Self::Err> {
19 match s {
20 "da" => Ok(Self::DA),
21 "ldn-v3" => Ok(Self::LDN),
22 "e-fil" => Ok(Self::EFIL),
23 _ => Err(format!("{} is not a valid datacap group", s)),
24 }
25 }
26}
27
28#[derive(Serialize, Deserialize, Debug, Clone)]
29pub struct ApplicationFile {
30 #[serde(rename = "Version")]
31 pub version: u8,
32 #[serde(rename = "ID")]
33 pub id: String,
34 #[serde(rename = "Issue Number")]
35 pub issue_number: String,
36 #[serde(rename = "Client")]
37 pub client: Client,
38 #[serde(rename = "Project")]
39 pub project: Project,
40 #[serde(rename = "Datacap")]
41 pub datacap: Datacap,
42 #[serde(rename = "Lifecycle")]
43 pub lifecycle: LifeCycle,
44 #[serde(rename = "Allocation Requests")]
45 pub allocation: Allocations,
46}
47
48#[derive(Serialize, Deserialize, Debug, Clone, Default)]
49pub struct Client {
50 #[serde(rename = "Name")]
51 pub name: String,
52 #[serde(rename = "Region")]
53 pub region: String,
54 #[serde(rename = "Industry")]
55 pub industry: String,
56 #[serde(rename = "Website")]
57 pub website: String,
58 #[serde(rename = "Social Media")]
59 pub social_media: String,
60 #[serde(rename = "Social Media Type")]
61 pub social_media_type: String,
62 #[serde(rename = "Role")]
63 pub role: String,
64}
65
66#[derive(Serialize, Deserialize, Debug, Clone)]
67pub struct Datacap {
68 #[serde(rename = "Type")]
69 pub _group: DatacapGroup,
70 #[serde(rename = "Data Type")]
71 pub data_type: DataType,
72 #[serde(rename = "Total Requested Amount")]
73 pub total_requested_amount: String,
74 #[serde(rename = "Single Size Dataset")]
75 pub single_size_dataset: String,
76 #[serde(rename = "Replicas")]
77 pub replicas: u8,
78 #[serde(rename = "Weekly Allocation")]
79 pub weekly_allocation: String,
80}
81
82impl Default for Datacap {
83 fn default() -> Self {
84 Self {
85 _group: DatacapGroup::LDN,
86 data_type: DataType::Slingshot,
87 total_requested_amount: "0".to_string(),
88 single_size_dataset: "0".to_string(),
89 replicas: 0,
90 weekly_allocation: "0".to_string(),
91 }
92 }
93}
94
95#[derive(Serialize, Deserialize, Debug, Clone)]
96pub enum DataType {
97 #[serde(rename = "Slingshot")]
98 Slingshot,
99 #[serde(rename = "Public, Open Dataset (Research/Non-Profit)")]
100 PublicOpenDatasetResearchNonProfit,
101 #[serde(rename = "Public, Open Commercial/Enterprise")]
102 PublicOpenCommercialEnterprise,
103 #[serde(rename = "Private Commercial/Enterprise")]
104 PrivateCommercialEnterprise,
105 #[serde(rename = "Private Non-Profit / Social impact")]
106 PrivateNonProfitSocialImpact,
107}
108
109impl FromStr for DataType {
110 type Err = String;
111 fn from_str(s: &str) -> Result<Self, Self::Err> {
112 match s {
113 "Slingshot" => Ok(Self::Slingshot),
114 "Public, Open Dataset (Research/Non-Profit)" => {
115 Ok(Self::PublicOpenDatasetResearchNonProfit)
116 }
117 "Public, Open Commercial/Enterprise" => Ok(Self::PublicOpenCommercialEnterprise),
118 "Private Commercial/Enterprise" => Ok(Self::PrivateCommercialEnterprise),
119 "Private Non-Profit / Social impact" => Ok(Self::PrivateNonProfitSocialImpact),
120 _ => Err(format!("{} is not a valid data type", s)),
121 }
122 }
123}
124
125#[derive(Serialize, Deserialize, Debug, Clone)]
126pub enum AssociatedProjects {
127 Yes(String),
128 No,
129}
130
131#[derive(Serialize, Deserialize, Debug, Clone)]
132pub enum PublicDataset {
133 Yes,
134 No(String),
135}
136
137#[derive(Serialize, Deserialize, Debug, Clone)]
138pub enum RetrivalFrequency {
139 Daily,
140 Weekly,
141 Monthly,
142 Yearly,
143 Sporadic,
144 Never,
145}
146
147#[derive(Serialize, Deserialize, Debug, Clone)]
148pub enum StorageModularity {
149 IPFS,
150 Lotus,
151 Singularity,
152 Graphsplit,
153 Other(String),
154}
155
156#[derive(Serialize, Deserialize, Debug, Clone)]
157pub enum StorageProviders {
158 AWSCloud,
159 GoogleCloud,
160 AzureCloud,
161 InternalStorage,
162 Other(String),
163}
164
165#[derive(Serialize, Deserialize, Debug, Clone, Default)]
166pub struct Project {
167 #[serde(rename = "Project Id")]
168 pub project_id: String,
169 #[serde(rename = "Brief history of your project and organization")]
170 pub history: String,
171 #[serde(rename = "Is this project associated with other projects/ecosystem stakeholders?")]
172 pub associated_projects: String,
173 #[serde(rename = "Describe the data being stored onto Filecoin")]
174 pub stored_data_desc: String,
175 #[serde(rename = "Where was the data currently stored in this dataset sourced from} ")]
176 pub previous_stoarge: String,
177 #[serde(rename = "How do you plan to prepare the dataset")]
178 pub dataset_prepare: String,
179 #[serde(
180 rename = "Please share a sample of the data (a link to a file, an image, a table, etc., are good ways to do this.)"
181 )]
182 pub data_sample_link: String,
183 #[serde(
184 rename = "Confirm that this is a public dataset that can be retrieved by anyone on the network (i.e., no specific permissions or access rights are required to view the data)"
185 )]
186 pub public_dataset: String,
187 #[serde(rename = "What is the expected retrieval frequency for this data")]
188 pub retrival_frequency: String,
189 #[serde(rename = "For how long do you plan to keep this dataset stored on Filecoin")]
190 pub dataset_life_span: String,
191 #[serde(rename = "In which geographies do you plan on making storage deals")]
192 pub geographis: String,
193 #[serde(rename = "How will you be distributing your data to storage providers")]
194 pub distribution: String,
195 #[serde(
196 rename = "Please list the provider IDs and location of the storage providers you will be working with. Note that it is a requirement to list a minimum of 5 unique provider IDs, and that your client address will be verified against this list in the future"
197 )]
198 pub providers: String,
199 #[serde(
200 rename = "Can you confirm that you will follow the Fil+ guideline (Data owner should engage at least 4 SPs and no single SP ID should receive >30% of a client's allocated DataCap)"
201 )]
202 pub filplus_guideline: String,
203}
204
205#[derive(Serialize, Deserialize, Debug, Clone)]
206pub enum DatasetLifeSpan {
207 LessThanAYear,
208 OneToOneAndHalfYears,
209 OneAndHalfToTwoYears,
210 TwoToThreeYears,
211 MoreThanThreeYears,
212 Permanently,
213}
214
215#[derive(Serialize, Deserialize, Debug, Clone)]
216pub struct Provider {
217 #[serde(rename = "ID")]
218 pub id: String,
219 #[serde(rename = "Location")]
220 pub location: String,
221 #[serde(rename = "SPOrg")]
222 pub spo_org: String,
223}
224
225#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq, PartialOrd)]
226pub enum AppState {
227 Submitted,
228 ReadyToSign,
229 StartSignDatacap,
230 Granted,
231 TotalDatacapReached,
232 Error,
233}
234
235#[derive(Serialize, Deserialize, Debug, Clone)]
236pub struct LifeCycle {
237 #[serde(rename = "State")]
238 pub state: AppState,
239 #[serde(rename = "Validated At")]
240 pub validated_at: String,
241 #[serde(rename = "Validated By")]
242 pub validated_by: String,
243 #[serde(rename = "Active")]
244 pub is_active: bool,
245 #[serde(rename = "Updated At")]
246 pub updated_at: String,
247 #[serde(rename = "Active Request ID")]
248 pub active_request: Option<String>,
249 #[serde(rename = "On Chain Address")]
250 pub client_on_chain_address: String,
251 #[serde(rename = "Multisig Address")]
252 pub multisig_address: String,
253}
254
255#[derive(Serialize, Deserialize, Debug, Clone)]
256pub struct Allocations(pub Vec<Allocation>);
257
258#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
259pub enum AllocationRequestType {
260 First,
261 Removal,
262 Refill(u8),
263}
264
265impl ToString for AllocationRequestType {
266 fn to_string(&self) -> String {
267 match self {
268 AllocationRequestType::First => "First".to_string(),
269 AllocationRequestType::Removal => "Removal".to_string(),
270 AllocationRequestType::Refill(_) => "Refill".to_string(),
271 }
272 }
273}
274
275#[derive(Serialize, Deserialize, Debug, Clone)]
276pub struct Allocation {
277 #[serde(rename = "ID")]
278 pub id: String,
279 #[serde(rename = "Request Type")]
280 pub request_type: String,
281 #[serde(rename = "Created At")]
282 pub created_at: String,
283 #[serde(rename = "Updated At")]
284 pub updated_at: String,
285 #[serde(rename = "Active")]
286 pub is_active: bool,
287 #[serde(rename = "Allocation Amount")]
288 pub amount: String,
289 #[serde(rename = "Signers")]
290 pub signers: Notaries,
291}
292
293#[derive(Serialize, Deserialize, Debug, Clone)]
294pub struct Notaries(pub Vec<Notary>);
295
296#[derive(Serialize, Deserialize, Debug, Clone)]
297pub struct NotaryInput {
298 pub github_username: String,
299 pub signing_address: String,
300 pub created_at: String,
301 pub message_cid: String,
302}
303
304impl From<NotaryInput> for Notary {
305 fn from(input: NotaryInput) -> Self {
306 Self {
307 github_username: input.github_username,
308 signing_address: input.signing_address,
309 created_at: input.created_at,
310 message_cid: input.message_cid,
311 }
312 }
313}
314
315#[derive(Serialize, Deserialize, Debug, Clone)]
316pub struct Notary {
317 #[serde(rename = "Github Username")]
318 pub github_username: String,
319 #[serde(rename = "Signing Address")]
320 pub signing_address: String,
321 #[serde(rename = "Created At")]
322 pub created_at: String,
323 #[serde(rename = "Message CID")]
324 pub message_cid: String,
325}
326
327#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)]
328pub struct AllocationRequest {
329 pub actor: String,
330 pub id: String,
331 pub kind: AllocationRequestType,
332 pub is_active: bool,
333 pub allocation_amount: String,
334}
335
336#[derive(Serialize, Deserialize, Debug, Clone)]
337pub struct ValidNotaryList {
338 notaries: Vec<String>,
339}
340
341impl ValidNotaryList {
342 pub fn is_valid(&self, notary: &str) -> bool {
343 self.notaries.contains(¬ary.to_string())
344 }
345}
346
347#[derive(Serialize, Deserialize, Debug, Clone)]
348pub struct ValidRKHList {
349 rkh: Vec<String>,
350}
351
352impl ValidRKHList {
353 pub fn is_valid(&self, rkh: &str) -> bool {
354 self.rkh.contains(&rkh.to_string())
355 }
356}