@@ -67,6 +67,7 @@ pub mod pallet {
6767 traits:: {
6868 tokens:: fungible, OriginTrait , QueryPreimage , StorePreimage , UnfilteredDispatchable ,
6969 } ,
70+ BoundedVec ,
7071 } ;
7172 use frame_system:: pallet_prelude:: * ;
7273 use sp_core:: H256 ;
@@ -133,11 +134,31 @@ pub mod pallet {
133134 /// Struct for NeuronCertificate.
134135 pub type NeuronCertificateOf = NeuronCertificate ;
135136 /// Data structure for NeuronCertificate information.
136- #[ freeze_struct( "e6193a76002d491 " ) ]
137+ #[ freeze_struct( "1c232be200d9ec6c " ) ]
137138 #[ derive( Decode , Encode , Default , TypeInfo , PartialEq , Eq , Clone , Debug ) ]
138139 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+ }
141162 }
142163
143164 /// Struct for Prometheus.
0 commit comments