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

Commit 6ab8aff

Browse files
committed
feat(solidity/core/solc-wrapper): added json to ast parsing
1 parent f58e84f commit 6ab8aff

File tree

3 files changed

+115
-1
lines changed

3 files changed

+115
-1
lines changed

libs/solc-wrapper/Cargo.lock

Lines changed: 93 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

libs/solc-wrapper/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ edition = "2021"
77

88
[dependencies]
99
serde_json = "1.0.113"
10+
solc-ast-rs-types = "0.1.0"
1011
thiserror = "1.0.56"

libs/solc-wrapper/src/lib.rs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,32 @@
11
mod solc;
22

3+
use solc_ast_rs_types::types::SourceUnit;
4+
35
#[derive(Debug)]
46
pub struct SolcJsonFile {
57
pub json: serde_json::Value,
68
pub file: String,
79
}
10+
#[derive(Debug)]
11+
pub struct SolcAstFile {
12+
pub file: String,
13+
pub ast: SourceUnit,
14+
}
15+
16+
pub fn get_ast_from_solc_output(output: &str) -> Result<Vec<SolcAstFile>, serde_json::Error> {
17+
let files = get_files_from_solc_output(output)?;
18+
let mut ast_files = Vec::new();
19+
for file in files {
20+
let ast: SourceUnit = serde_json::from_value(file.json)?;
21+
ast_files.push(SolcAstFile {
22+
file: file.file,
23+
ast
24+
});
25+
}
26+
Ok(ast_files)
27+
}
828

9-
pub fn get_files_from_solc_output(output: &str) -> Result<Vec<SolcJsonFile>, serde_json::Error> {
29+
fn get_files_from_solc_output(output: &str) -> Result<Vec<SolcJsonFile>, serde_json::Error> {
1030
let mut files = Vec::new();
1131
let mut current_json = String::new();
1232
let mut current_file = String::new();

0 commit comments

Comments
 (0)