1
- use anyhow:: Context ;
1
+ #![ allow( deprecated) ]
2
+
2
3
use mithril_common:: {
3
- crypto_helper:: {
4
- ProtocolOpCert , ProtocolSignerVerificationKey , ProtocolSignerVerificationKeySignature ,
5
- } ,
6
- entities:: { CertificatePending , Signer } ,
7
- messages:: { CertificatePendingMessage , SignerMessagePart , TryFromMessageAdapter } ,
4
+ entities:: CertificatePending ,
5
+ messages:: { CertificatePendingMessage , TryFromMessageAdapter } ,
8
6
StdResult ,
9
7
} ;
10
8
11
9
/// Adapter to turn [CertificatePendingMessage] instances into [CertificatePending].
12
10
pub struct FromPendingCertificateMessageAdapter ;
13
11
14
- fn to_signers ( messages : & [ SignerMessagePart ] ) -> StdResult < Vec < Signer > > {
15
- let mut signers: Vec < Signer > = Vec :: new ( ) ;
16
-
17
- for msg in messages {
18
- let signer = Signer :: new (
19
- msg. party_id . to_owned ( ) ,
20
- ProtocolSignerVerificationKey :: from_json_hex ( & msg. verification_key ) ?,
21
- match & msg. verification_key_signature {
22
- Some ( verification_key_signature) => Some (
23
- ProtocolSignerVerificationKeySignature :: from_json_hex (
24
- verification_key_signature,
25
- )
26
- . with_context ( || {
27
- format ! (
28
- "'FromPendingCertificateMessageAdapter' can not json hex decode the verification key signature: '{}'" ,
29
- verification_key_signature
30
- )
31
- } ) ?,
32
- ) ,
33
- _ => None ,
34
- } ,
35
- match & msg. operational_certificate {
36
- Some ( operational_certificate) => Some (
37
- ProtocolOpCert :: from_json_hex ( operational_certificate) . with_context ( || {
38
- format ! (
39
- "'FromPendingCertificateMessageAdapter' can not json hex decode the operational certificate: '{}'" ,
40
- operational_certificate
41
- )
42
- } ) ?,
43
- ) ,
44
- _ => None ,
45
- } ,
46
- msg. kes_period ,
47
- ) ;
48
- signers. push ( signer) ;
49
- }
50
-
51
- Ok ( signers)
52
- }
53
-
54
12
impl TryFromMessageAdapter < CertificatePendingMessage , CertificatePending >
55
13
for FromPendingCertificateMessageAdapter
56
14
{
57
15
/// Adapter method
58
- #[ allow( deprecated) ]
59
16
fn try_adapt ( message : CertificatePendingMessage ) -> StdResult < CertificatePending > {
60
17
let certificate = CertificatePending {
61
18
epoch : message. epoch ,
62
19
signed_entity_type : message. signed_entity_type ,
63
20
protocol_parameters : message. protocol_parameters ,
64
21
next_protocol_parameters : message. next_protocol_parameters ,
65
- signers : to_signers ( & message. signers ) . with_context ( || {
66
- format ! (
67
- "'FromPendingCertificateMessageAdapter' can not convert the list of current signers: '{:?}'" ,
68
- message. signers
69
- )
70
- } ) ?,
71
- next_signers : to_signers ( & message. next_signers ) . with_context ( || {
72
- format ! (
73
- "'FromPendingCertificateMessageAdapter' can not convert the list of next signers: '{:?}'" ,
74
- message. next_signers
75
- )
76
- } ) ?,
22
+ // This field is deprecated and should not be used in Signer.
23
+ signers : vec ! [ ] ,
24
+ // This field is deprecated and should not be used in Signer.
25
+ next_signers : vec ! [ ] ,
77
26
} ;
78
27
79
28
Ok ( certificate)
@@ -92,14 +41,4 @@ mod tests {
92
41
93
42
assert_eq ! ( epoch, certificate_pending. epoch) ;
94
43
}
95
-
96
- #[ test]
97
- fn adapt_signers ( ) {
98
- let mut message = CertificatePendingMessage :: dummy ( ) ;
99
- message. signers = vec ! [ SignerMessagePart :: dummy( ) , SignerMessagePart :: dummy( ) ] ;
100
- let certificate_pending = FromPendingCertificateMessageAdapter :: try_adapt ( message) . unwrap ( ) ;
101
-
102
- assert_eq ! ( 2 , certificate_pending. signers. len( ) ) ;
103
- assert_eq ! ( 1 , certificate_pending. next_signers. len( ) ) ;
104
- }
105
44
}
0 commit comments