diff --git a/Dockerfile b/Dockerfile index 20ddf64b..f56e51b9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -37,4 +37,4 @@ RUN ARCH=$(uname -m) && \ fi # Set the entry point for the container -CMD ["cdk-mintd"] \ No newline at end of file +CMD ["cdk-mintd"] diff --git a/crates/cdk-mintd/src/config.rs b/crates/cdk-mintd/src/config.rs index 44ebf29b..fc579b17 100644 --- a/crates/cdk-mintd/src/config.rs +++ b/crates/cdk-mintd/src/config.rs @@ -27,6 +27,7 @@ pub struct Info { #[serde(rename_all = "lowercase")] pub enum LnBackend { #[default] + None, Cln, Strike, LNbits, @@ -120,7 +121,9 @@ pub struct FakeWallet { pub supported_units: Vec, pub fee_percent: f32, pub reserve_fee_min: Amount, + #[serde(default = "default_min_delay_time")] pub min_delay_time: u64, + #[serde(default = "default_max_delay_time")] pub max_delay_time: u64, } @@ -136,6 +139,15 @@ impl Default for FakeWallet { } } +// Helper functions to provide default values +fn default_min_delay_time() -> u64 { + 1 +} + +fn default_max_delay_time() -> u64 { + 3 +} + #[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)] #[serde(rename_all = "lowercase")] pub enum DatabaseEngine { @@ -234,6 +246,7 @@ impl Settings { let settings: Settings = config.try_deserialize()?; match settings.ln.ln_backend { + LnBackend::None => panic!("Ln backend must be set"), LnBackend::Cln => assert!( settings.cln.is_some(), "CLN backend requires a valid config." diff --git a/crates/cdk-mintd/src/env_vars.rs b/crates/cdk-mintd/src/env_vars.rs index 2e89c58d..eae4de4d 100644 --- a/crates/cdk-mintd/src/env_vars.rs +++ b/crates/cdk-mintd/src/env_vars.rs @@ -2,7 +2,7 @@ use std::env; use std::path::PathBuf; use std::str::FromStr; -use anyhow::{anyhow, Result}; +use anyhow::{anyhow, bail, Result}; use cdk::nuts::CurrencyUnit; use crate::config::{ @@ -10,72 +10,64 @@ use crate::config::{ Phoenixd, Settings, Strike, }; -pub const DATABASE_ENV_VAR: &str = "CDK-MINTD-DATABASE"; -pub const ENV_URL: &str = "CDK-MINTD-URL"; -pub const ENV_LISTEN_HOST: &str = "CDK-MINTD-LISTEN-HOST"; -pub const ENV_LISTEN_PORT: &str = "CDK-MINTD-LISTEN-PORT"; -pub const ENV_MNEMONIC: &str = "CDK-MINTD-MNEMONIC"; -pub const ENV_SECONDS_QUOTE_VALID: &str = "CDK-MINTD-SECONDS-QUOTE-VALID"; -pub const ENV_CACHE_SECONDS: &str = "CDK-MINTD-CACHE-SECONDS"; -pub const ENV_EXTEND_CACHE_SECONDS: &str = "CDK-MINTD-EXTEND-CACHE-SECONDS"; -pub const ENV_INPUT_FEE_PPK: &str = "CDK-MINTD-INPUT-FEE-PPK"; -pub const ENV_ENABLE_SWAGGER: &str = "CDK-MINTD-ENABLE-SWAGGER"; - +pub const DATABASE_ENV_VAR: &str = "CDK_MINTD_DATABASE"; +pub const ENV_URL: &str = "CDK_MINTD_URL"; +pub const ENV_LISTEN_HOST: &str = "CDK_MINTD_LISTEN_HOST"; +pub const ENV_LISTEN_PORT: &str = "CDK_MINTD_LISTEN_PORT"; +pub const ENV_MNEMONIC: &str = "CDK_MINTD_MNEMONIC"; +pub const ENV_SECONDS_QUOTE_VALID: &str = "CDK_MINTD_SECONDS_QUOTE_VALID"; +pub const ENV_CACHE_SECONDS: &str = "CDK_MINTD_CACHE_SECONDS"; +pub const ENV_EXTEND_CACHE_SECONDS: &str = "CDK_MINTD_EXTEND_CACHE_SECONDS"; +pub const ENV_INPUT_FEE_PPK: &str = "CDK_MINTD_INPUT_FEE_PPK"; +pub const ENV_ENABLE_SWAGGER: &str = "CDK_MINTD_ENABLE_SWAGGER"; // MintInfo -pub const ENV_MINT_NAME: &str = "CDK-MINTD-MINT-NAME"; -pub const ENV_MINT_PUBKEY: &str = "CDK-MINTD-MINT-PUBKEY"; -pub const ENV_MINT_DESCRIPTION: &str = "CDK-MINTD-MINT-DESCRIPTION"; -pub const ENV_MINT_DESCRIPTION_LONG: &str = "CDK-MINTD-MINT-DESCRIPTION-LONG"; -pub const ENV_MINT_ICON_URL: &str = "CDK-MINTD-MINT-ICON-URL"; -pub const ENV_MINT_MOTD: &str = "CDK-MINTD-MINT-MOTD"; -pub const ENV_MINT_CONTACT_NOSTR: &str = "CDK-MINTD-MINT-CONTACT-NOSTR"; -pub const ENV_MINT_CONTACT_EMAIL: &str = "CDK-MINTD-MINT-CONTACT-EMAIL"; - +pub const ENV_MINT_NAME: &str = "CDK_MINTD_MINT_NAME"; +pub const ENV_MINT_PUBKEY: &str = "CDK_MINTD_MINT_PUBKEY"; +pub const ENV_MINT_DESCRIPTION: &str = "CDK_MINTD_MINT_DESCRIPTION"; +pub const ENV_MINT_DESCRIPTION_LONG: &str = "CDK_MINTD_MINT_DESCRIPTION_LONG"; +pub const ENV_MINT_ICON_URL: &str = "CDK_MINTD_MINT_ICON_URL"; +pub const ENV_MINT_MOTD: &str = "CDK_MINTD_MINT_MOTD"; +pub const ENV_MINT_CONTACT_NOSTR: &str = "CDK_MINTD_MINT_CONTACT_NOSTR"; +pub const ENV_MINT_CONTACT_EMAIL: &str = "CDK_MINTD_MINT_CONTACT_EMAIL"; // LN -pub const ENV_LN_BACKEND: &str = "CDK-MINTD-LN-BACKEND"; -pub const ENV_LN_INVOICE_DESCRIPTION: &str = "CDK-MINTD-LN-INVOICE-DESCRIPTION"; -pub const ENV_LN_MIN_MINT: &str = "CDK-MINTD-LN-MIN-MINT"; -pub const ENV_LN_MAX_MINT: &str = "CDK-MINTD-LN-MAX-MINT"; -pub const ENV_LN_MIN_MELT: &str = "CDK-MINTD-LN-MIN-MELT"; -pub const ENV_LN_MAX_MELT: &str = "CDK-MINTD-LN-MAX-MELT"; - +pub const ENV_LN_BACKEND: &str = "CDK_MINTD_LN_BACKEND"; +pub const ENV_LN_INVOICE_DESCRIPTION: &str = "CDK_MINTD_LN_INVOICE_DESCRIPTION"; +pub const ENV_LN_MIN_MINT: &str = "CDK_MINTD_LN_MIN_MINT"; +pub const ENV_LN_MAX_MINT: &str = "CDK_MINTD_LN_MAX_MINT"; +pub const ENV_LN_MIN_MELT: &str = "CDK_MINTD_LN_MIN_MELT"; +pub const ENV_LN_MAX_MELT: &str = "CDK_MINTD_LN_MAX_MELT"; // CLN -pub const ENV_CLN_RPC_PATH: &str = "CDK-MINTD-CLN-RPC-PATH"; -pub const ENV_CLN_BOLT12: &str = "CDK-MINTD-CLN-BOLT12"; -pub const ENV_CLN_FEE_PERCENT: &str = "CDK-MINTD-CLN-FEE-PERCENT"; -pub const ENV_CLN_RESERVE_FEE_MIN: &str = "CDK-MINTD-CLN-RESERVE-FEE-MIN"; - +pub const ENV_CLN_RPC_PATH: &str = "CDK_MINTD_CLN_RPC_PATH"; +pub const ENV_CLN_BOLT12: &str = "CDK_MINTD_CLN_BOLT12"; +pub const ENV_CLN_FEE_PERCENT: &str = "CDK_MINTD_CLN_FEE_PERCENT"; +pub const ENV_CLN_RESERVE_FEE_MIN: &str = "CDK_MINTD_CLN_RESERVE_FEE_MIN"; // Strike -pub const ENV_STRIKE_API_KEY: &str = "CDK-MINTD-STRIKE-API-KEY"; -pub const ENV_STRIKE_SUPPORTED_UNITS: &str = "CDK-MINTD-STRIKE-SUPPORTED-UNITS"; - +pub const ENV_STRIKE_API_KEY: &str = "CDK_MINTD_STRIKE_API_KEY"; +pub const ENV_STRIKE_SUPPORTED_UNITS: &str = "CDK_MINTD_STRIKE_SUPPORTED_UNITS"; // LND environment variables -pub const ENV_LND_ADDRESS: &str = "CDK-MINTD-LND-ADDRESS"; -pub const ENV_LND_CERT_FILE: &str = "CDK-MINTD-LND-CERT-FILE"; -pub const ENV_LND_MACAROON_FILE: &str = "CDK-MINTD-LND-MACAROON-FILE"; -pub const ENV_LND_FEE_PERCENT: &str = "CDK-MINTD-LND-FEE-PERCENT"; -pub const ENV_LND_RESERVE_FEE_MIN: &str = "CDK-MINTD-LND-RESERVE-FEE-MIN"; - +pub const ENV_LND_ADDRESS: &str = "CDK_MINTD_LND_ADDRESS"; +pub const ENV_LND_CERT_FILE: &str = "CDK_MINTD_LND_CERT_FILE"; +pub const ENV_LND_MACAROON_FILE: &str = "CDK_MINTD_LND_MACAROON_FILE"; +pub const ENV_LND_FEE_PERCENT: &str = "CDK_MINTD_LND_FEE_PERCENT"; +pub const ENV_LND_RESERVE_FEE_MIN: &str = "CDK_MINTD_LND_RESERVE_FEE_MIN"; // Phoenixd environment variables -pub const ENV_PHOENIXD_API_PASSWORD: &str = "CDK-MINTD-PHOENIXD-API-PASSWORD"; -pub const ENV_PHOENIXD_API_URL: &str = "CDK-MINTD-PHOENIXD-API-URL"; -pub const ENV_PHOENIXD_BOLT12: &str = "CDK-MINTD-PHOENIXD-BOLT12"; -pub const ENV_PHOENIXD_FEE_PERCENT: &str = "CDK-MINTD-PHOENIXD-FEE-PERCENT"; -pub const ENV_PHOENIXD_RESERVE_FEE_MIN: &str = "CDK-MINTD-PHOENIXD-RESERVE-FEE-MIN"; - +pub const ENV_PHOENIXD_API_PASSWORD: &str = "CDK_MINTD_PHOENIXD_API_PASSWORD"; +pub const ENV_PHOENIXD_API_URL: &str = "CDK_MINTD_PHOENIXD_API_URL"; +pub const ENV_PHOENIXD_BOLT12: &str = "CDK_MINTD_PHOENIXD_BOLT12"; +pub const ENV_PHOENIXD_FEE_PERCENT: &str = "CDK_MINTD_PHOENIXD_FEE_PERCENT"; +pub const ENV_PHOENIXD_RESERVE_FEE_MIN: &str = "CDK_MINTD_PHOENIXD_RESERVE_FEE_MIN"; // LNBits -pub const ENV_LNBITS_ADMIN_API_KEY: &str = "CDK-MINTD-LNBITS-ADMIN-API-KEY"; -pub const ENV_LNBITS_INVOICE_API_KEY: &str = "CDK-MINTD-LNBITS-INVOICE-API-KEY"; -pub const ENV_LNBITS_API: &str = "CDK-MINTD-LNBITS-API"; -pub const ENV_LNBITS_FEE_PERCENT: &str = "CDK-MINTD-LNBITS-FEE-PERCENT"; -pub const ENV_LNBITS_RESERVE_FEE_MIN: &str = "CDK-MINTD-LNBITS-RESERVE-FEE-MIN"; - +pub const ENV_LNBITS_ADMIN_API_KEY: &str = "CDK_MINTD_LNBITS_ADMIN_API_KEY"; +pub const ENV_LNBITS_INVOICE_API_KEY: &str = "CDK_MINTD_LNBITS_INVOICE_API_KEY"; +pub const ENV_LNBITS_API: &str = "CDK_MINTD_LNBITS_API"; +pub const ENV_LNBITS_FEE_PERCENT: &str = "CDK_MINTD_LNBITS_FEE_PERCENT"; +pub const ENV_LNBITS_RESERVE_FEE_MIN: &str = "CDK_MINTD_LNBITS_RESERVE_FEE_MIN"; // Fake Wallet -pub const ENV_FAKE_WALLET_SUPPORTED_UNITS: &str = "CDK-MINTD-FAKE-WALLET-SUPPORTED-UNITS"; -pub const ENV_FAKE_WALLET_FEE_PERCENT: &str = "CDK-MINTD-FAKE-WALLET-FEE-PERCENT"; -pub const ENV_FAKE_WALLET_RESERVE_FEE_MIN: &str = "CDK-MINTD-FAKE-WALLET-RESERVE-FEE-MIN"; -pub const ENV_FAKE_WALLET_MIN_DELAY: &str = "CDK-MINTD-FAKE-WALLET-MIN-DELAY"; -pub const ENV_FAKE_WALLET_MAX_DELAY: &str = "CDK-MINTD-FAKE-WALLET-MAX-DELAY"; +pub const ENV_FAKE_WALLET_SUPPORTED_UNITS: &str = "CDK_MINTD_FAKE_WALLET_SUPPORTED_UNITS"; +pub const ENV_FAKE_WALLET_FEE_PERCENT: &str = "CDK_MINTD_FAKE_WALLET_FEE_PERCENT"; +pub const ENV_FAKE_WALLET_RESERVE_FEE_MIN: &str = "CDK_MINTD_FAKE_WALLET_RESERVE_FEE_MIN"; +pub const ENV_FAKE_WALLET_MIN_DELAY: &str = "CDK_MINTD_FAKE_WALLET_MIN_DELAY"; +pub const ENV_FAKE_WALLET_MAX_DELAY: &str = "CDK_MINTD_FAKE_WALLET_MAX_DELAY"; impl Settings { pub fn from_env(&mut self) -> Result { @@ -86,6 +78,7 @@ impl Settings { self.info = self.info.clone().from_env(); self.mint_info = self.mint_info.clone().from_env(); + self.ln = self.ln.clone().from_env(); match self.ln.ln_backend { LnBackend::Cln => { @@ -106,6 +99,7 @@ impl Settings { LnBackend::Lnd => { self.lnd = Some(self.lnd.clone().unwrap_or_default().from_env()); } + LnBackend::None => bail!("Ln backend must be set"), } Ok(self.clone()) diff --git a/crates/cdk-mintd/src/main.rs b/crates/cdk-mintd/src/main.rs index a32daf4a..ac61daa6 100644 --- a/crates/cdk-mintd/src/main.rs +++ b/crates/cdk-mintd/src/main.rs @@ -63,9 +63,16 @@ async fn main() -> anyhow::Result<()> { None => work_dir.join("config.toml"), }; + tracing::info!("Using work dir: {}", work_dir.display()); + let mut mint_builder = MintBuilder::new(); - let mut settings = config::Settings::new(&Some(config_file_arg)); + let mut settings = if config_file_arg.exists() { + config::Settings::new(&Some(config_file_arg)) + } else { + tracing::info!("Config file does not exist. Attempting to read env vars"); + config::Settings::default() + }; // This check for any settings defined in ENV VARs // ENV VARS will take **priority** over those in the config @@ -133,6 +140,8 @@ async fn main() -> anyhow::Result<()> { melt_max: settings.ln.max_melt, }; + println!("{:?}", settings); + match settings.ln.ln_backend { LnBackend::Cln => { let cln_settings = settings @@ -256,6 +265,7 @@ async fn main() -> anyhow::Result<()> { mint_builder = mint_builder.add_supported_websockets(nut17_supported); } } + LnBackend::None => bail!("Ln backend must be set"), }; if let Some(long_description) = &settings.mint_info.description_long { @@ -383,6 +393,9 @@ async fn main() -> anyhow::Result<()> { fn work_dir() -> Result { let home_dir = home::home_dir().ok_or(anyhow!("Unknown home dir"))?; + let dir = home_dir.join(".cdk-mintd"); + + std::fs::create_dir_all(&dir)?; - Ok(home_dir.join(".cdk-mintd")) + Ok(dir) } diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 00000000..b0c6efb9 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,16 @@ +services: + mintd: + build: + context: . + dockerfile: Dockerfile + container_name: mint + ports: + - "8085:8085" + environment: + - CDK_MINTD_URL=https://example.com + - CDK_MINTD_LN_BACKEND=fakewallet + - CDK_MINTD_LISTEN_HOST=0.0.0.0 + - CDK_MINTD_LISTEN_PORT=8085 + - CDK_MINTD_MNEMONIC= + - CDK_MINTD_DATABASE=redb + command: ["cdk-mintd"]