-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from filecoin-project/schema-update
adding v1 file schema
- Loading branch information
Showing
15 changed files
with
1,378 additions
and
1,306 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
use chrono::Utc; | ||
|
||
use super::file::{ | ||
Allocation, AllocationRequest, AllocationRequestType, Allocations, Notaries, Notary, | ||
}; | ||
|
||
impl Default for Notaries { | ||
fn default() -> Self { | ||
Self(vec![]) | ||
} | ||
} | ||
|
||
impl Notaries { | ||
pub fn add(&self, signer: Notary) -> Self { | ||
let mut res = self.0.clone(); | ||
res.push(signer); | ||
Self(res) | ||
} | ||
} | ||
|
||
impl AllocationRequest { | ||
pub fn new( | ||
actor: String, | ||
id: String, | ||
kind: AllocationRequestType, | ||
allocation_amount: String, | ||
) -> Self { | ||
Self { | ||
actor, | ||
id, | ||
kind, | ||
allocation_amount, | ||
is_active: true, | ||
} | ||
} | ||
} | ||
|
||
impl Allocation { | ||
pub fn new(request_information: AllocationRequest) -> Self { | ||
Self { | ||
id: request_information.id, | ||
request_type: request_information.kind, | ||
created_at: Utc::now().to_string(), | ||
updated_at: Utc::now().to_string(), | ||
is_active: true, | ||
amount: request_information.allocation_amount, | ||
signers: Notaries::default(), | ||
} | ||
} | ||
} | ||
|
||
impl Default for Allocations { | ||
fn default() -> Self { | ||
Self(vec![]) | ||
} | ||
} | ||
|
||
impl Allocations { | ||
pub fn init(request_information: AllocationRequest) -> Self { | ||
let allocation = Allocation::new(request_information); | ||
Self(vec![allocation]) | ||
} | ||
|
||
// should be changed to option | ||
pub fn find_one(&self, request_id: String) -> Option<Allocation> { | ||
let curr: Vec<Allocation> = self.0.clone(); | ||
let mut allocation: Option<Allocation> = None; | ||
for alloc in curr.iter() { | ||
if alloc.id == request_id { | ||
allocation = Some(alloc.clone()); | ||
break; | ||
} | ||
} | ||
allocation | ||
} | ||
|
||
// should be changed to option | ||
pub fn is_active(&self, request_id: String) -> bool { | ||
let curr: Vec<Allocation> = self.0.clone(); | ||
let mut is_active = false; | ||
for alloc in curr.iter() { | ||
if alloc.id == request_id { | ||
is_active = alloc.is_active; | ||
break; | ||
} | ||
} | ||
is_active | ||
} | ||
|
||
pub fn add_signer(&self, request_id: String, signer: Notary) -> Self { | ||
let mut res: Vec<Allocation> = self.0.clone(); | ||
for allocation in res.iter_mut() { | ||
if allocation.id == request_id && allocation.is_active { | ||
allocation.signers = allocation.signers.add(signer); | ||
break; | ||
} | ||
} | ||
Self(res) | ||
} | ||
|
||
pub fn add_signer_and_complete(&self, request_id: String, signer: Notary) -> Self { | ||
let mut res: Vec<Allocation> = self.0.clone(); | ||
for allocation in res.iter_mut() { | ||
if allocation.id == request_id && allocation.is_active { | ||
allocation.signers = allocation.signers.add(signer); | ||
allocation.is_active = false; | ||
break; | ||
} | ||
} | ||
Self(res) | ||
} | ||
|
||
pub fn complete_allocation(&self, request_id: String) -> Self { | ||
let mut res: Vec<Allocation> = self.0.clone(); | ||
for allocation in res.iter_mut() { | ||
if allocation.id == request_id && allocation.is_active { | ||
allocation.is_active = false; | ||
} | ||
} | ||
Self(res) | ||
} | ||
|
||
pub fn push(&mut self, request: AllocationRequest) -> Self { | ||
let allocation = Allocation::new(request); | ||
self.0.push(allocation); | ||
self.clone() | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
use super::file::Client; | ||
|
||
impl Client { | ||
fn new(i: Client) -> Self { | ||
Self { ..i } | ||
} | ||
|
||
fn validate(&self) -> bool { | ||
let Client { | ||
name, | ||
region, | ||
industry, | ||
website, | ||
social_media, | ||
role, | ||
} = self; | ||
name.len() > 0 | ||
&& region.len() > 0 | ||
&& industry.len() > 0 | ||
&& website.len() > 0 | ||
&& social_media.len() > 0 | ||
&& role.len() > 0 | ||
} | ||
} |
Oops, something went wrong.