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	evm::{CallTrace, Trace},
19	tracing::Tracing,
20	Config,
21};
22
23mod call_tracing;
24pub use call_tracing::*;
25
26mod prestate_tracing;
27pub use prestate_tracing::*;
28
29/// A composite tracer.
30#[derive(derive_more::From, Debug)]
31pub enum Tracer<T> {
32	/// A tracer that traces calls.
33	CallTracer(CallTracer),
34	/// A tracer that traces the prestate.
35	PrestateTracer(PrestateTracer<T>),
36}
37
38impl<T: Config> Tracer<T>
39where
40	T::Nonce: Into<u32>,
41{
42	/// Returns an empty trace.
43	pub fn empty_trace(&self) -> Trace {
44		match self {
45			Tracer::CallTracer(_) => CallTrace::default().into(),
46			Tracer::PrestateTracer(tracer) => tracer.empty_trace().into(),
47		}
48	}
49
50	/// Get a mutable trait‐object reference to the inner tracer.
51	pub fn as_tracing(&mut self) -> &mut (dyn Tracing + 'static) {
52		match self {
53			Tracer::CallTracer(inner) => inner as &mut dyn Tracing,
54			Tracer::PrestateTracer(inner) => inner as &mut dyn Tracing,
55		}
56	}
57
58	/// Collect the traces and return them.
59	pub fn collect_trace(self) -> Option<Trace> {
60		match self {
61			Tracer::CallTracer(inner) => inner.collect_trace().map(Trace::Call),
62			Tracer::PrestateTracer(inner) => Some(inner.collect_trace().into()),
63		}
64	}
65}