@@ -24,22 +24,20 @@ pub(crate) fn get_is_plutus_data_instance(input: DeriveInput) -> Result<ItemImpl
24
24
25
25
let mut generics = input. generics ;
26
26
27
- // TODO(chfanghr): Do we care about type role?
27
+ // TODO(chfanghr): Do we care about type role? Can we determine it?
28
28
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 ) ) ;
32
30
} ) ;
33
31
34
32
let ( impl_generics, type_generics, where_clause) = generics. split_for_impl ( ) ;
35
33
36
34
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 {
39
37
#encoder
40
38
}
41
39
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 >
43
41
where Self : Sized {
44
42
#decoder
45
43
}
@@ -171,15 +169,15 @@ fn get_newtype_encoder_decoder(input: &DeriveInput) -> Result<(Block, Block)> {
171
169
Some ( field_name) => {
172
170
parse_quote ! ( {
173
171
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) ?
175
173
} )
176
174
} )
177
175
}
178
176
None => {
179
177
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
+ ) ? ) )
183
181
} )
184
182
}
185
183
} ;
@@ -311,11 +309,11 @@ fn enum_from_plutus_data_constr(e: &DataEnum, plutus_data_input_var: &Ident) ->
311
309
312
310
parse_quote ! (
313
311
{
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) ?;
315
313
316
314
match tag {
317
315
#( #arms) , *
318
- tag => Err ( plutus_ledger_api :: plutus_data:: PlutusDataError :: UnexpectedPlutusInvariant {
316
+ tag => Err ( plutus_data:: PlutusDataError :: UnexpectedPlutusInvariant {
319
317
wanted: format!( #expected_tags_str) ,
320
318
got: tag. to_string( ) ,
321
319
} ) ,
@@ -381,7 +379,7 @@ fn variant_with_named_fields_to_plutus_data(
381
379
let plutus_data_list = data_fields_to_list_of_plutus_data ( & field_accessors) ;
382
380
383
381
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)
385
383
)
386
384
}
387
385
@@ -408,7 +406,7 @@ fn variant_with_unnamed_field_to_plutus_data(
408
406
let plutus_data_list = data_fields_to_list_of_plutus_data ( & field_accessors) ;
409
407
410
408
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)
412
410
)
413
411
}
414
412
@@ -426,7 +424,7 @@ fn variant_with_unnamed_fields_from_plutus_data_list(
426
424
427
425
fn variant_with_no_field_to_plutus_data ( constructor : & Path , tag : usize ) -> Arm {
428
426
parse_quote ! (
429
- #constructor => plutus_ledger_api :: plutus_data:: PlutusData :: Constr ( #tag. into( ) , vec![ ] )
427
+ #constructor => plutus_data:: PlutusData :: Constr ( #tag. into( ) , vec![ ] )
430
428
)
431
429
}
432
430
@@ -464,7 +462,7 @@ fn struct_with_named_fields_to_plutus_data_list(fields: &FieldsNamed) -> Block {
464
462
let to_list_of_plutus_data = struct_with_named_fields_to_list_of_plutus_data ( fields) ;
465
463
466
464
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)
468
466
} )
469
467
}
470
468
@@ -478,7 +476,7 @@ fn struct_with_named_fields_from_plutus_data_list(
478
476
struct_with_named_fields_from_list_of_plutus_data ( fields, & list_of_plutus_data_var) ;
479
477
480
478
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) ?;
482
480
483
481
#from_list_of_plutus_data
484
482
} )
@@ -488,7 +486,7 @@ fn struct_with_named_fields_to_plutus_data_constr(fields: &FieldsNamed) -> Block
488
486
let to_list_of_plutus_data = struct_with_named_fields_to_list_of_plutus_data ( fields) ;
489
487
490
488
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)
492
490
} )
493
491
}
494
492
@@ -502,7 +500,7 @@ fn struct_with_named_fields_from_plutus_data_constr(
502
500
struct_with_named_fields_from_list_of_plutus_data ( fields, & plutus_data_list_var) ;
503
501
504
502
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 ) ?;
506
504
507
505
#from_plutus_data_list
508
506
} )
@@ -538,7 +536,7 @@ fn struct_with_unnamed_fields_to_plutus_data_list(fields: &FieldsUnnamed) -> Blo
538
536
let to_list_of_plutus_data = struct_with_unnamed_fields_to_list_of_plutus_data ( fields) ;
539
537
540
538
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)
542
540
} )
543
541
}
544
542
@@ -552,7 +550,7 @@ fn struct_with_unnamed_fields_from_plutus_data_list(
552
550
struct_with_unnamed_fields_from_list_of_plutus_data ( fields, & list_of_plutus_data_var) ;
553
551
554
552
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) ?;
556
554
557
555
#from_list_of_plutus_data
558
556
} )
@@ -562,31 +560,27 @@ fn struct_with_unnamed_fields_to_plutus_data_constr(fields: &FieldsUnnamed) -> B
562
560
let to_list_of_plutus_data = struct_with_unnamed_fields_to_list_of_plutus_data ( fields) ;
563
561
564
562
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)
566
564
} )
567
565
}
568
566
569
567
fn struct_with_unnamed_fields_from_plutus_data_constr (
570
568
fields : & FieldsUnnamed ,
571
569
plutus_data_input_var : & Ident ,
572
570
) -> Block {
573
- let plutus_data_list_var : Ident = parse_quote ! ( plutus_data_list ) ;
571
+ let fields_var : Ident = parse_quote ! ( fields ) ;
574
572
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) ;
577
574
578
575
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 ) ?;
580
577
581
- #from_list_of_plutus_data
578
+ #from_fields
582
579
} )
583
580
}
584
581
585
582
fn 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![ ] ) )
590
584
}
591
585
592
586
fn 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) ->
596
590
data_with_no_fields_from_list_of_plutus_data ( & parse_quote ! ( Self ) , & list_of_plutus_data_var) ;
597
591
598
592
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) ?;
603
594
604
595
#from_list_of_plutus_data
605
596
} )
606
597
}
607
598
608
599
fn 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![ ] ) )
613
601
}
614
602
615
603
fn 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 ) ;
617
605
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 ) ;
620
608
621
609
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 ) ?;
623
611
624
- #from_list_of_plutus_data
612
+ #from_fields
625
613
} )
626
614
}
627
615
@@ -652,7 +640,7 @@ fn data_with_named_fields_from_list_of_plutus_data(
652
640
let field_decoded_stmts = field_idents. clone ( ) . zip ( unparsed_field_idents. clone ( ) ) . map (
653
641
|( field_ident, unparsed_field_ident) | -> Stmt {
654
642
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) ?;
656
644
)
657
645
} ,
658
646
) ;
0 commit comments