Skip to content
This repository has been archived by the owner on Jul 3, 2024. It is now read-only.

Commit

Permalink
feat(solidity/core/solc-wrapper): added json to ast parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
0xSwapFeeder committed Feb 9, 2024
1 parent f58e84f commit 6ab8aff
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 1 deletion.
93 changes: 93 additions & 0 deletions libs/solc-wrapper/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions libs/solc-wrapper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ edition = "2021"

[dependencies]
serde_json = "1.0.113"
solc-ast-rs-types = "0.1.0"
thiserror = "1.0.56"
22 changes: 21 additions & 1 deletion libs/solc-wrapper/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,32 @@
mod solc;

use solc_ast_rs_types::types::SourceUnit;

#[derive(Debug)]
pub struct SolcJsonFile {
pub json: serde_json::Value,
pub file: String,
}
#[derive(Debug)]
pub struct SolcAstFile {
pub file: String,
pub ast: SourceUnit,
}

pub fn get_ast_from_solc_output(output: &str) -> Result<Vec<SolcAstFile>, serde_json::Error> {
let files = get_files_from_solc_output(output)?;
let mut ast_files = Vec::new();
for file in files {
let ast: SourceUnit = serde_json::from_value(file.json)?;
ast_files.push(SolcAstFile {
file: file.file,
ast
});
}
Ok(ast_files)
}

pub fn get_files_from_solc_output(output: &str) -> Result<Vec<SolcJsonFile>, serde_json::Error> {
fn get_files_from_solc_output(output: &str) -> Result<Vec<SolcJsonFile>, serde_json::Error> {
let mut files = Vec::new();
let mut current_json = String::new();
let mut current_file = String::new();
Expand Down

0 comments on commit 6ab8aff

Please sign in to comment.