pub use crate::{
exec::{ExecResult, ExportedFunction},
primitives::ExecReturnValue,
};
use crate::{Config, LOG_TARGET};
pub trait Debugger<T: Config>: Tracing<T> + CallInterceptor<T> {}
impl<T: Config, V> Debugger<T> for V where V: Tracing<T> + CallInterceptor<T> {}
pub trait Tracing<T: Config> {
type CallSpan: CallSpan;
fn new_call_span(
contract_address: &T::AccountId,
entry_point: ExportedFunction,
input_data: &[u8],
) -> Self::CallSpan;
}
pub trait CallSpan {
fn after_call(self, output: &ExecReturnValue);
}
impl<T: Config> Tracing<T> for () {
type CallSpan = ();
fn new_call_span(
contract_address: &T::AccountId,
entry_point: ExportedFunction,
input_data: &[u8],
) {
log::trace!(target: LOG_TARGET, "call {entry_point:?} account: {contract_address:?}, input_data: {input_data:?}")
}
}
impl CallSpan for () {
fn after_call(self, output: &ExecReturnValue) {
log::trace!(target: LOG_TARGET, "call result {output:?}")
}
}
pub trait CallInterceptor<T: Config> {
fn intercept_call(
contract_address: &T::AccountId,
entry_point: &ExportedFunction,
input_data: &[u8],
) -> Option<ExecResult>;
}
impl<T: Config> CallInterceptor<T> for () {
fn intercept_call(
_contract_address: &T::AccountId,
_entry_point: &ExportedFunction,
_input_data: &[u8],
) -> Option<ExecResult> {
None
}
}