X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Foffers%2Finvoice_error.rs;h=5476ad551b7b627d5e1abac8d19fc836b673e54c;hb=870a0f14bab32d21c7652773b5d9a37f8e59cd5e;hp=122049b9295438b0147224a76c6efbc75455146c;hpb=4b241357387bcbb5cb51e00c83fab2dbeaebd0b3;p=rust-lightning diff --git a/lightning/src/offers/invoice_error.rs b/lightning/src/offers/invoice_error.rs index 122049b9..5476ad55 100644 --- a/lightning/src/offers/invoice_error.rs +++ b/lightning/src/offers/invoice_error.rs @@ -48,6 +48,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 +80,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))),