11//! Support for compiling [ethers::solc::Project]
2- use crate :: { glob:: GlobMatcher , term, TestFunctionExt } ;
2+ use crate :: { compact_to_contract , glob:: GlobMatcher , term, TestFunctionExt } ;
33use comfy_table:: { presets:: ASCII_MARKDOWN , * } ;
44use ethers_etherscan:: contract:: Metadata ;
55use ethers_solc:: {
@@ -11,7 +11,7 @@ use ethers_solc::{
1111} ;
1212use eyre:: Result ;
1313use std:: {
14- collections:: BTreeMap ,
14+ collections:: { BTreeMap , HashMap } ,
1515 convert:: Infallible ,
1616 fmt:: Display ,
1717 path:: { Path , PathBuf } ,
@@ -171,6 +171,10 @@ impl ProjectCompiler {
171171 }
172172}
173173
174+ /// Map over artifacts contract sources name -> file_id -> (source, contract)
175+ #[ derive( Default , Debug , Clone ) ]
176+ pub struct ContractSources ( pub HashMap < String , HashMap < u32 , ( String , ContractBytecodeSome ) > > ) ;
177+
174178// https://eips.ethereum.org/EIPS/eip-170
175179const CONTRACT_SIZE_LIMIT : usize = 24576 ;
176180
@@ -398,10 +402,11 @@ pub fn compile_target_with_filter(
398402 }
399403}
400404
401- /// Creates and compiles a project from an Etherscan source.
405+ /// Compiles an Etherscan source from metadata by creating a project.
406+ /// Returns the artifact_id, the file_id, and the bytecode
402407pub async fn compile_from_source (
403408 metadata : & Metadata ,
404- ) -> Result < ( ArtifactId , ContractBytecodeSome ) > {
409+ ) -> Result < ( ArtifactId , u32 , ContractBytecodeSome ) > {
405410 let root = tempfile:: tempdir ( ) ?;
406411 let root_path = root. path ( ) ;
407412 let project = etherscan_project ( metadata, root_path) ?;
@@ -412,19 +417,18 @@ pub async fn compile_from_source(
412417 eyre:: bail!( project_output. to_string( ) )
413418 }
414419
415- let ( artifact_id, contract) = project_output
416- . into_contract_bytecodes ( )
420+ let ( artifact_id, file_id , contract) = project_output
421+ . into_artifacts ( )
417422 . find ( |( artifact_id, _) | artifact_id. name == metadata. contract_name )
423+ . map ( |( aid, art) | {
424+ ( aid, art. source_file ( ) . expect ( "no source file" ) . id , art. into_contract_bytecode ( ) )
425+ } )
418426 . expect ( "there should be a contract with bytecode" ) ;
419- let bytecode = ContractBytecodeSome {
420- abi : contract. abi . unwrap ( ) ,
421- bytecode : contract. bytecode . unwrap ( ) . into ( ) ,
422- deployed_bytecode : contract. deployed_bytecode . unwrap ( ) . into ( ) ,
423- } ;
427+ let bytecode = compact_to_contract ( contract) ?;
424428
425429 root. close ( ) ?;
426430
427- Ok ( ( artifact_id, bytecode) )
431+ Ok ( ( artifact_id, file_id , bytecode) )
428432}
429433
430434/// Creates a [Project] from an Etherscan source.
0 commit comments