Skip to main content

forge_verify/etherscan/
standard_json.rs

1use super::{EtherscanSourceProvider, VerifyArgs};
2use crate::{provider::VerificationContext, verify::ContractLanguage};
3use eyre::{Context, Result};
4use foundry_block_explorers::verify::CodeFormat;
5
6#[derive(Debug)]
7pub struct EtherscanStandardJsonSource;
8impl EtherscanSourceProvider for EtherscanStandardJsonSource {
9    fn source(
10        &self,
11        args: &VerifyArgs,
12        context: &VerificationContext,
13    ) -> Result<(String, String, CodeFormat)> {
14        let lang = args.detect_language(context);
15
16        let code_format = match lang {
17            ContractLanguage::Solidity => CodeFormat::StandardJsonInput,
18            ContractLanguage::Vyper => CodeFormat::VyperJson,
19        };
20
21        let source = match lang {
22            ContractLanguage::Solidity => {
23                let input = context.get_solc_standard_json_input()?;
24                serde_json::to_string(&input).wrap_err("Failed to parse standard json input")?
25            }
26            ContractLanguage::Vyper => {
27                let input = context.get_vyper_standard_json_input()?;
28                serde_json::to_string(&input).wrap_err("Failed to parse vyper json input")?
29            }
30        };
31
32        trace!(target: "forge::verify", standard_json=source, "determined standard json input");
33
34        let name = format!(
35            "{}:{}",
36            context
37                .target_path
38                .strip_prefix(context.project.root())
39                .unwrap_or(context.target_path.as_path())
40                .display(),
41            context.target_name.clone()
42        );
43        Ok((source, name, code_format))
44    }
45}