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

payjoin / rust-payjoin / 14117620655

27 Mar 2025 10:08PM UTC coverage: 81.699% (+0.2%) from 81.45%
14117620655

Pull #606

github

web-flow
Merge e38f7e1ad into 752fceebf
Pull Request #606: Reply json

74 of 111 new or added lines in 7 files covered. (66.67%)

5 existing lines in 3 files now uncovered.

5107 of 6251 relevant lines covered (81.7%)

739.49 hits per line

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

72.73
/payjoin/src/error_codes.rs
1
//! Well-known error codes as defined in BIP-78
2
//! See: <https://github.com/bitcoin/bips/blob/master/bip-0078.mediawiki#receivers-well-known-errors>
3

4
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5
pub enum ErrorCode {
6
    /// The payjoin endpoint is not available for now.
7
    Unavailable,
8
    /// The receiver added some inputs but could not bump the fee of the payjoin proposal.
9
    NotEnoughMoney,
10
    /// This version of payjoin is not supported.
11
    VersionUnsupported,
12
    /// The receiver rejected the original PSBT.
13
    OriginalPsbtRejected,
14
}
15

16
impl ErrorCode {
17
    pub const fn as_str(&self) -> &'static str {
3✔
18
        match self {
3✔
19
            Self::Unavailable => "unavailable",
2✔
NEW
20
            Self::NotEnoughMoney => "not-enough-money",
×
NEW
21
            Self::VersionUnsupported => "version-unsupported",
×
22
            Self::OriginalPsbtRejected => "original-psbt-rejected",
1✔
23
        }
24
    }
3✔
25
}
26

27
impl core::str::FromStr for ErrorCode {
28
    type Err = ();
29

30
    fn from_str(s: &str) -> Result<Self, Self::Err> {
3✔
31
        match s {
3✔
32
            "unavailable" => Ok(Self::Unavailable),
3✔
33
            "not-enough-money" => Ok(Self::NotEnoughMoney),
3✔
34
            "version-unsupported" => Ok(Self::VersionUnsupported),
3✔
35
            "original-psbt-rejected" => Ok(Self::OriginalPsbtRejected),
1✔
36
            _ => Err(()),
1✔
37
        }
38
    }
3✔
39
}
40

41
impl core::fmt::Display for ErrorCode {
42
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
3✔
43
        f.write_str(self.as_str())
3✔
44
    }
3✔
45
}
46

47
/// A well-known error that can be safely displayed to end users.
48
#[derive(Debug, Clone, PartialEq, Eq)]
49
pub struct WellKnownError {
50
    pub(crate) code: ErrorCode,
51
    pub(crate) message: String,
52
    pub(crate) supported_versions: Option<Vec<u64>>,
53
}
54

55
impl WellKnownError {
56
    /// Create a new well-known error with the given code and message.
NEW
57
    pub(crate) fn new(code: ErrorCode, message: String) -> Self {
×
NEW
58
        Self { code, message, supported_versions: None }
×
NEW
59
    }
×
60

61
    /// Create a version unsupported error with the given message and supported versions.
62
    pub(crate) fn version_unsupported(message: String, supported: Vec<u64>) -> Self {
2✔
63
        Self { code: ErrorCode::VersionUnsupported, message, supported_versions: Some(supported) }
2✔
64
    }
2✔
65
}
66

67
impl core::fmt::Display for WellKnownError {
68
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
1✔
69
        match self.code {
1✔
NEW
70
            ErrorCode::Unavailable => write!(f, "The payjoin endpoint is not available for now."),
×
NEW
71
            ErrorCode::NotEnoughMoney => write!(f, "The receiver added some inputs but could not bump the fee of the payjoin proposal."),
×
72
            ErrorCode::VersionUnsupported => {
73
                if let Some(supported) = &self.supported_versions {
1✔
74
                    write!(f, "This version of payjoin is not supported. Use version {:?}.", supported)
1✔
75
                } else {
NEW
76
                    write!(f, "This version of payjoin is not supported.")
×
77
                }
78
            }
NEW
79
            ErrorCode::OriginalPsbtRejected => write!(f, "The receiver rejected the original PSBT."),
×
80
        }
81
    }
1✔
82
}
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