use anyhow::Result; use serde::{Deserialize, Serialize}; use crate::Router; /// TollGate provisioning parameters. /// /// `mint_url` must be the externally-reachable URL of the Archy Cashu mint — /// TollGate customers connect from outside the Archy node's loopback, so /// localhost URLs will not work. Resolve this from the running mint app before /// calling `provision`. #[derive(Debug, Clone, Serialize, Deserialize)] pub struct TollGateConfig { /// SSID name for the pay-as-you-go network. pub ssid: String, /// Externally-reachable URL of the Archy Cashu mint. pub mint_url: String, /// Price in satoshis per `step_size` interval. pub price_sats: u64, /// Step size in milliseconds (default: 60000 = 1 minute). pub step_size_ms: u64, /// Minimum steps a customer must purchase at once. pub min_steps: u32, /// Whether the TollGate service should be running and enabled at boot. pub enabled: bool, } impl Default for TollGateConfig { fn default() -> Self { Self { ssid: "archipelago".to_string(), mint_url: String::new(), // must be set by caller from the running mint app price_sats: 10, step_size_ms: 60_000, min_steps: 1, enabled: true, } } } /// Write TollGate UCI configuration and commit. /// /// Maps TIP-01 / TIP-02 fields onto UCI keys used by tollgate-module-basic-go. pub fn apply(router: &Router, cfg: &TollGateConfig) -> Result<()> { router.uci_apply( "tollgate", &[ ("tollgate.main", "tollgate"), ("tollgate.main.enabled", if cfg.enabled { "1" } else { "0" }), ("tollgate.main.metric", "milliseconds"), ("tollgate.main.step_size", &cfg.step_size_ms.to_string()), ("tollgate.main.min_steps", &cfg.min_steps.to_string()), ("tollgate.main.price_per_step", &cfg.price_sats.to_string()), ("tollgate.main.currency", "sat"), ("tollgate.main.mint_url", &cfg.mint_url), ], )?; Ok(()) }