Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 17 additions & 8 deletions src/tracing/js/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ pub const RECURSION_LIMIT: usize = 10_000;
#[derive(Debug)]
pub struct JsInspector {
ctx: Context,
/// The javascript code provided to the inspector.
code: String,
/// The javascript config provided to the inspector.
_js_config_value: JsValue,
/// The input config object.
Expand Down Expand Up @@ -126,9 +128,10 @@ impl JsInspector {
register_builtins(&mut ctx)?;

// evaluate the code
let code = format!("({code})");
let obj =
ctx.eval(Source::from_bytes(code.as_bytes())).map_err(JsInspectorError::EvalCode)?;
let code_to_evaluate = format!("({code})");
let obj = ctx
.eval(Source::from_bytes(code_to_evaluate.as_bytes()))
.map_err(JsInspectorError::EvalCode)?;

let obj = obj.as_object().cloned().ok_or(JsInspectorError::ExpectedJsObject)?;

Expand Down Expand Up @@ -178,6 +181,7 @@ impl JsInspector {

Ok(Self {
ctx,
code,
_js_config_value,
config,
obj,
Expand All @@ -192,6 +196,11 @@ impl JsInspector {
})
}

/// Returns the javascript code.
pub const fn code(&self) -> &String {
&self.code
}

/// Returns the config object.
pub const fn config(&self) -> &serde_json::Value {
&self.config
Expand Down Expand Up @@ -219,7 +228,7 @@ impl JsInspector {
/// Note: This is supposed to be called after the inspection has finished.
pub fn json_result<DB>(
&mut self,
res: ResultAndState<impl HaltReasonTr>,
res: &ResultAndState<impl HaltReasonTr>,
tx: &impl Transaction,
block: &impl Block,
db: &DB,
Expand All @@ -235,7 +244,7 @@ impl JsInspector {
/// Calls the result function and returns the result.
pub fn result<TX, DB>(
&mut self,
res: ResultAndState<impl HaltReasonTr>,
res: &ResultAndState<impl HaltReasonTr>,
tx: &TX,
block: &impl Block,
db: &DB,
Expand All @@ -258,7 +267,7 @@ impl JsInspector {
output_bytes = Some(out);
}
Output::Create(out, addr) => {
to = addr;
to = addr.clone();
output_bytes = Some(out);
}
},
Expand Down Expand Up @@ -293,7 +302,7 @@ impl JsInspector {
value: tx.value(),
block: block.number(),
coinbase: block.beneficiary(),
output: output_bytes.unwrap_or_default(),
output: output_bytes.unwrap_or_default().clone(),
time: block.timestamp().to_string(),
intrinsic_gas: 0,
transaction_ctx: self.transaction_context,
Expand Down Expand Up @@ -718,7 +727,7 @@ mod tests {

assert_eq!(res.result.is_success(), success);
let (ctx, inspector) = evm.ctx_inspector();
inspector.json_result(res, ctx.tx(), ctx.block(), ctx.db_ref()).unwrap()
inspector.json_result(&res, ctx.tx(), ctx.block(), ctx.db_ref()).unwrap()
}

#[test]
Expand Down
Loading