1use crate::config_store::INITIAL_TESTNET_CONFIG;
3use crate::cost::RuntimeFeesConfig;
4use crate::parameter_table::ParameterTable;
5use unc_account_id::AccountId;
6use unc_primitives_core::types::Balance;
7use unc_primitives_core::version::PROTOCOL_VERSION;
8
9use super::parameter_table::InvalidConfigError;
10
11#[derive(Debug, Clone, PartialEq, Eq)]
13pub struct RuntimeConfig {
14 pub fees: RuntimeFeesConfig,
19 pub wasm_config: crate::vm::Config,
24 pub account_creation_config: AccountCreationConfig,
26}
27
28impl RuntimeConfig {
29 pub(crate) fn new(params: &ParameterTable) -> Result<Self, InvalidConfigError> {
30 RuntimeConfig::try_from(params)
31 }
32
33 pub fn initial_testnet_config() -> RuntimeConfig {
34 INITIAL_TESTNET_CONFIG
35 .parse()
36 .and_then(|params| RuntimeConfig::new(¶ms))
37 .expect("Failed parsing initial testnet config")
38 }
39
40 pub fn test() -> Self {
41 let config_store = super::config_store::RuntimeConfigStore::new(None);
42 let wasm_config =
43 crate::vm::Config::clone(&config_store.get_config(PROTOCOL_VERSION).wasm_config);
44 RuntimeConfig {
45 fees: RuntimeFeesConfig::test(),
46 wasm_config,
47 account_creation_config: AccountCreationConfig::default(),
48 }
49 }
50
51 pub fn free() -> Self {
52 let config_store = super::config_store::RuntimeConfigStore::new(None);
53 let mut wasm_config =
54 crate::vm::Config::clone(&config_store.get_config(PROTOCOL_VERSION).wasm_config);
55 wasm_config.make_free();
56 Self {
57 fees: RuntimeFeesConfig::free(),
58 wasm_config,
59 account_creation_config: AccountCreationConfig::default(),
60 }
61 }
62
63 pub fn storage_amount_per_byte(&self) -> Balance {
64 self.fees.storage_usage_config.storage_amount_per_byte
65 }
66}
67
68#[derive(Debug, Clone, PartialEq, Eq)]
70pub struct AccountCreationConfig {
71 pub min_allowed_top_level_account_length: u8,
73 pub registrar_account_id: AccountId,
76}
77
78impl Default for AccountCreationConfig {
79 fn default() -> Self {
80 Self {
81 min_allowed_top_level_account_length: 0,
82 registrar_account_id: "registrar".parse().unwrap(),
83 }
84 }
85}