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

payjoin / rust-payjoin / 28792629236

06 Jul 2026 12:47PM UTC coverage: 85.273% (-0.6%) from 85.899%
28792629236

Pull #1514

github

web-flow
Merge 373841f65 into b02065212
Pull Request #1514: [WIP] Add AS-aware relay selection

704 of 986 new or added lines in 7 files covered. (71.4%)

15 existing lines in 3 files now uncovered.

13954 of 16364 relevant lines covered (85.27%)

336.88 hits per line

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

87.8
/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::cli::Role;
15
#[cfg(feature = "v2")]
16
use crate::db::v2::SessionId;
17

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

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

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

56
        // wallet_create_funded_psbt requires a HashMap<address: String, Amount>
57
        let mut outputs = HashMap::with_capacity(1);
5✔
58
        outputs.insert(address.to_string(), amount);
5✔
59

60
        self.wallet().create_psbt(outputs, fee_rate, true)
5✔
61
    }
5✔
62

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

66
        let signed = self.wallet().process_psbt(&psbt)?;
4✔
67
        let tx = signed.extract_tx()?;
4✔
68

69
        let txid = self.wallet().broadcast_tx(&tx)?;
4✔
70

71
        println!("Payjoin sent. TXID: {txid}");
4✔
72
        Ok(txid)
4✔
73
    }
4✔
74
}
75

76
#[cfg(feature = "v1")]
77
fn http_agent(config: &Config) -> Result<reqwest::Client> {
3✔
78
    Ok(http_client_builder(config)?.build()?)
3✔
79
}
3✔
80

81
pub(crate) fn http_client_builder(config: &Config) -> Result<reqwest::ClientBuilder> {
13✔
82
    #[cfg(feature = "_manual-tls")]
83
    {
84
        let mut builder = reqwest::ClientBuilder::new().use_rustls_tls().http1_only();
13✔
85
        if let Some(root_cert_path) = config.root_certificate.as_ref() {
13✔
86
            let cert_der = std::fs::read(root_cert_path)?;
13✔
87
            builder = builder
13✔
88
                .add_root_certificate(reqwest::tls::Certificate::from_der(cert_der.as_slice())?);
13✔
NEW
89
        }
×
90
        Ok(builder)
13✔
91
    }
92

93
    #[cfg(not(feature = "_manual-tls"))]
94
    {
95
        let _ = config;
96
        Ok(reqwest::Client::builder().http1_only())
97
    }
98
}
13✔
99

100
async fn handle_interrupt(tx: watch::Sender<()>) {
21✔
101
    if let Err(e) = signal::ctrl_c().await {
21✔
102
        eprintln!("Error setting up Ctrl-C handler: {e}");
×
103
    }
14✔
104
    let _ = tx.send(());
14✔
105
}
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