@@ -24,22 +24,20 @@ pub(crate) fn get_is_plutus_data_instance(input: DeriveInput) -> Result<ItemImpl
2424
2525 let mut generics = input. generics ;
2626
27- // TODO(chfanghr): Do we care about type role?
27+ // TODO(chfanghr): Do we care about type role? Can we determine it?
2828 generics. type_params_mut ( ) . for_each ( |param| {
29- param
30- . bounds
31- . push ( parse_quote ! ( plutus_ledger_api:: plutus_Data:: IsPlutusData ) ) ;
29+ param. bounds . push ( parse_quote ! ( plutus_data:: IsPlutusData ) ) ;
3230 } ) ;
3331
3432 let ( impl_generics, type_generics, where_clause) = generics. split_for_impl ( ) ;
3533
3634 Ok ( parse_quote ! (
37- impl #impl_generics plutus_ledger_api :: plutus_data:: IsPlutusData for #type_name #type_generics #where_clause {
38- fn to_plutus_data( & self ) -> plutus_ledger_api :: plutus_data:: PlutusData {
35+ impl #impl_generics plutus_data:: IsPlutusData for #type_name #type_generics #where_clause {
36+ fn to_plutus_data( & self ) -> plutus_data:: PlutusData {
3937 #encoder
4038 }
4139
42- fn from_plutus_data( plutus_data: & plutus_ledger_api :: plutus_data:: PlutusData ) -> Result <Self , plutus_ledger_api :: plutus_data:: PlutusDataError >
40+ fn from_plutus_data( plutus_data: & plutus_data:: PlutusData ) -> Result <Self , plutus_data:: PlutusDataError >
4341 where Self : Sized {
4442 #decoder
4543 }
@@ -171,15 +169,15 @@ fn get_newtype_encoder_decoder(input: &DeriveInput) -> Result<(Block, Block)> {
171169 Some ( field_name) => {
172170 parse_quote ! ( {
173171 Ok ( Self {
174- #field_name: plutus_ledger_api :: plutus_data:: IsPlutusData :: from_plutus_data( plutus_data) ?
172+ #field_name: plutus_data:: IsPlutusData :: from_plutus_data( plutus_data) ?
175173 } )
176174 } )
177175 }
178176 None => {
179177 parse_quote ! ( {
180- Ok ( Self (
181- plutus_ledger_api :: plutus_data:: IsPlutusData :: from_plutus_data ( plutus_data ) ? ,
182- ) )
178+ Ok ( Self ( plutus_data :: IsPlutusData :: from_plutus_data (
179+ plutus_data,
180+ ) ? ) )
183181 } )
184182 }
185183 } ;
@@ -311,11 +309,11 @@ fn enum_from_plutus_data_constr(e: &DataEnum, plutus_data_input_var: &Ident) ->
311309
312310 parse_quote ! (
313311 {
314- let ( tag, #plutus_data_list_var) = plutus_ledger_api :: plutus_data :: parse_constr( #plutus_data_input_var) ?;
312+ let ( tag, #plutus_data_list_var) = plutus_data :: is_plutus_data :: aux :: parse_constr( #plutus_data_input_var) ?;
315313
316314 match tag {
317315 #( #arms) , *
318- tag => Err ( plutus_ledger_api :: plutus_data:: PlutusDataError :: UnexpectedPlutusInvariant {
316+ tag => Err ( plutus_data:: PlutusDataError :: UnexpectedPlutusInvariant {
319317 wanted: format!( #expected_tags_str) ,
320318 got: tag. to_string( ) ,
321319 } ) ,
@@ -381,7 +379,7 @@ fn variant_with_named_fields_to_plutus_data(
381379 let plutus_data_list = data_fields_to_list_of_plutus_data ( & field_accessors) ;
382380
383381 parse_quote ! (
384- #constructor{ #( #field_names) , * } => plutus_ledger_api :: plutus_data:: PlutusData :: Constr ( #tag. into( ) , #plutus_data_list)
382+ #constructor{ #( #field_names) , * } => plutus_data:: PlutusData :: Constr ( #tag. into( ) , #plutus_data_list)
385383 )
386384}
387385
@@ -408,7 +406,7 @@ fn variant_with_unnamed_field_to_plutus_data(
408406 let plutus_data_list = data_fields_to_list_of_plutus_data ( & field_accessors) ;
409407
410408 parse_quote ! (
411- #constructor( #( #field_names) , * ) => plutus_ledger_api :: plutus_data:: PlutusData :: Constr ( #tag. into( ) , #plutus_data_list)
409+ #constructor( #( #field_names) , * ) => plutus_data:: PlutusData :: Constr ( #tag. into( ) , #plutus_data_list)
412410 )
413411}
414412
@@ -426,7 +424,7 @@ fn variant_with_unnamed_fields_from_plutus_data_list(
426424
427425fn variant_with_no_field_to_plutus_data ( constructor : & Path , tag : usize ) -> Arm {
428426 parse_quote ! (
429- #constructor => plutus_ledger_api :: plutus_data:: PlutusData :: Constr ( #tag. into( ) , vec![ ] )
427+ #constructor => plutus_data:: PlutusData :: Constr ( #tag. into( ) , vec![ ] )
430428 )
431429}
432430
@@ -464,7 +462,7 @@ fn struct_with_named_fields_to_plutus_data_list(fields: &FieldsNamed) -> Block {
464462 let to_list_of_plutus_data = struct_with_named_fields_to_list_of_plutus_data ( fields) ;
465463
466464 parse_quote ! ( {
467- plutus_ledger_api :: plutus_data:: PlutusData :: List ( #to_list_of_plutus_data)
465+ plutus_data:: PlutusData :: List ( #to_list_of_plutus_data)
468466 } )
469467}
470468
@@ -478,7 +476,7 @@ fn struct_with_named_fields_from_plutus_data_list(
478476 struct_with_named_fields_from_list_of_plutus_data ( fields, & list_of_plutus_data_var) ;
479477
480478 parse_quote ! ( {
481- let #list_of_plutus_data_var = plutus_ledger_api :: plutus_data :: parse_list( #plutus_data_input_var) ?;
479+ let #list_of_plutus_data_var = plutus_data :: is_plutus_data :: aux :: parse_list( #plutus_data_input_var) ?;
482480
483481 #from_list_of_plutus_data
484482 } )
@@ -488,7 +486,7 @@ fn struct_with_named_fields_to_plutus_data_constr(fields: &FieldsNamed) -> Block
488486 let to_list_of_plutus_data = struct_with_named_fields_to_list_of_plutus_data ( fields) ;
489487
490488 parse_quote ! ( {
491- plutus_ledger_api :: plutus_data:: PlutusData :: Constr ( 0 . into( ) , #to_list_of_plutus_data)
489+ plutus_data:: PlutusData :: Constr ( 0 . into( ) , #to_list_of_plutus_data)
492490 } )
493491}
494492
@@ -502,7 +500,7 @@ fn struct_with_named_fields_from_plutus_data_constr(
502500 struct_with_named_fields_from_list_of_plutus_data ( fields, & plutus_data_list_var) ;
503501
504502 parse_quote ! ( {
505- let #plutus_data_list_var = plutus_ledger_api :: plutus_data :: parse_constr_with_tag( #plutus_data_input_var, 0 ) ?;
503+ let #plutus_data_list_var = plutus_data :: is_plutus_data :: aux :: parse_constr_with_tag( #plutus_data_input_var, 0 ) ?;
506504
507505 #from_plutus_data_list
508506 } )
@@ -538,7 +536,7 @@ fn struct_with_unnamed_fields_to_plutus_data_list(fields: &FieldsUnnamed) -> Blo
538536 let to_list_of_plutus_data = struct_with_unnamed_fields_to_list_of_plutus_data ( fields) ;
539537
540538 parse_quote ! ( {
541- plutus_ledger_api :: plutus_data:: PlutusData :: List ( #to_list_of_plutus_data)
539+ plutus_data:: PlutusData :: List ( #to_list_of_plutus_data)
542540 } )
543541}
544542
@@ -552,7 +550,7 @@ fn struct_with_unnamed_fields_from_plutus_data_list(
552550 struct_with_unnamed_fields_from_list_of_plutus_data ( fields, & list_of_plutus_data_var) ;
553551
554552 parse_quote ! ( {
555- let #list_of_plutus_data_var = plutus_ledger_api :: plutus_data :: parse_list( #plutus_data_input_var) ?;
553+ let #list_of_plutus_data_var = plutus_data :: is_plutus_data :: aux :: parse_list( #plutus_data_input_var) ?;
556554
557555 #from_list_of_plutus_data
558556 } )
@@ -562,31 +560,27 @@ fn struct_with_unnamed_fields_to_plutus_data_constr(fields: &FieldsUnnamed) -> B
562560 let to_list_of_plutus_data = struct_with_unnamed_fields_to_list_of_plutus_data ( fields) ;
563561
564562 parse_quote ! ( {
565- plutus_ledger_api :: plutus_data:: PlutusData :: Constr ( 0 . into( ) , #to_list_of_plutus_data)
563+ plutus_data:: PlutusData :: Constr ( 0 . into( ) , #to_list_of_plutus_data)
566564 } )
567565}
568566
569567fn struct_with_unnamed_fields_from_plutus_data_constr (
570568 fields : & FieldsUnnamed ,
571569 plutus_data_input_var : & Ident ,
572570) -> Block {
573- let plutus_data_list_var : Ident = parse_quote ! ( plutus_data_list ) ;
571+ let fields_var : Ident = parse_quote ! ( fields ) ;
574572
575- let from_list_of_plutus_data =
576- struct_with_unnamed_fields_from_list_of_plutus_data ( fields, & plutus_data_list_var) ;
573+ let from_fields = struct_with_unnamed_fields_from_list_of_plutus_data ( fields, & fields_var) ;
577574
578575 parse_quote ! ( {
579- let #plutus_data_list_var = plutus_ledger_api :: plutus_data :: parse_constr_with_tag( #plutus_data_input_var, 0 ) ?;
576+ let #fields_var = plutus_data :: is_plutus_data :: aux :: parse_constr_with_tag( #plutus_data_input_var, 0 ) ?;
580577
581- #from_list_of_plutus_data
578+ #from_fields
582579 } )
583580}
584581
585582fn struct_with_no_field_to_plutus_data_list ( ) -> Block {
586- parse_quote ! ( plutus_ledger_api:: plutus_data:: PlutusData :: Constr (
587- 0 . into( ) ,
588- vec![ ]
589- ) )
583+ parse_quote ! ( plutus_data:: PlutusData :: Constr ( 0 . into( ) , vec![ ] ) )
590584}
591585
592586fn struct_with_no_field_from_plutus_data_list ( plutus_data_input_var : & Ident ) -> Block {
@@ -596,32 +590,26 @@ fn struct_with_no_field_from_plutus_data_list(plutus_data_input_var: &Ident) ->
596590 data_with_no_fields_from_list_of_plutus_data ( & parse_quote ! ( Self ) , & list_of_plutus_data_var) ;
597591
598592 parse_quote ! ( {
599- let #list_of_plutus_data_var = plutus_ledger_api:: plutus_data:: parse_list( #plutus_data_input_var) ?;
600-
601-
602-
593+ let #list_of_plutus_data_var = plutus_data:: is_plutus_data:: aux:: parse_list( #plutus_data_input_var) ?;
603594
604595 #from_list_of_plutus_data
605596 } )
606597}
607598
608599fn struct_with_no_field_to_plutus_data_constr ( ) -> Block {
609- parse_quote ! ( plutus_ledger_api:: plutus_data:: PlutusData :: Constr (
610- 0 . into( ) ,
611- vec![ ]
612- ) )
600+ parse_quote ! ( plutus_data:: PlutusData :: Constr ( 0 . into( ) , vec![ ] ) )
613601}
614602
615603fn struct_with_no_field_from_plutus_data_constr ( plutus_data_input_var : & Ident ) -> Block {
616- let list_of_plutus_data_var : Ident = parse_quote ! ( list_of_plutus_data ) ;
604+ let fields_var : Ident = parse_quote ! ( fields ) ;
617605
618- let from_list_of_plutus_data =
619- data_with_no_fields_from_list_of_plutus_data ( & parse_quote ! ( Self ) , & list_of_plutus_data_var ) ;
606+ let from_fields =
607+ data_with_no_fields_from_list_of_plutus_data ( & parse_quote ! ( Self ) , & fields_var ) ;
620608
621609 parse_quote ! ( {
622- let #list_of_plutus_data_var = plutus_ledger_api :: plutus_data :: parse_constr_with_tag( #plutus_data_input_var, 0 ) ?;
610+ let #fields_var = plutus_data :: is_plutus_data :: aux :: parse_constr_with_tag( #plutus_data_input_var, 0 ) ?;
623611
624- #from_list_of_plutus_data
612+ #from_fields
625613 } )
626614}
627615
@@ -652,7 +640,7 @@ fn data_with_named_fields_from_list_of_plutus_data(
652640 let field_decoded_stmts = field_idents. clone ( ) . zip ( unparsed_field_idents. clone ( ) ) . map (
653641 |( field_ident, unparsed_field_ident) | -> Stmt {
654642 parse_quote ! (
655- let #field_ident = plutus_ledger_api :: plutus_data:: IsPlutusData :: from_plutus_data( #unparsed_field_ident) ?;
643+ let #field_ident = plutus_data:: IsPlutusData :: from_plutus_data( #unparsed_field_ident) ?;
656644 )
657645 } ,
658646 ) ;
0 commit comments