Allow(unused_imports) on prelude imports
[rust-lightning] / lightning / src / offers / invoice_error.rs
index 122049b9295438b0147224a76c6efbc75455146c..1b634525416acef1a249858a7d78cc44b3c03b06 100644 (file)
@@ -15,6 +15,7 @@ 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`].
@@ -48,6 +49,16 @@ pub struct ErroneousField {
        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)
@@ -70,7 +81,7 @@ impl Writeable for InvoiceError {
 
 impl Readable for InvoiceError {
        fn read<R: io::Read>(reader: &mut R) -> Result<Self, DecodeError> {
-               _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<u8>, WithoutLength))),
                        (5, error, (option, encoding: (UntrustedString, WithoutLength))),