X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning%2Fsrc%2Fonion_message%2Fpacket.rs;h=8738091a94267d959b606e88d8e6ce18202fcf16;hb=ec538d181677bdd4a9dd7b29f619fff032fc2120;hp=2afdbdd6570dc63c6d050e16d8d0d33161877282;hpb=75fd0f3cbbd1b788a8f9e3956ff78831669df55b;p=rust-lightning diff --git a/lightning/src/onion_message/packet.rs b/lightning/src/onion_message/packet.rs index 2afdbdd6..8738091a 100644 --- a/lightning/src/onion_message/packet.rs +++ b/lightning/src/onion_message/packet.rs @@ -104,13 +104,34 @@ pub(super) enum Payload { } } -// Coming soon: -// enum Message { -// InvoiceRequest(InvoiceRequest), -// Invoice(Invoice), -// InvoiceError(InvoiceError), -// CustomMessage, -// } +#[derive(Debug)] +/// The contents of an onion message. In the context of offers, this would be the invoice, invoice +/// request, or invoice error. +pub enum OnionMessageContents where T: CustomOnionMessageContents { + // Coming soon: + // Invoice, + // InvoiceRequest, + // InvoiceError, + /// A custom onion message specified by the user. + Custom(T), +} + +impl OnionMessageContents where T: CustomOnionMessageContents { + /// Returns the type that was used to decode the message payload. + pub fn tlv_type(&self) -> u64 { + match self { + &OnionMessageContents::Custom(ref msg) => msg.tlv_type(), + } + } +} + +impl Writeable for OnionMessageContents { + fn write(&self, w: &mut W) -> Result<(), io::Error> { + match self { + OnionMessageContents::Custom(msg) => Ok(msg.write(w)?), + } + } +} /// The contents of a custom onion message. Must implement `MaybeReadableArgs` where the `u64` /// is the custom TLV type attempting to be read, and return `Ok(None)` if the TLV type is unknown.