pallet_revive/
debug.rs

1// This file is part of Substrate.
2
3// Copyright (C) Parity Technologies (UK) Ltd.
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 scale_info::TypeInfo;
21use serde::{Deserialize, Serialize};
22use sp_core::Get;
23use sp_runtime::RuntimeDebug;
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}
42
43impl DebugSettings {
44	pub fn new(allow_unlimited_contract_size: bool) -> Self {
45		Self { allow_unlimited_contract_size }
46	}
47
48	/// Returns true if unlimited contract size is allowed.
49	pub fn is_unlimited_contract_size_allowed<T: Config>() -> bool {
50		T::DebugEnabled::get() && DebugSettingsOf::<T>::get().allow_unlimited_contract_size
51	}
52
53	/// Write the debug settings to storage.
54	pub fn write_to_storage<T: Config>(&self) {
55		DebugSettingsOf::<T>::put(self);
56		if !T::DebugEnabled::get() {
57			log::warn!(
58				target: crate::LOG_TARGET,
59				"Debug settings changed, but debug features are disabled in the runtime configuration."
60			);
61		}
62	}
63}