use crate::io;
use crate::ln::msgs::DecodeError;
+use crate::offers::merkle::SignError;
use crate::offers::parse::Bolt12SemanticError;
use crate::util::ser::{HighZeroBytesDroppedBigSize, Readable, WithoutLength, Writeable, Writer};
use crate::util::string::UntrustedString;
+#[allow(unused_imports)]
use crate::prelude::*;
/// An error in response to an [`InvoiceRequest`] or an [`Bolt12Invoice`].
pub suggested_value: Option<Vec<u8>>,
}
+impl InvoiceError {
+ /// Creates an [`InvoiceError`] with the given message.
+ pub fn from_string(s: String) -> Self {
+ Self {
+ erroneous_field: None,
+ message: UntrustedString(s),
+ }
+ }
+}
+
impl core::fmt::Display for InvoiceError {
fn fmt(&self, f: &mut core::fmt::Formatter) -> Result<(), core::fmt::Error> {
self.message.fmt(f)
}
}
+impl From<SignError> for InvoiceError {
+ fn from(error: SignError) -> Self {
+ let message = match error {
+ SignError::Signing => "Failed signing invoice",
+ SignError::Verification(_) => "Failed invoice signature verification",
+ };
+ InvoiceError {
+ erroneous_field: None,
+ message: UntrustedString(message.to_string()),
+ }
+ }
+}
+
#[cfg(test)]
mod tests {
use super::{ErroneousField, InvoiceError};