@@ -70,35 +70,46 @@ impl SignerWithStakeMessagePart {
70
70
71
71
/// Convert a set of signer message parts into a set of signers with stake
72
72
pub fn try_into_signers ( messages : Vec < Self > ) -> StdResult < Vec < SignerWithStake > > {
73
- let mut signers: Vec < SignerWithStake > = Vec :: new ( ) ;
73
+ messages
74
+ . into_iter ( )
75
+ . map ( SignerWithStakeMessagePart :: try_into)
76
+ . collect ( )
77
+ }
78
+ }
74
79
75
- for message in messages {
76
- let verification_key_signature: Option < ProtocolSignerVerificationKeySignature > = message. verification_key_signature
77
- . map ( |f| f. try_into ( ) )
78
- . transpose ( )
79
- . with_context ( || format ! ( "Error while parsing verification key signature message, party_id = '{}'" , message. party_id) ) ?;
80
- let operational_certificate: Option < ProtocolOpCert > = message
81
- . operational_certificate
82
- . map ( |f| f. try_into ( ) )
83
- . transpose ( )
84
- . with_context ( || {
85
- format ! (
86
- "Error while parsing operational certificate message, party_id = '{}'." ,
87
- message. party_id
88
- )
89
- } ) ?;
90
- let value = SignerWithStake {
91
- party_id : message. party_id ,
92
- verification_key : message. verification_key . try_into ( ) ?,
93
- verification_key_signature,
94
- kes_period : message. kes_period ,
95
- operational_certificate,
96
- stake : message. stake ,
97
- } ;
98
- signers. push ( value) ;
99
- }
80
+ impl TryInto < SignerWithStake > for SignerWithStakeMessagePart {
81
+ type Error = StdError ;
100
82
101
- Ok ( signers)
83
+ fn try_into ( self ) -> Result < SignerWithStake , Self :: Error > {
84
+ let verification_key_signature: Option < ProtocolSignerVerificationKeySignature > = self
85
+ . verification_key_signature
86
+ . map ( |f| f. try_into ( ) )
87
+ . transpose ( )
88
+ . with_context ( || {
89
+ format ! (
90
+ "Error while parsing verification key signature message, party_id = '{}'" ,
91
+ self . party_id
92
+ )
93
+ } ) ?;
94
+ let operational_certificate: Option < ProtocolOpCert > = self
95
+ . operational_certificate
96
+ . map ( |f| f. try_into ( ) )
97
+ . transpose ( )
98
+ . with_context ( || {
99
+ format ! (
100
+ "Error while parsing operational certificate message, party_id = '{}'." ,
101
+ self . party_id
102
+ )
103
+ } ) ?;
104
+ let value = SignerWithStake {
105
+ party_id : self . party_id ,
106
+ verification_key : self . verification_key . try_into ( ) ?,
107
+ verification_key_signature,
108
+ kes_period : self . kes_period ,
109
+ operational_certificate,
110
+ stake : self . stake ,
111
+ } ;
112
+ Ok ( value)
102
113
}
103
114
}
104
115
0 commit comments