X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Foffers%2Finvoice_error.rs;h=5ae5f457a84822172d970035286a562be0d67973;hb=478911d42a8b47020511bdcb793756723f3801be;hp=441dae265cbb4fb9c9ed8d527e6b9b65c1e61ad1;hpb=debc20cc3e1bb8ce8625e67294d0c3036314fdcb;p=rust-lightning diff --git a/lightning/src/offers/invoice_error.rs b/lightning/src/offers/invoice_error.rs index 441dae26..5ae5f457 100644 --- a/lightning/src/offers/invoice_error.rs +++ b/lightning/src/offers/invoice_error.rs @@ -11,10 +11,12 @@ 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`]. @@ -50,10 +52,10 @@ pub struct ErroneousField { impl InvoiceError { /// Creates an [`InvoiceError`] with the given message. - pub fn from_str(s: &str) -> Self { + pub fn from_string(s: String) -> Self { Self { erroneous_field: None, - message: UntrustedString(s.to_string()), + message: UntrustedString(s), } } } @@ -112,6 +114,19 @@ impl From for InvoiceError { } } +impl From 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};