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

payjoin / rust-payjoin / 16400574724

20 Jul 2025 01:48PM UTC coverage: 85.821% (+0.02%) from 85.8%
16400574724

Pull #874

github

web-flow
Merge c474b158d into 16c13d6e1
Pull Request #874: Add default directory to payjoin-cli

28 of 30 new or added lines in 2 files covered. (93.33%)

10 existing lines in 2 files now uncovered.

7723 of 8999 relevant lines covered (85.82%)

520.57 hits per line

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

85.37
/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
#[cfg(not(any(feature = "v1", feature = "v2")))]
14
compile_error!("At least one of the features ['v1', 'v2'] must be enabled");
15

16
fn ensure_payjoin_dirs() -> std::io::Result<PathBuf> {
10✔
17
    let config_dir = dirs::config_dir().expect("Could not determine home directory");
10✔
18
    let payjoin_dir = config_dir.join("payjoin-cli");
10✔
19
    std::fs::create_dir_all(&payjoin_dir)?;
10✔
20
    // Set permissions to 0o700 on Unix systems
21
    #[cfg(unix)]
22
    {
23
        use std::os::unix::fs::PermissionsExt;
24
        std::fs::set_permissions(&payjoin_dir, std::fs::Permissions::from_mode(0o700)).ok();
10✔
25
    }
26
    Ok(payjoin_dir)
10✔
27
}
10✔
28

29
fn find_config_path() -> Option<PathBuf> {
10✔
30
    // Look for a config.toml in the current working directory first
31
    //if not found, look for a config.toml in .config/payjoin-cli directory
32
    let cwd = std::env::current_dir().ok()?;
10✔
33
    let local_config = cwd.join("config.toml");
10✔
34
    if local_config.exists() {
10✔
NEW
UNCOV
35
        return Some(local_config);
×
36
    }
10✔
37
    let config_dir = dirs::config_dir()?;
10✔
38
    let payjoin_config = config_dir.join(".payjoin-cli").join("config.toml");
10✔
39
    if payjoin_config.exists() {
10✔
NEW
40
        Some(payjoin_config)
×
41
    } else {
42
        None
10✔
43
    }
44
}
10✔
45

46
#[tokio::main]
47
async fn main() -> Result<()> {
10✔
48
    env_logger::init();
10✔
49

50
    ensure_payjoin_dirs().expect("Failed to create ~/.payjoin directory");
10✔
51

52
    let cli = Cli::parse();
10✔
53
    let config_path = find_config_path();
10✔
54
    let config = Config::new(&cli, config_path)?;
10✔
55

56
    #[allow(clippy::if_same_then_else)]
57
    let app: Box<dyn AppTrait> = if cli.flags.bip78.unwrap_or(false) {
10✔
58
        #[cfg(feature = "v1")]
59
        {
60
            Box::new(crate::app::v1::App::new(config)?)
4✔
61
        }
62
        #[cfg(not(feature = "v1"))]
63
        {
64
            anyhow::bail!(
65
                "BIP78 (v1) support is not enabled in this build. Recompile with --features v1"
66
            )
67
        }
68
    } else if cli.flags.bip77.unwrap_or(false) {
6✔
69
        #[cfg(feature = "v2")]
70
        {
UNCOV
71
            Box::new(crate::app::v2::App::new(config)?)
×
72
        }
73
        #[cfg(not(feature = "v2"))]
74
        {
UNCOV
75
            anyhow::bail!(
×
UNCOV
76
                "BIP77 (v2) support is not enabled in this build. Recompile with --features v2"
×
77
            )
78
        }
79
    } else {
80
        #[cfg(feature = "v2")]
81
        {
82
            Box::new(crate::app::v2::App::new(config)?)
6✔
83
        }
84
        #[cfg(all(feature = "v1", not(feature = "v2")))]
85
        {
UNCOV
86
            Box::new(crate::app::v1::App::new(config)?)
×
87
        }
88
        #[cfg(not(any(feature = "v1", feature = "v2")))]
89
        {
90
            anyhow::bail!("No valid version available - must compile with v1 or v2 feature")
91
        }
92
    };
93

94
    match &cli.command {
10✔
95
        Commands::Send { bip21, fee_rate } => {
4✔
96
            app.send_payjoin(bip21, *fee_rate).await?;
4✔
97
        }
98
        Commands::Receive { amount, .. } => {
3✔
99
            app.receive_payjoin(*amount).await?;
3✔
100
        }
101
        #[cfg(feature = "v2")]
102
        Commands::Resume => {
103
            app.resume_payjoins().await?;
3✔
104
        }
105
    };
106

107
    Ok(())
18✔
108
}
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