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

payjoin / rust-payjoin / 20606037119

30 Dec 2025 09:12PM UTC coverage: 82.903% (+0.001%) from 82.902%
20606037119

Pull #1224

github

web-flow
Merge 84765b670 into 08a212baf
Pull Request #1224: Adding flake check and weekly flake.lock maintence job in git workflow

12 of 13 new or added lines in 4 files covered. (92.31%)

24 existing lines in 3 files now uncovered.

9669 of 11663 relevant lines covered (82.9%)

450.43 hits per line

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

88.37
/payjoin-cli/src/app/mod.rs
1
use std::collections::HashMap;
2

3
use anyhow::Result;
4
use payjoin::bitcoin::psbt::Psbt;
5
use payjoin::bitcoin::{self, Address, Amount, FeeRate};
6
use tokio::signal;
7
use tokio::sync::watch;
8

9
pub mod config;
10
pub mod wallet;
11
use crate::app::config::Config;
12
use crate::app::wallet::BitcoindWallet;
13

14
#[cfg(feature = "v1")]
15
pub(crate) mod v1;
16
#[cfg(feature = "v2")]
17
pub(crate) mod v2;
18

19
#[async_trait::async_trait]
20
pub trait App: Send + Sync {
21
    async fn new(config: Config) -> Result<Self>
22
    where
23
        Self: Sized;
24
    fn wallet(&self) -> BitcoindWallet;
25
    async fn send_payjoin(&self, bip21: &str, fee_rate: FeeRate) -> Result<()>;
26
    async fn receive_payjoin(&self, amount: Amount) -> Result<()>;
27
    #[cfg(feature = "v2")]
28
    async fn resume_payjoins(&self) -> Result<()>;
29
    #[cfg(feature = "v2")]
30
    async fn history(&self) -> Result<()>;
31

32
    fn create_original_psbt(
4✔
33
        &self,
4✔
34
        address: &Address,
4✔
35
        amount: Amount,
4✔
36
        fee_rate: FeeRate,
4✔
37
    ) -> Result<Psbt> {
4✔
38
        // Check if wallet has spendable UTXOs before attempting to create PSBT
39
        if !self.wallet().has_spendable_utxos()? {
4✔
40
            return Err(anyhow::anyhow!(
×
41
                "No spendable UTXOs available in wallet. Please ensure your wallet has confirmed funds."
×
42
            ));
×
43
        }
4✔
44

45
        // wallet_create_funded_psbt requires a HashMap<address: String, Amount>
46
        let mut outputs = HashMap::with_capacity(1);
4✔
47
        outputs.insert(address.to_string(), amount);
4✔
48

49
        self.wallet().create_psbt(outputs, fee_rate, true)
4✔
50
    }
4✔
51

52
    fn process_pj_response(&self, psbt: Psbt) -> Result<bitcoin::Txid> {
4✔
53
        tracing::trace!("Proposed psbt: {psbt:#?}");
4✔
54

55
        let signed = self.wallet().process_psbt(&psbt)?;
4✔
56
        let tx = signed.extract_tx()?;
4✔
57

58
        let txid = self.wallet().broadcast_tx(&tx)?;
4✔
59

60
        println!("Payjoin sent. TXID: {txid}");
4✔
61
        Ok(txid)
4✔
62
    }
4✔
63
}
64

65
#[cfg(feature = "_manual-tls")]
66
fn http_agent(config: &Config) -> Result<reqwest::Client> {
10✔
67
    Ok(http_agent_builder(config.root_certificate.as_ref())?.build()?)
10✔
68
}
10✔
69

70
#[cfg(not(feature = "_manual-tls"))]
71
fn http_agent(_config: &Config) -> Result<reqwest::Client> {
72
    Ok(reqwest::Client::builder().http1_only().build()?)
73
}
74

75
#[cfg(feature = "_manual-tls")]
76
fn http_agent_builder(
10✔
77
    root_cert_path: Option<&std::path::PathBuf>,
10✔
78
) -> Result<reqwest::ClientBuilder> {
10✔
79
    let mut builder = reqwest::ClientBuilder::new().use_rustls_tls().http1_only();
10✔
80

81
    if let Some(root_cert_path) = root_cert_path {
10✔
82
        let cert_der = std::fs::read(root_cert_path)?;
10✔
83
        builder =
10✔
84
            builder.add_root_certificate(reqwest::tls::Certificate::from_der(cert_der.as_slice())?)
10✔
UNCOV
85
    }
×
86
    Ok(builder)
10✔
87
}
10✔
88

89
async fn handle_interrupt(tx: watch::Sender<()>) {
13✔
90
    if let Err(e) = signal::ctrl_c().await {
13✔
UNCOV
91
        eprintln!("Error setting up Ctrl-C handler: {e}");
×
92
    }
10✔
93
    let _ = tx.send(());
10✔
94
}
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