1use crate::{Config, DebugSettingsOf};
19use codec::{Decode, Encode, MaxEncodedLen};
20use scale_info::TypeInfo;
21use serde::{Deserialize, Serialize};
22use sp_core::Get;
23use sp_runtime::RuntimeDebug;
24
25#[derive(
27 Encode,
28 Decode,
29 Default,
30 Clone,
31 PartialEq,
32 RuntimeDebug,
33 TypeInfo,
34 MaxEncodedLen,
35 Serialize,
36 Deserialize,
37)]
38pub struct DebugSettings {
39 allow_unlimited_contract_size: bool,
41 bypass_eip_3607: bool,
44 pvm_logs: bool,
46}
47
48impl DebugSettings {
49 pub fn new(allow_unlimited_contract_size: bool, bypass_eip_3607: bool, pvm_logs: bool) -> Self {
50 Self { allow_unlimited_contract_size, bypass_eip_3607, pvm_logs }
51 }
52
53 pub fn is_unlimited_contract_size_allowed<T: Config>() -> bool {
55 T::DebugEnabled::get() && DebugSettingsOf::<T>::get().allow_unlimited_contract_size
56 }
57
58 pub fn bypass_eip_3607<T: Config>() -> bool {
61 T::DebugEnabled::get() && DebugSettingsOf::<T>::get().bypass_eip_3607
62 }
63
64 pub fn is_pvm_logs_enabled<T: Config>() -> bool {
66 T::DebugEnabled::get() && DebugSettingsOf::<T>::get().pvm_logs
67 }
68
69 pub fn write_to_storage<T: Config>(&self) {
71 DebugSettingsOf::<T>::put(self);
72 if !T::DebugEnabled::get() {
73 log::warn!(
74 target: crate::LOG_TARGET,
75 "Debug settings changed, but debug features are disabled in the runtime configuration."
76 );
77 }
78 }
79}