use crate::{Config, DebugSettingsOf};
use codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
use serde::{Deserialize, Serialize};
use sp_core::Get;
use sp_runtime::RuntimeDebug;
#[derive(
Encode,
Decode,
Default,
Clone,
PartialEq,
RuntimeDebug,
TypeInfo,
MaxEncodedLen,
Serialize,
Deserialize,
)]
pub struct DebugSettings {
allow_unlimited_contract_size: bool,
bypass_eip_3607: bool,
pvm_logs: bool,
}
impl DebugSettings {
pub fn new(allow_unlimited_contract_size: bool, bypass_eip_3607: bool, pvm_logs: bool) -> Self {
Self { allow_unlimited_contract_size, bypass_eip_3607, pvm_logs }
}
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."
);
}
}
}