pezpallet_revive/
debug.rs

1// This file is part of Bizinikiwi.
2
3// Copyright (C) Parity Technologies (UK) Ltd. and Dijital Kurdistan Tech Institute
4// SPDX-License-Identifier: Apache-2.0
5
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// 	http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18use crate::{Config, DebugSettingsOf};
19use codec::{Decode, Encode, MaxEncodedLen};
20use pezsp_core::Get;
21use pezsp_runtime::RuntimeDebug;
22use scale_info::TypeInfo;
23use serde::{Deserialize, Serialize};
24
25/// Debugging settings that can be configured when DebugEnabled config is true.
26#[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	/// Whether to allow unlimited contract size.
40	allow_unlimited_contract_size: bool,
41	/// Whether to allow bypassing EIP-3607 (allowing transactions coming from contract or
42	/// precompile accounts).
43	bypass_eip_3607: bool,
44}
45
46impl DebugSettings {
47	pub fn new(allow_unlimited_contract_size: bool, bypass_eip_3607: bool) -> Self {
48		Self { allow_unlimited_contract_size, bypass_eip_3607 }
49	}
50
51	/// Returns true if unlimited contract size is allowed.
52	pub fn is_unlimited_contract_size_allowed<T: Config>() -> bool {
53		T::DebugEnabled::get() && DebugSettingsOf::<T>::get().allow_unlimited_contract_size
54	}
55
56	/// Returns true if transactions coming from contract or precompile accounts are allowed
57	/// (bypassing EIP-3607)
58	pub fn bypass_eip_3607<T: Config>() -> bool {
59		T::DebugEnabled::get() && DebugSettingsOf::<T>::get().bypass_eip_3607
60	}
61
62	/// Write the debug settings to storage.
63	pub fn write_to_storage<T: Config>(&self) {
64		DebugSettingsOf::<T>::put(self);
65		if !T::DebugEnabled::get() {
66			log::warn!(
67				target: crate::LOG_TARGET,
68				"Debug settings changed, but debug features are disabled in the runtime configuration."
69			);
70		}
71	}
72}