1
- use mithril_common:: entities:: { Epoch , ProtocolMessage , SignedEntityType , SingleSignatures } ;
1
+ use chrono:: NaiveDateTime ;
2
+ use mithril_common:: entities:: {
3
+ Epoch , PartyId , ProtocolMessage , SignedEntityType , SingleSignatures ,
4
+ } ;
2
5
3
6
use crate :: database:: provider:: { OpenMessageRecord , OpenMessageWithSingleSignaturesRecord } ;
4
7
@@ -9,9 +12,6 @@ use crate::database::provider::{OpenMessageRecord, OpenMessageWithSingleSignatur
9
12
/// generated if possible.
10
13
#[ derive( Debug , Clone , PartialEq ) ]
11
14
pub struct OpenMessage {
12
- /// OpenMessage unique identifier
13
- // pub open_message_id: Uuid, // do we need it in the entity ?
14
-
15
15
/// Epoch
16
16
pub epoch : Epoch ,
17
17
@@ -26,9 +26,20 @@ pub struct OpenMessage {
26
26
27
27
/// associated single signatures
28
28
pub single_signatures : Vec < SingleSignatures > ,
29
+
30
+ /// Message creation datetime
31
+ pub created_at : NaiveDateTime ,
29
32
}
30
33
31
34
impl OpenMessage {
35
+ /// Gather all signers party_id for this open message
36
+ pub fn get_signers_id ( & self ) -> Vec < PartyId > {
37
+ self . single_signatures
38
+ . iter ( )
39
+ . map ( |sig| sig. party_id . to_owned ( ) )
40
+ . collect ( )
41
+ }
42
+
32
43
#[ cfg( test) ]
33
44
/// Create a dumb OpenMessage instance mainly for test purposes
34
45
pub fn dummy ( ) -> Self {
@@ -47,6 +58,7 @@ impl OpenMessage {
47
58
fake_data:: single_signatures( vec![ 1 , 4 , 5 ] ) ,
48
59
fake_data:: single_signatures( vec![ 2 , 3 , 8 ] ) ,
49
60
] ,
61
+ created_at : chrono:: Local :: now ( ) . naive_local ( ) ,
50
62
}
51
63
}
52
64
}
@@ -59,6 +71,7 @@ impl From<OpenMessageRecord> for OpenMessage {
59
71
protocol_message : record. protocol_message ,
60
72
is_certified : record. is_certified ,
61
73
single_signatures : vec ! [ ] ,
74
+ created_at : record. created_at ,
62
75
}
63
76
}
64
77
}
@@ -71,6 +84,7 @@ impl From<OpenMessageWithSingleSignaturesRecord> for OpenMessage {
71
84
protocol_message : record. protocol_message ,
72
85
is_certified : record. is_certified ,
73
86
single_signatures : record. single_signatures ,
87
+ created_at : record. created_at ,
74
88
}
75
89
}
76
90
}
@@ -89,20 +103,22 @@ mod test {
89
103
90
104
#[ test]
91
105
fn test_from_record ( ) {
106
+ let created_at = chrono:: Local :: now ( ) . naive_local ( ) ;
92
107
let record = OpenMessageRecord {
93
108
open_message_id : Uuid :: new_v4 ( ) ,
94
109
epoch : Epoch ( 1 ) ,
95
110
signed_entity_type : SignedEntityType :: dummy ( ) ,
96
111
protocol_message : ProtocolMessage :: default ( ) ,
97
112
is_certified : false ,
98
- created_at : chrono :: Local :: now ( ) . naive_local ( ) ,
113
+ created_at,
99
114
} ;
100
115
let expected = OpenMessage {
101
116
epoch : Epoch ( 1 ) ,
102
117
signed_entity_type : SignedEntityType :: dummy ( ) ,
103
118
protocol_message : ProtocolMessage :: default ( ) ,
104
119
is_certified : false ,
105
120
single_signatures : vec ! [ ] ,
121
+ created_at,
106
122
} ;
107
123
let result: OpenMessage = record. into ( ) ;
108
124
@@ -111,13 +127,14 @@ mod test {
111
127
112
128
#[ test]
113
129
fn test_from_record_with_single_signatures ( ) {
130
+ let created_at = chrono:: Local :: now ( ) . naive_local ( ) ;
114
131
let record = OpenMessageWithSingleSignaturesRecord {
115
132
open_message_id : Uuid :: new_v4 ( ) ,
116
133
epoch : Epoch ( 1 ) ,
117
134
signed_entity_type : SignedEntityType :: dummy ( ) ,
118
135
protocol_message : ProtocolMessage :: default ( ) ,
119
136
is_certified : false ,
120
- created_at : chrono :: Local :: now ( ) . naive_local ( ) ,
137
+ created_at,
121
138
single_signatures : vec ! [ fake_data:: single_signatures( vec![ 1 , 4 , 5 ] ) ] ,
122
139
} ;
123
140
let expected = OpenMessage {
@@ -126,6 +143,7 @@ mod test {
126
143
protocol_message : ProtocolMessage :: default ( ) ,
127
144
is_certified : false ,
128
145
single_signatures : vec ! [ fake_data:: single_signatures( vec![ 1 , 4 , 5 ] ) ] ,
146
+ created_at,
129
147
} ;
130
148
let result: OpenMessage = record. into ( ) ;
131
149
0 commit comments