Skip to content

Commit

Permalink
feat: cli clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
thesimplekid committed Oct 12, 2024
1 parent 455c1e1 commit 326ead5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 58 deletions.
3 changes: 1 addition & 2 deletions crates/cdk-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ use std::path::PathBuf;
use std::str::FromStr;
use std::sync::Arc;

use anyhow::{bail, Result};
use anyhow::Result;
use bip39::Mnemonic;
use cdk::cdk_database;
use cdk::cdk_database::WalletDatabase;
use cdk::wallet::client::HttpClient;
use cdk::wallet::{MultiMintWallet, Wallet};
Expand Down
17 changes: 3 additions & 14 deletions crates/cdk-cli/src/sub_commands/receive.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
use std::collections::HashSet;
use std::str::FromStr;
use std::sync::Arc;

use anyhow::{anyhow, Result};
use anyhow::Result;
use cdk::cdk_database::{self, WalletDatabase};
use cdk::nuts::{SecretKey, Token};
use cdk::util::unix_time;
use cdk::wallet::multi_mint_wallet::{MultiMintWallet, WalletKey};
use cdk::wallet::Wallet;
use cdk::Amount;
Expand All @@ -18,7 +16,6 @@ pub struct ReceiveSubCommand {
/// Signing Key
#[arg(short, long, action = clap::ArgAction::Append)]
signing_key: Vec<String>,
/// Nostr key
}

pub async fn receive(
Expand All @@ -27,16 +24,8 @@ pub async fn receive(
seed: &[u8],
sub_command_args: &ReceiveSubCommand,
) -> Result<()> {

let amount = receive_token(
multi_mint_wallet,
localstore,
seed,
token_str,
&[],
&[],
)
.await?;
let token_str = sub_command_args.token.clone().unwrap();
let amount = receive_token(multi_mint_wallet, localstore, seed, &token_str, &[], &[]).await?;
println!("Received: {}", amount);

Ok(())
Expand Down
60 changes: 18 additions & 42 deletions crates/cdk-mintd/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,22 @@ use std::sync::Arc;
use anyhow::{anyhow, bail, Result};
use axum::Router;
use bip39::Mnemonic;
use cdk::cdk_database::{self, MintDatabase};
use cdk::cdk_lightning;
use cdk::cdk_lightning::MintLightning;
use cdk::mint::{FeeReserve, MeltQuote, Mint};
use cdk::mint_url::MintUrl;
use cdk::nuts::{
nut04, nut05, ContactInfo, CurrencyUnit, MeltMethodSettings, MeltQuoteState, MintInfo,
MintMethodSettings, MintVersion, MppMethodSettings, Nuts, PaymentMethod,
nut04, nut05, ContactInfo, MeltMethodSettings, MeltQuoteState, MintInfo, MintMethodSettings,
MintVersion, MppMethodSettings, Nuts, PaymentMethod,
};
use cdk::types::{LnKey, QuoteTTL};
use cdk_cln::Cln;
use cdk_fake_wallet::FakeWallet;
use cdk_lnbits::LNbits;
use cdk_lnd::Lnd;
use cdk_phoenixd::Phoenixd;
use cdk_redb::MintRedbDatabase;
use cdk_sqlite::MintSqliteDatabase;
use cdk_strike::Strike;
use clap::Parser;
use cli::CLIArgs;
use config::{DatabaseEngine, LnBackend};
use tokio::sync::{Mutex, Notify};
use tokio::sync::Notify;
use tower_http::cors::CorsLayer;
use tracing_subscriber::EnvFilter;
use url::Url;

mod cli;
mod config;
Expand Down Expand Up @@ -125,26 +116,26 @@ async fn main() -> anyhow::Result<()> {
let mut supported_units = HashMap::new();
let input_fee_ppk = settings.info.input_fee_ppk.unwrap_or(0);

let mint_url: MintUrl = settings.info.url.parse()?;
let _mint_url: MintUrl = settings.info.url.parse()?;
// Consider: we probably need only one unit, so this element might be redundant
let units = settings.fake_wallet.unwrap_or_default().supported_units;

for unit in units {
let ln_key = LnKey::new(unit, PaymentMethod::Bolt11);
for unit in units {
let ln_key = LnKey::new(unit, PaymentMethod::Bolt11);

let wallet = Arc::new(FakeWallet::new(
fee_reserve.clone(),
MintMethodSettings::default(),
MeltMethodSettings::default(),
HashMap::default(),
HashSet::default(),
0,
));
let wallet = Arc::new(FakeWallet::new(
fee_reserve.clone(),
MintMethodSettings::default(),
MeltMethodSettings::default(),
HashMap::default(),
HashSet::default(),
0,
));

ln_backends.insert(ln_key, wallet);
ln_backends.insert(ln_key, wallet);

supported_units.insert(unit, (input_fee_ppk, 64));
}
supported_units.insert(unit, (input_fee_ppk, 64));
}

let (nut04_settings, nut05_settings, mpp_settings): (
nut04::Settings,
Expand Down Expand Up @@ -273,7 +264,7 @@ async fn main() -> anyhow::Result<()> {

let v1_service = cdk_axum::create_mint_router(Arc::clone(&mint), cache_ttl, cache_tti).await?;

let mut mint_service = Router::new()
let mint_service = Router::new()
.merge(v1_service)
.layer(CorsLayer::permissive());

Expand Down Expand Up @@ -431,21 +422,6 @@ async fn check_pending_melt_quotes(
Ok(())
}

fn expand_path(path: &str) -> Option<PathBuf> {
if path.starts_with('~') {
if let Some(home_dir) = home::home_dir().as_mut() {
let remainder = &path[2..];
home_dir.push(remainder);
let expanded_path = home_dir;
Some(expanded_path.clone())
} else {
None
}
} else {
Some(PathBuf::from(path))
}
}

fn work_dir() -> Result<PathBuf> {
let home_dir = home::home_dir().ok_or(anyhow!("Unknown home dir"))?;

Expand Down

0 comments on commit 326ead5

Please sign in to comment.