1- use alloy_json_abi:: { Event , Function } ;
1+ use alloy_json_abi:: { Error , Event , Function } ;
22use alloy_primitives:: { hex, map:: HashSet } ;
33use foundry_common:: {
4- abi:: { get_event, get_func} ,
4+ abi:: { get_error , get_event, get_func} ,
55 fs,
66 selectors:: { OpenChainClient , SelectorType } ,
77} ;
@@ -13,6 +13,7 @@ pub type SingleSignaturesIdentifier = Arc<RwLock<SignaturesIdentifier>>;
1313
1414#[ derive( Debug , Default , Serialize , Deserialize ) ]
1515pub struct CachedSignatures {
16+ pub errors : BTreeMap < String , String > ,
1617 pub events : BTreeMap < String , String > ,
1718 pub functions : BTreeMap < String , String > ,
1819}
@@ -39,7 +40,7 @@ impl CachedSignatures {
3940/// `https://openchain.xyz` or a local cache.
4041#[ derive( Debug ) ]
4142pub struct SignaturesIdentifier {
42- /// Cached selectors for functions and events .
43+ /// Cached selectors for functions, events and custom errors .
4344 cached : CachedSignatures ,
4445 /// Location where to save `CachedSignatures`.
4546 cached_path : Option < PathBuf > ,
@@ -101,6 +102,7 @@ impl SignaturesIdentifier {
101102 let cache = match selector_type {
102103 SelectorType :: Function => & mut self . cached . functions ,
103104 SelectorType :: Event => & mut self . cached . events ,
105+ SelectorType :: Error => & mut self . cached . errors ,
104106 } ;
105107
106108 let hex_identifiers: Vec < String > =
@@ -157,6 +159,19 @@ impl SignaturesIdentifier {
157159 pub async fn identify_event ( & mut self , identifier : & [ u8 ] ) -> Option < Event > {
158160 self . identify_events ( & [ identifier] ) . await . pop ( ) . unwrap ( )
159161 }
162+
163+ /// Identifies `Error`s from its cache or `https://api.openchain.xyz`.
164+ pub async fn identify_errors (
165+ & mut self ,
166+ identifiers : impl IntoIterator < Item = impl AsRef < [ u8 ] > > ,
167+ ) -> Vec < Option < Error > > {
168+ self . identify ( SelectorType :: Error , identifiers, get_error) . await
169+ }
170+
171+ /// Identifies `Error` from its cache or `https://api.openchain.xyz`.
172+ pub async fn identify_error ( & mut self , identifier : & [ u8 ] ) -> Option < Error > {
173+ self . identify_errors ( & [ identifier] ) . await . pop ( ) . unwrap ( )
174+ }
160175}
161176
162177impl Drop for SignaturesIdentifier {
0 commit comments