@@ -67,6 +67,7 @@ pub mod pallet {
67
67
traits:: {
68
68
tokens:: fungible, OriginTrait , QueryPreimage , StorePreimage , UnfilteredDispatchable ,
69
69
} ,
70
+ BoundedVec ,
70
71
} ;
71
72
use frame_system:: pallet_prelude:: * ;
72
73
use sp_core:: H256 ;
@@ -133,11 +134,31 @@ pub mod pallet {
133
134
/// Struct for NeuronCertificate.
134
135
pub type NeuronCertificateOf = NeuronCertificate ;
135
136
/// Data structure for NeuronCertificate information.
136
- #[ freeze_struct( "e6193a76002d491 " ) ]
137
+ #[ freeze_struct( "1c232be200d9ec6c " ) ]
137
138
#[ derive( Decode , Encode , Default , TypeInfo , PartialEq , Eq , Clone , Debug ) ]
138
139
pub struct NeuronCertificate {
139
- /// The neuron certificate.
140
- pub certificate : Vec < u8 > ,
140
+ /// The neuron TLS public key
141
+ pub public_key : BoundedVec < u8 , ConstU32 < 64 > > ,
142
+ /// The algorithm used to generate the public key
143
+ pub algorithm : u8 ,
144
+ }
145
+
146
+ impl TryFrom < Vec < u8 > > for NeuronCertificate {
147
+ type Error = ( ) ;
148
+
149
+ fn try_from ( value : Vec < u8 > ) -> Result < Self , Self :: Error > {
150
+ if value. len ( ) > 65 {
151
+ return Err ( ( ) ) ;
152
+ }
153
+ // take the first byte as the algorithm
154
+ let algorithm = value. first ( ) . ok_or ( ( ) ) ?;
155
+ // and the rest as the public_key
156
+ let certificate = value. get ( 1 ..) . ok_or ( ( ) ) ?. to_vec ( ) ;
157
+ Ok ( Self {
158
+ public_key : BoundedVec :: try_from ( certificate) . map_err ( |_| ( ) ) ?,
159
+ algorithm : * algorithm,
160
+ } )
161
+ }
141
162
}
142
163
143
164
/// Struct for Prometheus.
0 commit comments