@@ -95,30 +95,48 @@ impl DeserializeEmbeddedGroup for Transaction {
9595 let witness_set = ( || -> Result < _ , DeserializeError > {
9696 Ok ( TransactionWitnessSet :: deserialize ( raw) ?)
9797 } ) ( ) . map_err ( |e| e. annotate ( "witness_set" ) ) ?;
98+ let mut checked_auxiliary_data = false ;
99+ let mut auxiliary_data = None ;
98100 let is_valid = ( || -> Result < _ , DeserializeError > {
99101 match raw. cbor_type ( ) ? == CBORType :: Special {
100102 true => {
101- if let CBORSpecial :: Bool ( b) = raw. special ( ) ? {
103+ // if it's special it can be either a bool or null. if it's null, then it's empty auxiliary data, otherwise not a valid encoding
104+ let special = raw. special ( ) ?;
105+ if let CBORSpecial :: Bool ( b) = special {
102106 return Ok ( b) ;
107+ } else if special == CBORSpecial :: Null {
108+ checked_auxiliary_data = true ;
109+ return Ok ( true ) ;
110+ } else {
111+ return Err ( DeserializeFailure :: ExpectedBool . into ( ) ) ;
103112 }
104- return Err ( DeserializeFailure :: ExpectedBool . into ( ) ) ;
105113 } ,
106- _ => return Err ( DeserializeFailure :: ExpectedBool . into ( ) )
114+ false => {
115+ // if no special symbol was detected, it must have auxiliary data
116+ auxiliary_data = ( || -> Result < _ , DeserializeError > {
117+ Ok ( Some ( AuxiliaryData :: deserialize ( raw) ?) )
118+ } ) ( ) . map_err ( |e| e. annotate ( "auxiliary_data" ) ) ?;
119+ checked_auxiliary_data = true ;
120+ return Ok ( true ) ;
121+ }
107122 }
108123 } ) ( ) . map_err ( |e| e. annotate ( "is_valid" ) ) ?;
109- let auxiliary_data = ( || -> Result < _ , DeserializeError > {
110- Ok ( match raw. cbor_type ( ) ? != CBORType :: Special {
111- true => {
112- Some ( AuxiliaryData :: deserialize ( raw) ?)
113- } ,
114- false => {
115- if raw. special ( ) ? != CBORSpecial :: Null {
116- return Err ( DeserializeFailure :: ExpectedNull . into ( ) ) ;
124+ if ( !checked_auxiliary_data) {
125+ // this branch is reached, if the 3rd argument was a bool. then it simply follows the rules for checking auxiliary data
126+ auxiliary_data = ( || -> Result < _ , DeserializeError > {
127+ Ok ( match raw. cbor_type ( ) ? != CBORType :: Special {
128+ true => {
129+ Some ( AuxiliaryData :: deserialize ( raw) ?)
130+ } ,
131+ false => {
132+ if raw. special ( ) ? != CBORSpecial :: Null {
133+ return Err ( DeserializeFailure :: ExpectedNull . into ( ) ) ;
134+ }
135+ None
117136 }
118- None
119- }
120- } )
121- } ) ( ) . map_err ( |e| e. annotate ( "auxiliary_data" ) ) ?;
137+ } )
138+ } ) ( ) . map_err ( |e| e. annotate ( "auxiliary_data" ) ) ?;
139+ }
122140 Ok ( Transaction {
123141 body,
124142 witness_set,
0 commit comments