Skip to content

Commit

Permalink
db and config cli args
Browse files Browse the repository at this point in the history
  • Loading branch information
thesimplekid committed Jul 17, 2023
1 parent 10cceea commit 5611494
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 4 deletions.
137 changes: 135 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions mint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}
20 changes: 20 additions & 0 deletions mint/src/cli.rs
Original file line number Diff line number Diff line change
@@ -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 <directory> as the location of the database",
required = false
)]
pub db: Option<String>,
#[arg(
short,
long,
help = "Use the <file name> as the location of the config file",
required = false
)]
pub config: Option<String>,
}
19 changes: 17 additions & 2 deletions mint/src/main.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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();

Expand Down

0 comments on commit 5611494

Please sign in to comment.