1
// Copyright 2019-2025 PureStake Inc.
2
// This file is part of Moonbeam.
3

            
4
// Moonbeam is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8

            
9
// Moonbeam is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13

            
14
use std::path::PathBuf;
15
// You should have received a copy of the GNU General Public License
16
// along with Moonbeam.  If not, see <http://www.gnu.org/licenses/>.
17
use primitive_types::H256;
18
use std::str::FromStr;
19

            
20
pub mod account_key;
21

            
22
/// Block authoring scheme to be used by the dev service.
23
#[derive(Debug, Copy, Clone)]
24
pub enum Sealing {
25
	/// Author a block immediately upon receiving a transaction into the transaction pool
26
	Instant,
27
	/// Author a block upon receiving an RPC command
28
	Manual,
29
	/// Author blocks at a regular interval specified in milliseconds
30
	Interval(u64),
31
}
32

            
33
impl FromStr for Sealing {
34
	type Err = String;
35

            
36
940
	fn from_str(s: &str) -> Result<Self, Self::Err> {
37
940
		Ok(match s {
38
940
			"instant" => Self::Instant,
39
934
			"manual" => Self::Manual,
40
			s => {
41
				let millis =
42
					u64::from_str_radix(s, 10).map_err(|_| "couldn't decode sealing param")?;
43
				Self::Interval(millis)
44
			}
45
		})
46
940
	}
47
}
48

            
49
#[derive(Debug, PartialEq, Clone)]
50
pub enum EthApi {
51
	Txpool,
52
	Debug,
53
	Trace,
54
}
55

            
56
impl FromStr for EthApi {
57
	type Err = String;
58

            
59
934
	fn from_str(s: &str) -> Result<Self, Self::Err> {
60
934
		Ok(match s {
61
934
			"txpool" => Self::Txpool,
62
			"debug" => Self::Debug,
63
			"trace" => Self::Trace,
64
			_ => {
65
				return Err(format!(
66
					"`{}` is not recognized as a supported Ethereum Api",
67
					s
68
				))
69
			}
70
		})
71
934
	}
72
}
73

            
74
/// Available frontier backend types.
75
#[derive(Debug, Copy, Clone, Default, clap::ValueEnum)]
76
pub enum FrontierBackendType {
77
	/// Either RocksDb or ParityDb as per inherited from the global backend settings.
78
	#[default]
79
	KeyValue,
80
	/// Sql database with custom log indexing.
81
	Sql,
82
}
83

            
84
/// Defines the frontier backend configuration.
85
pub enum FrontierBackendConfig {
86
	KeyValue,
87
	Sql {
88
		pool_size: u32,
89
		num_ops_timeout: u32,
90
		thread_count: u32,
91
		cache_size: u64,
92
	},
93
}
94

            
95
impl Default for FrontierBackendConfig {
96
	fn default() -> FrontierBackendConfig {
97
		FrontierBackendConfig::KeyValue
98
	}
99
}
100

            
101
pub struct RpcConfig {
102
	pub ethapi: Vec<EthApi>,
103
	pub ethapi_max_permits: u32,
104
	pub ethapi_trace_max_count: u32,
105
	pub ethapi_trace_cache_duration: u64,
106
	pub eth_log_block_cache: usize,
107
	pub eth_statuses_cache: usize,
108
	pub fee_history_limit: u64,
109
	pub max_past_logs: u32,
110
	pub max_block_range: u32,
111
	pub relay_chain_rpc_urls: Vec<url::Url>,
112
	pub tracing_raw_max_memory_usage: usize,
113
	pub frontier_backend_config: FrontierBackendConfig,
114
	pub no_prometheus_prefix: bool,
115
}
116

            
117
#[derive(Clone)]
118
pub struct LazyLoadingConfig {
119
	pub state_rpc: url::Url,
120
	pub from_block: Option<H256>,
121
	pub state_overrides_path: Option<PathBuf>,
122
	pub runtime_override: Option<PathBuf>,
123
	pub delay_between_requests: u32,
124
	pub max_retries_per_request: u32,
125
}