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

payjoin / rust-payjoin / 17735121824

15 Sep 2025 01:41PM UTC coverage: 85.688% (-0.1%) from 85.783%
17735121824

Pull #1071

github

web-flow
Merge 213f98b2e into df3a415f6
Pull Request #1071: Check for spendable UTXOs before payjoin operations

13 of 22 new or added lines in 4 files covered. (59.09%)

3 existing lines in 1 file now uncovered.

8065 of 9412 relevant lines covered (85.69%)

496.56 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

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

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

47
        self.wallet().create_psbt(outputs, fee_rate, true)
4✔
48
    }
4✔
49

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

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

56
        let txid = self.wallet().broadcast_tx(&tx)?;
4✔
57

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

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

68
#[cfg(not(feature = "_manual-tls"))]
69
fn http_agent(_config: &Config) -> Result<reqwest::Client> { Ok(reqwest::Client::new()) }
70

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

77
    if let Some(root_cert_path) = root_cert_path {
10✔
78
        let cert_der = std::fs::read(root_cert_path)?;
10✔
79
        builder =
10✔
80
            builder.add_root_certificate(reqwest::tls::Certificate::from_der(cert_der.as_slice())?)
10✔
81
    }
×
82
    Ok(builder)
10✔
83
}
10✔
84

85
async fn handle_interrupt(tx: watch::Sender<()>) {
12✔
86
    if let Err(e) = signal::ctrl_c().await {
12✔
87
        eprintln!("Error setting up Ctrl-C handler: {e}");
×
88
    }
9✔
89
    let _ = tx.send(());
9✔
90
}
9✔
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