diff --git a/Cargo.lock b/Cargo.lock index ff56fcd..e689ab9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -85,6 +85,55 @@ dependencies = [ "libc", ] +[[package]] +name = "anstream" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is-terminal", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a30da5c5f2d5e72842e00bcb57657162cdabef0931f40e2deb9b4140440cecd" + +[[package]] +name = "anstyle-parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "180abfa45703aebe0093f79badacc01b8fd4ea2e35118747e5811127f926e188" +dependencies = [ + "anstyle", + "windows-sys", +] + [[package]] name = "anyhow" version = "1.0.71" @@ -533,6 +582,7 @@ dependencies = [ "bitcoin_hashes 0.12.0", "cashu-crab", "chrono", + "clap", "cln-rpc", "config", "dirs", @@ -619,6 +669,47 @@ dependencies = [ "zeroize", ] +[[package]] +name = "clap" +version = "4.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98330784c494e49850cb23b8e2afcca13587d2500b2e3f1f78ae20248059c9be" +dependencies = [ + "clap_builder", + "clap_derive", + "once_cell", +] + +[[package]] +name = "clap_builder" +version = "4.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e182eb5f2562a67dda37e2c57af64d720a9e010c5e860ed87c056586aeafa52e" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54a9bb5758fc5dfe728d1019941681eccaf0cf8a4189b692a0ee2f2ecf90a050" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.24", +] + +[[package]] +name = "clap_lex" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b" + [[package]] name = "cln-grpc" version = "0.1.3" @@ -651,6 +742,12 @@ dependencies = [ "tokio-util", ] +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + [[package]] name = "config" version = "0.13.3" @@ -1634,6 +1731,17 @@ version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28b29a3cd74f0f4598934efe3aeba42bae0eb4680554128851ebbecb02af14e6" +[[package]] +name = "is-terminal" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" +dependencies = [ + "hermit-abi 0.3.2", + "rustix 0.38.4", + "windows-sys", +] + [[package]] name = "itertools" version = "0.10.5" @@ -1849,6 +1957,12 @@ version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" +[[package]] +name = "linux-raw-sys" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09fc20d2ca12cb9f044c93e3bd6d32d523e6e2ec3db4f7b2939cd99026ecd3f0" + [[package]] name = "lock_api" version = "0.4.10" @@ -2647,7 +2761,20 @@ dependencies = [ "errno", "io-lifetimes", "libc", - "linux-raw-sys", + "linux-raw-sys 0.3.8", + "windows-sys", +] + +[[package]] +name = "rustix" +version = "0.38.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a962918ea88d644592894bc6dc55acc6c0956488adcebbfb6e273506b7fd6e5" +dependencies = [ + "bitflags 2.3.3", + "errno", + "libc", + "linux-raw-sys 0.4.3", "windows-sys", ] @@ -3047,7 +3174,7 @@ dependencies = [ "cfg-if", "fastrand", "redox_syscall 0.3.5", - "rustix", + "rustix 0.37.23", "windows-sys", ] @@ -3501,6 +3628,12 @@ dependencies = [ "serde", ] +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + [[package]] name = "uuid" version = "1.4.0" diff --git a/mint/Cargo.toml b/mint/Cargo.toml index c49baf5..563e9d6 100644 --- a/mint/Cargo.toml +++ b/mint/Cargo.toml @@ -37,3 +37,4 @@ jwt-compact = { workspace = true } axum-extra = { version = "0.7.4", features = ["cookie"] } time = "0.3.22" chrono = "0.4.26" +clap = { version = "4.3.14", features = ["env", "default", "derive"]} \ No newline at end of file diff --git a/mint/src/cli.rs b/mint/src/cli.rs new file mode 100644 index 0000000..cd5e49f --- /dev/null +++ b/mint/src/cli.rs @@ -0,0 +1,20 @@ +use clap::Parser; + +#[derive(Parser)] +#[command(about = "A cashu mint written in rust", author = env!("CARGO_PKG_AUTHORS"), version = env!("CARGO_PKG_VERSION"))] +pub struct CLIArgs { + #[arg( + short, + long, + help = "Use the as the location of the database", + required = false + )] + pub db: Option, + #[arg( + short, + long, + help = "Use the as the location of the config file", + required = false + )] + pub config: Option, +} diff --git a/mint/src/main.rs b/mint/src/main.rs index 1460bba..12e16cc 100644 --- a/mint/src/main.rs +++ b/mint/src/main.rs @@ -1,5 +1,6 @@ use std::collections::HashMap; use std::net::{Ipv4Addr, SocketAddr}; +use std::path::PathBuf; use std::str::FromStr; use std::sync::Arc; @@ -20,6 +21,7 @@ use cashu_crab::nuts::nut07::{CheckSpendableRequest, CheckSpendableResponse}; use cashu_crab::nuts::nut08::{MeltRequest, MeltResponse}; use cashu_crab::nuts::*; use cashu_crab::{mint::Mint, Sha256}; +use clap::Parser; use ln::cln::fee_reserve; use ln::greenlight::Greenlight; use ln::ldk::Ldk; @@ -30,11 +32,13 @@ use tracing::{debug, warn}; use types::KeysetInfo; use utils::unix_time; +use crate::cli::CLIArgs; use crate::config::LnBackend; use crate::database::Db; use crate::error::Error; use crate::ln::cln::Cln; +mod cli; mod config; mod database; mod error; @@ -48,9 +52,20 @@ async fn main() -> anyhow::Result<()> { .with_max_level(tracing::Level::DEBUG) .init(); - let settings = config::Settings::new(&Some("./config.toml".to_string())); + let args = CLIArgs::parse(); - let db_path = settings.info.clone().db_path; + // get config file name from args + let config_file_arg = match args.config { + Some(c) => c, + None => "./config.toml".to_string(), + }; + + let settings = config::Settings::new(&Some(config_file_arg)); + + let db_path = match args.db { + Some(path) => PathBuf::from_str(&path)?, + None => settings.info.clone().db_path, + }; let db = Db::new(db_path).await.unwrap();