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

payjoin / rust-payjoin / 26115328632

19 May 2026 05:55PM UTC coverage: 85.211% (-0.09%) from 85.297%
26115328632

Pull #1557

github

web-flow
Merge c57d338ad into a0cddf73e
Pull Request #1557: Sender Pending Fallback state

34 of 56 new or added lines in 6 files covered. (60.71%)

90 existing lines in 5 files now uncovered.

11691 of 13720 relevant lines covered (85.21%)

394.42 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
#[cfg(feature = "v2")]
14
use crate::db::v2::SessionId;
15

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

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

38
    fn create_original_psbt(
5✔
39
        &self,
5✔
40
        address: &Address,
5✔
41
        amount: Amount,
5✔
42
        fee_rate: FeeRate,
5✔
43
    ) -> Result<Psbt> {
5✔
44
        // Check if wallet has spendable UTXOs before attempting to create PSBT
45
        if !self.wallet().has_spendable_utxos()? {
5✔
46
            return Err(anyhow::anyhow!(
×
UNCOV
47
                "No spendable UTXOs available in wallet. Please ensure your wallet has confirmed funds."
×
UNCOV
48
            ));
×
49
        }
5✔
50

51
        // wallet_create_funded_psbt requires a HashMap<address: String, Amount>
52
        let mut outputs = HashMap::with_capacity(1);
5✔
53
        outputs.insert(address.to_string(), amount);
5✔
54

55
        self.wallet().create_psbt(outputs, fee_rate, true)
5✔
56
    }
5✔
57

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

61
        let signed = self.wallet().process_psbt(&psbt)?;
4✔
62
        let tx = signed.extract_tx()?;
4✔
63

64
        let txid = self.wallet().broadcast_tx(&tx)?;
4✔
65

66
        println!("Payjoin sent. TXID: {txid}");
4✔
67
        Ok(txid)
4✔
68
    }
4✔
69
}
70

71
#[cfg(feature = "_manual-tls")]
72
fn http_agent(config: &Config) -> Result<reqwest::Client> {
14✔
73
    Ok(http_agent_builder(config.root_certificate.as_ref())?.build()?)
14✔
74
}
14✔
75

76
#[cfg(not(feature = "_manual-tls"))]
77
fn http_agent(_config: &Config) -> Result<reqwest::Client> {
78
    Ok(reqwest::Client::builder().http1_only().build()?)
79
}
80

81
#[cfg(feature = "_manual-tls")]
82
fn http_agent_builder(
14✔
83
    root_cert_path: Option<&std::path::PathBuf>,
14✔
84
) -> Result<reqwest::ClientBuilder> {
14✔
85
    let mut builder = reqwest::ClientBuilder::new().use_rustls_tls().http1_only();
14✔
86

87
    if let Some(root_cert_path) = root_cert_path {
14✔
88
        let cert_der = std::fs::read(root_cert_path)?;
14✔
89
        builder =
14✔
90
            builder.add_root_certificate(reqwest::tls::Certificate::from_der(cert_der.as_slice())?)
14✔
UNCOV
91
    }
×
92
    Ok(builder)
14✔
93
}
14✔
94

95
async fn handle_interrupt(tx: watch::Sender<()>) {
17✔
96
    if let Err(e) = signal::ctrl_c().await {
17✔
UNCOV
97
        eprintln!("Error setting up Ctrl-C handler: {e}");
×
98
    }
14✔
99
    let _ = tx.send(());
14✔
100
}
14✔
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