• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

payjoin / rust-payjoin / 16608648650

29 Jul 2025 10:16PM UTC coverage: 85.916% (+0.1%) from 85.783%
16608648650

Pull #874

github

web-flow
Merge 57e50278d into 7040ccac6
Pull Request #874: Add default directory to payjoin-cli

18 of 21 new or added lines in 2 files covered. (85.71%)

27 existing lines in 4 files now uncovered.

7955 of 9259 relevant lines covered (85.92%)

506.3 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

81.82
/payjoin-cli/src/main.rs
1
use std::path::PathBuf;
2

3
use anyhow::Result;
4
use app::config::Config;
5
use app::App as AppTrait;
6
use clap::Parser;
7
use cli::{Cli, Commands};
8

9
mod app;
10
mod cli;
11
mod db;
12

13
const CONFIG_DIR: &str = "payjoin-cli";
14

15
#[cfg(not(any(feature = "v1", feature = "v2")))]
16
compile_error!("At least one of the features ['v1', 'v2'] must be enabled");
17

18
fn find_config_path() -> Option<PathBuf> {
10✔
19
    // Look for a config.toml in the current working directory first
20
    // if not found, look for a config.toml in .config/payjoin-cli directory
21
    let cwd = std::env::current_dir().ok()?;
10✔
22
    let local_config = cwd.join("config.toml");
10✔
23
    if local_config.exists() {
10✔
NEW
24
        return Some(local_config);
×
25
    }
10✔
26
    let config_dir = dirs::config_dir()?;
10✔
27
    let payjoin_config = config_dir.join(CONFIG_DIR).join("config.toml");
10✔
28
    if payjoin_config.exists() {
10✔
NEW
29
        Some(payjoin_config)
×
30
    } else {
31
        None
10✔
32
    }
33
}
10✔
34

35
#[tokio::main]
36
async fn main() -> Result<()> {
10✔
37
    env_logger::init();
10✔
38

39
    let cli = Cli::parse();
10✔
40
    let config_path = find_config_path();
10✔
41
    let config = Config::new(&cli, config_path)?;
10✔
42

43
    #[allow(clippy::if_same_then_else)]
44
    let app: Box<dyn AppTrait> = if cli.flags.bip78.unwrap_or(false) {
10✔
45
        #[cfg(feature = "v1")]
46
        {
47
            Box::new(crate::app::v1::App::new(config)?)
4✔
48
        }
49
        #[cfg(not(feature = "v1"))]
50
        {
51
            anyhow::bail!(
52
                "BIP78 (v1) support is not enabled in this build. Recompile with --features v1"
53
            )
54
        }
55
    } else if cli.flags.bip77.unwrap_or(false) {
6✔
56
        #[cfg(feature = "v2")]
57
        {
58
            Box::new(crate::app::v2::App::new(config)?)
×
59
        }
60
        #[cfg(not(feature = "v2"))]
61
        {
62
            anyhow::bail!(
×
63
                "BIP77 (v2) support is not enabled in this build. Recompile with --features v2"
×
64
            )
65
        }
66
    } else {
67
        #[cfg(feature = "v2")]
68
        {
69
            Box::new(crate::app::v2::App::new(config)?)
6✔
70
        }
71
        #[cfg(all(feature = "v1", not(feature = "v2")))]
72
        {
73
            Box::new(crate::app::v1::App::new(config)?)
×
74
        }
75
        #[cfg(not(any(feature = "v1", feature = "v2")))]
76
        {
77
            anyhow::bail!("No valid version available - must compile with v1 or v2 feature")
78
        }
79
    };
80

81
    match &cli.command {
10✔
82
        Commands::Send { bip21, fee_rate } => {
4✔
83
            app.send_payjoin(bip21, *fee_rate).await?;
4✔
84
        }
85
        Commands::Receive { amount, .. } => {
3✔
86
            app.receive_payjoin(*amount).await?;
3✔
87
        }
88
        #[cfg(feature = "v2")]
89
        Commands::Resume => {
90
            app.resume_payjoins().await?;
3✔
91
        }
92
    };
93

94
    Ok(())
18✔
95
}
10✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc