1
1
use alloy_json_abi:: JsonAbi ;
2
2
use alloy_primitives:: Address ;
3
3
use eyre:: { Result , WrapErr } ;
4
- use foundry_common:: { compile:: ProjectCompiler , fs, shell, ContractsByArtifact , TestFunctionExt } ;
4
+ use foundry_common:: {
5
+ compile:: ProjectCompiler , fs, selectors:: SelectorKind , shell, ContractsByArtifact ,
6
+ TestFunctionExt ,
7
+ } ;
5
8
use foundry_compilers:: {
6
9
artifacts:: { CompactBytecode , Settings } ,
7
10
cache:: { CacheEntry , CompilerCache } ,
@@ -16,7 +19,7 @@ use foundry_evm::{
16
19
traces:: {
17
20
debug:: { ContractSources , DebugTraceIdentifier } ,
18
21
decode_trace_arena,
19
- identifier:: { CachedSignatures , SignaturesIdentifier , TraceIdentifiers } ,
22
+ identifier:: { SignaturesCache , SignaturesIdentifier , TraceIdentifiers } ,
20
23
render_trace_arena_inner, CallTraceDecoder , CallTraceDecoderBuilder , TraceKind , Traces ,
21
24
} ,
22
25
} ;
@@ -364,10 +367,7 @@ pub async fn handle_traces(
364
367
365
368
let mut builder = CallTraceDecoderBuilder :: new ( )
366
369
. with_labels ( labels. chain ( config_labels) )
367
- . with_signature_identifier ( SignaturesIdentifier :: new (
368
- Config :: foundry_cache_dir ( ) ,
369
- config. offline ,
370
- ) ?) ;
370
+ . with_signature_identifier ( SignaturesIdentifier :: from_config ( config) ?) ;
371
371
let mut identifier = TraceIdentifiers :: new ( ) . with_etherscan ( config, chain) ?;
372
372
if let Some ( contracts) = & known_contracts {
373
373
builder = builder. with_known_contracts ( contracts) ;
@@ -416,7 +416,7 @@ pub async fn print_traces(
416
416
}
417
417
418
418
for ( _, arena) in traces {
419
- decode_trace_arena ( arena, decoder) . await ? ;
419
+ decode_trace_arena ( arena, decoder) . await ;
420
420
sh_println ! ( "{}" , render_trace_arena_inner( arena, verbose, state_changes) ) ?;
421
421
}
422
422
@@ -437,34 +437,21 @@ pub async fn print_traces(
437
437
438
438
/// Traverse the artifacts in the project to generate local signatures and merge them into the cache
439
439
/// file.
440
- pub fn cache_local_signatures ( output : & ProjectCompileOutput , cache_path : PathBuf ) -> Result < ( ) > {
441
- let path = cache_path . join ( "signatures" ) ;
442
- let mut cached_signatures = CachedSignatures :: load ( cache_path ) ;
443
- output . artifacts ( ) . for_each ( | ( _, artifact) | {
440
+ pub fn cache_local_signatures ( output : & ProjectCompileOutput , cache_dir : & Path ) -> Result < ( ) > {
441
+ let path = cache_dir . join ( "signatures" ) ;
442
+ let mut signatures = SignaturesCache :: load ( & path ) ;
443
+ for ( _, artifact) in output . artifacts ( ) {
444
444
if let Some ( abi) = & artifact. abi {
445
- for func in abi. functions ( ) {
446
- cached_signatures. functions . insert ( func. selector ( ) . to_string ( ) , func. signature ( ) ) ;
447
- }
448
- for event in abi. events ( ) {
449
- cached_signatures
450
- . events
451
- . insert ( event. selector ( ) . to_string ( ) , event. full_signature ( ) ) ;
452
- }
453
- for error in abi. errors ( ) {
454
- cached_signatures. errors . insert ( error. selector ( ) . to_string ( ) , error. signature ( ) ) ;
455
- }
456
- // External libraries doesn't have functions included in abi, but `methodIdentifiers`.
457
- if let Some ( method_identifiers) = & artifact. method_identifiers {
458
- method_identifiers. iter ( ) . for_each ( |( signature, selector) | {
459
- cached_signatures
460
- . functions
461
- . entry ( format ! ( "0x{selector}" ) )
462
- . or_insert ( signature. to_string ( ) ) ;
463
- } ) ;
464
- }
445
+ signatures. extend_from_abi ( abi) ;
465
446
}
466
- } ) ;
467
447
468
- fs:: write_json_file ( & path, & cached_signatures) ?;
448
+ // External libraries don't have functions included in the ABI, but `methodIdentifiers`.
449
+ if let Some ( method_identifiers) = & artifact. method_identifiers {
450
+ signatures. extend ( method_identifiers. iter ( ) . filter_map ( |( signature, selector) | {
451
+ Some ( ( SelectorKind :: Function ( selector. parse ( ) . ok ( ) ?) , signature. clone ( ) ) )
452
+ } ) ) ;
453
+ }
454
+ }
455
+ signatures. save ( & path) ;
469
456
Ok ( ( ) )
470
457
}
0 commit comments