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

payjoin / rust-payjoin / 14668081009

25 Apr 2025 03:27PM UTC coverage: 81.936% (+0.1%) from 81.835%
14668081009

push

github

web-flow
Fix uninline format rust 1.88.0 clippy violations (#667)

50 of 145 new or added lines in 30 files covered. (34.48%)

3 existing lines in 2 files now uncovered.

5325 of 6499 relevant lines covered (81.94%)

711.53 hits per line

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

97.14
/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 = "_danger-local-https")]
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

3✔
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 = "_danger-local-https")]
59
fn http_agent() -> Result<reqwest::Client> { Ok(http_agent_builder()?.build()?) }
10✔
60

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

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

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

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

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