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

payjoin / rust-payjoin / 14042339636

24 Mar 2025 05:53PM UTC coverage: 81.092% (+0.2%) from 80.865%
14042339636

push

github

web-flow
Correct the pjos parameter parity (#546)

alter and corrected the logic for `pjos` parameter

fixes #545

122 of 134 new or added lines in 11 files covered. (91.04%)

2 existing lines in 2 files now uncovered.

5005 of 6172 relevant lines covered (81.09%)

748.84 hits per line

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

73.61
/payjoin/src/receive/optional_parameters.rs
1
use std::borrow::Borrow;
2
use std::fmt;
3

4
use bitcoin::FeeRate;
5
use log::warn;
6

7
use crate::output_substitution::OutputSubstitution;
8

9
#[derive(Debug, Clone)]
10
pub(crate) struct Params {
11
    // version
12
    pub v: usize,
13
    // disableoutputsubstitution
14
    pub output_substitution: OutputSubstitution,
15
    // maxadditionalfeecontribution, additionalfeeoutputindex
16
    pub additional_fee_contribution: Option<(bitcoin::Amount, usize)>,
17
    // minfeerate
18
    pub min_fee_rate: FeeRate,
19
    #[cfg(feature = "_multiparty")]
20
    /// Opt in to optimistic psbt merge
21
    pub optimistic_merge: bool,
22
}
23

24
impl Default for Params {
25
    fn default() -> Self {
30✔
26
        Params {
30✔
27
            v: 1,
30✔
28
            output_substitution: OutputSubstitution::Enabled,
30✔
29
            additional_fee_contribution: None,
30✔
30
            min_fee_rate: FeeRate::BROADCAST_MIN,
30✔
31
            #[cfg(feature = "_multiparty")]
30✔
32
            optimistic_merge: false,
30✔
33
        }
30✔
34
    }
30✔
35
}
36

37
impl Params {
38
    pub fn from_query_pairs<K, V, I>(
26✔
39
        pairs: I,
26✔
40
        supported_versions: &'static [usize],
26✔
41
    ) -> Result<Self, Error>
26✔
42
    where
26✔
43
        I: Iterator<Item = (K, V)>,
26✔
44
        K: Borrow<str> + Into<String>,
26✔
45
        V: Borrow<str> + Into<String>,
26✔
46
    {
26✔
47
        let mut params = Params::default();
26✔
48

26✔
49
        let mut additional_fee_output_index = None;
26✔
50
        let mut max_additional_fee_contribution = None;
26✔
51

52
        for (key, v) in pairs {
105✔
53
            match (key.borrow(), v.borrow()) {
79✔
54
                ("v", version) =>
79✔
55
                    params.v = match version.parse::<usize>() {
20✔
56
                        Ok(version) if supported_versions.contains(&version) => version,
20✔
57
                        _ => return Err(Error::UnknownVersion { supported_versions }),
×
58
                    },
59
                ("additionalfeeoutputindex", index) =>
59✔
60
                    additional_fee_output_index = match index.parse::<usize>() {
17✔
61
                        Ok(index) => Some(index),
17✔
62
                        Err(_error) => {
×
63
                            warn!(
×
64
                                "bad `additionalfeeoutputindex` query value '{}': {}",
×
65
                                index, _error
66
                            );
67
                            None
×
68
                        }
69
                    },
70
                ("maxadditionalfeecontribution", fee) =>
42✔
71
                    max_additional_fee_contribution =
17✔
72
                        match bitcoin::Amount::from_str_in(fee, bitcoin::Denomination::Satoshi) {
17✔
73
                            Ok(contribution) => Some(contribution),
17✔
74
                            Err(_error) => {
×
75
                                warn!(
×
76
                                    "bad `maxadditionalfeecontribution` query value '{}': {}",
×
77
                                    fee, _error
78
                                );
79
                                None
×
80
                            }
81
                        },
82
                ("minfeerate", fee_rate) =>
25✔
83
                    params.min_fee_rate = match fee_rate.parse::<f32>() {
13✔
84
                        Ok(fee_rate_sat_per_vb) => {
13✔
85
                            // TODO Parse with serde when rust-bitcoin supports it
13✔
86
                            let fee_rate_sat_per_kwu = fee_rate_sat_per_vb * 250.0_f32;
13✔
87
                            // since it's a minimum, we want to round up
13✔
88
                            FeeRate::from_sat_per_kwu(fee_rate_sat_per_kwu.ceil() as u64)
13✔
89
                        }
90
                        Err(_) => return Err(Error::FeeRate),
×
91
                    },
92
                ("disableoutputsubstitution", v) =>
12✔
93
                    params.output_substitution = if v == "true" {
4✔
94
                        OutputSubstitution::Disabled
4✔
95
                    } else {
NEW
96
                        OutputSubstitution::Enabled
×
97
                    },
98
                #[cfg(feature = "_multiparty")]
99
                ("optimisticmerge", v) => params.optimistic_merge = v == "true",
8✔
100
                _ => (),
×
101
            }
102
        }
103

104
        match (max_additional_fee_contribution, additional_fee_output_index) {
26✔
105
            (Some(amount), Some(index)) =>
17✔
106
                params.additional_fee_contribution = Some((amount, index)),
17✔
107
            (Some(_), None) | (None, Some(_)) => {
108
                warn!("only one additional-fee parameter specified: {:?}", params);
×
109
            }
110
            _ => (),
9✔
111
        }
112

113
        log::debug!("parsed optional parameters: {:?}", params);
26✔
114
        Ok(params)
26✔
115
    }
26✔
116
}
117

118
#[derive(Debug)]
119
pub(crate) enum Error {
120
    UnknownVersion { supported_versions: &'static [usize] },
121
    FeeRate,
122
}
123

124
impl fmt::Display for Error {
125
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
×
126
        match self {
×
127
            Error::UnknownVersion { .. } => write!(f, "unknown version"),
×
128
            Error::FeeRate => write!(f, "could not parse feerate"),
×
129
        }
130
    }
×
131
}
132

133
impl std::error::Error for Error {
134
    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { None }
×
135
}
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