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