Skip to content

Commit f0f15f7

Browse files
committed
feat(mux-tracer): Support JS tracer in MUX tracer.
Ref: #58
1 parent 2fb7b9b commit f0f15f7

File tree

4 files changed

+214
-77
lines changed

4 files changed

+214
-77
lines changed

src/tracing/js/mod.rs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ pub const RECURSION_LIMIT: usize = 10_000;
5454
#[derive(Debug)]
5555
pub struct JsInspector {
5656
ctx: Context,
57+
/// The javascript code provided to the inspector.
58+
code: String,
5759
/// The javascript config provided to the inspector.
5860
_js_config_value: JsValue,
5961
/// The input config object.
@@ -126,9 +128,10 @@ impl JsInspector {
126128
register_builtins(&mut ctx)?;
127129

128130
// evaluate the code
129-
let code = format!("({code})");
130-
let obj =
131-
ctx.eval(Source::from_bytes(code.as_bytes())).map_err(JsInspectorError::EvalCode)?;
131+
let code_to_evaluate = format!("({code})");
132+
let obj = ctx
133+
.eval(Source::from_bytes(code_to_evaluate.as_bytes()))
134+
.map_err(JsInspectorError::EvalCode)?;
132135

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

@@ -178,6 +181,7 @@ impl JsInspector {
178181

179182
Ok(Self {
180183
ctx,
184+
code,
181185
_js_config_value,
182186
config,
183187
obj,
@@ -192,6 +196,11 @@ impl JsInspector {
192196
})
193197
}
194198

199+
/// Returns the javascript code.
200+
pub const fn code(&self) -> &String {
201+
&self.code
202+
}
203+
195204
/// Returns the config object.
196205
pub const fn config(&self) -> &serde_json::Value {
197206
&self.config
@@ -219,7 +228,7 @@ impl JsInspector {
219228
/// Note: This is supposed to be called after the inspection has finished.
220229
pub fn json_result<DB>(
221230
&mut self,
222-
res: ResultAndState<impl HaltReasonTr>,
231+
res: &ResultAndState<impl HaltReasonTr>,
223232
tx: &impl Transaction,
224233
block: &impl Block,
225234
db: &DB,
@@ -235,7 +244,7 @@ impl JsInspector {
235244
/// Calls the result function and returns the result.
236245
pub fn result<TX, DB>(
237246
&mut self,
238-
res: ResultAndState<impl HaltReasonTr>,
247+
res: &ResultAndState<impl HaltReasonTr>,
239248
tx: &TX,
240249
block: &impl Block,
241250
db: &DB,
@@ -258,7 +267,7 @@ impl JsInspector {
258267
output_bytes = Some(out);
259268
}
260269
Output::Create(out, addr) => {
261-
to = addr;
270+
to = addr.clone();
262271
output_bytes = Some(out);
263272
}
264273
},
@@ -293,7 +302,7 @@ impl JsInspector {
293302
value: tx.value(),
294303
block: block.number(),
295304
coinbase: block.beneficiary(),
296-
output: output_bytes.unwrap_or_default(),
305+
output: output_bytes.unwrap_or_default().clone(),
297306
time: block.timestamp().to_string(),
298307
intrinsic_gas: 0,
299308
transaction_ctx: self.transaction_context,
@@ -718,7 +727,7 @@ mod tests {
718727

719728
assert_eq!(res.result.is_success(), success);
720729
let (ctx, inspector) = evm.ctx_inspector();
721-
inspector.json_result(res, ctx.tx(), ctx.block(), ctx.db_ref()).unwrap()
730+
inspector.json_result(&res, ctx.tx(), ctx.block(), ctx.db_ref()).unwrap()
722731
}
723732

724733
#[test]

0 commit comments

Comments
 (0)