referrerpolicy=no-referrer-when-downgrade

pallet_revive/evm/
tracing.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: Apache-2.0
5
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// 	http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17use crate::{
18	Config,
19	evm::{CallTrace, ExecutionTrace, Trace},
20	tracing::Tracing,
21};
22
23mod call_tracing;
24pub use call_tracing::*;
25
26mod prestate_tracing;
27pub use prestate_tracing::*;
28
29mod execution_tracing;
30pub use execution_tracing::*;
31
32/// A composite tracer.
33#[derive(derive_more::From, Debug)]
34pub enum Tracer<T> {
35	/// A tracer that traces calls.
36	CallTracer(CallTracer),
37	/// A tracer that traces the prestate.
38	PrestateTracer(PrestateTracer<T>),
39	/// A tracer that traces opcodes and syscalls.
40	ExecutionTracer(ExecutionTracer),
41}
42
43impl<T: Config> Tracer<T>
44where
45	T::Nonce: Into<u32>,
46{
47	/// Returns an empty trace.
48	pub fn empty_trace(&self) -> Trace {
49		match self {
50			Tracer::CallTracer(_) => CallTrace::default().into(),
51			Tracer::PrestateTracer(tracer) => tracer.empty_trace().into(),
52			Tracer::ExecutionTracer(_) => ExecutionTrace::default().into(),
53		}
54	}
55
56	/// Get a mutable trait‐object reference to the inner tracer.
57	pub fn as_tracing(&mut self) -> &mut (dyn Tracing + 'static) {
58		match self {
59			Tracer::CallTracer(inner) => inner as &mut dyn Tracing,
60			Tracer::PrestateTracer(inner) => inner as &mut dyn Tracing,
61			Tracer::ExecutionTracer(inner) => inner as &mut dyn Tracing,
62		}
63	}
64
65	/// Collect the traces and return them.
66	pub fn collect_trace(self) -> Option<Trace> {
67		match self {
68			Tracer::CallTracer(inner) => inner.collect_trace().map(Trace::Call),
69			Tracer::PrestateTracer(inner) => Some(inner.collect_trace().into()),
70			Tracer::ExecutionTracer(inner) => Some(inner.collect_trace().into()),
71		}
72	}
73
74	/// Check if this is an execution tracer.
75	pub fn is_execution_tracer(&self) -> bool {
76		matches!(self, Tracer::ExecutionTracer(_))
77	}
78}