pub struct Config {
pub server: ServerConfig,
pub policy: PolicyConfig,
pub keys: KeysConfig,
}Expand description
Top-level configuration for the TxGate signing service.
This struct contains all configuration sections for the TxGate daemon:
- Server: Unix socket path and request timeout settings
- Keys: Key storage directory and default key name
- Policy: Transaction approval rules (whitelist, blacklist, limits)
§Examples
use txgate_core::config::Config;
// Load from TOML string
let toml_str = r#"
[server]
socket_path = "/var/run/txgate.sock"
timeout_secs = 60
[keys]
directory = "/var/lib/txgate/keys"
default_key = "main"
[policy]
whitelist_enabled = true
whitelist = ["0x742d35Cc6634C0532925a3b844Bc454e7595f"]
"#;
let config: Config = toml::from_str(toml_str).expect("valid TOML");
assert_eq!(config.server.timeout_secs, 60);Fields§
§server: ServerConfigServer configuration for the TxGate daemon.
policy: PolicyConfigPolicy configuration for transaction approval rules.
keys: KeysConfigKey storage configuration.
Implementations§
Source§impl Config
impl Config
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new configuration with default values.
§Examples
use txgate_core::config::Config;
let config = Config::new();
assert_eq!(config.server.timeout_secs, 30);Sourcepub fn validate(&self) -> Result<(), ConfigError>
pub fn validate(&self) -> Result<(), ConfigError>
Validates the configuration.
This method checks for configuration errors such as:
- Invalid socket path (empty)
- Invalid timeout (zero)
- Invalid keys directory (empty)
- Invalid default key name (empty)
- Invalid policy configuration (whitelist/blacklist overlap)
§Returns
Ok(()) if the configuration is valid, or a ConfigError describing the issue.
§Errors
Returns ConfigError::InvalidValue if:
server.socket_pathis emptyserver.timeout_secsis zerokeys.directoryis emptykeys.default_keyis empty
Returns a wrapped PolicyError (via ConfigError::ParseFailed) if:
- An address appears in both the whitelist and blacklist
§Examples
use txgate_core::config::Config;
let config = Config::default();
assert!(config.validate().is_ok());
// Invalid: empty socket path
let mut invalid_config = Config::default();
invalid_config.server.socket_path = String::new();
assert!(invalid_config.validate().is_err());Sourcepub fn default_toml() -> String
pub fn default_toml() -> String
Generates the default configuration as a TOML string.
This method produces a well-formatted TOML configuration file with comments explaining each section. It can be used to create an initial configuration file for new installations.
§Returns
A TOML-formatted string containing the default configuration.
§Examples
use txgate_core::config::Config;
let toml = Config::default_toml();
assert!(toml.contains("[server]"));
assert!(toml.contains("[keys]"));
assert!(toml.contains("[policy]"));Sourcepub fn builder() -> ConfigBuilder
pub fn builder() -> ConfigBuilder
Creates a configuration builder for customizing values.
§Examples
use txgate_core::config::Config;
let config = Config::builder()
.socket_path("/var/run/txgate.sock")
.timeout_secs(60)
.build();
assert_eq!(config.server.socket_path, "/var/run/txgate.sock");Trait Implementations§
Source§impl<'de> Deserialize<'de> for Config
impl<'de> Deserialize<'de> for Config
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Config
impl StructuralPartialEq for Config
Auto Trait Implementations§
impl Freeze for Config
impl RefUnwindSafe for Config
impl Send for Config
impl Sync for Config
impl Unpin for Config
impl UnwindSafe for Config
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.