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
use sda_protocol::*;
use SdaServerResult;
pub trait BaseStore : Sync + Send {
fn ping(&self) -> SdaServerResult<()>;
}
pub type AuthToken = Labelled<AgentId, String>;
pub trait AuthTokensStore: BaseStore {
fn upsert_auth_token(&self, token:&AuthToken) -> SdaServerResult<()>;
fn get_auth_token(&self, id:&AgentId) -> SdaServerResult<Option<AuthToken>>;
fn delete_auth_token(&self, id:&AgentId) -> SdaServerResult<()>;
}
pub trait AgentsStore: BaseStore {
fn create_agent(&self, agent: &Agent) -> SdaServerResult<()>;
fn get_agent(&self, id: &AgentId) -> SdaServerResult<Option<Agent>>;
fn upsert_profile(&self, profile: &Profile) -> SdaServerResult<()>;
fn get_profile(&self, owner: &AgentId) -> SdaServerResult<Option<Profile>>;
fn create_encryption_key(&self, key: &SignedEncryptionKey) -> SdaServerResult<()>;
fn get_encryption_key(&self, key: &EncryptionKeyId) -> SdaServerResult<Option<SignedEncryptionKey>>;
fn suggest_committee(&self) -> SdaServerResult<Vec<ClerkCandidate>>;
}
pub trait AggregationsStore: BaseStore {
fn list_aggregations(&self, filter: Option<&str>, recipient:Option<&AgentId>) -> SdaServerResult<Vec<AggregationId>>;
fn create_aggregation(&self, aggregation: &Aggregation) -> SdaServerResult<()>;
fn get_aggregation(&self, aggregation: &AggregationId) -> SdaServerResult<Option<Aggregation>>;
fn delete_aggregation(&self, aggregation: &AggregationId) -> SdaServerResult<()>;
fn get_committee(&self, owner: &AggregationId) -> SdaServerResult<Option<Committee>>;
fn create_committee(&self, committee: &Committee) -> SdaServerResult<()>;
fn create_participation(&self, participation: &Participation) -> SdaServerResult<()>;
fn create_snapshot(&self, snapshot: &Snapshot) -> SdaServerResult<()>;
fn list_snapshots(&self, aggregation: &AggregationId) -> SdaServerResult<Vec<SnapshotId>>;
fn get_snapshot(&self, aggregation: &AggregationId, snapshot: &SnapshotId) -> SdaServerResult<Option<Snapshot>>;
fn count_participations(&self, aggregation:&AggregationId) -> SdaServerResult<usize>;
fn snapshot_participations(&self, aggregation: &AggregationId, snapshot:&SnapshotId) -> SdaServerResult<()>;
fn iter_snapped_participations<'a, 'b>(&'b self, aggregation:&AggregationId, snapshot:&SnapshotId)
-> SdaServerResult<Box<Iterator<Item = SdaServerResult<Participation>> + 'a>>
where 'b: 'a;
fn count_participations_snapshot(&self, aggregation:&AggregationId, snapshot: &SnapshotId) -> SdaServerResult<usize> {
Ok(self.iter_snapped_participations(aggregation, snapshot)?.count())
}
fn iter_snapshot_clerk_jobs_data<'a, 'b> (&'b self, aggregation: &AggregationId, snapshot: &SnapshotId, clerks_number: usize)
-> SdaServerResult<Box<Iterator<Item = SdaServerResult<Vec<Encryption>>> + 'a>>
where 'b: 'a
{
let participations = self.count_participations_snapshot(aggregation, snapshot)?;
let mut shares: Vec<Vec<Encryption>> = (0..clerks_number)
.map(|_| Vec::with_capacity(participations))
.collect();
for participation in self.iter_snapped_participations(aggregation, snapshot)? {
for (ix, share) in participation?.clerk_encryptions.into_iter().enumerate() {
shares[ix].push(share.1);
}
}
Ok(Box::new(shares.into_iter().map(|data| Ok(data))))
}
fn create_snapshot_mask(&self, snapshot:&SnapshotId, mask:Vec<Encryption>) -> SdaServerResult<()>;
fn get_snapshot_mask(&self, snapshot:&SnapshotId) -> SdaServerResult<Option<Vec<Encryption>>>;
}
pub trait ClerkingJobsStore: BaseStore {
fn enqueue_clerking_job(&self, job:&ClerkingJob) -> SdaServerResult<()>;
fn poll_clerking_job(&self, clerk:&AgentId) -> SdaServerResult<Option<ClerkingJob>>;
fn get_clerking_job(&self, clerk:&AgentId, job:&ClerkingJobId) -> SdaServerResult<Option<ClerkingJob>>;
fn create_clerking_result(&self, result: &ClerkingResult) -> SdaServerResult<()>;
fn list_results(&self, snapshot: &SnapshotId) -> SdaServerResult<Vec<ClerkingJobId>>;
fn get_result(&self, snapshot: &SnapshotId, job:&ClerkingJobId) -> SdaServerResult<Option<ClerkingResult>>;
}