use crate::{Config, DebugSettingsOf};
use Debug;
use codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
use serde::{Deserialize, Serialize};
use sp_core::Get;
#[derive(
Encode,
Decode,
Default,
Clone,
PartialEq,
Debug,
TypeInfo,
MaxEncodedLen,
Serialize,
Deserialize,
)]
pub struct DebugSettings {
allow_unlimited_contract_size: bool,
bypass_eip_3607: bool,
pvm_logs: bool,
disable_execution_tracing: bool,
}
impl DebugSettings {
pub fn set_bypass_eip_3607(mut self, value: bool) -> Self {
self.bypass_eip_3607 = value;
self
}
pub fn set_allow_unlimited_contract_size(mut self, value: bool) -> Self {
self.allow_unlimited_contract_size = value;
self
}
pub fn set_enable_pvm_logs(mut self, value: bool) -> Self {
self.pvm_logs = value;
self
}
pub fn is_execution_tracing_enabled<T: Config>() -> bool {
T::DebugEnabled::get() && !DebugSettingsOf::<T>::get().disable_execution_tracing
}
pub fn is_unlimited_contract_size_allowed<T: Config>() -> bool {
T::DebugEnabled::get() && DebugSettingsOf::<T>::get().allow_unlimited_contract_size
}
pub fn bypass_eip_3607<T: Config>() -> bool {
T::DebugEnabled::get() && DebugSettingsOf::<T>::get().bypass_eip_3607
}
pub fn is_pvm_logs_enabled<T: Config>() -> bool {
T::DebugEnabled::get() && DebugSettingsOf::<T>::get().pvm_logs
}
pub fn write_to_storage<T: Config>(&self) {
DebugSettingsOf::<T>::put(self);
if !T::DebugEnabled::get() {
log::warn!(
target: crate::LOG_TARGET,
"Debug settings changed, but debug features are disabled in the runtime configuration."
);
}
}
}