1- use std:: { collections:: HashSet , fs, iter :: Map , path:: Path } ;
1+ use std:: { collections:: HashSet , fs, path:: Path } ;
22
33use ethers:: {
44 types:: { ValueOrArray , H256 } ,
@@ -178,12 +178,33 @@ pub enum ReadAbiError {
178178
179179impl ABIItem {
180180 pub fn format_event_signature ( & self ) -> Result < String , ParamTypeError > {
181- let formatted_inputs = self
182- . inputs
183- . iter ( )
184- . map ( |component| component. format_param_type ( ) )
185- . collect :: < Result < Vec < _ > , _ > > ( ) ?;
186- Ok ( formatted_inputs. join ( "," ) )
181+ let name = & self . name ;
182+ let params = self . inputs . iter ( )
183+ . map ( Self :: format_param_type)
184+ . collect :: < Result < Vec < _ > , _ > > ( ) ?
185+ . join ( "," ) ;
186+
187+ Ok ( format ! ( "{}({})" , name, params) )
188+ }
189+
190+ fn format_param_type ( input : & ABIInput ) -> Result < String , ParamTypeError > {
191+ let base_type = input. type_ . split ( '[' ) . next ( ) . unwrap_or ( & input. type_ ) ;
192+ let array_suffix = input. type_ . strip_prefix ( base_type) . unwrap_or ( "" ) ;
193+
194+ let type_str = match base_type {
195+ "tuple" => {
196+ let inner = input. components . as_ref ( )
197+ . ok_or ( ParamTypeError :: MissingComponents ) ?
198+ . iter ( )
199+ . map ( Self :: format_param_type)
200+ . collect :: < Result < Vec < _ > , _ > > ( ) ?
201+ . join ( "," ) ;
202+ format ! ( "({})" , inner)
203+ } ,
204+ _ => base_type. to_string ( ) ,
205+ } ;
206+
207+ Ok ( format ! ( "{}{}" , type_str, array_suffix) )
187208 }
188209
189210 pub fn extract_event_names_and_signatures_from_abi (
@@ -193,6 +214,7 @@ impl ABIItem {
193214 for item in abi_json. into_iter ( ) {
194215 if item. type_ == "event" {
195216 let signature = item. format_event_signature ( ) ?;
217+ // println!("signature {}", signature);
196218 events. push ( EventInfo :: new ( item, signature) ) ;
197219 }
198220 }
@@ -275,13 +297,12 @@ impl EventInfo {
275297 }
276298
277299 pub fn topic_id ( & self ) -> H256 {
278- let event_signature = format ! ( "{}({})" , self . name , self . signature) ;
300+ let event_signature = self . signature . clone ( ) ;
279301 H256 :: from_slice ( & keccak256 ( event_signature) )
280302 }
281303
282304 pub fn topic_id_as_hex_string ( & self ) -> String {
283- let event_signature = format ! ( "{}({})" , self . name, self . signature) ;
284- Map :: collect ( keccak256 ( event_signature) . iter ( ) . map ( |byte| format ! ( "{:02x}" , byte) ) )
305+ format ! ( "0x{:x}" , self . topic_id( ) )
285306 }
286307
287308 pub fn struct_result ( & self ) -> & str {
0 commit comments