The goal here is to try to get JSON from the AST using ethers-rs
.
So to do that, I modified the ethers-rs
lib by adding the function get_data
here (I don't think this is the best option here to do, but for now it works) =>
get_data()
impl Node {
/// Reads the content of the file and returns a [Node] containing relevant information
pub fn read(file: impl AsRef<Path>) -> Result<Self> {
let file = file.as_ref();
let source = Source::read(file).map_err(|err| {
if !err.path().exists() && err.path().is_symlink() {
SolcError::ResolveBadSymlink(err)
} else {
SolcError::Resolve(err)
}
})?;
let data = SolData::parse(source.as_ref(), file);
Ok(Self { path: file.to_path_buf(), source, data })
}
pub fn content(&self) -> &str {
&self.source.content
}
pub fn imports(&self) -> &Vec<SolDataUnit<SolImport>> {
&self.data.imports
}
pub fn version(&self) -> &Option<SolDataUnit<String>> {
&self.data.version
}
pub fn experimental(&self) -> &Option<SolDataUnit<String>> {
&self.data.experimental
}
pub fn license(&self) -> &Option<SolDataUnit<String>> {
&self.data.license
}
pub fn unpack(&self) -> (&PathBuf, &Source) {
(&self.path, &self.source)
}
pub fn get_data(&self) -> &SolData { //here the get_data to get back the SolData and then try to walk it.
&self.data
}
}
So now using get_data, we can walk over the object SolContract
but for some compatibilities and sharing purposes in the future would like to get a JSON output (Think you could use Deserialize stuffs over all the type but didn't succed)
The final is to get output exactly like this project from ConsenSys written in Python => https://github.com/ConsenSys/python-solidity-parser
So for the moment, I am able to work on the AST(Rust object) but would like to find a way to convert it into JSON or find a way to get JSON directly.