fplus_lib/core/application/
mod.rs1use self::file::{AllocationRequest, Allocations, LifeCycle, Notary};
2
3pub mod allocation;
4pub mod client;
5pub mod datacap;
6pub mod file;
7pub mod lifecycle;
8pub mod project;
9
10impl file::ApplicationFile {
11 pub async fn new(
12 issue_number: String,
13 multisig_address: String,
14 version: u8,
15 id: String,
16 client: file::Client,
17 project: file::Project,
18 datacap: file::Datacap,
19 ) -> Self {
20 let allocation = Allocations::default();
21 let lifecycle = LifeCycle::submitted(id.clone(), multisig_address.clone());
22 Self {
23 version,
24 issue_number,
25 id,
26 client,
27 project,
28 datacap,
29 lifecycle,
30 allocation,
31 }
32 }
33
34 pub fn reached_total_datacap(&self) -> Self {
35 let new_life_cycle = self.lifecycle.clone().reached_total_datacap();
36 Self {
37 lifecycle: new_life_cycle,
38 ..self.clone()
39 }
40 }
41
42 pub fn move_back_to_governance_review(&self) -> Self {
43 let new_life_cycle = self.lifecycle.clone().move_back_to_governance_review(); let allocation = Allocations::default(); Self {
46 lifecycle: new_life_cycle,
47 allocation,
48 ..self.clone()
49 }
50 }
51
52 pub fn complete_governance_review(&self, actor: String, request: AllocationRequest) -> Self {
53 let new_life_cycle = self
54 .lifecycle
55 .clone()
56 .finish_governance_review(actor, request.id.clone());
57 let allocations = Allocations::init(request.clone());
58 Self {
59 lifecycle: new_life_cycle,
60 allocation: allocations,
61 ..self.clone()
62 }
63 }
64
65 pub fn start_refill_request(&mut self, request: AllocationRequest) -> Self {
66 let new_life_cycle = self
67 .lifecycle
68 .clone()
69 .start_refill_request(request.id.clone());
70 let allocations = self.allocation.clone().push(request.clone());
71 Self {
72 lifecycle: new_life_cycle,
73 allocation: allocations,
74 ..self.clone()
75 }
76 }
77
78 pub fn add_signer_to_allocation(
79 &self,
80 signer: Notary,
81 request_id: String,
82 app_lifecycle: LifeCycle,
83 ) -> Self {
84 let new_allocation = self.allocation.clone().add_signer(request_id, signer);
85 Self {
86 allocation: new_allocation,
87 lifecycle: app_lifecycle,
88 ..self.clone()
89 }
90 }
91
92 pub fn add_signer_to_allocation_and_complete(
93 &self,
94 signer: Notary,
95 request_id: String,
96 app_lifecycle: LifeCycle,
97 ) -> Self {
98 let new_allocation = self
99 .allocation
100 .clone()
101 .add_signer_and_complete(request_id, signer);
102 Self {
103 allocation: new_allocation,
104 lifecycle: app_lifecycle,
105 ..self.clone()
106 }
107 }
108}
109
110impl std::str::FromStr for file::ApplicationFile {
111 type Err = serde_json::Error;
112 fn from_str(s: &str) -> Result<Self, Self::Err> {
113 serde_json::from_str(s)
114 }
115}