@@ -17,7 +17,8 @@ use syn::{
1717
1818use crate :: {
1919 parse_ident_from_pat, parse_ident_from_path, parse_path, parse_path_segment,
20- pascal_ident_to_call, snake_ident_to_pascal, snake_ident_to_screaming,
20+ pascal_ident_to_call, pascal_ident_to_consts_mod, snake_ident_to_pascal,
21+ snake_ident_to_screaming,
2122} ;
2223
2324struct Is {
@@ -453,6 +454,7 @@ mod kw {
453454/// Rust methods are parsed into this structure when Solidity code is generated
454455struct Method {
455456 name : Ident ,
457+ consts_mod_name : Ident ,
456458 camel_name : String ,
457459 pascal_name : Ident ,
458460 screaming_name : Ident ,
@@ -466,7 +468,7 @@ struct Method {
466468 enum_attrs : Vec < TokenStream > ,
467469}
468470impl Method {
469- fn try_from ( value : & mut ImplItemMethod , variant_attrs : & BTreeSet < Ident > ) -> syn:: Result < Self > {
471+ fn try_from ( value : & mut ImplItemMethod , interface_info : & InterfaceInfo ) -> syn:: Result < Self > {
470472 let mut info = MethodInfo {
471473 rename_selector : None ,
472474 hide : false ,
@@ -490,7 +492,7 @@ impl Method {
490492 _ => unreachable ! ( ) ,
491493 } ;
492494 docs. push ( value) ;
493- } else if variant_attrs . contains ( ident) {
495+ } else if interface_info . enum_variant_attrs . contains ( ident) {
494496 let path = & attr. path ;
495497 let tokens = & attr. tokens ;
496498 extra_enum_attrs. push ( quote ! { #path #tokens} ) ;
@@ -561,6 +563,7 @@ impl Method {
561563
562564 Ok ( Self {
563565 name : ident. clone ( ) ,
566+ consts_mod_name : pascal_ident_to_consts_mod ( & interface_info. name ) ,
564567 camel_name,
565568 pascal_name : snake_ident_to_pascal ( ident) ,
566569 screaming_name : snake_ident_to_screaming ( ident) ,
@@ -611,11 +614,11 @@ impl Method {
611614 let custom_signature = self . expand_custom_signature ( ) ;
612615 quote ! {
613616 const #screaming_name_signature: :: evm_coder:: custom_signature:: SignatureUnit = #custom_signature;
614- const #screaming_name: :: evm_coder:: types:: Bytes4 = {
617+ pub const #screaming_name: :: evm_coder:: types:: Bytes4 = {
615618 let mut sum = :: evm_coder:: sha3_const:: Keccak256 :: new( ) ;
616619 let mut pos = 0 ;
617- while pos < Self :: #screaming_name_signature. len {
618- sum = sum. update( & [ Self :: #screaming_name_signature. data[ pos] ; 1 ] ) ;
620+ while pos < #screaming_name_signature. len {
621+ sum = sum. update( & [ #screaming_name_signature. data[ pos] ; 1 ] ) ;
619622 pos += 1 ;
620623 }
621624 let a = sum. finalize( ) ;
@@ -626,22 +629,24 @@ impl Method {
626629
627630 fn expand_interface_id ( & self ) -> proc_macro2:: TokenStream {
628631 let screaming_name = & self . screaming_name ;
632+ let consts_mod_name = & self . consts_mod_name ;
629633 quote ! {
630- interface_id ^= u32 :: from_be_bytes( Self :: #screaming_name. 0 ) ;
634+ interface_id ^= u32 :: from_be_bytes( #consts_mod_name :: #screaming_name. 0 ) ;
631635 }
632636 }
633637
634638 fn expand_parse ( & self ) -> proc_macro2:: TokenStream {
635639 let pascal_name = & self . pascal_name ;
636640 let screaming_name = & self . screaming_name ;
641+ let consts_mod_name = & self . consts_mod_name ;
637642 if self . has_normal_args {
638643 let args_iter = self . args . iter ( ) . filter ( |a| !a. is_special ( ) ) ;
639644 let arg_type = args_iter. clone ( ) . map ( |a| & a. ty ) ;
640645 let parsers = args_iter
641646 . enumerate ( )
642647 . map ( |( i, m) | m. expand_extract_parsed ( i) ) ;
643648 quote ! {
644- Self :: #screaming_name => {
649+ #consts_mod_name :: #screaming_name => {
645650 let parsed = <( #( #arg_type, ) * ) as :: evm_coder:: abi:: AbiDecode >:: abi_decode( reader) ?;
646651 return Ok ( Some ( Self :: #pascal_name {
647652 #(
@@ -651,7 +656,7 @@ impl Method {
651656 }
652657 }
653658 } else {
654- quote ! { Self :: #screaming_name => return Ok ( Some ( Self :: #pascal_name) ) }
659+ quote ! { #consts_mod_name :: #screaming_name => return Ok ( Some ( Self :: #pascal_name) ) }
655660 }
656661 }
657662
@@ -725,6 +730,7 @@ impl Method {
725730
726731 fn expand_solidity_function ( & self ) -> proc_macro2:: TokenStream {
727732 let camel_name = & self . camel_name ;
733+ let consts_mod_name = & self . consts_mod_name ;
728734 let mutability = match self . mutability {
729735 Mutability :: Mutable => quote ! { SolidityMutability :: Mutable } ,
730736 Mutability :: View => quote ! { SolidityMutability :: View } ,
@@ -747,7 +753,7 @@ impl Method {
747753 SolidityFunction {
748754 docs: & [ #( #docs) , * ] ,
749755 hide: #hide,
750- selector: u32 :: from_be_bytes( Self :: #screaming_name. 0 ) ,
756+ selector: u32 :: from_be_bytes( #consts_mod_name :: #screaming_name. 0 ) ,
751757 custom_signature: #custom_signature,
752758 name: #camel_name,
753759 mutability: #mutability,
@@ -820,7 +826,7 @@ impl SolidityInterface {
820826
821827 for item in & mut value. items {
822828 if let ImplItem :: Method ( method) = item {
823- methods. push ( Method :: try_from ( method, & info. enum_variant_attrs ) ?) ;
829+ methods. push ( Method :: try_from ( method, & info) ?) ;
824830 }
825831 }
826832 let mut docs = vec ! [ ] ;
@@ -858,6 +864,7 @@ impl SolidityInterface {
858864 let name = self . name ;
859865
860866 let solidity_name = self . info . name . to_string ( ) ;
867+ let call_constants_mod_name = pascal_ident_to_consts_mod ( & self . info . name ) ;
861868 let call_name = pascal_ident_to_call ( & self . info . name ) ;
862869 let generics = self . generics ;
863870 let gen_ref = generics_reference ( & generics) ;
@@ -952,10 +959,15 @@ impl SolidityInterface {
952959
953960 #expect_selector
954961
955- impl #gen_ref #call_name #gen_ref {
962+ mod #call_constants_mod_name {
963+ use super :: * ;
964+
956965 #(
957966 #consts
958967 ) *
968+ }
969+
970+ impl #gen_ref #call_name #gen_ref {
959971 /// Return this call ERC165 selector
960972 pub const fn interface_id( ) -> :: evm_coder:: types:: Bytes4 {
961973 let mut interface_id = 0 ;
0 commit comments