@@ -6,7 +6,7 @@ use crate::{
6
6
HexEncodedOpCert , HexEncodedVerificationKey , HexEncodedVerificationKeySignature , PartyId ,
7
7
Signer , SignerWithStake , Stake ,
8
8
} ,
9
- StdResult ,
9
+ StdError , StdResult ,
10
10
} ;
11
11
use anyhow:: Context ;
12
12
use serde:: { Deserialize , Serialize } ;
@@ -180,34 +180,10 @@ pub struct SignerMessagePart {
180
180
impl SignerMessagePart {
181
181
/// Convert a set of signer message parts into a set of signers
182
182
pub fn try_into_signers ( messages : Vec < Self > ) -> StdResult < Vec < Signer > > {
183
- let mut signers: Vec < Signer > = Vec :: new ( ) ;
184
-
185
- for message in messages {
186
- let verification_key_signature: Option < ProtocolSignerVerificationKeySignature > = message. verification_key_signature
187
- . map ( |f| f. try_into ( ) )
188
- . transpose ( )
189
- . with_context ( || format ! ( "Error while parsing verification key signature message, party_id = '{}'" , message. party_id) ) ?;
190
- let operational_certificate: Option < ProtocolOpCert > = message
191
- . operational_certificate
192
- . map ( |f| f. try_into ( ) )
193
- . transpose ( )
194
- . with_context ( || {
195
- format ! (
196
- "Error while parsing operational certificate message, party_id = '{}'." ,
197
- message. party_id
198
- )
199
- } ) ?;
200
- let value = Signer {
201
- party_id : message. party_id ,
202
- verification_key : message. verification_key . try_into ( ) ?,
203
- verification_key_signature,
204
- kes_period : message. kes_period ,
205
- operational_certificate,
206
- } ;
207
- signers. push ( value) ;
208
- }
209
-
210
- Ok ( signers)
183
+ messages
184
+ . into_iter ( )
185
+ . map ( |m| SignerMessagePart :: try_into ( m) )
186
+ . collect ( )
211
187
}
212
188
213
189
/// Convert a set of signers into message parts
@@ -231,6 +207,41 @@ impl SignerMessagePart {
231
207
}
232
208
}
233
209
210
+ impl TryInto < Signer > for SignerMessagePart {
211
+ type Error = StdError ;
212
+
213
+ fn try_into ( self ) -> Result < Signer , Self :: Error > {
214
+ let verification_key_signature: Option < ProtocolSignerVerificationKeySignature > = self
215
+ . verification_key_signature
216
+ . map ( |f| f. try_into ( ) )
217
+ . transpose ( )
218
+ . with_context ( || {
219
+ format ! (
220
+ "Error while parsing verification key signature message, party_id = '{}'" ,
221
+ self . party_id
222
+ )
223
+ } ) ?;
224
+ let operational_certificate: Option < ProtocolOpCert > = self
225
+ . operational_certificate
226
+ . map ( |f| f. try_into ( ) )
227
+ . transpose ( )
228
+ . with_context ( || {
229
+ format ! (
230
+ "Error while parsing operational certificate message, party_id = '{}'." ,
231
+ self . party_id
232
+ )
233
+ } ) ?;
234
+ let value = Signer {
235
+ party_id : self . party_id ,
236
+ verification_key : self . verification_key . try_into ( ) ?,
237
+ verification_key_signature,
238
+ kes_period : self . kes_period ,
239
+ operational_certificate,
240
+ } ;
241
+ Ok ( value)
242
+ }
243
+ }
244
+
234
245
impl From < Signer > for SignerMessagePart {
235
246
fn from ( value : Signer ) -> Self {
236
247
Self {
0 commit comments