Skip to content

Commit 9351f18

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

File tree

4 files changed

+210
-76
lines changed

4 files changed

+210
-76
lines changed

src/tracing/js/mod.rs

Lines changed: 15 additions & 7 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,9 @@ impl JsInspector {
126128
register_builtins(&mut ctx)?;
127129

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

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

@@ -178,6 +180,7 @@ impl JsInspector {
178180

179181
Ok(Self {
180182
ctx,
183+
code,
181184
_js_config_value,
182185
config,
183186
obj,
@@ -192,6 +195,11 @@ impl JsInspector {
192195
})
193196
}
194197

198+
/// Returns the javascript code.
199+
pub const fn code(&self) -> &String {
200+
&self.code
201+
}
202+
195203
/// Returns the config object.
196204
pub const fn config(&self) -> &serde_json::Value {
197205
&self.config
@@ -219,7 +227,7 @@ impl JsInspector {
219227
/// Note: This is supposed to be called after the inspection has finished.
220228
pub fn json_result<DB>(
221229
&mut self,
222-
res: ResultAndState<impl HaltReasonTr>,
230+
res: &ResultAndState<impl HaltReasonTr>,
223231
tx: &impl Transaction,
224232
block: &impl Block,
225233
db: &DB,
@@ -235,7 +243,7 @@ impl JsInspector {
235243
/// Calls the result function and returns the result.
236244
pub fn result<TX, DB>(
237245
&mut self,
238-
res: ResultAndState<impl HaltReasonTr>,
246+
res: &ResultAndState<impl HaltReasonTr>,
239247
tx: &TX,
240248
block: &impl Block,
241249
db: &DB,
@@ -258,7 +266,7 @@ impl JsInspector {
258266
output_bytes = Some(out);
259267
}
260268
Output::Create(out, addr) => {
261-
to = addr;
269+
to = addr.clone();
262270
output_bytes = Some(out);
263271
}
264272
},
@@ -293,7 +301,7 @@ impl JsInspector {
293301
value: tx.value(),
294302
block: block.number(),
295303
coinbase: block.beneficiary(),
296-
output: output_bytes.unwrap_or_default(),
304+
output: output_bytes.unwrap_or_default().clone(),
297305
time: block.timestamp().to_string(),
298306
intrinsic_gas: 0,
299307
transaction_ctx: self.transaction_context,
@@ -718,7 +726,7 @@ mod tests {
718726

719727
assert_eq!(res.result.is_success(), success);
720728
let (ctx, inspector) = evm.ctx_inspector();
721-
inspector.json_result(res, ctx.tx(), ctx.block(), ctx.db_ref()).unwrap()
729+
inspector.json_result(&res, ctx.tx(), ctx.block(), ctx.db_ref()).unwrap()
722730
}
723731

724732
#[test]

0 commit comments

Comments
 (0)