use parity_scale_codec::Encode;
use sp_runtime_interface::runtime_interface;
use crate::sp_externalities::{decl_extension, ExternalitiesExt};
#[runtime_interface]
pub trait ContractCallDebugger {
fn after_call(
&mut self,
contract_address: Vec<u8>,
is_call: bool,
input_data: Vec<u8>,
result: Vec<u8>,
) {
if let Some(ext) = self.extension::<TracingExt>() {
ext.after_call(contract_address, is_call, input_data, result);
}
}
fn intercept_call(
&mut self,
contract_address: Vec<u8>,
is_call: bool,
input_data: Vec<u8>,
) -> Option<Vec<u8>> {
self.extension::<InterceptingExt>()
.map(|ext| ext.intercept_call(contract_address, is_call, input_data))
}
}
pub trait TracingExtT {
fn after_call(
&self,
_contract_address: Vec<u8>,
_is_call: bool,
_input_data: Vec<u8>,
_result: Vec<u8>,
) {
}
}
decl_extension! {
pub struct TracingExt(Box<dyn TracingExtT + Send>);
}
pub trait InterceptingExtT {
fn intercept_call(
&self,
_contract_address: Vec<u8>,
_is_call: bool,
_input_data: Vec<u8>,
) -> Vec<u8> {
None::<()>.encode()
}
}
decl_extension! {
pub struct InterceptingExt(Box<dyn InterceptingExtT + Send>);
}
pub struct NoopExt;
impl TracingExtT for NoopExt {}
impl InterceptingExtT for NoopExt {}