@@ -149,9 +149,12 @@ impl SignaturesCache {
149
149
/// An identifier that tries to identify functions and events using signatures found at
150
150
/// `https://openchain.xyz` or a local cache.
151
151
#[ derive( Clone , Debug ) ]
152
- pub struct SignaturesIdentifier {
152
+ pub struct SignaturesIdentifier ( Arc < SignaturesIdentifierInner > ) ;
153
+
154
+ #[ derive( Debug ) ]
155
+ struct SignaturesIdentifierInner {
153
156
/// Cached selectors for functions, events and custom errors.
154
- cache : Arc < RwLock < SignaturesCache > > ,
157
+ cache : RwLock < SignaturesCache > ,
155
158
/// Location where to save the signature cache.
156
159
cache_path : Option < PathBuf > ,
157
160
/// The OpenChain client to fetch signatures from. `None` if disabled on construction.
@@ -182,17 +185,16 @@ impl SignaturesIdentifier {
182
185
} else {
183
186
Default :: default ( )
184
187
} ;
185
- Ok ( Self { cache : Arc :: new ( RwLock :: new ( cache) ) , cache_path, client } )
188
+ Ok ( Self ( Arc :: new ( SignaturesIdentifierInner {
189
+ cache : RwLock :: new ( cache) ,
190
+ cache_path,
191
+ client,
192
+ } ) ) )
186
193
}
187
194
188
195
/// Saves the cache to the file system.
189
196
pub fn save ( & self ) {
190
- if let Some ( path) = & self . cache_path {
191
- self . cache
192
- . try_read ( )
193
- . expect ( "SignaturesIdentifier cache is locked while attempting to save" )
194
- . save ( path) ;
195
- }
197
+ self . 0 . save ( ) ;
196
198
}
197
199
198
200
/// Identifies `Function`s.
@@ -241,20 +243,20 @@ impl SignaturesIdentifier {
241
243
}
242
244
trace ! ( target: "evm::traces" , ?selectors, "identifying selectors" ) ;
243
245
244
- let mut cache_r = self . cache . read ( ) . await ;
245
- if let Some ( client) = & self . client {
246
+ let mut cache_r = self . 0 . cache . read ( ) . await ;
247
+ if let Some ( client) = & self . 0 . client {
246
248
let query =
247
249
selectors. iter ( ) . copied ( ) . filter ( |v| !cache_r. contains_key ( v) ) . collect :: < Vec < _ > > ( ) ;
248
250
if !query. is_empty ( ) {
249
251
drop ( cache_r) ;
250
- let mut cache_w = self . cache . write ( ) . await ;
252
+ let mut cache_w = self . 0 . cache . write ( ) . await ;
251
253
if let Ok ( res) = client. decode_selectors ( & query) . await {
252
254
for ( selector, signatures) in std:: iter:: zip ( query, res) {
253
255
cache_w. signatures . insert ( selector, signatures. into_iter ( ) . next ( ) ) ;
254
256
}
255
257
}
256
258
drop ( cache_w) ;
257
- cache_r = self . cache . read ( ) . await ;
259
+ cache_r = self . 0 . cache . read ( ) . await ;
258
260
}
259
261
}
260
262
selectors. iter ( ) . map ( |selector| cache_r. get ( selector) . unwrap_or_default ( ) ) . collect ( )
@@ -270,7 +272,18 @@ impl SignaturesIdentifier {
270
272
}
271
273
}
272
274
273
- impl Drop for SignaturesIdentifier {
275
+ impl SignaturesIdentifierInner {
276
+ fn save ( & self ) {
277
+ if let Some ( path) = & self . cache_path {
278
+ self . cache
279
+ . try_read ( )
280
+ . expect ( "SignaturesIdentifier cache is locked while attempting to save" )
281
+ . save ( path) ;
282
+ }
283
+ }
284
+ }
285
+
286
+ impl Drop for SignaturesIdentifierInner {
274
287
fn drop ( & mut self ) {
275
288
self . save ( ) ;
276
289
}
0 commit comments