Skip to content

Commit

Permalink
Etherscan could also have a plain source mapping
Browse files Browse the repository at this point in the history
Reference: 0x68b26dcf21180d2a8de5a303f8cc5b14c8d99c4c
  • Loading branch information
wtdcode committed Jul 1, 2023
1 parent 5faea1b commit 8fc7368
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion ethers-etherscan/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ pub enum SourceCodeMetadata {
#[serde(default, skip_serializing_if = "Option::is_none")]
settings: Option<serde_json::Value>,
},
/// Contains just mapped source code.
Sources {
/// Source path => source code
#[serde(default)]
sources: HashMap<String, SourceCodeEntry>,
},
/// Contains only the source code.
SourceCode(String),
}
Expand All @@ -57,21 +63,26 @@ impl SourceCodeMetadata {
match self {
Self::Metadata { sources, .. } => {
sources.values().map(|s| s.content.clone()).collect::<Vec<_>>().join("\n")
}
},
Self::Sources { sources, .. } => {
sources.values().map(|s| s.content.clone()).collect::<Vec<_>>().join("\n")
},
Self::SourceCode(s) => s.clone(),
}
}

pub fn language(&self) -> Option<SourceCodeLanguage> {
match self {
Self::Metadata { language, .. } => language.clone(),
Self::Sources { .. } => None,
Self::SourceCode(_) => None,
}
}

pub fn sources(&self) -> HashMap<String, SourceCodeEntry> {
match self {
Self::Metadata { sources, .. } => sources.clone(),
Self::Sources { sources, .. } => sources.clone(),
Self::SourceCode(s) => HashMap::from([("Contract".into(), s.into())]),
}
}
Expand All @@ -89,6 +100,7 @@ impl SourceCodeMetadata {
}
None => Ok(None),
},
Self::Sources { .. } => Ok(None),
Self::SourceCode(_) => Ok(None),
}
}
Expand All @@ -97,6 +109,7 @@ impl SourceCodeMetadata {
pub fn settings(&self) -> Option<&serde_json::Value> {
match self {
Self::Metadata { settings, .. } => settings.as_ref(),
Self::Sources { .. } => None,
Self::SourceCode(_) => None,
}
}
Expand Down

0 comments on commit 8fc7368

Please sign in to comment.