@@ -2,18 +2,21 @@ use alloy_json_abi::{EventParam, InternalType, JsonAbi, Param};
2
2
use alloy_primitives:: { hex, keccak256} ;
3
3
use clap:: Parser ;
4
4
use comfy_table:: { modifiers:: UTF8_ROUND_CORNERS , Cell , Table } ;
5
- use eyre:: Result ;
5
+ use eyre:: { eyre , Result } ;
6
6
use foundry_cli:: opts:: { BuildOpts , CompilerOpts } ;
7
7
use foundry_common:: {
8
8
compile:: { PathOrContractInfo , ProjectCompiler } ,
9
9
find_matching_contract_artifact, find_target_path, shell,
10
10
} ;
11
- use foundry_compilers:: artifacts:: {
12
- output_selection:: {
13
- BytecodeOutputSelection , ContractOutputSelection , DeployedBytecodeOutputSelection ,
14
- EvmOutputSelection , EwasmOutputSelection ,
11
+ use foundry_compilers:: {
12
+ artifacts:: {
13
+ output_selection:: {
14
+ BytecodeOutputSelection , ContractOutputSelection , DeployedBytecodeOutputSelection ,
15
+ EvmOutputSelection , EwasmOutputSelection ,
16
+ } ,
17
+ StorageLayout ,
15
18
} ,
16
- StorageLayout ,
19
+ solc :: SolcLanguage ,
17
20
} ;
18
21
use regex:: Regex ;
19
22
use serde_json:: { Map , Value } ;
@@ -47,8 +50,8 @@ impl InspectArgs {
47
50
48
51
// Map field to ContractOutputSelection
49
52
let mut cos = build. compiler . extra_output ;
50
- if !field. is_default ( ) && !cos. iter ( ) . any ( |selected| field == * selected) {
51
- cos. push ( field. into ( ) ) ;
53
+ if !field. can_skip_field ( ) && !cos. iter ( ) . any ( |selected| field == * selected) {
54
+ cos. push ( field. try_into ( ) ? ) ;
52
55
}
53
56
54
57
// Run Optimized?
@@ -58,6 +61,9 @@ impl InspectArgs {
58
61
build. compiler . optimize
59
62
} ;
60
63
64
+ // Get the solc version if specified
65
+ let solc_version = build. use_solc . clone ( ) ;
66
+
61
67
// Build modified Args
62
68
let modified_build_args = BuildOpts {
63
69
compiler : CompilerOpts { extra_output : cos, optimize : optimized, ..build. compiler } ,
@@ -129,6 +135,18 @@ impl InspectArgs {
129
135
let out = artifact. abi . as_ref ( ) . map_or ( Map :: new ( ) , parse_events) ;
130
136
print_errors_events ( & out, false ) ?;
131
137
}
138
+ ContractArtifactField :: StandardJson => {
139
+ let standard_json = if let Some ( version) = solc_version {
140
+ let version = version. parse ( ) ?;
141
+ let mut standard_json =
142
+ project. standard_json_input ( & target_path) ?. normalize_evm_version ( & version) ;
143
+ standard_json. settings . sanitize ( & version, SolcLanguage :: Solidity ) ;
144
+ standard_json
145
+ } else {
146
+ project. standard_json_input ( & target_path) ?
147
+ } ;
148
+ print_json ( & standard_json) ?;
149
+ }
132
150
} ;
133
151
134
152
Ok ( ( ) )
@@ -353,6 +371,7 @@ pub enum ContractArtifactField {
353
371
Ewasm ,
354
372
Errors ,
355
373
Events ,
374
+ StandardJson ,
356
375
}
357
376
358
377
macro_rules! impl_value_enum {
@@ -440,31 +459,39 @@ impl_value_enum! {
440
459
Ewasm => "ewasm" | "e-wasm" ,
441
460
Errors => "errors" | "er" ,
442
461
Events => "events" | "ev" ,
462
+ StandardJson => "standardJson" | "standard-json" | "standard_json" ,
443
463
}
444
464
}
445
465
446
- impl From < ContractArtifactField > for ContractOutputSelection {
447
- fn from ( field : ContractArtifactField ) -> Self {
466
+ impl TryFrom < ContractArtifactField > for ContractOutputSelection {
467
+ type Error = eyre:: Error ;
468
+
469
+ fn try_from ( field : ContractArtifactField ) -> Result < Self , Self :: Error > {
448
470
type Caf = ContractArtifactField ;
449
471
match field {
450
- Caf :: Abi => Self :: Abi ,
451
- Caf :: Bytecode => Self :: Evm ( EvmOutputSelection :: ByteCode ( BytecodeOutputSelection :: All ) ) ,
452
- Caf :: DeployedBytecode => Self :: Evm ( EvmOutputSelection :: DeployedByteCode (
472
+ Caf :: Abi => Ok ( Self :: Abi ) ,
473
+ Caf :: Bytecode => {
474
+ Ok ( Self :: Evm ( EvmOutputSelection :: ByteCode ( BytecodeOutputSelection :: All ) ) )
475
+ }
476
+ Caf :: DeployedBytecode => Ok ( Self :: Evm ( EvmOutputSelection :: DeployedByteCode (
453
477
DeployedBytecodeOutputSelection :: All ,
454
- ) ) ,
455
- Caf :: Assembly | Caf :: AssemblyOptimized => Self :: Evm ( EvmOutputSelection :: Assembly ) ,
456
- Caf :: LegacyAssembly => Self :: Evm ( EvmOutputSelection :: LegacyAssembly ) ,
457
- Caf :: MethodIdentifiers => Self :: Evm ( EvmOutputSelection :: MethodIdentifiers ) ,
458
- Caf :: GasEstimates => Self :: Evm ( EvmOutputSelection :: GasEstimates ) ,
459
- Caf :: StorageLayout => Self :: StorageLayout ,
460
- Caf :: DevDoc => Self :: DevDoc ,
461
- Caf :: Ir => Self :: Ir ,
462
- Caf :: IrOptimized => Self :: IrOptimized ,
463
- Caf :: Metadata => Self :: Metadata ,
464
- Caf :: UserDoc => Self :: UserDoc ,
465
- Caf :: Ewasm => Self :: Ewasm ( EwasmOutputSelection :: All ) ,
466
- Caf :: Errors => Self :: Abi ,
467
- Caf :: Events => Self :: Abi ,
478
+ ) ) ) ,
479
+ Caf :: Assembly | Caf :: AssemblyOptimized => Ok ( Self :: Evm ( EvmOutputSelection :: Assembly ) ) ,
480
+ Caf :: LegacyAssembly => Ok ( Self :: Evm ( EvmOutputSelection :: LegacyAssembly ) ) ,
481
+ Caf :: MethodIdentifiers => Ok ( Self :: Evm ( EvmOutputSelection :: MethodIdentifiers ) ) ,
482
+ Caf :: GasEstimates => Ok ( Self :: Evm ( EvmOutputSelection :: GasEstimates ) ) ,
483
+ Caf :: StorageLayout => Ok ( Self :: StorageLayout ) ,
484
+ Caf :: DevDoc => Ok ( Self :: DevDoc ) ,
485
+ Caf :: Ir => Ok ( Self :: Ir ) ,
486
+ Caf :: IrOptimized => Ok ( Self :: IrOptimized ) ,
487
+ Caf :: Metadata => Ok ( Self :: Metadata ) ,
488
+ Caf :: UserDoc => Ok ( Self :: UserDoc ) ,
489
+ Caf :: Ewasm => Ok ( Self :: Ewasm ( EwasmOutputSelection :: All ) ) ,
490
+ Caf :: Errors => Ok ( Self :: Abi ) ,
491
+ Caf :: Events => Ok ( Self :: Abi ) ,
492
+ Caf :: StandardJson => {
493
+ Err ( eyre ! ( "StandardJson is not supported for ContractOutputSelection" ) )
494
+ }
468
495
}
469
496
}
470
497
}
@@ -501,9 +528,9 @@ impl fmt::Display for ContractArtifactField {
501
528
}
502
529
503
530
impl ContractArtifactField {
504
- /// Returns true if this field is generated by default .
505
- pub const fn is_default ( & self ) -> bool {
506
- matches ! ( self , Self :: Bytecode | Self :: DeployedBytecode )
531
+ /// Returns true if this field does not need to be passed to the compiler .
532
+ pub const fn can_skip_field ( & self ) -> bool {
533
+ matches ! ( self , Self :: Bytecode | Self :: DeployedBytecode | Self :: StandardJson )
507
534
}
508
535
}
509
536
@@ -556,14 +583,22 @@ mod tests {
556
583
#[ test]
557
584
fn contract_output_selection ( ) {
558
585
for & field in ContractArtifactField :: ALL {
559
- let selection: ContractOutputSelection = field. into ( ) ;
560
- assert_eq ! ( field, selection) ;
561
-
562
- let s = field. as_str ( ) ;
563
- assert_eq ! ( s, field. to_string( ) ) ;
564
- assert_eq ! ( s. parse:: <ContractArtifactField >( ) . unwrap( ) , field) ;
565
- for alias in field. aliases ( ) {
566
- assert_eq ! ( alias. parse:: <ContractArtifactField >( ) . unwrap( ) , field) ;
586
+ if field == ContractArtifactField :: StandardJson {
587
+ let selection: Result < ContractOutputSelection , _ > = field. try_into ( ) ;
588
+ assert ! ( selection
589
+ . unwrap_err( )
590
+ . to_string( )
591
+ . eq( "StandardJson is not supported for ContractOutputSelection" ) ) ;
592
+ } else {
593
+ let selection: ContractOutputSelection = field. try_into ( ) . unwrap ( ) ;
594
+ assert_eq ! ( field, selection) ;
595
+
596
+ let s = field. as_str ( ) ;
597
+ assert_eq ! ( s, field. to_string( ) ) ;
598
+ assert_eq ! ( s. parse:: <ContractArtifactField >( ) . unwrap( ) , field) ;
599
+ for alias in field. aliases ( ) {
600
+ assert_eq ! ( alias. parse:: <ContractArtifactField >( ) . unwrap( ) , field) ;
601
+ }
567
602
}
568
603
}
569
604
}
0 commit comments