X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-c-bindings%2Fsrc%2Flightning%2Fonion_message%2Fpacket.rs;h=8b253aad30d36acc559c755cf3bfa21823f8163e;hb=7ebc93258c70a014e9129c0b464256d2ee670751;hp=90c0238577a3f86ca8d6215f963fb8a2b33b97ba;hpb=a21177846ed75d66f68a1603f768410f07a65791;p=ldk-c-bindings diff --git a/lightning-c-bindings/src/lightning/onion_message/packet.rs b/lightning-c-bindings/src/lightning/onion_message/packet.rs index 90c0238..8b253aa 100644 --- a/lightning-c-bindings/src/lightning/onion_message/packet.rs +++ b/lightning-c-bindings/src/lightning/onion_message/packet.rs @@ -16,6 +16,66 @@ use crate::c_types::*; #[cfg(feature="no-std")] use alloc::{vec::Vec, boxed::Box}; +/// The contents of an onion message. In the context of offers, this would be the invoice, invoice +/// request, or invoice error. +#[must_use] +#[repr(C)] +pub enum OnionMessageContents { + /// A message related to BOLT 12 Offers. + Offers( + crate::lightning::onion_message::offers::OffersMessage), + /// A custom onion message specified by the user. + Custom( + crate::lightning::onion_message::packet::CustomOnionMessageContents), +} +use lightning::onion_message::packet::OnionMessageContents as OnionMessageContentsImport; +pub(crate) type nativeOnionMessageContents = OnionMessageContentsImport; + +impl OnionMessageContents { + #[allow(unused)] + pub(crate) fn into_native(self) -> nativeOnionMessageContents { + match self { + OnionMessageContents::Offers (mut a, ) => { + nativeOnionMessageContents::Offers ( + a.into_native(), + ) + }, + OnionMessageContents::Custom (mut a, ) => { + nativeOnionMessageContents::Custom ( + a, + ) + }, + } + } + #[allow(unused)] + pub(crate) fn native_into(native: nativeOnionMessageContents) -> Self { + match native { + nativeOnionMessageContents::Offers (mut a, ) => { + OnionMessageContents::Offers ( + crate::lightning::onion_message::offers::OffersMessage::native_into(a), + ) + }, + nativeOnionMessageContents::Custom (mut a, ) => { + OnionMessageContents::Custom ( + Into::into(a), + ) + }, + } + } +} +/// Frees any resources used by the OnionMessageContents +#[no_mangle] +pub extern "C" fn OnionMessageContents_free(this_ptr: OnionMessageContents) { } +#[no_mangle] +/// Utility method to constructs a new Offers-variant OnionMessageContents +pub extern "C" fn OnionMessageContents_offers(a: crate::lightning::onion_message::offers::OffersMessage) -> OnionMessageContents { + OnionMessageContents::Offers(a, ) +} +#[no_mangle] +/// Utility method to constructs a new Custom-variant OnionMessageContents +pub extern "C" fn OnionMessageContents_custom(a: crate::lightning::onion_message::packet::CustomOnionMessageContents) -> OnionMessageContents { + OnionMessageContents::Custom(a, ) +} /// The contents of a custom onion message. #[repr(C)] pub struct CustomOnionMessageContents { @@ -23,7 +83,6 @@ pub struct CustomOnionMessageContents { /// This has no meaning in the LDK, and can be NULL or any other value. pub this_arg: *mut c_void, /// Returns the TLV type identifying the message contents. MUST be >= 64. - #[must_use] pub tlv_type: extern "C" fn (this_arg: *const c_void) -> u64, /// Serialize the object into a byte array pub write: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::CVec_u8Z,