@@ -296,7 +296,11 @@ impl Decode<'_, DecodeContext<'_, '_>> for Cip509 {
296296 // below we should try to recover as much data as possible and not to return early.
297297 let map_len = decode_map_len ( d, context) ?;
298298
299- let mut result = Self :: with_decode_context ( decode_context) ;
299+ let mut purpose = None ;
300+ let mut txn_inputs_hash = None ;
301+ let mut prv_tx_id = None ;
302+ let mut validation_signature = None ;
303+ let mut metadata = None ;
300304
301305 let mut found_keys = Vec :: new ( ) ;
302306 let mut is_metadata_found = false ;
@@ -305,7 +309,7 @@ impl Decode<'_, DecodeContext<'_, '_>> for Cip509 {
305309 // We don't want to consume key here because it can be a part of chunked metadata that
306310 // is decoded below.
307311 let Ok ( key) = d. probe ( ) . u8 ( ) else {
308- result . report . other (
312+ decode_context . report . other (
309313 & format ! ( "Unable to decode map key ({index} index)" ) ,
310314 context,
311315 ) ;
@@ -315,25 +319,26 @@ impl Decode<'_, DecodeContext<'_, '_>> for Cip509 {
315319 // Consume the key. This should never fail because we used `probe` above.
316320 let _: u8 = decode_helper ( d, context, & mut ( ) ) ?;
317321
318- if report_duplicated_key ( & found_keys, & key, index, context, & result. report ) {
322+ if report_duplicated_key ( & found_keys, & key, index, context, & decode_context. report )
323+ {
319324 continue ;
320325 }
321326 found_keys. push ( key) ;
322327
323328 match key {
324329 Cip509IntIdentifier :: Purpose => {
325- result . purpose = decode_purpose ( d, context, & result . report ) ;
330+ purpose = decode_purpose ( d, context, & decode_context . report ) ;
326331 } ,
327332 Cip509IntIdentifier :: TxInputsHash => {
328- result . txn_inputs_hash = decode_input_hash ( d, context, & result . report ) ;
333+ txn_inputs_hash = decode_input_hash ( d, context, & decode_context . report ) ;
329334 } ,
330335 Cip509IntIdentifier :: PreviousTxId => {
331- result . prv_tx_id =
332- decode_previous_transaction_id ( d, context, & result . report ) ;
336+ prv_tx_id =
337+ decode_previous_transaction_id ( d, context, & decode_context . report ) ;
333338 } ,
334339 Cip509IntIdentifier :: ValidationSignature => {
335- result . validation_signature =
336- decode_validation_signature ( d, context, & result . report ) ;
340+ validation_signature =
341+ decode_validation_signature ( d, context, & decode_context . report ) ;
337342 } ,
338343 }
339344 } else {
@@ -342,7 +347,7 @@ impl Decode<'_, DecodeContext<'_, '_>> for Cip509 {
342347 // metadata, but it isn't allowed. See this link for more details:
343348 // https://github.com/input-output-hk/catalyst-CIPs/blob/x509-envelope-metadata/CIP-XXXX/README.md#keys-10-11-or-12---x509-chunked-data
344349 if is_metadata_found {
345- result . report . duplicate_field (
350+ decode_context . report . duplicate_field (
346351 "metadata" ,
347352 "Only one instance of the chunked metadata should be present" ,
348353 context,
@@ -352,9 +357,9 @@ impl Decode<'_, DecodeContext<'_, '_>> for Cip509 {
352357 is_metadata_found = true ;
353358
354359 match X509Chunks :: decode ( d, decode_context) {
355- Ok ( chunks) => result . metadata = chunks. into ( ) ,
360+ Ok ( chunks) => metadata = chunks. into ( ) ,
356361 Err ( e) => {
357- result . report . other (
362+ decode_context . report . other (
358363 & format ! ( "Unable to decode metadata from chunks: {e:?}" ) ,
359364 context,
360365 ) ;
@@ -368,14 +373,27 @@ impl Decode<'_, DecodeContext<'_, '_>> for Cip509 {
368373 Cip509IntIdentifier :: TxInputsHash ,
369374 Cip509IntIdentifier :: ValidationSignature ,
370375 ] ;
371- report_missing_keys ( & found_keys, & required_keys, context, & result . report ) ;
376+ report_missing_keys ( & found_keys, & required_keys, context, & decode_context . report ) ;
372377 if !is_metadata_found {
373- result
378+ decode_context
374379 . report
375380 . missing_field ( "metadata (10, 11 or 12 chunks)" , context) ;
376381 }
377382
378- Ok ( result)
383+ let txn_hash = MultiEraTx :: Conway ( Box :: new ( Cow :: Borrowed ( decode_context. txn ) ) )
384+ . hash ( )
385+ . into ( ) ;
386+ Ok ( Self {
387+ purpose,
388+ txn_inputs_hash,
389+ prv_tx_id,
390+ metadata,
391+ validation_signature,
392+ payment_history : Default :: default ( ) ,
393+ txn_hash,
394+ origin : decode_context. origin . clone ( ) ,
395+ report : decode_context. report . clone ( ) ,
396+ } )
379397 }
380398}
381399
0 commit comments