Skip to content

Commit

Permalink
extended JsonResult structure (foundry-rs#8565)
Browse files Browse the repository at this point in the history
* extended JsonResult structure

* removed breakpoints in JsonResult

* chore: nits

---------

Co-authored-by: DaniPopes <[email protected]>
  • Loading branch information
francesco-gaglione and DaniPopes authored Aug 8, 2024
1 parent 1f33c6f commit 14e50ed
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
16 changes: 7 additions & 9 deletions crates/script/src/execute.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use super::{runner::ScriptRunner, JsonResult, NestedValue, ScriptResult};
use crate::{
build::{CompiledState, LinkedBuildData},
simulate::PreSimulationState,
ScriptArgs, ScriptConfig,
};

use super::{runner::ScriptRunner, JsonResult, NestedValue, ScriptResult};
use alloy_dyn_abi::FunctionExt;
use alloy_json_abi::{Function, InternalType, JsonAbi};
use alloy_primitives::{Address, Bytes};
Expand Down Expand Up @@ -382,14 +381,13 @@ impl PreSimulationState {
pub fn show_json(&self) -> Result<()> {
let result = &self.execution_result;

let console_logs = decode_console_logs(&result.logs);
let output = JsonResult {
logs: console_logs,
gas_used: result.gas_used,
returns: self.execution_artifacts.returns.clone(),
let json_result = JsonResult {
logs: decode_console_logs(&result.logs),
returns: &self.execution_artifacts.returns,
result,
};
let j = serde_json::to_string(&output)?;
shell::println(j)?;
let json = serde_json::to_string(&json_result)?;
shell::println(json)?;

if !self.execution_result.success {
return Err(eyre::eyre!(
Expand Down
14 changes: 9 additions & 5 deletions crates/script/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,16 +457,19 @@ impl Provider for ScriptArgs {
}
}

#[derive(Default)]
#[derive(Default, Serialize)]
pub struct ScriptResult {
pub success: bool,
#[serde(rename = "raw_logs")]
pub logs: Vec<Log>,
pub traces: Traces,
pub gas_used: u64,
pub labeled_addresses: HashMap<Address, String>,
#[serde(skip)]
pub transactions: Option<BroadcastableTransactions>,
pub returned: Bytes,
pub address: Option<Address>,
#[serde(skip)]
pub breakpoints: Breakpoints,
}

Expand All @@ -490,11 +493,12 @@ impl ScriptResult {
}
}

#[derive(Serialize, Deserialize)]
struct JsonResult {
#[derive(Serialize)]
struct JsonResult<'a> {
logs: Vec<String>,
gas_used: u64,
returns: HashMap<String, NestedValue>,
returns: &'a HashMap<String, NestedValue>,
#[serde(flatten)]
result: &'a ScriptResult,
}

#[derive(Clone, Serialize, Deserialize)]
Expand Down

0 comments on commit 14e50ed

Please sign in to comment.