Skip to main content

Config

Struct Config 

Source
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: ServerConfig

Server configuration for the TxGate daemon.

§policy: PolicyConfig

Policy configuration for transaction approval rules.

§keys: KeysConfig

Key storage configuration.

Implementations§

Source§

impl Config

Source

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);
Source

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_path is empty
  • server.timeout_secs is zero
  • keys.directory is empty
  • keys.default_key is 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());
Source

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]"));
Source

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 Clone for Config

Source§

fn clone(&self) -> Config

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Config

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Config

Source§

fn default() -> Config

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Config

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Config

Source§

fn eq(&self, other: &Config) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for Config

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for Config

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,