forge_verify/etherscan/
standard_json.rs

1use super::{EtherscanSourceProvider, VerifyArgs};
2use crate::provider::VerificationContext;
3use eyre::{Context, Result};
4use foundry_block_explorers::verify::CodeFormat;
5use foundry_compilers::{artifacts::StandardJsonCompilerInput, solc::SolcLanguage};
6
7#[derive(Debug)]
8pub struct EtherscanStandardJsonSource;
9impl EtherscanSourceProvider for EtherscanStandardJsonSource {
10    fn source(
11        &self,
12        _args: &VerifyArgs,
13        context: &VerificationContext,
14    ) -> Result<(String, String, CodeFormat)> {
15        let mut input: StandardJsonCompilerInput = context
16            .project
17            .standard_json_input(&context.target_path)
18            .wrap_err("Failed to get standard json input")?
19            .normalize_evm_version(&context.compiler_version);
20
21        let mut settings = context.compiler_settings.solc.settings.clone();
22        settings.libraries.libs = input
23            .settings
24            .libraries
25            .libs
26            .into_iter()
27            .map(|(f, libs)| {
28                (f.strip_prefix(context.project.root()).unwrap_or(&f).to_path_buf(), libs)
29            })
30            .collect();
31
32        settings.remappings = input.settings.remappings;
33
34        // remove all incompatible settings
35        settings.sanitize(&context.compiler_version, SolcLanguage::Solidity);
36
37        input.settings = settings;
38
39        let source =
40            serde_json::to_string(&input).wrap_err("Failed to parse standard json input")?;
41
42        trace!(target: "forge::verify", standard_json=source, "determined standard json input");
43
44        let name = format!(
45            "{}:{}",
46            context
47                .target_path
48                .strip_prefix(context.project.root())
49                .unwrap_or(context.target_path.as_path())
50                .display(),
51            context.target_name.clone()
52        );
53        Ok((source, name, CodeFormat::StandardJsonInput))
54    }
55}