radix_transactions/validation/
transaction_validator.rs

1use radix_substate_store_interface::interface::SubstateDatabase;
2
3use crate::internal_prelude::*;
4
5#[derive(Debug, Copy, Clone, PartialEq, Eq)]
6pub struct TransactionValidator {
7    pub(super) config: TransactionValidationConfig,
8    pub(super) required_network_id: Option<u8>,
9}
10
11impl TransactionValidator {
12    /// This is the best constructor to use, as it reads the configuration dynamically
13    /// Note that the validator needs recreating every time a protocol update runs,
14    /// as the config can get updated then.
15    pub fn new(database: &impl SubstateDatabase, network_definition: &NetworkDefinition) -> Self {
16        Self::new_with_static_config(
17            TransactionValidationConfig::load(database),
18            network_definition.id,
19        )
20    }
21
22    pub fn new_for_latest_simulator() -> Self {
23        Self::new_with_static_config(
24            TransactionValidationConfig::latest(),
25            NetworkDefinition::simulator().id,
26        )
27    }
28
29    pub fn new_with_latest_config(network_definition: &NetworkDefinition) -> Self {
30        Self::new_with_static_config(TransactionValidationConfig::latest(), network_definition.id)
31    }
32
33    pub fn new_with_static_config(config: TransactionValidationConfig, network_id: u8) -> Self {
34        Self {
35            config,
36            required_network_id: Some(network_id),
37        }
38    }
39
40    pub fn new_with_latest_config_network_agnostic() -> Self {
41        Self::new_with_static_config_network_agnostic(TransactionValidationConfig::latest())
42    }
43
44    pub fn new_with_static_config_network_agnostic(config: TransactionValidationConfig) -> Self {
45        Self {
46            config,
47            required_network_id: None,
48        }
49    }
50
51    /// Will typically be [`Some`], but [`None`] if the validator is network-independent.
52    pub fn network_id(&self) -> Option<u8> {
53        self.required_network_id
54    }
55
56    pub fn config(&self) -> &TransactionValidationConfig {
57        &self.config
58    }
59
60    pub fn preparation_settings(&self) -> &PreparationSettings {
61        &self.config.preparation_settings
62    }
63}
64
65// Concrete methods on `TransactionValidator` are implemented across
66// other modules, such as `transaction_validator_v1`, to avoid this
67// file growing to an unmanagable size.