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

payjoin / rust-payjoin / 17134170419

21 Aug 2025 05:23PM UTC coverage: 86.156% (-0.4%) from 86.523%
17134170419

Pull #980

github

web-flow
Merge 2c7bb9bac into 959f51358
Pull Request #980: Workflow optimizations

7885 of 9152 relevant lines covered (86.16%)

510.84 hits per line

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

94.74
/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 rpc;
11
pub mod wallet;
12
use crate::app::config::Config;
13
use crate::app::wallet::BitcoindWallet;
14

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

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

31
    fn create_original_psbt(
4✔
32
        &self,
4✔
33
        address: &Address,
4✔
34
        amount: Amount,
4✔
35
        fee_rate: FeeRate,
4✔
36
    ) -> Result<Psbt> {
4✔
37
        // wallet_create_funded_psbt requires a HashMap<address: String, Amount>
38
        let mut outputs = HashMap::with_capacity(1);
4✔
39
        outputs.insert(address.to_string(), amount);
4✔
40

41
        self.wallet().create_psbt(outputs, fee_rate, true)
4✔
42
    }
4✔
43

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

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

50
        let txid = self.wallet().broadcast_tx(&tx)?;
4✔
51

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

57
#[cfg(feature = "_manual-tls")]
58
fn http_agent(config: &Config) -> Result<reqwest::Client> {
10✔
59
    Ok(http_agent_builder(config.root_certificate.as_ref())?.build()?)
10✔
60
}
10✔
61

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

65
#[cfg(feature = "_manual-tls")]
66
fn http_agent_builder(
10✔
67
    root_cert_path: Option<&std::path::PathBuf>,
10✔
68
) -> Result<reqwest::ClientBuilder> {
10✔
69
    let mut builder = reqwest::ClientBuilder::new().use_rustls_tls();
10✔
70

71
    if let Some(root_cert_path) = root_cert_path {
10✔
72
        let cert_der = std::fs::read(root_cert_path)?;
10✔
73
        builder =
10✔
74
            builder.add_root_certificate(reqwest::tls::Certificate::from_der(cert_der.as_slice())?)
10✔
75
    }
×
76
    Ok(builder)
10✔
77
}
10✔
78

79
async fn handle_interrupt(tx: watch::Sender<()>) {
12✔
80
    if let Err(e) = signal::ctrl_c().await {
12✔
81
        eprintln!("Error setting up Ctrl-C handler: {e}");
×
82
    }
9✔
83
    let _ = tx.send(());
9✔
84
}
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