@@ -56,6 +56,17 @@ pub struct Header {
5656 /// 3 bytes in accordance to Scala implementation, but will use `Vec` until further improvements
5757 #[ cfg_attr( feature = "json" , serde( rename = "votes" ) ) ]
5858 pub votes : Votes ,
59+ /// Unparsed bytes that encode new possible fields
60+ #[ cfg_attr(
61+ feature = "json" ,
62+ serde(
63+ rename = "unparsedBytes" ,
64+ default ,
65+ serialize_with = "crate::json::autolykos_solution::as_base16_string" ,
66+ deserialize_with = "crate::json::autolykos_solution::from_base16_string"
67+ )
68+ ) ]
69+ pub unparsed_bytes : Box < [ u8 ] > ,
5970}
6071
6172impl Header {
@@ -82,7 +93,8 @@ impl Header {
8293 // For block version >= 2, this new byte encodes length of possible new fields.
8394 // Set to 0 for now, so no new fields.
8495 if self . version > 1 {
85- w. put_i8 ( 0 ) ?;
96+ w. put_u8 ( self . unparsed_bytes . len ( ) . try_into ( ) ?) ?;
97+ w. write_all ( & self . unparsed_bytes ) ?;
8698 }
8799 Ok ( data)
88100 }
@@ -127,13 +139,18 @@ impl ScorexSerializable for Header {
127139
128140 // For block version >= 2, a new byte encodes length of possible new fields. If this byte >
129141 // 0, we read new fields but do nothing, as semantics of the fields is not known.
130- if version > 1 {
142+ let unparsed_bytes : Box < [ u8 ] > = if version > 1 {
131143 let new_field_size = r. get_u8 ( ) ?;
132144 if new_field_size > 0 {
133145 let mut field_bytes: Vec < u8 > = vec ! [ 0 ; new_field_size as usize ] ;
134146 r. read_exact ( & mut field_bytes) ?;
147+ field_bytes. into ( )
148+ } else {
149+ Box :: new ( [ ] )
135150 }
136- }
151+ } else {
152+ Box :: new ( [ ] )
153+ } ;
137154
138155 // Parse `AutolykosSolution`
139156 let autolykos_solution = if version == 1 {
@@ -182,6 +199,7 @@ impl ScorexSerializable for Header {
182199 extension_root,
183200 autolykos_solution : autolykos_solution. clone ( ) ,
184201 votes,
202+ unparsed_bytes,
185203 } ;
186204
187205 let mut id_bytes = header. serialize_without_pow ( ) ?;
@@ -296,6 +314,7 @@ mod arbitrary {
296314 prop:: sample:: select ( vec ! [ 1_u8 , 2 ] ) ,
297315 any :: < Box < AutolykosSolution > > ( ) ,
298316 uniform3 ( 1u8 ..) ,
317+ proptest:: collection:: vec ( any :: < u8 > ( ) , 0 ..=255 ) ,
299318 )
300319 . prop_map (
301320 |(
@@ -309,6 +328,7 @@ mod arbitrary {
309328 version,
310329 autolykos_solution,
311330 votes,
331+ unparsed_bytes,
312332 ) | {
313333 let parent_id = BlockId ( Digest ( parent_id) ) ;
314334 let ad_proofs_root = Digest ( ad_proofs_root) ;
@@ -332,6 +352,11 @@ mod arbitrary {
332352 extension_root,
333353 autolykos_solution : * autolykos_solution. clone ( ) ,
334354 votes,
355+ unparsed_bytes : if version > 1 {
356+ unparsed_bytes. into ( )
357+ } else {
358+ Box :: new ( [ ] )
359+ } ,
335360 } ;
336361 let mut id_bytes = header. serialize_without_pow ( ) . unwrap ( ) ;
337362 let mut data = Vec :: new ( ) ;
0 commit comments