1use crate::{Config, DebugSettingsOf};
19use Debug;
20use codec::{Decode, Encode, MaxEncodedLen};
21use scale_info::TypeInfo;
22use serde::{Deserialize, Serialize};
23use sp_core::Get;
24
25#[derive(
27 Encode,
28 Decode,
29 Default,
30 Clone,
31 PartialEq,
32 Debug,
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 disable_execution_tracing: bool,
48}
49
50impl DebugSettings {
51 pub fn set_bypass_eip_3607(mut self, value: bool) -> Self {
52 self.bypass_eip_3607 = value;
53 self
54 }
55
56 pub fn set_allow_unlimited_contract_size(mut self, value: bool) -> Self {
57 self.allow_unlimited_contract_size = value;
58 self
59 }
60
61 pub fn set_enable_pvm_logs(mut self, value: bool) -> Self {
62 self.pvm_logs = value;
63 self
64 }
65
66 pub fn is_execution_tracing_enabled<T: Config>() -> bool {
67 T::DebugEnabled::get() && !DebugSettingsOf::<T>::get().disable_execution_tracing
68 }
69
70 pub fn is_unlimited_contract_size_allowed<T: Config>() -> bool {
72 T::DebugEnabled::get() && DebugSettingsOf::<T>::get().allow_unlimited_contract_size
73 }
74
75 pub fn bypass_eip_3607<T: Config>() -> bool {
78 T::DebugEnabled::get() && DebugSettingsOf::<T>::get().bypass_eip_3607
79 }
80
81 pub fn is_pvm_logs_enabled<T: Config>() -> bool {
83 T::DebugEnabled::get() && DebugSettingsOf::<T>::get().pvm_logs
84 }
85
86 pub fn write_to_storage<T: Config>(&self) {
88 DebugSettingsOf::<T>::put(self);
89 if !T::DebugEnabled::get() {
90 log::warn!(
91 target: crate::LOG_TARGET,
92 "Debug settings changed, but debug features are disabled in the runtime configuration."
93 );
94 }
95 }
96}