foundry_debugger/
builder.rsuse crate::{node::flatten_call_trace, DebugNode, Debugger};
use alloy_primitives::{map::AddressHashMap, Address};
use foundry_common::{evm::Breakpoints, get_contract_name};
use foundry_evm_traces::{debug::ContractSources, CallTraceArena, CallTraceDecoder, Traces};
#[derive(Debug, Default)]
#[must_use = "builders do nothing unless you call `build` on them"]
pub struct DebuggerBuilder {
debug_arena: Vec<DebugNode>,
identified_contracts: AddressHashMap<String>,
sources: ContractSources,
breakpoints: Breakpoints,
}
impl DebuggerBuilder {
#[inline]
pub fn new() -> Self {
Self::default()
}
#[inline]
pub fn traces(mut self, traces: Traces) -> Self {
for (_, arena) in traces {
self = self.trace_arena(arena.arena);
}
self
}
#[inline]
pub fn trace_arena(mut self, arena: CallTraceArena) -> Self {
flatten_call_trace(arena, &mut self.debug_arena);
self
}
#[inline]
pub fn decoders(mut self, decoders: &[CallTraceDecoder]) -> Self {
for decoder in decoders {
self = self.decoder(decoder);
}
self
}
#[inline]
pub fn decoder(self, decoder: &CallTraceDecoder) -> Self {
let c = decoder.contracts.iter().map(|(k, v)| (*k, get_contract_name(v).to_string()));
self.identified_contracts(c)
}
#[inline]
pub fn identified_contracts(
mut self,
identified_contracts: impl IntoIterator<Item = (Address, String)>,
) -> Self {
self.identified_contracts.extend(identified_contracts);
self
}
#[inline]
pub fn sources(mut self, sources: ContractSources) -> Self {
self.sources = sources;
self
}
#[inline]
pub fn breakpoints(mut self, breakpoints: Breakpoints) -> Self {
self.breakpoints = breakpoints;
self
}
#[inline]
pub fn build(self) -> Debugger {
let Self { debug_arena, identified_contracts, sources, breakpoints } = self;
Debugger::new(debug_arena, identified_contracts, sources, breakpoints)
}
}