use crate::config_store::INITIAL_TESTNET_CONFIG;
use crate::cost::RuntimeFeesConfig;
use crate::parameter_table::ParameterTable;
use near_account_id::AccountId;
use near_primitives_core::types::Balance;
use near_primitives_core::version::PROTOCOL_VERSION;
use super::parameter_table::InvalidConfigError;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct RuntimeConfig {
pub fees: RuntimeFeesConfig,
pub wasm_config: crate::vm::Config,
pub account_creation_config: AccountCreationConfig,
}
impl RuntimeConfig {
pub(crate) fn new(params: &ParameterTable) -> Result<Self, InvalidConfigError> {
RuntimeConfig::try_from(params)
}
pub fn initial_testnet_config() -> RuntimeConfig {
INITIAL_TESTNET_CONFIG
.parse()
.and_then(|params| RuntimeConfig::new(¶ms))
.expect("Failed parsing initial testnet config")
}
pub fn test() -> Self {
let config_store = super::config_store::RuntimeConfigStore::new(None);
let wasm_config =
crate::vm::Config::clone(&config_store.get_config(PROTOCOL_VERSION).wasm_config);
RuntimeConfig {
fees: RuntimeFeesConfig::test(),
wasm_config,
account_creation_config: AccountCreationConfig::default(),
}
}
pub fn free() -> Self {
let config_store = super::config_store::RuntimeConfigStore::new(None);
let mut wasm_config =
crate::vm::Config::clone(&config_store.get_config(PROTOCOL_VERSION).wasm_config);
wasm_config.make_free();
Self {
fees: RuntimeFeesConfig::free(),
wasm_config,
account_creation_config: AccountCreationConfig::default(),
}
}
pub fn storage_amount_per_byte(&self) -> Balance {
self.fees.storage_usage_config.storage_amount_per_byte
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AccountCreationConfig {
pub min_allowed_top_level_account_length: u8,
pub registrar_account_id: AccountId,
}
impl Default for AccountCreationConfig {
fn default() -> Self {
Self {
min_allowed_top_level_account_length: 0,
registrar_account_id: "registrar".parse().unwrap(),
}
}
}