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

payjoin / rust-payjoin / 16707770162

03 Aug 2025 05:49PM UTC coverage: 86.023%. Remained the same
16707770162

Pull #763

github

web-flow
Merge 04b0aa5b9 into a5d82d1df
Pull Request #763: Rename _danger-local-https to _manual-tls

81 of 104 new or added lines in 5 files covered. (77.88%)

61 existing lines in 5 files now uncovered.

8007 of 9308 relevant lines covered (86.02%)

503.72 hits per line

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

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

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

11
pub mod config;
12
pub mod wallet;
13
use crate::app::config::Config;
14
use crate::app::wallet::BitcoindWallet;
15

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

21
#[cfg(feature = "_manual-tls")]
22
pub const LOCAL_CERT_FILE: &str = "localhost.der";
23

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

35
    fn create_original_psbt(&self, uri: &PjUri, fee_rate: FeeRate) -> Result<Psbt> {
3✔
36
        let amount = uri.amount.ok_or_else(|| anyhow!("please specify the amount in the Uri"))?;
3✔
37

38
        // wallet_create_funded_psbt requires a HashMap<address: String, Amount>
39
        let mut outputs = HashMap::with_capacity(1);
3✔
40
        outputs.insert(uri.address.to_string(), amount);
3✔
41

42
        self.wallet().create_psbt(outputs, fee_rate, true)
3✔
43
    }
3✔
44

45
    fn process_pj_response(&self, psbt: Psbt) -> Result<bitcoin::Txid> {
3✔
46
        log::debug!("Proposed psbt: {psbt:#?}");
3✔
47

48
        let signed = self.wallet().process_psbt(&psbt)?;
3✔
49
        let tx = self.wallet().finalize_psbt(&signed)?;
3✔
50

51
        let txid = self.wallet().broadcast_tx(&tx)?;
3✔
52

53
        println!("Payjoin sent. TXID: {txid}");
3✔
54
        Ok(txid)
3✔
55
    }
3✔
56
}
57

58
#[cfg(feature = "_manual-tls")]
59
fn http_agent() -> Result<reqwest::Client> { Ok(http_agent_builder()?.build()?) }
9✔
60

61
#[cfg(not(feature = "_manual-tls"))]
62
fn http_agent() -> Result<reqwest::Client> { Ok(reqwest::Client::new()) }
63

64
#[cfg(feature = "_manual-tls")]
65
fn http_agent_builder() -> Result<reqwest::ClientBuilder> {
9✔
66
    use rustls::pki_types::CertificateDer;
67
    use rustls::RootCertStore;
68

69
    let cert_der = read_local_cert()?;
9✔
70
    let mut root_cert_store = RootCertStore::empty();
9✔
71
    root_cert_store.add(CertificateDer::from(cert_der.as_slice()))?;
9✔
72
    Ok(reqwest::ClientBuilder::new()
9✔
73
        .use_rustls_tls()
9✔
74
        .add_root_certificate(reqwest::tls::Certificate::from_der(cert_der.as_slice())?))
9✔
75
}
9✔
76

77
#[cfg(feature = "_manual-tls")]
78
fn read_local_cert() -> Result<Vec<u8>> {
12✔
79
    let mut local_cert_path = std::env::temp_dir();
12✔
80
    local_cert_path.push(LOCAL_CERT_FILE);
12✔
81
    Ok(std::fs::read(local_cert_path)?)
12✔
82
}
12✔
83

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