X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;ds=sidebyside;f=lightning%2Fsrc%2Foffers%2Finvoice_error.rs;h=1b634525416acef1a249858a7d78cc44b3c03b06;hb=3a9fe209e104e048921ad50be77a80b18a98b45c;hp=e843264b4e3ed851afc5642fc1e8b5d0869854e5;hpb=c3c105075aeb8128699e043f777b4c89c452e54d;p=rust-lightning diff --git a/lightning/src/offers/invoice_error.rs b/lightning/src/offers/invoice_error.rs index e843264b..1b634525 100644 --- a/lightning/src/offers/invoice_error.rs +++ b/lightning/src/offers/invoice_error.rs @@ -11,33 +11,34 @@ use crate::io; use crate::ln::msgs::DecodeError; -use crate::offers::parse::SemanticError; +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 [`Invoice`]. +/// An error in response to an [`InvoiceRequest`] or an [`Bolt12Invoice`]. /// /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest -/// [`Invoice`]: crate::offers::invoice::Invoice +/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice #[derive(Clone, Debug)] #[cfg_attr(test, derive(PartialEq))] pub struct InvoiceError { - /// The field in the [`InvoiceRequest`] or the [`Invoice`] that contained an error. + /// The field in the [`InvoiceRequest`] or the [`Bolt12Invoice`] that contained an error. /// /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest - /// [`Invoice`]: crate::offers::invoice::Invoice + /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice pub erroneous_field: Option, /// An explanation of the error. pub message: UntrustedString, } -/// The field in the [`InvoiceRequest`] or the [`Invoice`] that contained an error. +/// The field in the [`InvoiceRequest`] or the [`Bolt12Invoice`] that contained an error. /// /// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest -/// [`Invoice`]: crate::offers::invoice::Invoice +/// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice #[derive(Clone, Debug)] #[cfg_attr(test, derive(PartialEq))] pub struct ErroneousField { @@ -48,6 +49,16 @@ pub struct ErroneousField { pub suggested_value: Option>, } +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) @@ -70,7 +81,7 @@ impl Writeable for InvoiceError { impl Readable for InvoiceError { fn read(reader: &mut R) -> Result { - _init_and_read_tlv_fields!(reader, { + _init_and_read_len_prefixed_tlv_fields!(reader, { (1, erroneous_field, (option, encoding: (u64, HighZeroBytesDroppedBigSize))), (3, suggested_value, (option, encoding: (Vec, WithoutLength))), (5, error, (option, encoding: (UntrustedString, WithoutLength))), @@ -93,8 +104,8 @@ impl Readable for InvoiceError { } } -impl From for InvoiceError { - fn from(error: SemanticError) -> Self { +impl From for InvoiceError { + fn from(error: Bolt12SemanticError) -> Self { InvoiceError { erroneous_field: None, message: UntrustedString(format!("{:?}", error)),