@@ -3,16 +3,54 @@ use crate::*;
33
44impl Deserialize for FixedBlock {
55 fn deserialize < R : BufRead + Seek > ( raw : & mut Deserializer < R > ) -> Result < Self , DeserializeError > {
6- let ( (
7- header,
8- transaction_bodies,
9- transaction_witness_sets,
10- auxiliary_data_set,
11- invalid_transactions,
12- ) , orig_bytes) = deserilized_with_orig_bytes ( raw, |raw| -> Result < _ , DeserializeError > {
13- deserialize_block ( raw)
14- } ) . map_err ( |e| e. annotate ( "Block" ) ) ?;
15- let block_hash = BlockHash ( blake2b256 ( orig_bytes. as_ref ( ) ) ) ;
6+ let len = raw. array ( ) ?;
7+ let mut read_len = CBORReadLen :: new ( len) ;
8+ read_len. read_elems ( 4 ) ?;
9+ let ( header, header_bytes) =
10+ deserilized_with_orig_bytes ( raw, |raw| -> Result < _ , DeserializeError > {
11+ Ok ( Header :: deserialize ( raw) ?)
12+ } )
13+ . map_err ( |e| e. annotate ( "header" ) ) ?;
14+ let transaction_bodies =
15+ ( || -> Result < _ , DeserializeError > { Ok ( FixedTransactionBodies :: deserialize ( raw) ?) } ) ( )
16+ . map_err ( |e| e. annotate ( "fixed_transaction_bodies" ) ) ?;
17+ let transaction_witness_sets =
18+ ( || -> Result < _ , DeserializeError > { Ok ( TransactionWitnessSets :: deserialize ( raw) ?) } ) ( )
19+ . map_err ( |e| e. annotate ( "transaction_witness_sets" ) ) ?;
20+ let auxiliary_data_set =
21+ ( || -> Result < _ , DeserializeError > { Ok ( AuxiliaryDataSet :: deserialize ( raw) ?) } ) ( )
22+ . map_err ( |e| e. annotate ( "auxiliary_data_set" ) ) ?;
23+ let invalid_present = match len {
24+ Len :: Indefinite => raw. cbor_type ( ) ? == CBORType :: Array ,
25+ Len :: Len ( 4 ) => false ,
26+ _ => true ,
27+ } ;
28+ let invalid_transactions = ( || -> Result < _ , DeserializeError > {
29+ let mut arr = Vec :: new ( ) ;
30+ if invalid_present {
31+ read_len. read_elems ( 1 ) ?;
32+ let len = raw. array ( ) ?;
33+ while match len {
34+ Len :: Len ( n) => arr. len ( ) < n as usize ,
35+ Len :: Indefinite => true ,
36+ } {
37+ if is_break_tag ( raw, "invalid_transactions" ) ? {
38+ break ;
39+ }
40+ arr. push ( TransactionIndex :: deserialize ( raw) ?) ;
41+ }
42+ }
43+ Ok ( arr)
44+ } ) ( )
45+ . map_err ( |e| e. annotate ( "invalid_transactions" ) ) ?;
46+ match len {
47+ Len :: Len ( _) => ( ) ,
48+ Len :: Indefinite => match raw. special ( ) ? {
49+ CBORSpecial :: Break => ( ) ,
50+ _ => return Err ( DeserializeFailure :: EndingBreakMissing . into ( ) ) ,
51+ } ,
52+ }
53+ let block_hash = BlockHash ( blake2b256 ( header_bytes. as_ref ( ) ) ) ;
1654 Ok ( FixedBlock {
1755 header,
1856 transaction_bodies,
@@ -23,61 +61,3 @@ impl Deserialize for FixedBlock {
2361 } )
2462 }
2563}
26-
27- fn deserialize_block < R : BufRead + Seek > (
28- raw : & mut Deserializer < R > ,
29- ) -> Result < ( Header , FixedTransactionBodies , TransactionWitnessSets , AuxiliaryDataSet , TransactionIndexes ) , DeserializeError > {
30- let len = raw. array ( ) ?;
31- let mut read_len = CBORReadLen :: new ( len) ;
32- read_len. read_elems ( 4 ) ?;
33- let header = ( || -> Result < _ , DeserializeError > { Ok ( Header :: deserialize ( raw) ?) } ) ( )
34- . map_err ( |e| e. annotate ( "header" ) ) ?;
35- let transaction_bodies = ( || -> Result < _ , DeserializeError > {
36- Ok ( FixedTransactionBodies :: deserialize ( raw) ?)
37- } ) ( )
38- . map_err ( |e| e. annotate ( "fixed_transaction_bodies" ) ) ?;
39- let transaction_witness_sets = ( || -> Result < _ , DeserializeError > {
40- Ok ( TransactionWitnessSets :: deserialize ( raw) ?)
41- } ) ( )
42- . map_err ( |e| e. annotate ( "transaction_witness_sets" ) ) ?;
43- let auxiliary_data_set =
44- ( || -> Result < _ , DeserializeError > { Ok ( AuxiliaryDataSet :: deserialize ( raw) ?) } ) ( )
45- . map_err ( |e| e. annotate ( "auxiliary_data_set" ) ) ?;
46- let invalid_present = match len {
47- Len :: Indefinite => raw. cbor_type ( ) ? == CBORType :: Array ,
48- Len :: Len ( 4 ) => false ,
49- _ => true ,
50- } ;
51- let invalid_transactions = ( || -> Result < _ , DeserializeError > {
52- let mut arr = Vec :: new ( ) ;
53- if invalid_present {
54- read_len. read_elems ( 1 ) ?;
55- let len = raw. array ( ) ?;
56- while match len {
57- Len :: Len ( n) => arr. len ( ) < n as usize ,
58- Len :: Indefinite => true ,
59- } {
60- if is_break_tag ( raw, "Block.invalid_transactions" ) ? {
61- break ;
62- }
63- arr. push ( TransactionIndex :: deserialize ( raw) ?) ;
64- }
65- }
66- Ok ( arr)
67- } ) ( )
68- . map_err ( |e| e. annotate ( "invalid_transactions" ) ) ?;
69- match len {
70- Len :: Len ( _) => ( ) ,
71- Len :: Indefinite => match raw. special ( ) ? {
72- CBORSpecial :: Break => ( ) ,
73- _ => return Err ( DeserializeFailure :: EndingBreakMissing . into ( ) ) ,
74- } ,
75- }
76- Ok ( (
77- header,
78- transaction_bodies,
79- transaction_witness_sets,
80- auxiliary_data_set,
81- invalid_transactions,
82- ) )
83- }
0 commit comments