X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-c-bindings%2Fsrc%2Flightning%2Fln%2Fmsgs.rs;h=54269e6537261d750915b9dd71d9bc57b62cafb5;hb=11b997c3a0452ea1da5b7b352e7887798105db29;hp=36cf43f65df988c99bc610352a9f70c374ef9df5;hpb=f10bdbea94cd8c638a42ab637a52e86a7cfd8157;p=ldk-c-bindings diff --git a/lightning-c-bindings/src/lightning/ln/msgs.rs b/lightning-c-bindings/src/lightning/ln/msgs.rs index 36cf43f..54269e6 100644 --- a/lightning-c-bindings/src/lightning/ln/msgs.rs +++ b/lightning-c-bindings/src/lightning/ln/msgs.rs @@ -11,12 +11,12 @@ //! For a normal node you probably don't need to use anything here, however, if you wish to split a //! node into an internet-facing route/message socket handling daemon and a separate daemon (or //! server entirely) which handles only channel-related messages you may wish to implement -//! ChannelMessageHandler yourself and use it to re-serialize messages and pass them across +//! [`ChannelMessageHandler`] yourself and use it to re-serialize messages and pass them across //! daemons/servers. //! //! Note that if you go with such an architecture (instead of passing raw socket events to a //! non-internet-facing system) you trust the frontend internet-facing system to not lie about the -//! source node_id of the message, however this does allow you to significantly reduce bandwidth +//! source `node_id` of the message, however this does allow you to significantly reduce bandwidth //! between the systems as routing messages can represent a significant chunk of bandwidth usage //! (especially for non-channel-publicly-announcing nodes). As an alternate design which avoids //! this issue, if you have sufficient bidirectional bandwidth between your systems, you may send @@ -31,81 +31,154 @@ use crate::c_types::*; #[cfg(feature="no-std")] use alloc::{vec::Vec, boxed::Box}; - -use lightning::ln::msgs::DecodeError as nativeDecodeErrorImport; -pub(crate) type nativeDecodeError = nativeDecodeErrorImport; - /// An error in decoding a message or struct. +#[derive(Clone)] #[must_use] #[repr(C)] -pub struct DecodeError { - /// A pointer to the opaque Rust object. - - /// Nearly everywhere, inner must be non-null, however in places where - /// the Rust equivalent takes an Option, it may be set to null to indicate None. - pub inner: *mut nativeDecodeError, - /// Indicates that this is the only struct which contains the same pointer. - - /// Rust functions which take ownership of an object provided via an argument require - /// this to be true and invalidate the object pointed to by inner. - pub is_owned: bool, -} +pub enum DecodeError { + /// A version byte specified something we don't know how to handle. + /// + /// Includes unknown realm byte in an onion hop data packet. + UnknownVersion, + /// Unknown feature mandating we fail to parse message (e.g., TLV with an even, unknown type) + UnknownRequiredFeature, + /// Value was invalid. + /// + /// For example, a byte which was supposed to be a bool was something other than a 0 + /// or 1, a public key/private key/signature was invalid, text wasn't UTF-8, TLV was + /// syntactically incorrect, etc. + InvalidValue, + /// The buffer to be read was too short. + ShortRead, + /// A length descriptor in the packet didn't describe the later data correctly. + BadLengthDescriptor, + /// Error from [`std::io`]. + Io( + crate::c_types::IOError), + /// The message included zlib-compressed values, which we don't support. + UnsupportedCompression, +} +use lightning::ln::msgs::DecodeError as DecodeErrorImport; +pub(crate) type nativeDecodeError = DecodeErrorImport; -impl Drop for DecodeError { - fn drop(&mut self) { - if self.is_owned && !<*mut nativeDecodeError>::is_null(self.inner) { - let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; - } - } -} -/// Frees any resources used by the DecodeError, if is_owned is set and inner is non-NULL. -#[no_mangle] -pub extern "C" fn DecodeError_free(this_obj: DecodeError) { } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn DecodeError_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDecodeError); } -} -#[allow(unused)] impl DecodeError { - pub(crate) fn get_native_ref(&self) -> &'static nativeDecodeError { - unsafe { &*ObjOps::untweak_ptr(self.inner) } + #[allow(unused)] + pub(crate) fn to_native(&self) -> nativeDecodeError { + match self { + DecodeError::UnknownVersion => nativeDecodeError::UnknownVersion, + DecodeError::UnknownRequiredFeature => nativeDecodeError::UnknownRequiredFeature, + DecodeError::InvalidValue => nativeDecodeError::InvalidValue, + DecodeError::ShortRead => nativeDecodeError::ShortRead, + DecodeError::BadLengthDescriptor => nativeDecodeError::BadLengthDescriptor, + DecodeError::Io (ref a, ) => { + let mut a_nonref = Clone::clone(a); + nativeDecodeError::Io ( + a_nonref.to_rust_kind(), + ) + }, + DecodeError::UnsupportedCompression => nativeDecodeError::UnsupportedCompression, + } } - pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDecodeError { - unsafe { &mut *ObjOps::untweak_ptr(self.inner) } + #[allow(unused)] + pub(crate) fn into_native(self) -> nativeDecodeError { + match self { + DecodeError::UnknownVersion => nativeDecodeError::UnknownVersion, + DecodeError::UnknownRequiredFeature => nativeDecodeError::UnknownRequiredFeature, + DecodeError::InvalidValue => nativeDecodeError::InvalidValue, + DecodeError::ShortRead => nativeDecodeError::ShortRead, + DecodeError::BadLengthDescriptor => nativeDecodeError::BadLengthDescriptor, + DecodeError::Io (mut a, ) => { + nativeDecodeError::Io ( + a.to_rust_kind(), + ) + }, + DecodeError::UnsupportedCompression => nativeDecodeError::UnsupportedCompression, + } } - /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy - pub(crate) fn take_inner(mut self) -> *mut nativeDecodeError { - assert!(self.is_owned); - let ret = ObjOps::untweak_ptr(self.inner); - self.inner = core::ptr::null_mut(); - ret + #[allow(unused)] + pub(crate) fn from_native(native: &nativeDecodeError) -> Self { + match native { + nativeDecodeError::UnknownVersion => DecodeError::UnknownVersion, + nativeDecodeError::UnknownRequiredFeature => DecodeError::UnknownRequiredFeature, + nativeDecodeError::InvalidValue => DecodeError::InvalidValue, + nativeDecodeError::ShortRead => DecodeError::ShortRead, + nativeDecodeError::BadLengthDescriptor => DecodeError::BadLengthDescriptor, + nativeDecodeError::Io (ref a, ) => { + let mut a_nonref = Clone::clone(a); + DecodeError::Io ( + crate::c_types::IOError::from_rust_kind(a_nonref), + ) + }, + nativeDecodeError::UnsupportedCompression => DecodeError::UnsupportedCompression, + } } -} -impl Clone for DecodeError { - fn clone(&self) -> Self { - Self { - inner: if <*mut nativeDecodeError>::is_null(self.inner) { core::ptr::null_mut() } else { - ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, - is_owned: true, + #[allow(unused)] + pub(crate) fn native_into(native: nativeDecodeError) -> Self { + match native { + nativeDecodeError::UnknownVersion => DecodeError::UnknownVersion, + nativeDecodeError::UnknownRequiredFeature => DecodeError::UnknownRequiredFeature, + nativeDecodeError::InvalidValue => DecodeError::InvalidValue, + nativeDecodeError::ShortRead => DecodeError::ShortRead, + nativeDecodeError::BadLengthDescriptor => DecodeError::BadLengthDescriptor, + nativeDecodeError::Io (mut a, ) => { + DecodeError::Io ( + crate::c_types::IOError::from_rust_kind(a), + ) + }, + nativeDecodeError::UnsupportedCompression => DecodeError::UnsupportedCompression, } } } -#[allow(unused)] -/// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn DecodeError_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDecodeError)).clone() })) as *mut c_void -} +/// Frees any resources used by the DecodeError #[no_mangle] +pub extern "C" fn DecodeError_free(this_ptr: DecodeError) { } /// Creates a copy of the DecodeError +#[no_mangle] pub extern "C" fn DecodeError_clone(orig: &DecodeError) -> DecodeError { orig.clone() } +#[no_mangle] +/// Utility method to constructs a new UnknownVersion-variant DecodeError +pub extern "C" fn DecodeError_unknown_version() -> DecodeError { + DecodeError::UnknownVersion} +#[no_mangle] +/// Utility method to constructs a new UnknownRequiredFeature-variant DecodeError +pub extern "C" fn DecodeError_unknown_required_feature() -> DecodeError { + DecodeError::UnknownRequiredFeature} +#[no_mangle] +/// Utility method to constructs a new InvalidValue-variant DecodeError +pub extern "C" fn DecodeError_invalid_value() -> DecodeError { + DecodeError::InvalidValue} +#[no_mangle] +/// Utility method to constructs a new ShortRead-variant DecodeError +pub extern "C" fn DecodeError_short_read() -> DecodeError { + DecodeError::ShortRead} +#[no_mangle] +/// Utility method to constructs a new BadLengthDescriptor-variant DecodeError +pub extern "C" fn DecodeError_bad_length_descriptor() -> DecodeError { + DecodeError::BadLengthDescriptor} +#[no_mangle] +/// Utility method to constructs a new Io-variant DecodeError +pub extern "C" fn DecodeError_io(a: crate::c_types::IOError) -> DecodeError { + DecodeError::Io(a, ) +} +#[no_mangle] +/// Utility method to constructs a new UnsupportedCompression-variant DecodeError +pub extern "C" fn DecodeError_unsupported_compression() -> DecodeError { + DecodeError::UnsupportedCompression} +/// Checks if two DecodeErrors contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +#[no_mangle] +pub extern "C" fn DecodeError_eq(a: &DecodeError, b: &DecodeError) -> bool { + if &a.to_native() == &b.to_native() { true } else { false } +} use lightning::ln::msgs::Init as nativeInitImport; pub(crate) type nativeInit = nativeInitImport; -/// An init message to be sent or received from a peer +/// An [`init`] message to be sent to or received from a peer. +/// +/// [`init`]: https://github.com/lightning/bolts/blob/master/01-messaging.md#the-init-message #[must_use] #[repr(C)] pub struct Init { @@ -134,7 +207,7 @@ pub extern "C" fn Init_free(this_obj: Init) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn Init_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInit); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeInit) }; } #[allow(unused)] impl Init { @@ -152,31 +225,35 @@ impl Init { ret } } -/// The relevant features which the sender supports +/// The relevant features which the sender supports. #[no_mangle] pub extern "C" fn Init_get_features(this_ptr: &Init) -> crate::lightning::ln::features::InitFeatures { let mut inner_val = &mut this_ptr.get_native_mut_ref().features; crate::lightning::ln::features::InitFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::features::InitFeatures<>) as *mut _) }, is_owned: false } } -/// The relevant features which the sender supports +/// The relevant features which the sender supports. #[no_mangle] pub extern "C" fn Init_set_features(this_ptr: &mut Init, mut val: crate::lightning::ln::features::InitFeatures) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) }; } -/// The receipient's network address. This adds the option to report a remote IP address -/// back to a connecting peer using the init message. A node can decide to use that information -/// to discover a potential update to its public IPv4 address (NAT) and use -/// that for a node_announcement update message containing the new address. +/// The receipient's network address. +/// +/// This adds the option to report a remote IP address back to a connecting peer using the init +/// message. A node can decide to use that information to discover a potential update to its +/// public IPv4 address (NAT) and use that for a [`NodeAnnouncement`] update message containing +/// the new address. #[no_mangle] pub extern "C" fn Init_get_remote_network_address(this_ptr: &Init) -> crate::c_types::derived::COption_NetAddressZ { let mut inner_val = &mut this_ptr.get_native_mut_ref().remote_network_address; let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_NetAddressZ::None } else { crate::c_types::derived::COption_NetAddressZ::Some(/* WARNING: CLONING CONVERSION HERE! &Option is otherwise un-expressable. */ { crate::lightning::ln::msgs::NetAddress::native_into(inner_val.clone().unwrap()) }) }; local_inner_val } -/// The receipient's network address. This adds the option to report a remote IP address -/// back to a connecting peer using the init message. A node can decide to use that information -/// to discover a potential update to its public IPv4 address (NAT) and use -/// that for a node_announcement update message containing the new address. +/// The receipient's network address. +/// +/// This adds the option to report a remote IP address back to a connecting peer using the init +/// message. A node can decide to use that information to discover a potential update to its +/// public IPv4 address (NAT) and use that for a [`NodeAnnouncement`] update message containing +/// the new address. #[no_mangle] pub extern "C" fn Init_set_remote_network_address(this_ptr: &mut Init, mut val: crate::c_types::derived::COption_NetAddressZ) { let mut local_val = { /* val*/ let val_opt = val; { } if val_opt.is_none() { None } else { Some({ val_opt.take().into_native() }) } }; @@ -211,11 +288,22 @@ pub(crate) extern "C" fn Init_clone_void(this_ptr: *const c_void) -> *mut c_void pub extern "C" fn Init_clone(orig: &Init) -> Init { orig.clone() } +/// Checks if two Inits contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn Init_eq(a: &Init, b: &Init) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if a.get_native_ref() == b.get_native_ref() { true } else { false } +} use lightning::ln::msgs::ErrorMessage as nativeErrorMessageImport; pub(crate) type nativeErrorMessage = nativeErrorMessageImport; -/// An error message to be sent or received from a peer +/// An [`error`] message to be sent to or received from a peer. +/// +/// [`error`]: https://github.com/lightning/bolts/blob/master/01-messaging.md#the-error-and-warning-messages #[must_use] #[repr(C)] pub struct ErrorMessage { @@ -244,7 +332,7 @@ pub extern "C" fn ErrorMessage_free(this_obj: ErrorMessage) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ErrorMessage_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeErrorMessage); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeErrorMessage) }; } #[allow(unused)] impl ErrorMessage { @@ -280,8 +368,9 @@ pub extern "C" fn ErrorMessage_set_channel_id(this_ptr: &mut ErrorMessage, mut v unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = val.data; } /// A possibly human-readable error description. -/// The string should be sanitized before it is used (e.g. emitted to logs or printed to -/// stdout). Otherwise, a well crafted error message may trigger a security vulnerability in +/// +/// The string should be sanitized before it is used (e.g., emitted to logs or printed to +/// `stdout`). Otherwise, a well crafted error message may trigger a security vulnerability in /// the terminal emulator or the logging subsystem. #[no_mangle] pub extern "C" fn ErrorMessage_get_data(this_ptr: &ErrorMessage) -> crate::c_types::Str { @@ -289,8 +378,9 @@ pub extern "C" fn ErrorMessage_get_data(this_ptr: &ErrorMessage) -> crate::c_typ inner_val.as_str().into() } /// A possibly human-readable error description. -/// The string should be sanitized before it is used (e.g. emitted to logs or printed to -/// stdout). Otherwise, a well crafted error message may trigger a security vulnerability in +/// +/// The string should be sanitized before it is used (e.g., emitted to logs or printed to +/// `stdout`). Otherwise, a well crafted error message may trigger a security vulnerability in /// the terminal emulator or the logging subsystem. #[no_mangle] pub extern "C" fn ErrorMessage_set_data(this_ptr: &mut ErrorMessage, mut val: crate::c_types::Str) { @@ -324,11 +414,22 @@ pub(crate) extern "C" fn ErrorMessage_clone_void(this_ptr: *const c_void) -> *mu pub extern "C" fn ErrorMessage_clone(orig: &ErrorMessage) -> ErrorMessage { orig.clone() } +/// Checks if two ErrorMessages contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn ErrorMessage_eq(a: &ErrorMessage, b: &ErrorMessage) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if a.get_native_ref() == b.get_native_ref() { true } else { false } +} use lightning::ln::msgs::WarningMessage as nativeWarningMessageImport; pub(crate) type nativeWarningMessage = nativeWarningMessageImport; -/// A warning message to be sent or received from a peer +/// A [`warning`] message to be sent to or received from a peer. +/// +/// [`warning`]: https://github.com/lightning/bolts/blob/master/01-messaging.md#the-error-and-warning-messages #[must_use] #[repr(C)] pub struct WarningMessage { @@ -357,7 +458,7 @@ pub extern "C" fn WarningMessage_free(this_obj: WarningMessage) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn WarningMessage_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeWarningMessage); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeWarningMessage) }; } #[allow(unused)] impl WarningMessage { @@ -391,6 +492,7 @@ pub extern "C" fn WarningMessage_set_channel_id(this_ptr: &mut WarningMessage, m unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = val.data; } /// A possibly human-readable warning description. +/// /// The string should be sanitized before it is used (e.g. emitted to logs or printed to /// stdout). Otherwise, a well crafted error message may trigger a security vulnerability in /// the terminal emulator or the logging subsystem. @@ -400,6 +502,7 @@ pub extern "C" fn WarningMessage_get_data(this_ptr: &WarningMessage) -> crate::c inner_val.as_str().into() } /// A possibly human-readable warning description. +/// /// The string should be sanitized before it is used (e.g. emitted to logs or printed to /// stdout). Otherwise, a well crafted error message may trigger a security vulnerability in /// the terminal emulator or the logging subsystem. @@ -435,11 +538,22 @@ pub(crate) extern "C" fn WarningMessage_clone_void(this_ptr: *const c_void) -> * pub extern "C" fn WarningMessage_clone(orig: &WarningMessage) -> WarningMessage { orig.clone() } +/// Checks if two WarningMessages contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn WarningMessage_eq(a: &WarningMessage, b: &WarningMessage) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if a.get_native_ref() == b.get_native_ref() { true } else { false } +} use lightning::ln::msgs::Ping as nativePingImport; pub(crate) type nativePing = nativePingImport; -/// A ping message to be sent or received from a peer +/// A [`ping`] message to be sent to or received from a peer. +/// +/// [`ping`]: https://github.com/lightning/bolts/blob/master/01-messaging.md#the-ping-and-pong-messages #[must_use] #[repr(C)] pub struct Ping { @@ -468,7 +582,7 @@ pub extern "C" fn Ping_free(this_obj: Ping) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn Ping_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativePing); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativePing) }; } #[allow(unused)] impl Ping { @@ -486,18 +600,19 @@ impl Ping { ret } } -/// The desired response length +/// The desired response length. #[no_mangle] pub extern "C" fn Ping_get_ponglen(this_ptr: &Ping) -> u16 { let mut inner_val = &mut this_ptr.get_native_mut_ref().ponglen; *inner_val } -/// The desired response length +/// The desired response length. #[no_mangle] pub extern "C" fn Ping_set_ponglen(this_ptr: &mut Ping, mut val: u16) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.ponglen = val; } /// The ping packet size. +/// /// This field is not sent on the wire. byteslen zeros are sent. #[no_mangle] pub extern "C" fn Ping_get_byteslen(this_ptr: &Ping) -> u16 { @@ -505,6 +620,7 @@ pub extern "C" fn Ping_get_byteslen(this_ptr: &Ping) -> u16 { *inner_val } /// The ping packet size. +/// /// This field is not sent on the wire. byteslen zeros are sent. #[no_mangle] pub extern "C" fn Ping_set_byteslen(this_ptr: &mut Ping, mut val: u16) { @@ -538,11 +654,22 @@ pub(crate) extern "C" fn Ping_clone_void(this_ptr: *const c_void) -> *mut c_void pub extern "C" fn Ping_clone(orig: &Ping) -> Ping { orig.clone() } +/// Checks if two Pings contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn Ping_eq(a: &Ping, b: &Ping) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if a.get_native_ref() == b.get_native_ref() { true } else { false } +} use lightning::ln::msgs::Pong as nativePongImport; pub(crate) type nativePong = nativePongImport; -/// A pong message to be sent or received from a peer +/// A [`pong`] message to be sent to or received from a peer. +/// +/// [`pong`]: https://github.com/lightning/bolts/blob/master/01-messaging.md#the-ping-and-pong-messages #[must_use] #[repr(C)] pub struct Pong { @@ -571,7 +698,7 @@ pub extern "C" fn Pong_free(this_obj: Pong) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn Pong_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativePong); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativePong) }; } #[allow(unused)] impl Pong { @@ -590,6 +717,7 @@ impl Pong { } } /// The pong packet size. +/// /// This field is not sent on the wire. byteslen zeros are sent. #[no_mangle] pub extern "C" fn Pong_get_byteslen(this_ptr: &Pong) -> u16 { @@ -597,6 +725,7 @@ pub extern "C" fn Pong_get_byteslen(this_ptr: &Pong) -> u16 { *inner_val } /// The pong packet size. +/// /// This field is not sent on the wire. byteslen zeros are sent. #[no_mangle] pub extern "C" fn Pong_set_byteslen(this_ptr: &mut Pong, mut val: u16) { @@ -629,11 +758,22 @@ pub(crate) extern "C" fn Pong_clone_void(this_ptr: *const c_void) -> *mut c_void pub extern "C" fn Pong_clone(orig: &Pong) -> Pong { orig.clone() } +/// Checks if two Pongs contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn Pong_eq(a: &Pong, b: &Pong) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if a.get_native_ref() == b.get_native_ref() { true } else { false } +} use lightning::ln::msgs::OpenChannel as nativeOpenChannelImport; pub(crate) type nativeOpenChannel = nativeOpenChannelImport; -/// An open_channel message to be sent or received from a peer +/// An [`open_channel`] message to be sent to or received from a peer. +/// +/// [`open_channel`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#the-open_channel-message #[must_use] #[repr(C)] pub struct OpenChannel { @@ -662,7 +802,7 @@ pub extern "C" fn OpenChannel_free(this_obj: OpenChannel) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn OpenChannel_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeOpenChannel); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeOpenChannel) }; } #[allow(unused)] impl OpenChannel { @@ -768,24 +908,28 @@ pub extern "C" fn OpenChannel_get_htlc_minimum_msat(this_ptr: &OpenChannel) -> u pub extern "C" fn OpenChannel_set_htlc_minimum_msat(this_ptr: &mut OpenChannel, mut val: u64) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_minimum_msat = val; } -/// The feerate per 1000-weight of sender generated transactions, until updated by update_fee +/// The feerate per 1000-weight of sender generated transactions, until updated by +/// [`UpdateFee`] #[no_mangle] pub extern "C" fn OpenChannel_get_feerate_per_kw(this_ptr: &OpenChannel) -> u32 { let mut inner_val = &mut this_ptr.get_native_mut_ref().feerate_per_kw; *inner_val } -/// The feerate per 1000-weight of sender generated transactions, until updated by update_fee +/// The feerate per 1000-weight of sender generated transactions, until updated by +/// [`UpdateFee`] #[no_mangle] pub extern "C" fn OpenChannel_set_feerate_per_kw(this_ptr: &mut OpenChannel, mut val: u32) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.feerate_per_kw = val; } -/// The number of blocks which the counterparty will have to wait to claim on-chain funds if they broadcast a commitment transaction +/// The number of blocks which the counterparty will have to wait to claim on-chain funds if +/// they broadcast a commitment transaction #[no_mangle] pub extern "C" fn OpenChannel_get_to_self_delay(this_ptr: &OpenChannel) -> u16 { let mut inner_val = &mut this_ptr.get_native_mut_ref().to_self_delay; *inner_val } -/// The number of blocks which the counterparty will have to wait to claim on-chain funds if they broadcast a commitment transaction +/// The number of blocks which the counterparty will have to wait to claim on-chain funds if +/// they broadcast a commitment transaction #[no_mangle] pub extern "C" fn OpenChannel_set_to_self_delay(this_ptr: &mut OpenChannel, mut val: u16) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.to_self_delay = val; @@ -867,20 +1011,21 @@ pub extern "C" fn OpenChannel_get_first_per_commitment_point(this_ptr: &OpenChan pub extern "C" fn OpenChannel_set_first_per_commitment_point(this_ptr: &mut OpenChannel, mut val: crate::c_types::PublicKey) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.first_per_commitment_point = val.into_rust(); } -/// Channel flags +/// The channel flags to be used #[no_mangle] pub extern "C" fn OpenChannel_get_channel_flags(this_ptr: &OpenChannel) -> u8 { let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_flags; *inner_val } -/// Channel flags +/// The channel flags to be used #[no_mangle] pub extern "C" fn OpenChannel_set_channel_flags(this_ptr: &mut OpenChannel, mut val: u8) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_flags = val; } -/// The channel type that this channel will represent. If none is set, we derive the channel -/// type from the intersection of our feature bits with our counterparty's feature bits from -/// the Init message. +/// The channel type that this channel will represent +/// +/// If this is `None`, we derive the channel type from the intersection of our +/// feature bits with our counterparty's feature bits from the [`Init`] message. /// /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None #[no_mangle] @@ -889,9 +1034,10 @@ pub extern "C" fn OpenChannel_get_channel_type(this_ptr: &OpenChannel) -> crate: let mut local_inner_val = crate::lightning::ln::features::ChannelTypeFeatures { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::ln::features::ChannelTypeFeatures<>) as *mut _ }, is_owned: false }; local_inner_val } -/// The channel type that this channel will represent. If none is set, we derive the channel -/// type from the intersection of our feature bits with our counterparty's feature bits from -/// the Init message. +/// The channel type that this channel will represent +/// +/// If this is `None`, we derive the channel type from the intersection of our +/// feature bits with our counterparty's feature bits from the [`Init`] message. /// /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None #[no_mangle] @@ -918,11 +1064,22 @@ pub(crate) extern "C" fn OpenChannel_clone_void(this_ptr: *const c_void) -> *mut pub extern "C" fn OpenChannel_clone(orig: &OpenChannel) -> OpenChannel { orig.clone() } +/// Checks if two OpenChannels contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn OpenChannel_eq(a: &OpenChannel, b: &OpenChannel) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if a.get_native_ref() == b.get_native_ref() { true } else { false } +} use lightning::ln::msgs::AcceptChannel as nativeAcceptChannelImport; pub(crate) type nativeAcceptChannel = nativeAcceptChannelImport; -/// An accept_channel message to be sent or received from a peer +/// An [`accept_channel`] message to be sent to or received from a peer. +/// +/// [`accept_channel`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#the-accept_channel-message #[must_use] #[repr(C)] pub struct AcceptChannel { @@ -951,7 +1108,7 @@ pub extern "C" fn AcceptChannel_free(this_obj: AcceptChannel) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn AcceptChannel_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeAcceptChannel); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeAcceptChannel) }; } #[allow(unused)] impl AcceptChannel { @@ -1123,10 +1280,10 @@ pub extern "C" fn AcceptChannel_get_first_per_commitment_point(this_ptr: &Accept pub extern "C" fn AcceptChannel_set_first_per_commitment_point(this_ptr: &mut AcceptChannel, mut val: crate::c_types::PublicKey) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.first_per_commitment_point = val.into_rust(); } -/// The channel type that this channel will represent. If none is set, we derive the channel -/// type from the intersection of our feature bits with our counterparty's feature bits from -/// the Init message. +/// The channel type that this channel will represent. /// +/// If this is `None`, we derive the channel type from the intersection of +/// our feature bits with our counterparty's feature bits from the [`Init`] message. /// This is required to match the equivalent field in [`OpenChannel::channel_type`]. /// /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None @@ -1136,10 +1293,10 @@ pub extern "C" fn AcceptChannel_get_channel_type(this_ptr: &AcceptChannel) -> cr let mut local_inner_val = crate::lightning::ln::features::ChannelTypeFeatures { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::ln::features::ChannelTypeFeatures<>) as *mut _ }, is_owned: false }; local_inner_val } -/// The channel type that this channel will represent. If none is set, we derive the channel -/// type from the intersection of our feature bits with our counterparty's feature bits from -/// the Init message. +/// The channel type that this channel will represent. /// +/// If this is `None`, we derive the channel type from the intersection of +/// our feature bits with our counterparty's feature bits from the [`Init`] message. /// This is required to match the equivalent field in [`OpenChannel::channel_type`]. /// /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None @@ -1167,11 +1324,22 @@ pub(crate) extern "C" fn AcceptChannel_clone_void(this_ptr: *const c_void) -> *m pub extern "C" fn AcceptChannel_clone(orig: &AcceptChannel) -> AcceptChannel { orig.clone() } +/// Checks if two AcceptChannels contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn AcceptChannel_eq(a: &AcceptChannel, b: &AcceptChannel) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if a.get_native_ref() == b.get_native_ref() { true } else { false } +} use lightning::ln::msgs::FundingCreated as nativeFundingCreatedImport; pub(crate) type nativeFundingCreated = nativeFundingCreatedImport; -/// A funding_created message to be sent or received from a peer +/// A [`funding_created`] message to be sent to or received from a peer. +/// +/// [`funding_created`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#the-funding_created-message #[must_use] #[repr(C)] pub struct FundingCreated { @@ -1200,7 +1368,7 @@ pub extern "C" fn FundingCreated_free(this_obj: FundingCreated) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn FundingCreated_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeFundingCreated); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeFundingCreated) }; } #[allow(unused)] impl FundingCreated { @@ -1292,11 +1460,22 @@ pub(crate) extern "C" fn FundingCreated_clone_void(this_ptr: *const c_void) -> * pub extern "C" fn FundingCreated_clone(orig: &FundingCreated) -> FundingCreated { orig.clone() } +/// Checks if two FundingCreateds contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn FundingCreated_eq(a: &FundingCreated, b: &FundingCreated) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if a.get_native_ref() == b.get_native_ref() { true } else { false } +} use lightning::ln::msgs::FundingSigned as nativeFundingSignedImport; pub(crate) type nativeFundingSigned = nativeFundingSignedImport; -/// A funding_signed message to be sent or received from a peer +/// A [`funding_signed`] message to be sent to or received from a peer. +/// +/// [`funding_signed`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#the-funding_signed-message #[must_use] #[repr(C)] pub struct FundingSigned { @@ -1325,7 +1504,7 @@ pub extern "C" fn FundingSigned_free(this_obj: FundingSigned) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn FundingSigned_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeFundingSigned); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeFundingSigned) }; } #[allow(unused)] impl FundingSigned { @@ -1393,11 +1572,22 @@ pub(crate) extern "C" fn FundingSigned_clone_void(this_ptr: *const c_void) -> *m pub extern "C" fn FundingSigned_clone(orig: &FundingSigned) -> FundingSigned { orig.clone() } +/// Checks if two FundingSigneds contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn FundingSigned_eq(a: &FundingSigned, b: &FundingSigned) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if a.get_native_ref() == b.get_native_ref() { true } else { false } +} use lightning::ln::msgs::ChannelReady as nativeChannelReadyImport; pub(crate) type nativeChannelReady = nativeChannelReadyImport; -/// A channel_ready message to be sent or received from a peer +/// A [`channel_ready`] message to be sent to or received from a peer. +/// +/// [`channel_ready`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#the-channel_ready-message #[must_use] #[repr(C)] pub struct ChannelReady { @@ -1426,7 +1616,7 @@ pub extern "C" fn ChannelReady_free(this_obj: ChannelReady) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ChannelReady_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelReady); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelReady) }; } #[allow(unused)] impl ChannelReady { @@ -1466,16 +1656,20 @@ pub extern "C" fn ChannelReady_get_next_per_commitment_point(this_ptr: &ChannelR pub extern "C" fn ChannelReady_set_next_per_commitment_point(this_ptr: &mut ChannelReady, mut val: crate::c_types::PublicKey) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.next_per_commitment_point = val.into_rust(); } -/// If set, provides a short_channel_id alias for this channel. The sender will accept payments -/// to be forwarded over this SCID and forward them to this messages' recipient. +/// If set, provides a `short_channel_id` alias for this channel. +/// +/// The sender will accept payments to be forwarded over this SCID and forward them to this +/// messages' recipient. #[no_mangle] pub extern "C" fn ChannelReady_get_short_channel_id_alias(this_ptr: &ChannelReady) -> crate::c_types::derived::COption_u64Z { let mut inner_val = &mut this_ptr.get_native_mut_ref().short_channel_id_alias; let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { inner_val.unwrap() }) }; local_inner_val } -/// If set, provides a short_channel_id alias for this channel. The sender will accept payments -/// to be forwarded over this SCID and forward them to this messages' recipient. +/// If set, provides a `short_channel_id` alias for this channel. +/// +/// The sender will accept payments to be forwarded over this SCID and forward them to this +/// messages' recipient. #[no_mangle] pub extern "C" fn ChannelReady_set_short_channel_id_alias(this_ptr: &mut ChannelReady, mut val: crate::c_types::derived::COption_u64Z) { let mut local_val = if val.is_some() { Some( { val.take() }) } else { None }; @@ -1511,11 +1705,22 @@ pub(crate) extern "C" fn ChannelReady_clone_void(this_ptr: *const c_void) -> *mu pub extern "C" fn ChannelReady_clone(orig: &ChannelReady) -> ChannelReady { orig.clone() } +/// Checks if two ChannelReadys contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn ChannelReady_eq(a: &ChannelReady, b: &ChannelReady) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if a.get_native_ref() == b.get_native_ref() { true } else { false } +} use lightning::ln::msgs::Shutdown as nativeShutdownImport; pub(crate) type nativeShutdown = nativeShutdownImport; -/// A shutdown message to be sent or received from a peer +/// A [`shutdown`] message to be sent to or received from a peer. +/// +/// [`shutdown`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#closing-initiation-shutdown #[must_use] #[repr(C)] pub struct Shutdown { @@ -1544,7 +1749,7 @@ pub extern "C" fn Shutdown_free(this_obj: Shutdown) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn Shutdown_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeShutdown); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeShutdown) }; } #[allow(unused)] impl Shutdown { @@ -1574,14 +1779,16 @@ pub extern "C" fn Shutdown_set_channel_id(this_ptr: &mut Shutdown, mut val: crat unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = val.data; } /// The destination of this peer's funds on closing. -/// Must be in one of these forms: p2pkh, p2sh, p2wpkh, p2wsh. +/// +/// Must be in one of these forms: P2PKH, P2SH, P2WPKH, P2WSH, P2TR. #[no_mangle] pub extern "C" fn Shutdown_get_scriptpubkey(this_ptr: &Shutdown) -> crate::c_types::u8slice { let mut inner_val = &mut this_ptr.get_native_mut_ref().scriptpubkey; crate::c_types::u8slice::from_slice(&inner_val[..]) } /// The destination of this peer's funds on closing. -/// Must be in one of these forms: p2pkh, p2sh, p2wpkh, p2wsh. +/// +/// Must be in one of these forms: P2PKH, P2SH, P2WPKH, P2WSH, P2TR. #[no_mangle] pub extern "C" fn Shutdown_set_scriptpubkey(this_ptr: &mut Shutdown, mut val: crate::c_types::derived::CVec_u8Z) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.scriptpubkey = ::bitcoin::blockdata::script::Script::from(val.into_rust()); @@ -1614,11 +1821,21 @@ pub(crate) extern "C" fn Shutdown_clone_void(this_ptr: *const c_void) -> *mut c_ pub extern "C" fn Shutdown_clone(orig: &Shutdown) -> Shutdown { orig.clone() } +/// Checks if two Shutdowns contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn Shutdown_eq(a: &Shutdown, b: &Shutdown) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if a.get_native_ref() == b.get_native_ref() { true } else { false } +} use lightning::ln::msgs::ClosingSignedFeeRange as nativeClosingSignedFeeRangeImport; pub(crate) type nativeClosingSignedFeeRange = nativeClosingSignedFeeRangeImport; /// The minimum and maximum fees which the sender is willing to place on the closing transaction. +/// /// This is provided in [`ClosingSigned`] by both sides to indicate the fee range they are willing /// to use. #[must_use] @@ -1649,7 +1866,7 @@ pub extern "C" fn ClosingSignedFeeRange_free(this_obj: ClosingSignedFeeRange) { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ClosingSignedFeeRange_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeClosingSignedFeeRange); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeClosingSignedFeeRange) }; } #[allow(unused)] impl ClosingSignedFeeRange { @@ -1721,11 +1938,22 @@ pub(crate) extern "C" fn ClosingSignedFeeRange_clone_void(this_ptr: *const c_voi pub extern "C" fn ClosingSignedFeeRange_clone(orig: &ClosingSignedFeeRange) -> ClosingSignedFeeRange { orig.clone() } +/// Checks if two ClosingSignedFeeRanges contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn ClosingSignedFeeRange_eq(a: &ClosingSignedFeeRange, b: &ClosingSignedFeeRange) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if a.get_native_ref() == b.get_native_ref() { true } else { false } +} use lightning::ln::msgs::ClosingSigned as nativeClosingSignedImport; pub(crate) type nativeClosingSigned = nativeClosingSignedImport; -/// A closing_signed message to be sent or received from a peer +/// A [`closing_signed`] message to be sent to or received from a peer. +/// +/// [`closing_signed`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#closing-negotiation-closing_signed #[must_use] #[repr(C)] pub struct ClosingSigned { @@ -1754,7 +1982,7 @@ pub extern "C" fn ClosingSigned_free(this_obj: ClosingSigned) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ClosingSigned_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeClosingSigned); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeClosingSigned) }; } #[allow(unused)] impl ClosingSigned { @@ -1855,11 +2083,22 @@ pub(crate) extern "C" fn ClosingSigned_clone_void(this_ptr: *const c_void) -> *m pub extern "C" fn ClosingSigned_clone(orig: &ClosingSigned) -> ClosingSigned { orig.clone() } +/// Checks if two ClosingSigneds contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn ClosingSigned_eq(a: &ClosingSigned, b: &ClosingSigned) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if a.get_native_ref() == b.get_native_ref() { true } else { false } +} use lightning::ln::msgs::UpdateAddHTLC as nativeUpdateAddHTLCImport; pub(crate) type nativeUpdateAddHTLC = nativeUpdateAddHTLCImport; -/// An update_add_htlc message to be sent or received from a peer +/// An [`update_add_htlc`] message to be sent to or received from a peer. +/// +/// [`update_add_htlc`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#adding-an-htlc-update_add_htlc #[must_use] #[repr(C)] pub struct UpdateAddHTLC { @@ -1888,7 +2127,7 @@ pub extern "C" fn UpdateAddHTLC_free(this_obj: UpdateAddHTLC) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn UpdateAddHTLC_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeUpdateAddHTLC); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeUpdateAddHTLC) }; } #[allow(unused)] impl UpdateAddHTLC { @@ -1980,11 +2219,113 @@ pub(crate) extern "C" fn UpdateAddHTLC_clone_void(this_ptr: *const c_void) -> *m pub extern "C" fn UpdateAddHTLC_clone(orig: &UpdateAddHTLC) -> UpdateAddHTLC { orig.clone() } +/// Checks if two UpdateAddHTLCs contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn UpdateAddHTLC_eq(a: &UpdateAddHTLC, b: &UpdateAddHTLC) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if a.get_native_ref() == b.get_native_ref() { true } else { false } +} + +use lightning::ln::msgs::OnionMessage as nativeOnionMessageImport; +pub(crate) type nativeOnionMessage = nativeOnionMessageImport; + +/// An onion message to be sent to or received from a peer. +/// +#[must_use] +#[repr(C)] +pub struct OnionMessage { + /// A pointer to the opaque Rust object. + + /// Nearly everywhere, inner must be non-null, however in places where + /// the Rust equivalent takes an Option, it may be set to null to indicate None. + pub inner: *mut nativeOnionMessage, + /// Indicates that this is the only struct which contains the same pointer. + + /// Rust functions which take ownership of an object provided via an argument require + /// this to be true and invalidate the object pointed to by inner. + pub is_owned: bool, +} + +impl Drop for OnionMessage { + fn drop(&mut self) { + if self.is_owned && !<*mut nativeOnionMessage>::is_null(self.inner) { + let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; + } + } +} +/// Frees any resources used by the OnionMessage, if is_owned is set and inner is non-NULL. +#[no_mangle] +pub extern "C" fn OnionMessage_free(this_obj: OnionMessage) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn OnionMessage_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeOnionMessage) }; +} +#[allow(unused)] +impl OnionMessage { + pub(crate) fn get_native_ref(&self) -> &'static nativeOnionMessage { + unsafe { &*ObjOps::untweak_ptr(self.inner) } + } + pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeOnionMessage { + unsafe { &mut *ObjOps::untweak_ptr(self.inner) } + } + /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy + pub(crate) fn take_inner(mut self) -> *mut nativeOnionMessage { + assert!(self.is_owned); + let ret = ObjOps::untweak_ptr(self.inner); + self.inner = core::ptr::null_mut(); + ret + } +} +/// Used in decrypting the onion packet's payload. +#[no_mangle] +pub extern "C" fn OnionMessage_get_blinding_point(this_ptr: &OnionMessage) -> crate::c_types::PublicKey { + let mut inner_val = &mut this_ptr.get_native_mut_ref().blinding_point; + crate::c_types::PublicKey::from_rust(&inner_val) +} +/// Used in decrypting the onion packet's payload. +#[no_mangle] +pub extern "C" fn OnionMessage_set_blinding_point(this_ptr: &mut OnionMessage, mut val: crate::c_types::PublicKey) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.blinding_point = val.into_rust(); +} +impl Clone for OnionMessage { + fn clone(&self) -> Self { + Self { + inner: if <*mut nativeOnionMessage>::is_null(self.inner) { core::ptr::null_mut() } else { + ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, + is_owned: true, + } + } +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn OnionMessage_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeOnionMessage)).clone() })) as *mut c_void +} +#[no_mangle] +/// Creates a copy of the OnionMessage +pub extern "C" fn OnionMessage_clone(orig: &OnionMessage) -> OnionMessage { + orig.clone() +} +/// Checks if two OnionMessages contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn OnionMessage_eq(a: &OnionMessage, b: &OnionMessage) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if a.get_native_ref() == b.get_native_ref() { true } else { false } +} use lightning::ln::msgs::UpdateFulfillHTLC as nativeUpdateFulfillHTLCImport; pub(crate) type nativeUpdateFulfillHTLC = nativeUpdateFulfillHTLCImport; -/// An update_fulfill_htlc message to be sent or received from a peer +/// An [`update_fulfill_htlc`] message to be sent to or received from a peer. +/// +/// [`update_fulfill_htlc`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#removing-an-htlc-update_fulfill_htlc-update_fail_htlc-and-update_fail_malformed_htlc #[must_use] #[repr(C)] pub struct UpdateFulfillHTLC { @@ -2013,7 +2354,7 @@ pub extern "C" fn UpdateFulfillHTLC_free(this_obj: UpdateFulfillHTLC) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn UpdateFulfillHTLC_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeUpdateFulfillHTLC); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeUpdateFulfillHTLC) }; } #[allow(unused)] impl UpdateFulfillHTLC { @@ -2093,11 +2434,22 @@ pub(crate) extern "C" fn UpdateFulfillHTLC_clone_void(this_ptr: *const c_void) - pub extern "C" fn UpdateFulfillHTLC_clone(orig: &UpdateFulfillHTLC) -> UpdateFulfillHTLC { orig.clone() } +/// Checks if two UpdateFulfillHTLCs contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn UpdateFulfillHTLC_eq(a: &UpdateFulfillHTLC, b: &UpdateFulfillHTLC) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if a.get_native_ref() == b.get_native_ref() { true } else { false } +} use lightning::ln::msgs::UpdateFailHTLC as nativeUpdateFailHTLCImport; pub(crate) type nativeUpdateFailHTLC = nativeUpdateFailHTLCImport; -/// An update_fail_htlc message to be sent or received from a peer +/// An [`update_fail_htlc`] message to be sent to or received from a peer. +/// +/// [`update_fail_htlc`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#removing-an-htlc-update_fulfill_htlc-update_fail_htlc-and-update_fail_malformed_htlc #[must_use] #[repr(C)] pub struct UpdateFailHTLC { @@ -2126,7 +2478,7 @@ pub extern "C" fn UpdateFailHTLC_free(this_obj: UpdateFailHTLC) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn UpdateFailHTLC_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeUpdateFailHTLC); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeUpdateFailHTLC) }; } #[allow(unused)] impl UpdateFailHTLC { @@ -2185,11 +2537,22 @@ pub(crate) extern "C" fn UpdateFailHTLC_clone_void(this_ptr: *const c_void) -> * pub extern "C" fn UpdateFailHTLC_clone(orig: &UpdateFailHTLC) -> UpdateFailHTLC { orig.clone() } +/// Checks if two UpdateFailHTLCs contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn UpdateFailHTLC_eq(a: &UpdateFailHTLC, b: &UpdateFailHTLC) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if a.get_native_ref() == b.get_native_ref() { true } else { false } +} use lightning::ln::msgs::UpdateFailMalformedHTLC as nativeUpdateFailMalformedHTLCImport; pub(crate) type nativeUpdateFailMalformedHTLC = nativeUpdateFailMalformedHTLCImport; -/// An update_fail_malformed_htlc message to be sent or received from a peer +/// An [`update_fail_malformed_htlc`] message to be sent to or received from a peer. +/// +/// [`update_fail_malformed_htlc`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#removing-an-htlc-update_fulfill_htlc-update_fail_htlc-and-update_fail_malformed_htlc #[must_use] #[repr(C)] pub struct UpdateFailMalformedHTLC { @@ -2218,7 +2581,7 @@ pub extern "C" fn UpdateFailMalformedHTLC_free(this_obj: UpdateFailMalformedHTLC #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn UpdateFailMalformedHTLC_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeUpdateFailMalformedHTLC); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeUpdateFailMalformedHTLC) }; } #[allow(unused)] impl UpdateFailMalformedHTLC { @@ -2288,11 +2651,22 @@ pub(crate) extern "C" fn UpdateFailMalformedHTLC_clone_void(this_ptr: *const c_v pub extern "C" fn UpdateFailMalformedHTLC_clone(orig: &UpdateFailMalformedHTLC) -> UpdateFailMalformedHTLC { orig.clone() } +/// Checks if two UpdateFailMalformedHTLCs contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn UpdateFailMalformedHTLC_eq(a: &UpdateFailMalformedHTLC, b: &UpdateFailMalformedHTLC) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if a.get_native_ref() == b.get_native_ref() { true } else { false } +} use lightning::ln::msgs::CommitmentSigned as nativeCommitmentSignedImport; pub(crate) type nativeCommitmentSigned = nativeCommitmentSignedImport; -/// A commitment_signed message to be sent or received from a peer +/// A [`commitment_signed`] message to be sent to or received from a peer. +/// +/// [`commitment_signed`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#committing-updates-so-far-commitment_signed #[must_use] #[repr(C)] pub struct CommitmentSigned { @@ -2321,7 +2695,7 @@ pub extern "C" fn CommitmentSigned_free(this_obj: CommitmentSigned) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn CommitmentSigned_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeCommitmentSigned); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeCommitmentSigned) }; } #[allow(unused)] impl CommitmentSigned { @@ -2362,6 +2736,15 @@ pub extern "C" fn CommitmentSigned_set_signature(this_ptr: &mut CommitmentSigned unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.signature = val.into_rust(); } /// Signatures on the HTLC transactions +/// +/// Returns a copy of the field. +#[no_mangle] +pub extern "C" fn CommitmentSigned_get_htlc_signatures(this_ptr: &CommitmentSigned) -> crate::c_types::derived::CVec_SignatureZ { + let mut inner_val = this_ptr.get_native_mut_ref().htlc_signatures.clone(); + let mut local_inner_val = Vec::new(); for mut item in inner_val.drain(..) { local_inner_val.push( { crate::c_types::Signature::from_rust(&item) }); }; + local_inner_val.into() +} +/// Signatures on the HTLC transactions #[no_mangle] pub extern "C" fn CommitmentSigned_set_htlc_signatures(this_ptr: &mut CommitmentSigned, mut val: crate::c_types::derived::CVec_SignatureZ) { let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item.into_rust() }); }; @@ -2397,11 +2780,22 @@ pub(crate) extern "C" fn CommitmentSigned_clone_void(this_ptr: *const c_void) -> pub extern "C" fn CommitmentSigned_clone(orig: &CommitmentSigned) -> CommitmentSigned { orig.clone() } +/// Checks if two CommitmentSigneds contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn CommitmentSigned_eq(a: &CommitmentSigned, b: &CommitmentSigned) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if a.get_native_ref() == b.get_native_ref() { true } else { false } +} use lightning::ln::msgs::RevokeAndACK as nativeRevokeAndACKImport; pub(crate) type nativeRevokeAndACK = nativeRevokeAndACKImport; -/// A revoke_and_ack message to be sent or received from a peer +/// A [`revoke_and_ack`] message to be sent to or received from a peer. +/// +/// [`revoke_and_ack`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#completing-the-transition-to-the-updated-state-revoke_and_ack #[must_use] #[repr(C)] pub struct RevokeAndACK { @@ -2430,7 +2824,7 @@ pub extern "C" fn RevokeAndACK_free(this_obj: RevokeAndACK) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn RevokeAndACK_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRevokeAndACK); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRevokeAndACK) }; } #[allow(unused)] impl RevokeAndACK { @@ -2510,11 +2904,22 @@ pub(crate) extern "C" fn RevokeAndACK_clone_void(this_ptr: *const c_void) -> *mu pub extern "C" fn RevokeAndACK_clone(orig: &RevokeAndACK) -> RevokeAndACK { orig.clone() } +/// Checks if two RevokeAndACKs contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn RevokeAndACK_eq(a: &RevokeAndACK, b: &RevokeAndACK) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if a.get_native_ref() == b.get_native_ref() { true } else { false } +} use lightning::ln::msgs::UpdateFee as nativeUpdateFeeImport; pub(crate) type nativeUpdateFee = nativeUpdateFeeImport; -/// An update_fee message to be sent or received from a peer +/// An [`update_fee`] message to be sent to or received from a peer +/// +/// [`update_fee`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#updating-fees-update_fee #[must_use] #[repr(C)] pub struct UpdateFee { @@ -2543,7 +2948,7 @@ pub extern "C" fn UpdateFee_free(this_obj: UpdateFee) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn UpdateFee_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeUpdateFee); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeUpdateFee) }; } #[allow(unused)] impl UpdateFee { @@ -2611,13 +3016,23 @@ pub(crate) extern "C" fn UpdateFee_clone_void(this_ptr: *const c_void) -> *mut c pub extern "C" fn UpdateFee_clone(orig: &UpdateFee) -> UpdateFee { orig.clone() } +/// Checks if two UpdateFees contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn UpdateFee_eq(a: &UpdateFee, b: &UpdateFee) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if a.get_native_ref() == b.get_native_ref() { true } else { false } +} use lightning::ln::msgs::DataLossProtect as nativeDataLossProtectImport; pub(crate) type nativeDataLossProtect = nativeDataLossProtectImport; /// Proof that the sender knows the per-commitment secret of the previous commitment transaction. +/// /// This is used to convince the recipient that the channel is at a certain commitment -/// number even if they lost that data due to a local failure. Of course, the peer may lie +/// number even if they lost that data due to a local failure. Of course, the peer may lie /// and even later commitments may have been revoked. #[must_use] #[repr(C)] @@ -2647,7 +3062,7 @@ pub extern "C" fn DataLossProtect_free(this_obj: DataLossProtect) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn DataLossProtect_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDataLossProtect); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeDataLossProtect) }; } #[allow(unused)] impl DataLossProtect { @@ -2717,11 +3132,22 @@ pub(crate) extern "C" fn DataLossProtect_clone_void(this_ptr: *const c_void) -> pub extern "C" fn DataLossProtect_clone(orig: &DataLossProtect) -> DataLossProtect { orig.clone() } +/// Checks if two DataLossProtects contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn DataLossProtect_eq(a: &DataLossProtect, b: &DataLossProtect) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if a.get_native_ref() == b.get_native_ref() { true } else { false } +} use lightning::ln::msgs::ChannelReestablish as nativeChannelReestablishImport; pub(crate) type nativeChannelReestablish = nativeChannelReestablishImport; -/// A channel_reestablish message to be sent or received from a peer +/// A [`channel_reestablish`] message to be sent to or received from a peer. +/// +/// [`channel_reestablish`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#message-retransmission #[must_use] #[repr(C)] pub struct ChannelReestablish { @@ -2750,7 +3176,7 @@ pub extern "C" fn ChannelReestablish_free(this_obj: ChannelReestablish) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ChannelReestablish_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelReestablish); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelReestablish) }; } #[allow(unused)] impl ChannelReestablish { @@ -2820,11 +3246,22 @@ pub(crate) extern "C" fn ChannelReestablish_clone_void(this_ptr: *const c_void) pub extern "C" fn ChannelReestablish_clone(orig: &ChannelReestablish) -> ChannelReestablish { orig.clone() } +/// Checks if two ChannelReestablishs contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn ChannelReestablish_eq(a: &ChannelReestablish, b: &ChannelReestablish) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if a.get_native_ref() == b.get_native_ref() { true } else { false } +} use lightning::ln::msgs::AnnouncementSignatures as nativeAnnouncementSignaturesImport; pub(crate) type nativeAnnouncementSignatures = nativeAnnouncementSignaturesImport; -/// An announcement_signatures message to be sent or received from a peer +/// An [`announcement_signatures`] message to be sent to or received from a peer. +/// +/// [`announcement_signatures`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#the-announcement_signatures-message #[must_use] #[repr(C)] pub struct AnnouncementSignatures { @@ -2853,7 +3290,7 @@ pub extern "C" fn AnnouncementSignatures_free(this_obj: AnnouncementSignatures) #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn AnnouncementSignatures_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeAnnouncementSignatures); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeAnnouncementSignatures) }; } #[allow(unused)] impl AnnouncementSignatures { @@ -2945,7 +3382,16 @@ pub(crate) extern "C" fn AnnouncementSignatures_clone_void(this_ptr: *const c_vo pub extern "C" fn AnnouncementSignatures_clone(orig: &AnnouncementSignatures) -> AnnouncementSignatures { orig.clone() } -/// An address which can be used to connect to a remote peer +/// Checks if two AnnouncementSignaturess contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn AnnouncementSignatures_eq(a: &AnnouncementSignatures, b: &AnnouncementSignatures) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if a.get_native_ref() == b.get_native_ref() { true } else { false } +} +/// An address which can be used to connect to a remote peer. #[derive(Clone)] #[must_use] #[repr(C)] @@ -2971,7 +3417,8 @@ pub enum NetAddress { OnionV2( crate::c_types::TwelveBytes), /// A new-style Tor onion address/port on which the peer is listening. - /// To create the human-readable \"hostname\", concatenate ed25519_pubkey, checksum, and version, + /// + /// To create the human-readable \"hostname\", concatenate the ED25519 pubkey, checksum, and version, /// wrap as base32 and append \".onion\". OnionV3 { /// The ed25519 long-term public key of the peer @@ -2999,32 +3446,32 @@ impl NetAddress { pub(crate) fn to_native(&self) -> nativeNetAddress { match self { NetAddress::IPv4 {ref addr, ref port, } => { - let mut addr_nonref = (*addr).clone(); - let mut port_nonref = (*port).clone(); + let mut addr_nonref = Clone::clone(addr); + let mut port_nonref = Clone::clone(port); nativeNetAddress::IPv4 { addr: addr_nonref.data, port: port_nonref, } }, NetAddress::IPv6 {ref addr, ref port, } => { - let mut addr_nonref = (*addr).clone(); - let mut port_nonref = (*port).clone(); + let mut addr_nonref = Clone::clone(addr); + let mut port_nonref = Clone::clone(port); nativeNetAddress::IPv6 { addr: addr_nonref.data, port: port_nonref, } }, NetAddress::OnionV2 (ref a, ) => { - let mut a_nonref = (*a).clone(); + let mut a_nonref = Clone::clone(a); nativeNetAddress::OnionV2 ( a_nonref.data, ) }, NetAddress::OnionV3 {ref ed25519_pubkey, ref checksum, ref version, ref port, } => { - let mut ed25519_pubkey_nonref = (*ed25519_pubkey).clone(); - let mut checksum_nonref = (*checksum).clone(); - let mut version_nonref = (*version).clone(); - let mut port_nonref = (*port).clone(); + let mut ed25519_pubkey_nonref = Clone::clone(ed25519_pubkey); + let mut checksum_nonref = Clone::clone(checksum); + let mut version_nonref = Clone::clone(version); + let mut port_nonref = Clone::clone(port); nativeNetAddress::OnionV3 { ed25519_pubkey: ed25519_pubkey_nonref.data, checksum: checksum_nonref, @@ -3033,8 +3480,8 @@ impl NetAddress { } }, NetAddress::Hostname {ref hostname, ref port, } => { - let mut hostname_nonref = (*hostname).clone(); - let mut port_nonref = (*port).clone(); + let mut hostname_nonref = Clone::clone(hostname); + let mut port_nonref = Clone::clone(port); nativeNetAddress::Hostname { hostname: *unsafe { Box::from_raw(hostname_nonref.take_inner()) }, port: port_nonref, @@ -3082,32 +3529,32 @@ impl NetAddress { pub(crate) fn from_native(native: &nativeNetAddress) -> Self { match native { nativeNetAddress::IPv4 {ref addr, ref port, } => { - let mut addr_nonref = (*addr).clone(); - let mut port_nonref = (*port).clone(); + let mut addr_nonref = Clone::clone(addr); + let mut port_nonref = Clone::clone(port); NetAddress::IPv4 { addr: crate::c_types::FourBytes { data: addr_nonref }, port: port_nonref, } }, nativeNetAddress::IPv6 {ref addr, ref port, } => { - let mut addr_nonref = (*addr).clone(); - let mut port_nonref = (*port).clone(); + let mut addr_nonref = Clone::clone(addr); + let mut port_nonref = Clone::clone(port); NetAddress::IPv6 { addr: crate::c_types::SixteenBytes { data: addr_nonref }, port: port_nonref, } }, nativeNetAddress::OnionV2 (ref a, ) => { - let mut a_nonref = (*a).clone(); + let mut a_nonref = Clone::clone(a); NetAddress::OnionV2 ( crate::c_types::TwelveBytes { data: a_nonref }, ) }, nativeNetAddress::OnionV3 {ref ed25519_pubkey, ref checksum, ref version, ref port, } => { - let mut ed25519_pubkey_nonref = (*ed25519_pubkey).clone(); - let mut checksum_nonref = (*checksum).clone(); - let mut version_nonref = (*version).clone(); - let mut port_nonref = (*port).clone(); + let mut ed25519_pubkey_nonref = Clone::clone(ed25519_pubkey); + let mut checksum_nonref = Clone::clone(checksum); + let mut version_nonref = Clone::clone(version); + let mut port_nonref = Clone::clone(port); NetAddress::OnionV3 { ed25519_pubkey: crate::c_types::ThirtyTwoBytes { data: ed25519_pubkey_nonref }, checksum: checksum_nonref, @@ -3116,8 +3563,8 @@ impl NetAddress { } }, nativeNetAddress::Hostname {ref hostname, ref port, } => { - let mut hostname_nonref = (*hostname).clone(); - let mut port_nonref = (*port).clone(); + let mut hostname_nonref = Clone::clone(hostname); + let mut port_nonref = Clone::clone(port); NetAddress::Hostname { hostname: crate::lightning::util::ser::Hostname { inner: ObjOps::heap_alloc(hostname_nonref), is_owned: true }, port: port_nonref, @@ -3209,6 +3656,12 @@ pub extern "C" fn NetAddress_hostname(hostname: crate::lightning::util::ser::Hos port, } } +/// Checks if two NetAddresss contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +#[no_mangle] +pub extern "C" fn NetAddress_eq(a: &NetAddress, b: &NetAddress) -> bool { + if &a.to_native() == &b.to_native() { true } else { false } +} #[no_mangle] /// Serialize the NetAddress object into a byte array which can be read by NetAddress_read pub extern "C" fn NetAddress_write(obj: &crate::lightning::ln::msgs::NetAddress) -> crate::c_types::derived::CVec_u8Z { @@ -3218,14 +3671,150 @@ pub extern "C" fn NetAddress_write(obj: &crate::lightning::ln::msgs::NetAddress) /// Read a NetAddress from a byte array, created by NetAddress_write pub extern "C" fn NetAddress_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NetAddressDecodeErrorZ { let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::NetAddress::native_into(o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::NetAddress::native_into(o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; local_res } +/// Represents the set of gossip messages that require a signature from a node's identity key. +#[derive(Clone)] +#[must_use] +#[repr(C)] +pub enum UnsignedGossipMessage { + /// An unsigned channel announcement. + ChannelAnnouncement( + crate::lightning::ln::msgs::UnsignedChannelAnnouncement), + /// An unsigned channel update. + ChannelUpdate( + crate::lightning::ln::msgs::UnsignedChannelUpdate), + /// An unsigned node announcement. + NodeAnnouncement( + crate::lightning::ln::msgs::UnsignedNodeAnnouncement), +} +use lightning::ln::msgs::UnsignedGossipMessage as UnsignedGossipMessageImport; +pub(crate) type nativeUnsignedGossipMessage = UnsignedGossipMessageImport; + +impl UnsignedGossipMessage { + #[allow(unused)] + pub(crate) fn to_native(&self) -> nativeUnsignedGossipMessage { + match self { + UnsignedGossipMessage::ChannelAnnouncement (ref a, ) => { + let mut a_nonref = Clone::clone(a); + nativeUnsignedGossipMessage::ChannelAnnouncement ( + *unsafe { Box::from_raw(a_nonref.take_inner()) }, + ) + }, + UnsignedGossipMessage::ChannelUpdate (ref a, ) => { + let mut a_nonref = Clone::clone(a); + nativeUnsignedGossipMessage::ChannelUpdate ( + *unsafe { Box::from_raw(a_nonref.take_inner()) }, + ) + }, + UnsignedGossipMessage::NodeAnnouncement (ref a, ) => { + let mut a_nonref = Clone::clone(a); + nativeUnsignedGossipMessage::NodeAnnouncement ( + *unsafe { Box::from_raw(a_nonref.take_inner()) }, + ) + }, + } + } + #[allow(unused)] + pub(crate) fn into_native(self) -> nativeUnsignedGossipMessage { + match self { + UnsignedGossipMessage::ChannelAnnouncement (mut a, ) => { + nativeUnsignedGossipMessage::ChannelAnnouncement ( + *unsafe { Box::from_raw(a.take_inner()) }, + ) + }, + UnsignedGossipMessage::ChannelUpdate (mut a, ) => { + nativeUnsignedGossipMessage::ChannelUpdate ( + *unsafe { Box::from_raw(a.take_inner()) }, + ) + }, + UnsignedGossipMessage::NodeAnnouncement (mut a, ) => { + nativeUnsignedGossipMessage::NodeAnnouncement ( + *unsafe { Box::from_raw(a.take_inner()) }, + ) + }, + } + } + #[allow(unused)] + pub(crate) fn from_native(native: &nativeUnsignedGossipMessage) -> Self { + match native { + nativeUnsignedGossipMessage::ChannelAnnouncement (ref a, ) => { + let mut a_nonref = Clone::clone(a); + UnsignedGossipMessage::ChannelAnnouncement ( + crate::lightning::ln::msgs::UnsignedChannelAnnouncement { inner: ObjOps::heap_alloc(a_nonref), is_owned: true }, + ) + }, + nativeUnsignedGossipMessage::ChannelUpdate (ref a, ) => { + let mut a_nonref = Clone::clone(a); + UnsignedGossipMessage::ChannelUpdate ( + crate::lightning::ln::msgs::UnsignedChannelUpdate { inner: ObjOps::heap_alloc(a_nonref), is_owned: true }, + ) + }, + nativeUnsignedGossipMessage::NodeAnnouncement (ref a, ) => { + let mut a_nonref = Clone::clone(a); + UnsignedGossipMessage::NodeAnnouncement ( + crate::lightning::ln::msgs::UnsignedNodeAnnouncement { inner: ObjOps::heap_alloc(a_nonref), is_owned: true }, + ) + }, + } + } + #[allow(unused)] + pub(crate) fn native_into(native: nativeUnsignedGossipMessage) -> Self { + match native { + nativeUnsignedGossipMessage::ChannelAnnouncement (mut a, ) => { + UnsignedGossipMessage::ChannelAnnouncement ( + crate::lightning::ln::msgs::UnsignedChannelAnnouncement { inner: ObjOps::heap_alloc(a), is_owned: true }, + ) + }, + nativeUnsignedGossipMessage::ChannelUpdate (mut a, ) => { + UnsignedGossipMessage::ChannelUpdate ( + crate::lightning::ln::msgs::UnsignedChannelUpdate { inner: ObjOps::heap_alloc(a), is_owned: true }, + ) + }, + nativeUnsignedGossipMessage::NodeAnnouncement (mut a, ) => { + UnsignedGossipMessage::NodeAnnouncement ( + crate::lightning::ln::msgs::UnsignedNodeAnnouncement { inner: ObjOps::heap_alloc(a), is_owned: true }, + ) + }, + } + } +} +/// Frees any resources used by the UnsignedGossipMessage +#[no_mangle] +pub extern "C" fn UnsignedGossipMessage_free(this_ptr: UnsignedGossipMessage) { } +/// Creates a copy of the UnsignedGossipMessage +#[no_mangle] +pub extern "C" fn UnsignedGossipMessage_clone(orig: &UnsignedGossipMessage) -> UnsignedGossipMessage { + orig.clone() +} +#[no_mangle] +/// Utility method to constructs a new ChannelAnnouncement-variant UnsignedGossipMessage +pub extern "C" fn UnsignedGossipMessage_channel_announcement(a: crate::lightning::ln::msgs::UnsignedChannelAnnouncement) -> UnsignedGossipMessage { + UnsignedGossipMessage::ChannelAnnouncement(a, ) +} +#[no_mangle] +/// Utility method to constructs a new ChannelUpdate-variant UnsignedGossipMessage +pub extern "C" fn UnsignedGossipMessage_channel_update(a: crate::lightning::ln::msgs::UnsignedChannelUpdate) -> UnsignedGossipMessage { + UnsignedGossipMessage::ChannelUpdate(a, ) +} +#[no_mangle] +/// Utility method to constructs a new NodeAnnouncement-variant UnsignedGossipMessage +pub extern "C" fn UnsignedGossipMessage_node_announcement(a: crate::lightning::ln::msgs::UnsignedNodeAnnouncement) -> UnsignedGossipMessage { + UnsignedGossipMessage::NodeAnnouncement(a, ) +} +#[no_mangle] +/// Serialize the UnsignedGossipMessage object into a byte array which can be read by UnsignedGossipMessage_read +pub extern "C" fn UnsignedGossipMessage_write(obj: &crate::lightning::ln::msgs::UnsignedGossipMessage) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(&unsafe { &*obj }.to_native()) +} use lightning::ln::msgs::UnsignedNodeAnnouncement as nativeUnsignedNodeAnnouncementImport; pub(crate) type nativeUnsignedNodeAnnouncement = nativeUnsignedNodeAnnouncementImport; -/// The unsigned part of a node_announcement +/// The unsigned part of a [`node_announcement`] message. +/// +/// [`node_announcement`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#the-node_announcement-message #[must_use] #[repr(C)] pub struct UnsignedNodeAnnouncement { @@ -3254,7 +3843,7 @@ pub extern "C" fn UnsignedNodeAnnouncement_free(this_obj: UnsignedNodeAnnounceme #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn UnsignedNodeAnnouncement_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeUnsignedNodeAnnouncement); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeUnsignedNodeAnnouncement) }; } #[allow(unused)] impl UnsignedNodeAnnouncement { @@ -3294,18 +3883,18 @@ pub extern "C" fn UnsignedNodeAnnouncement_get_timestamp(this_ptr: &UnsignedNode pub extern "C" fn UnsignedNodeAnnouncement_set_timestamp(this_ptr: &mut UnsignedNodeAnnouncement, mut val: u32) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.timestamp = val; } -/// The node_id this announcement originated from (don't rebroadcast the node_announcement back +/// The `node_id` this announcement originated from (don't rebroadcast the `node_announcement` back /// to this node). #[no_mangle] -pub extern "C" fn UnsignedNodeAnnouncement_get_node_id(this_ptr: &UnsignedNodeAnnouncement) -> crate::c_types::PublicKey { +pub extern "C" fn UnsignedNodeAnnouncement_get_node_id(this_ptr: &UnsignedNodeAnnouncement) -> crate::lightning::routing::gossip::NodeId { let mut inner_val = &mut this_ptr.get_native_mut_ref().node_id; - crate::c_types::PublicKey::from_rust(&inner_val) + crate::lightning::routing::gossip::NodeId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::routing::gossip::NodeId<>) as *mut _) }, is_owned: false } } -/// The node_id this announcement originated from (don't rebroadcast the node_announcement back +/// The `node_id` this announcement originated from (don't rebroadcast the `node_announcement` back /// to this node). #[no_mangle] -pub extern "C" fn UnsignedNodeAnnouncement_set_node_id(this_ptr: &mut UnsignedNodeAnnouncement, mut val: crate::c_types::PublicKey) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_id = val.into_rust(); +pub extern "C" fn UnsignedNodeAnnouncement_set_node_id(this_ptr: &mut UnsignedNodeAnnouncement, mut val: crate::lightning::routing::gossip::NodeId) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_id = *unsafe { Box::from_raw(val.take_inner()) }; } /// An RGB color for UI purposes #[no_mangle] @@ -3318,20 +3907,31 @@ pub extern "C" fn UnsignedNodeAnnouncement_get_rgb(this_ptr: &UnsignedNodeAnnoun pub extern "C" fn UnsignedNodeAnnouncement_set_rgb(this_ptr: &mut UnsignedNodeAnnouncement, mut val: crate::c_types::ThreeBytes) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.rgb = val.data; } -/// An alias, for UI purposes. This should be sanitized before use. There is no guarantee -/// of uniqueness. +/// An alias, for UI purposes. +/// +/// This should be sanitized before use. There is no guarantee of uniqueness. #[no_mangle] pub extern "C" fn UnsignedNodeAnnouncement_get_alias(this_ptr: &UnsignedNodeAnnouncement) -> *const [u8; 32] { let mut inner_val = &mut this_ptr.get_native_mut_ref().alias; inner_val } -/// An alias, for UI purposes. This should be sanitized before use. There is no guarantee -/// of uniqueness. +/// An alias, for UI purposes. +/// +/// This should be sanitized before use. There is no guarantee of uniqueness. #[no_mangle] pub extern "C" fn UnsignedNodeAnnouncement_set_alias(this_ptr: &mut UnsignedNodeAnnouncement, mut val: crate::c_types::ThirtyTwoBytes) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.alias = val.data; } /// List of addresses on which this node is reachable +/// +/// Returns a copy of the field. +#[no_mangle] +pub extern "C" fn UnsignedNodeAnnouncement_get_addresses(this_ptr: &UnsignedNodeAnnouncement) -> crate::c_types::derived::CVec_NetAddressZ { + let mut inner_val = this_ptr.get_native_mut_ref().addresses.clone(); + let mut local_inner_val = Vec::new(); for mut item in inner_val.drain(..) { local_inner_val.push( { crate::lightning::ln::msgs::NetAddress::native_into(item) }); }; + local_inner_val.into() +} +/// List of addresses on which this node is reachable #[no_mangle] pub extern "C" fn UnsignedNodeAnnouncement_set_addresses(this_ptr: &mut UnsignedNodeAnnouncement, mut val: crate::c_types::derived::CVec_NetAddressZ) { let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item.into_native() }); }; @@ -3356,11 +3956,22 @@ pub(crate) extern "C" fn UnsignedNodeAnnouncement_clone_void(this_ptr: *const c_ pub extern "C" fn UnsignedNodeAnnouncement_clone(orig: &UnsignedNodeAnnouncement) -> UnsignedNodeAnnouncement { orig.clone() } +/// Checks if two UnsignedNodeAnnouncements contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn UnsignedNodeAnnouncement_eq(a: &UnsignedNodeAnnouncement, b: &UnsignedNodeAnnouncement) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if a.get_native_ref() == b.get_native_ref() { true } else { false } +} use lightning::ln::msgs::NodeAnnouncement as nativeNodeAnnouncementImport; pub(crate) type nativeNodeAnnouncement = nativeNodeAnnouncementImport; -/// A node_announcement message to be sent or received from a peer +/// A [`node_announcement`] message to be sent to or received from a peer. +/// +/// [`node_announcement`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#the-node_announcement-message #[must_use] #[repr(C)] pub struct NodeAnnouncement { @@ -3389,7 +4000,7 @@ pub extern "C" fn NodeAnnouncement_free(this_obj: NodeAnnouncement) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn NodeAnnouncement_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeAnnouncement); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeNodeAnnouncement) }; } #[allow(unused)] impl NodeAnnouncement { @@ -3457,11 +4068,22 @@ pub(crate) extern "C" fn NodeAnnouncement_clone_void(this_ptr: *const c_void) -> pub extern "C" fn NodeAnnouncement_clone(orig: &NodeAnnouncement) -> NodeAnnouncement { orig.clone() } +/// Checks if two NodeAnnouncements contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn NodeAnnouncement_eq(a: &NodeAnnouncement, b: &NodeAnnouncement) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if a.get_native_ref() == b.get_native_ref() { true } else { false } +} use lightning::ln::msgs::UnsignedChannelAnnouncement as nativeUnsignedChannelAnnouncementImport; pub(crate) type nativeUnsignedChannelAnnouncement = nativeUnsignedChannelAnnouncementImport; -/// The unsigned part of a channel_announcement +/// The unsigned part of a [`channel_announcement`] message. +/// +/// [`channel_announcement`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#the-channel_announcement-message #[must_use] #[repr(C)] pub struct UnsignedChannelAnnouncement { @@ -3490,7 +4112,7 @@ pub extern "C" fn UnsignedChannelAnnouncement_free(this_obj: UnsignedChannelAnno #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn UnsignedChannelAnnouncement_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeUnsignedChannelAnnouncement); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeUnsignedChannelAnnouncement) }; } #[allow(unused)] impl UnsignedChannelAnnouncement { @@ -3541,49 +4163,49 @@ pub extern "C" fn UnsignedChannelAnnouncement_get_short_channel_id(this_ptr: &Un pub extern "C" fn UnsignedChannelAnnouncement_set_short_channel_id(this_ptr: &mut UnsignedChannelAnnouncement, mut val: u64) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.short_channel_id = val; } -/// One of the two node_ids which are endpoints of this channel +/// One of the two `node_id`s which are endpoints of this channel #[no_mangle] -pub extern "C" fn UnsignedChannelAnnouncement_get_node_id_1(this_ptr: &UnsignedChannelAnnouncement) -> crate::c_types::PublicKey { +pub extern "C" fn UnsignedChannelAnnouncement_get_node_id_1(this_ptr: &UnsignedChannelAnnouncement) -> crate::lightning::routing::gossip::NodeId { let mut inner_val = &mut this_ptr.get_native_mut_ref().node_id_1; - crate::c_types::PublicKey::from_rust(&inner_val) + crate::lightning::routing::gossip::NodeId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::routing::gossip::NodeId<>) as *mut _) }, is_owned: false } } -/// One of the two node_ids which are endpoints of this channel +/// One of the two `node_id`s which are endpoints of this channel #[no_mangle] -pub extern "C" fn UnsignedChannelAnnouncement_set_node_id_1(this_ptr: &mut UnsignedChannelAnnouncement, mut val: crate::c_types::PublicKey) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_id_1 = val.into_rust(); +pub extern "C" fn UnsignedChannelAnnouncement_set_node_id_1(this_ptr: &mut UnsignedChannelAnnouncement, mut val: crate::lightning::routing::gossip::NodeId) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_id_1 = *unsafe { Box::from_raw(val.take_inner()) }; } -/// The other of the two node_ids which are endpoints of this channel +/// The other of the two `node_id`s which are endpoints of this channel #[no_mangle] -pub extern "C" fn UnsignedChannelAnnouncement_get_node_id_2(this_ptr: &UnsignedChannelAnnouncement) -> crate::c_types::PublicKey { +pub extern "C" fn UnsignedChannelAnnouncement_get_node_id_2(this_ptr: &UnsignedChannelAnnouncement) -> crate::lightning::routing::gossip::NodeId { let mut inner_val = &mut this_ptr.get_native_mut_ref().node_id_2; - crate::c_types::PublicKey::from_rust(&inner_val) + crate::lightning::routing::gossip::NodeId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::routing::gossip::NodeId<>) as *mut _) }, is_owned: false } } -/// The other of the two node_ids which are endpoints of this channel +/// The other of the two `node_id`s which are endpoints of this channel #[no_mangle] -pub extern "C" fn UnsignedChannelAnnouncement_set_node_id_2(this_ptr: &mut UnsignedChannelAnnouncement, mut val: crate::c_types::PublicKey) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_id_2 = val.into_rust(); +pub extern "C" fn UnsignedChannelAnnouncement_set_node_id_2(this_ptr: &mut UnsignedChannelAnnouncement, mut val: crate::lightning::routing::gossip::NodeId) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.node_id_2 = *unsafe { Box::from_raw(val.take_inner()) }; } /// The funding key for the first node #[no_mangle] -pub extern "C" fn UnsignedChannelAnnouncement_get_bitcoin_key_1(this_ptr: &UnsignedChannelAnnouncement) -> crate::c_types::PublicKey { +pub extern "C" fn UnsignedChannelAnnouncement_get_bitcoin_key_1(this_ptr: &UnsignedChannelAnnouncement) -> crate::lightning::routing::gossip::NodeId { let mut inner_val = &mut this_ptr.get_native_mut_ref().bitcoin_key_1; - crate::c_types::PublicKey::from_rust(&inner_val) + crate::lightning::routing::gossip::NodeId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::routing::gossip::NodeId<>) as *mut _) }, is_owned: false } } /// The funding key for the first node #[no_mangle] -pub extern "C" fn UnsignedChannelAnnouncement_set_bitcoin_key_1(this_ptr: &mut UnsignedChannelAnnouncement, mut val: crate::c_types::PublicKey) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.bitcoin_key_1 = val.into_rust(); +pub extern "C" fn UnsignedChannelAnnouncement_set_bitcoin_key_1(this_ptr: &mut UnsignedChannelAnnouncement, mut val: crate::lightning::routing::gossip::NodeId) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.bitcoin_key_1 = *unsafe { Box::from_raw(val.take_inner()) }; } /// The funding key for the second node #[no_mangle] -pub extern "C" fn UnsignedChannelAnnouncement_get_bitcoin_key_2(this_ptr: &UnsignedChannelAnnouncement) -> crate::c_types::PublicKey { +pub extern "C" fn UnsignedChannelAnnouncement_get_bitcoin_key_2(this_ptr: &UnsignedChannelAnnouncement) -> crate::lightning::routing::gossip::NodeId { let mut inner_val = &mut this_ptr.get_native_mut_ref().bitcoin_key_2; - crate::c_types::PublicKey::from_rust(&inner_val) + crate::lightning::routing::gossip::NodeId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::routing::gossip::NodeId<>) as *mut _) }, is_owned: false } } /// The funding key for the second node #[no_mangle] -pub extern "C" fn UnsignedChannelAnnouncement_set_bitcoin_key_2(this_ptr: &mut UnsignedChannelAnnouncement, mut val: crate::c_types::PublicKey) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.bitcoin_key_2 = val.into_rust(); +pub extern "C" fn UnsignedChannelAnnouncement_set_bitcoin_key_2(this_ptr: &mut UnsignedChannelAnnouncement, mut val: crate::lightning::routing::gossip::NodeId) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.bitcoin_key_2 = *unsafe { Box::from_raw(val.take_inner()) }; } impl Clone for UnsignedChannelAnnouncement { fn clone(&self) -> Self { @@ -3604,11 +4226,22 @@ pub(crate) extern "C" fn UnsignedChannelAnnouncement_clone_void(this_ptr: *const pub extern "C" fn UnsignedChannelAnnouncement_clone(orig: &UnsignedChannelAnnouncement) -> UnsignedChannelAnnouncement { orig.clone() } +/// Checks if two UnsignedChannelAnnouncements contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn UnsignedChannelAnnouncement_eq(a: &UnsignedChannelAnnouncement, b: &UnsignedChannelAnnouncement) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if a.get_native_ref() == b.get_native_ref() { true } else { false } +} use lightning::ln::msgs::ChannelAnnouncement as nativeChannelAnnouncementImport; pub(crate) type nativeChannelAnnouncement = nativeChannelAnnouncementImport; -/// A channel_announcement message to be sent or received from a peer +/// A [`channel_announcement`] message to be sent to or received from a peer. +/// +/// [`channel_announcement`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#the-channel_announcement-message #[must_use] #[repr(C)] pub struct ChannelAnnouncement { @@ -3637,7 +4270,7 @@ pub extern "C" fn ChannelAnnouncement_free(this_obj: ChannelAnnouncement) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ChannelAnnouncement_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelAnnouncement); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelAnnouncement) }; } #[allow(unused)] impl ChannelAnnouncement { @@ -3741,11 +4374,22 @@ pub(crate) extern "C" fn ChannelAnnouncement_clone_void(this_ptr: *const c_void) pub extern "C" fn ChannelAnnouncement_clone(orig: &ChannelAnnouncement) -> ChannelAnnouncement { orig.clone() } +/// Checks if two ChannelAnnouncements contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn ChannelAnnouncement_eq(a: &ChannelAnnouncement, b: &ChannelAnnouncement) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if a.get_native_ref() == b.get_native_ref() { true } else { false } +} use lightning::ln::msgs::UnsignedChannelUpdate as nativeUnsignedChannelUpdateImport; pub(crate) type nativeUnsignedChannelUpdate = nativeUnsignedChannelUpdateImport; -/// The unsigned part of a channel_update +/// The unsigned part of a [`channel_update`] message. +/// +/// [`channel_update`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#the-channel_update-message #[must_use] #[repr(C)] pub struct UnsignedChannelUpdate { @@ -3774,7 +4418,7 @@ pub extern "C" fn UnsignedChannelUpdate_free(this_obj: UnsignedChannelUpdate) { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn UnsignedChannelUpdate_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeUnsignedChannelUpdate); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeUnsignedChannelUpdate) }; } #[allow(unused)] impl UnsignedChannelUpdate { @@ -3838,10 +4482,10 @@ pub extern "C" fn UnsignedChannelUpdate_set_flags(this_ptr: &mut UnsignedChannel } /// The number of blocks such that if: /// `incoming_htlc.cltv_expiry < outgoing_htlc.cltv_expiry + cltv_expiry_delta` -/// then we need to fail the HTLC backwards. When forwarding an HTLC, cltv_expiry_delta determines -/// the outgoing HTLC's minimum cltv_expiry value -- so, if an incoming HTLC comes in with a -/// cltv_expiry of 100000, and the node we're forwarding to has a cltv_expiry_delta value of 10, -/// then we'll check that the outgoing HTLC's cltv_expiry value is at least 100010 before +/// then we need to fail the HTLC backwards. When forwarding an HTLC, `cltv_expiry_delta` determines +/// the outgoing HTLC's minimum `cltv_expiry` value -- so, if an incoming HTLC comes in with a +/// `cltv_expiry` of 100000, and the node we're forwarding to has a `cltv_expiry_delta` value of 10, +/// then we'll check that the outgoing HTLC's `cltv_expiry` value is at least 100010 before /// forwarding. Note that the HTLC sender is the one who originally sets this value when /// constructing the route. #[no_mangle] @@ -3851,10 +4495,10 @@ pub extern "C" fn UnsignedChannelUpdate_get_cltv_expiry_delta(this_ptr: &Unsigne } /// The number of blocks such that if: /// `incoming_htlc.cltv_expiry < outgoing_htlc.cltv_expiry + cltv_expiry_delta` -/// then we need to fail the HTLC backwards. When forwarding an HTLC, cltv_expiry_delta determines -/// the outgoing HTLC's minimum cltv_expiry value -- so, if an incoming HTLC comes in with a -/// cltv_expiry of 100000, and the node we're forwarding to has a cltv_expiry_delta value of 10, -/// then we'll check that the outgoing HTLC's cltv_expiry value is at least 100010 before +/// then we need to fail the HTLC backwards. When forwarding an HTLC, `cltv_expiry_delta` determines +/// the outgoing HTLC's minimum `cltv_expiry` value -- so, if an incoming HTLC comes in with a +/// `cltv_expiry` of 100000, and the node we're forwarding to has a `cltv_expiry_delta` value of 10, +/// then we'll check that the outgoing HTLC's `cltv_expiry` value is at least 100010 before /// forwarding. Note that the HTLC sender is the one who originally sets this value when /// constructing the route. #[no_mangle] @@ -3872,13 +4516,17 @@ pub extern "C" fn UnsignedChannelUpdate_get_htlc_minimum_msat(this_ptr: &Unsigne pub extern "C" fn UnsignedChannelUpdate_set_htlc_minimum_msat(this_ptr: &mut UnsignedChannelUpdate, mut val: u64) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_minimum_msat = val; } -/// The maximum HTLC value incoming to sender, in milli-satoshi. Used to be optional. +/// The maximum HTLC value incoming to sender, in milli-satoshi. +/// +/// This used to be optional. #[no_mangle] pub extern "C" fn UnsignedChannelUpdate_get_htlc_maximum_msat(this_ptr: &UnsignedChannelUpdate) -> u64 { let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_maximum_msat; *inner_val } -/// The maximum HTLC value incoming to sender, in milli-satoshi. Used to be optional. +/// The maximum HTLC value incoming to sender, in milli-satoshi. +/// +/// This used to be optional. #[no_mangle] pub extern "C" fn UnsignedChannelUpdate_set_htlc_maximum_msat(this_ptr: &mut UnsignedChannelUpdate, mut val: u64) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_maximum_msat = val; @@ -3906,8 +4554,21 @@ pub extern "C" fn UnsignedChannelUpdate_set_fee_proportional_millionths(this_ptr unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.fee_proportional_millionths = val; } /// Excess data which was signed as a part of the message which we do not (yet) understand how -/// to decode. This is stored to ensure forward-compatibility as new fields are added to the -/// lightning gossip +/// to decode. +/// +/// This is stored to ensure forward-compatibility as new fields are added to the lightning gossip protocol. +/// +/// Returns a copy of the field. +#[no_mangle] +pub extern "C" fn UnsignedChannelUpdate_get_excess_data(this_ptr: &UnsignedChannelUpdate) -> crate::c_types::derived::CVec_u8Z { + let mut inner_val = this_ptr.get_native_mut_ref().excess_data.clone(); + let mut local_inner_val = Vec::new(); for mut item in inner_val.drain(..) { local_inner_val.push( { item }); }; + local_inner_val.into() +} +/// Excess data which was signed as a part of the message which we do not (yet) understand how +/// to decode. +/// +/// This is stored to ensure forward-compatibility as new fields are added to the lightning gossip protocol. #[no_mangle] pub extern "C" fn UnsignedChannelUpdate_set_excess_data(this_ptr: &mut UnsignedChannelUpdate, mut val: crate::c_types::derived::CVec_u8Z) { let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); }; @@ -3950,11 +4611,22 @@ pub(crate) extern "C" fn UnsignedChannelUpdate_clone_void(this_ptr: *const c_voi pub extern "C" fn UnsignedChannelUpdate_clone(orig: &UnsignedChannelUpdate) -> UnsignedChannelUpdate { orig.clone() } +/// Checks if two UnsignedChannelUpdates contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn UnsignedChannelUpdate_eq(a: &UnsignedChannelUpdate, b: &UnsignedChannelUpdate) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if a.get_native_ref() == b.get_native_ref() { true } else { false } +} use lightning::ln::msgs::ChannelUpdate as nativeChannelUpdateImport; pub(crate) type nativeChannelUpdate = nativeChannelUpdateImport; -/// A channel_update message to be sent or received from a peer +/// A [`channel_update`] message to be sent to or received from a peer. +/// +/// [`channel_update`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#the-channel_update-message #[must_use] #[repr(C)] pub struct ChannelUpdate { @@ -3983,7 +4655,7 @@ pub extern "C" fn ChannelUpdate_free(this_obj: ChannelUpdate) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ChannelUpdate_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelUpdate); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelUpdate) }; } #[allow(unused)] impl ChannelUpdate { @@ -4051,14 +4723,25 @@ pub(crate) extern "C" fn ChannelUpdate_clone_void(this_ptr: *const c_void) -> *m pub extern "C" fn ChannelUpdate_clone(orig: &ChannelUpdate) -> ChannelUpdate { orig.clone() } +/// Checks if two ChannelUpdates contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn ChannelUpdate_eq(a: &ChannelUpdate, b: &ChannelUpdate) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if a.get_native_ref() == b.get_native_ref() { true } else { false } +} use lightning::ln::msgs::QueryChannelRange as nativeQueryChannelRangeImport; pub(crate) type nativeQueryChannelRange = nativeQueryChannelRangeImport; -/// A query_channel_range message is used to query a peer for channel +/// A [`query_channel_range`] message is used to query a peer for channel /// UTXOs in a range of blocks. The recipient of a query makes a best -/// effort to reply to the query using one or more reply_channel_range +/// effort to reply to the query using one or more [`ReplyChannelRange`] /// messages. +/// +/// [`query_channel_range`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#the-query_channel_range-and-reply_channel_range-messages #[must_use] #[repr(C)] pub struct QueryChannelRange { @@ -4087,7 +4770,7 @@ pub extern "C" fn QueryChannelRange_free(this_obj: QueryChannelRange) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn QueryChannelRange_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeQueryChannelRange); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeQueryChannelRange) }; } #[allow(unused)] impl QueryChannelRange { @@ -4167,17 +4850,30 @@ pub(crate) extern "C" fn QueryChannelRange_clone_void(this_ptr: *const c_void) - pub extern "C" fn QueryChannelRange_clone(orig: &QueryChannelRange) -> QueryChannelRange { orig.clone() } +/// Checks if two QueryChannelRanges contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn QueryChannelRange_eq(a: &QueryChannelRange, b: &QueryChannelRange) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if a.get_native_ref() == b.get_native_ref() { true } else { false } +} use lightning::ln::msgs::ReplyChannelRange as nativeReplyChannelRangeImport; pub(crate) type nativeReplyChannelRange = nativeReplyChannelRangeImport; -/// A reply_channel_range message is a reply to a query_channel_range -/// message. Multiple reply_channel_range messages can be sent in reply -/// to a single query_channel_range message. The query recipient makes a +/// A [`reply_channel_range`] message is a reply to a [`QueryChannelRange`] +/// message. +/// +/// Multiple `reply_channel_range` messages can be sent in reply +/// to a single [`QueryChannelRange`] message. The query recipient makes a /// best effort to respond based on their local network view which may -/// not be a perfect view of the network. The short_channel_ids in the -/// reply are encoded. We only support encoding_type=0 uncompressed -/// serialization and do not support encoding_type=1 zlib serialization. +/// not be a perfect view of the network. The `short_channel_id`s in the +/// reply are encoded. We only support `encoding_type=0` uncompressed +/// serialization and do not support `encoding_type=1` zlib serialization. +/// +/// [`reply_channel_range`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#the-query_channel_range-and-reply_channel_range-messages #[must_use] #[repr(C)] pub struct ReplyChannelRange { @@ -4206,7 +4902,7 @@ pub extern "C" fn ReplyChannelRange_free(this_obj: ReplyChannelRange) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ReplyChannelRange_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeReplyChannelRange); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeReplyChannelRange) }; } #[allow(unused)] impl ReplyChannelRange { @@ -4268,7 +4964,16 @@ pub extern "C" fn ReplyChannelRange_get_sync_complete(this_ptr: &ReplyChannelRan pub extern "C" fn ReplyChannelRange_set_sync_complete(this_ptr: &mut ReplyChannelRange, mut val: bool) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.sync_complete = val; } -/// The short_channel_ids in the channel range +/// The `short_channel_id`s in the channel range +/// +/// Returns a copy of the field. +#[no_mangle] +pub extern "C" fn ReplyChannelRange_get_short_channel_ids(this_ptr: &ReplyChannelRange) -> crate::c_types::derived::CVec_u64Z { + let mut inner_val = this_ptr.get_native_mut_ref().short_channel_ids.clone(); + let mut local_inner_val = Vec::new(); for mut item in inner_val.drain(..) { local_inner_val.push( { item }); }; + local_inner_val.into() +} +/// The `short_channel_id`s in the channel range #[no_mangle] pub extern "C" fn ReplyChannelRange_set_short_channel_ids(this_ptr: &mut ReplyChannelRange, mut val: crate::c_types::derived::CVec_u64Z) { let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); }; @@ -4306,18 +5011,30 @@ pub(crate) extern "C" fn ReplyChannelRange_clone_void(this_ptr: *const c_void) - pub extern "C" fn ReplyChannelRange_clone(orig: &ReplyChannelRange) -> ReplyChannelRange { orig.clone() } +/// Checks if two ReplyChannelRanges contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn ReplyChannelRange_eq(a: &ReplyChannelRange, b: &ReplyChannelRange) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if a.get_native_ref() == b.get_native_ref() { true } else { false } +} use lightning::ln::msgs::QueryShortChannelIds as nativeQueryShortChannelIdsImport; pub(crate) type nativeQueryShortChannelIds = nativeQueryShortChannelIdsImport; -/// A query_short_channel_ids message is used to query a peer for -/// routing gossip messages related to one or more short_channel_ids. +/// A [`query_short_channel_ids`] message is used to query a peer for +/// routing gossip messages related to one or more `short_channel_id`s. +/// /// The query recipient will reply with the latest, if available, -/// channel_announcement, channel_update and node_announcement messages -/// it maintains for the requested short_channel_ids followed by a -/// reply_short_channel_ids_end message. The short_channel_ids sent in -/// this query are encoded. We only support encoding_type=0 uncompressed -/// serialization and do not support encoding_type=1 zlib serialization. +/// [`ChannelAnnouncement`], [`ChannelUpdate`] and [`NodeAnnouncement`] messages +/// it maintains for the requested `short_channel_id`s followed by a +/// [`ReplyShortChannelIdsEnd`] message. The `short_channel_id`s sent in +/// this query are encoded. We only support `encoding_type=0` uncompressed +/// serialization and do not support `encoding_type=1` zlib serialization. +/// +/// [`query_short_channel_ids`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#the-query_short_channel_idsreply_short_channel_ids_end-messages #[must_use] #[repr(C)] pub struct QueryShortChannelIds { @@ -4346,7 +5063,7 @@ pub extern "C" fn QueryShortChannelIds_free(this_obj: QueryShortChannelIds) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn QueryShortChannelIds_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeQueryShortChannelIds); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeQueryShortChannelIds) }; } #[allow(unused)] impl QueryShortChannelIds { @@ -4376,6 +5093,15 @@ pub extern "C" fn QueryShortChannelIds_set_chain_hash(this_ptr: &mut QueryShortC unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_hash = ::bitcoin::hash_types::BlockHash::from_slice(&val.data[..]).unwrap(); } /// The short_channel_ids that are being queried +/// +/// Returns a copy of the field. +#[no_mangle] +pub extern "C" fn QueryShortChannelIds_get_short_channel_ids(this_ptr: &QueryShortChannelIds) -> crate::c_types::derived::CVec_u64Z { + let mut inner_val = this_ptr.get_native_mut_ref().short_channel_ids.clone(); + let mut local_inner_val = Vec::new(); for mut item in inner_val.drain(..) { local_inner_val.push( { item }); }; + local_inner_val.into() +} +/// The short_channel_ids that are being queried #[no_mangle] pub extern "C" fn QueryShortChannelIds_set_short_channel_ids(this_ptr: &mut QueryShortChannelIds, mut val: crate::c_types::derived::CVec_u64Z) { let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); }; @@ -4410,14 +5136,25 @@ pub(crate) extern "C" fn QueryShortChannelIds_clone_void(this_ptr: *const c_void pub extern "C" fn QueryShortChannelIds_clone(orig: &QueryShortChannelIds) -> QueryShortChannelIds { orig.clone() } +/// Checks if two QueryShortChannelIdss contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn QueryShortChannelIds_eq(a: &QueryShortChannelIds, b: &QueryShortChannelIds) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if a.get_native_ref() == b.get_native_ref() { true } else { false } +} use lightning::ln::msgs::ReplyShortChannelIdsEnd as nativeReplyShortChannelIdsEndImport; pub(crate) type nativeReplyShortChannelIdsEnd = nativeReplyShortChannelIdsEndImport; -/// A reply_short_channel_ids_end message is sent as a reply to a -/// query_short_channel_ids message. The query recipient makes a best +/// A [`reply_short_channel_ids_end`] message is sent as a reply to a +/// message. The query recipient makes a best /// effort to respond based on their local network view which may not be /// a perfect view of the network. +/// +/// [`reply_short_channel_ids_end`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#the-query_short_channel_idsreply_short_channel_ids_end-messages #[must_use] #[repr(C)] pub struct ReplyShortChannelIdsEnd { @@ -4446,7 +5183,7 @@ pub extern "C" fn ReplyShortChannelIdsEnd_free(this_obj: ReplyShortChannelIdsEnd #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ReplyShortChannelIdsEnd_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeReplyShortChannelIdsEnd); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeReplyShortChannelIdsEnd) }; } #[allow(unused)] impl ReplyShortChannelIdsEnd { @@ -4476,14 +5213,14 @@ pub extern "C" fn ReplyShortChannelIdsEnd_set_chain_hash(this_ptr: &mut ReplySho unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_hash = ::bitcoin::hash_types::BlockHash::from_slice(&val.data[..]).unwrap(); } /// Indicates if the query recipient maintains up-to-date channel -/// information for the chain_hash +/// information for the `chain_hash` #[no_mangle] pub extern "C" fn ReplyShortChannelIdsEnd_get_full_information(this_ptr: &ReplyShortChannelIdsEnd) -> bool { let mut inner_val = &mut this_ptr.get_native_mut_ref().full_information; *inner_val } /// Indicates if the query recipient maintains up-to-date channel -/// information for the chain_hash +/// information for the `chain_hash` #[no_mangle] pub extern "C" fn ReplyShortChannelIdsEnd_set_full_information(this_ptr: &mut ReplyShortChannelIdsEnd, mut val: bool) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.full_information = val; @@ -4516,13 +5253,24 @@ pub(crate) extern "C" fn ReplyShortChannelIdsEnd_clone_void(this_ptr: *const c_v pub extern "C" fn ReplyShortChannelIdsEnd_clone(orig: &ReplyShortChannelIdsEnd) -> ReplyShortChannelIdsEnd { orig.clone() } +/// Checks if two ReplyShortChannelIdsEnds contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn ReplyShortChannelIdsEnd_eq(a: &ReplyShortChannelIdsEnd, b: &ReplyShortChannelIdsEnd) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if a.get_native_ref() == b.get_native_ref() { true } else { false } +} use lightning::ln::msgs::GossipTimestampFilter as nativeGossipTimestampFilterImport; pub(crate) type nativeGossipTimestampFilter = nativeGossipTimestampFilterImport; -/// A gossip_timestamp_filter message is used by a node to request +/// A [`gossip_timestamp_filter`] message is used by a node to request /// gossip relay for messages in the requested time range when the -/// gossip_queries feature has been negotiated. +/// `gossip_queries` feature has been negotiated. +/// +/// [`gossip_timestamp_filter`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#the-gossip_timestamp_filter-message #[must_use] #[repr(C)] pub struct GossipTimestampFilter { @@ -4551,7 +5299,7 @@ pub extern "C" fn GossipTimestampFilter_free(this_obj: GossipTimestampFilter) { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn GossipTimestampFilter_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeGossipTimestampFilter); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeGossipTimestampFilter) }; } #[allow(unused)] impl GossipTimestampFilter { @@ -4631,7 +5379,16 @@ pub(crate) extern "C" fn GossipTimestampFilter_clone_void(this_ptr: *const c_voi pub extern "C" fn GossipTimestampFilter_clone(orig: &GossipTimestampFilter) -> GossipTimestampFilter { orig.clone() } -/// Used to put an error message in a LightningError +/// Checks if two GossipTimestampFilters contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn GossipTimestampFilter_eq(a: &GossipTimestampFilter, b: &GossipTimestampFilter) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if a.get_native_ref() == b.get_native_ref() { true } else { false } +} +/// Used to put an error message in a [`LightningError`]. #[derive(Clone)] #[must_use] #[repr(C)] @@ -4676,7 +5433,7 @@ impl ErrorAction { pub(crate) fn to_native(&self) -> nativeErrorAction { match self { ErrorAction::DisconnectPeer {ref msg, } => { - let mut msg_nonref = (*msg).clone(); + let mut msg_nonref = Clone::clone(msg); let mut local_msg_nonref = if msg_nonref.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(msg_nonref.take_inner()) } }) }; nativeErrorAction::DisconnectPeer { msg: local_msg_nonref, @@ -4684,21 +5441,21 @@ impl ErrorAction { }, ErrorAction::IgnoreError => nativeErrorAction::IgnoreError, ErrorAction::IgnoreAndLog (ref a, ) => { - let mut a_nonref = (*a).clone(); + let mut a_nonref = Clone::clone(a); nativeErrorAction::IgnoreAndLog ( a_nonref.into_native(), ) }, ErrorAction::IgnoreDuplicateGossip => nativeErrorAction::IgnoreDuplicateGossip, ErrorAction::SendErrorMessage {ref msg, } => { - let mut msg_nonref = (*msg).clone(); + let mut msg_nonref = Clone::clone(msg); nativeErrorAction::SendErrorMessage { msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) }, } }, ErrorAction::SendWarningMessage {ref msg, ref log_level, } => { - let mut msg_nonref = (*msg).clone(); - let mut log_level_nonref = (*log_level).clone(); + let mut msg_nonref = Clone::clone(msg); + let mut log_level_nonref = Clone::clone(log_level); nativeErrorAction::SendWarningMessage { msg: *unsafe { Box::from_raw(msg_nonref.take_inner()) }, log_level: log_level_nonref.into_native(), @@ -4739,7 +5496,7 @@ impl ErrorAction { pub(crate) fn from_native(native: &nativeErrorAction) -> Self { match native { nativeErrorAction::DisconnectPeer {ref msg, } => { - let mut msg_nonref = (*msg).clone(); + let mut msg_nonref = Clone::clone(msg); let mut local_msg_nonref = crate::lightning::ln::msgs::ErrorMessage { inner: if msg_nonref.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((msg_nonref.unwrap())) } }, is_owned: true }; ErrorAction::DisconnectPeer { msg: local_msg_nonref, @@ -4747,21 +5504,21 @@ impl ErrorAction { }, nativeErrorAction::IgnoreError => ErrorAction::IgnoreError, nativeErrorAction::IgnoreAndLog (ref a, ) => { - let mut a_nonref = (*a).clone(); + let mut a_nonref = Clone::clone(a); ErrorAction::IgnoreAndLog ( crate::lightning::util::logger::Level::native_into(a_nonref), ) }, nativeErrorAction::IgnoreDuplicateGossip => ErrorAction::IgnoreDuplicateGossip, nativeErrorAction::SendErrorMessage {ref msg, } => { - let mut msg_nonref = (*msg).clone(); + let mut msg_nonref = Clone::clone(msg); ErrorAction::SendErrorMessage { msg: crate::lightning::ln::msgs::ErrorMessage { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true }, } }, nativeErrorAction::SendWarningMessage {ref msg, ref log_level, } => { - let mut msg_nonref = (*msg).clone(); - let mut log_level_nonref = (*log_level).clone(); + let mut msg_nonref = Clone::clone(msg); + let mut log_level_nonref = Clone::clone(log_level); ErrorAction::SendWarningMessage { msg: crate::lightning::ln::msgs::WarningMessage { inner: ObjOps::heap_alloc(msg_nonref), is_owned: true }, log_level: crate::lightning::util::logger::Level::native_into(log_level_nonref), @@ -4875,7 +5632,7 @@ pub extern "C" fn LightningError_free(this_obj: LightningError) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn LightningError_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeLightningError); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeLightningError) }; } #[allow(unused)] impl LightningError { @@ -4947,7 +5704,7 @@ pub extern "C" fn LightningError_clone(orig: &LightningError) -> LightningError use lightning::ln::msgs::CommitmentUpdate as nativeCommitmentUpdateImport; pub(crate) type nativeCommitmentUpdate = nativeCommitmentUpdateImport; -/// Struct used to return values from revoke_and_ack messages, containing a bunch of commitment +/// Struct used to return values from [`RevokeAndACK`] messages, containing a bunch of commitment /// transaction updates if they were pending. #[must_use] #[repr(C)] @@ -4977,7 +5734,7 @@ pub extern "C" fn CommitmentUpdate_free(this_obj: CommitmentUpdate) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn CommitmentUpdate_free_void(this_ptr: *mut c_void) { - unsafe { let _ = Box::from_raw(this_ptr as *mut nativeCommitmentUpdate); } + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeCommitmentUpdate) }; } #[allow(unused)] impl CommitmentUpdate { @@ -4995,59 +5752,59 @@ impl CommitmentUpdate { ret } } -/// update_add_htlc messages which should be sent +/// `update_add_htlc` messages which should be sent #[no_mangle] pub extern "C" fn CommitmentUpdate_get_update_add_htlcs(this_ptr: &CommitmentUpdate) -> crate::c_types::derived::CVec_UpdateAddHTLCZ { let mut inner_val = &mut this_ptr.get_native_mut_ref().update_add_htlcs; let mut local_inner_val = Vec::new(); for item in inner_val.iter() { local_inner_val.push( { crate::lightning::ln::msgs::UpdateAddHTLC { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const lightning::ln::msgs::UpdateAddHTLC<>) as *mut _) }, is_owned: false } }); }; local_inner_val.into() } -/// update_add_htlc messages which should be sent +/// `update_add_htlc` messages which should be sent #[no_mangle] pub extern "C" fn CommitmentUpdate_set_update_add_htlcs(this_ptr: &mut CommitmentUpdate, mut val: crate::c_types::derived::CVec_UpdateAddHTLCZ) { let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); }; unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.update_add_htlcs = local_val; } -/// update_fulfill_htlc messages which should be sent +/// `update_fulfill_htlc` messages which should be sent #[no_mangle] pub extern "C" fn CommitmentUpdate_get_update_fulfill_htlcs(this_ptr: &CommitmentUpdate) -> crate::c_types::derived::CVec_UpdateFulfillHTLCZ { let mut inner_val = &mut this_ptr.get_native_mut_ref().update_fulfill_htlcs; let mut local_inner_val = Vec::new(); for item in inner_val.iter() { local_inner_val.push( { crate::lightning::ln::msgs::UpdateFulfillHTLC { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const lightning::ln::msgs::UpdateFulfillHTLC<>) as *mut _) }, is_owned: false } }); }; local_inner_val.into() } -/// update_fulfill_htlc messages which should be sent +/// `update_fulfill_htlc` messages which should be sent #[no_mangle] pub extern "C" fn CommitmentUpdate_set_update_fulfill_htlcs(this_ptr: &mut CommitmentUpdate, mut val: crate::c_types::derived::CVec_UpdateFulfillHTLCZ) { let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); }; unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.update_fulfill_htlcs = local_val; } -/// update_fail_htlc messages which should be sent +/// `update_fail_htlc` messages which should be sent #[no_mangle] pub extern "C" fn CommitmentUpdate_get_update_fail_htlcs(this_ptr: &CommitmentUpdate) -> crate::c_types::derived::CVec_UpdateFailHTLCZ { let mut inner_val = &mut this_ptr.get_native_mut_ref().update_fail_htlcs; let mut local_inner_val = Vec::new(); for item in inner_val.iter() { local_inner_val.push( { crate::lightning::ln::msgs::UpdateFailHTLC { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const lightning::ln::msgs::UpdateFailHTLC<>) as *mut _) }, is_owned: false } }); }; local_inner_val.into() } -/// update_fail_htlc messages which should be sent +/// `update_fail_htlc` messages which should be sent #[no_mangle] pub extern "C" fn CommitmentUpdate_set_update_fail_htlcs(this_ptr: &mut CommitmentUpdate, mut val: crate::c_types::derived::CVec_UpdateFailHTLCZ) { let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); }; unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.update_fail_htlcs = local_val; } -/// update_fail_malformed_htlc messages which should be sent +/// `update_fail_malformed_htlc` messages which should be sent #[no_mangle] pub extern "C" fn CommitmentUpdate_get_update_fail_malformed_htlcs(this_ptr: &CommitmentUpdate) -> crate::c_types::derived::CVec_UpdateFailMalformedHTLCZ { let mut inner_val = &mut this_ptr.get_native_mut_ref().update_fail_malformed_htlcs; let mut local_inner_val = Vec::new(); for item in inner_val.iter() { local_inner_val.push( { crate::lightning::ln::msgs::UpdateFailMalformedHTLC { inner: unsafe { ObjOps::nonnull_ptr_to_inner((item as *const lightning::ln::msgs::UpdateFailMalformedHTLC<>) as *mut _) }, is_owned: false } }); }; local_inner_val.into() } -/// update_fail_malformed_htlc messages which should be sent +/// `update_fail_malformed_htlc` messages which should be sent #[no_mangle] pub extern "C" fn CommitmentUpdate_set_update_fail_malformed_htlcs(this_ptr: &mut CommitmentUpdate, mut val: crate::c_types::derived::CVec_UpdateFailMalformedHTLCZ) { let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { *unsafe { Box::from_raw(item.take_inner()) } }); }; unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.update_fail_malformed_htlcs = local_val; } -/// An update_fee message which should be sent +/// An `update_fee` message which should be sent /// /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None #[no_mangle] @@ -5056,7 +5813,7 @@ pub extern "C" fn CommitmentUpdate_get_update_fee(this_ptr: &CommitmentUpdate) - let mut local_inner_val = crate::lightning::ln::msgs::UpdateFee { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::ln::msgs::UpdateFee<>) as *mut _ }, is_owned: false }; local_inner_val } -/// An update_fee message which should be sent +/// An `update_fee` message which should be sent /// /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None #[no_mangle] @@ -5064,13 +5821,13 @@ pub extern "C" fn CommitmentUpdate_set_update_fee(this_ptr: &mut CommitmentUpdat let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) }; unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.update_fee = local_val; } -/// Finally, the commitment_signed message which should be sent +/// A `commitment_signed` message which should be sent #[no_mangle] pub extern "C" fn CommitmentUpdate_get_commitment_signed(this_ptr: &CommitmentUpdate) -> crate::lightning::ln::msgs::CommitmentSigned { let mut inner_val = &mut this_ptr.get_native_mut_ref().commitment_signed; crate::lightning::ln::msgs::CommitmentSigned { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::msgs::CommitmentSigned<>) as *mut _) }, is_owned: false } } -/// Finally, the commitment_signed message which should be sent +/// A `commitment_signed` message which should be sent #[no_mangle] pub extern "C" fn CommitmentUpdate_set_commitment_signed(this_ptr: &mut CommitmentUpdate, mut val: crate::lightning::ln::msgs::CommitmentSigned) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.commitment_signed = *unsafe { Box::from_raw(val.take_inner()) }; @@ -5112,58 +5869,81 @@ pub(crate) extern "C" fn CommitmentUpdate_clone_void(this_ptr: *const c_void) -> pub extern "C" fn CommitmentUpdate_clone(orig: &CommitmentUpdate) -> CommitmentUpdate { orig.clone() } +/// Checks if two CommitmentUpdates contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn CommitmentUpdate_eq(a: &CommitmentUpdate, b: &CommitmentUpdate) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if a.get_native_ref() == b.get_native_ref() { true } else { false } +} /// A trait to describe an object which can receive channel messages. /// -/// Messages MAY be called in parallel when they originate from different their_node_ids, however -/// they MUST NOT be called in parallel when the two calls have the same their_node_id. +/// Messages MAY be called in parallel when they originate from different `their_node_ids`, however +/// they MUST NOT be called in parallel when the two calls have the same `their_node_id`. #[repr(C)] pub struct ChannelMessageHandler { /// An opaque pointer which is passed to your function implementations as an argument. /// This has no meaning in the LDK, and can be NULL or any other value. pub this_arg: *mut c_void, - /// Handle an incoming open_channel message from the given peer. - pub handle_open_channel: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, their_features: crate::lightning::ln::features::InitFeatures, msg: &crate::lightning::ln::msgs::OpenChannel), - /// Handle an incoming accept_channel message from the given peer. - pub handle_accept_channel: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, their_features: crate::lightning::ln::features::InitFeatures, msg: &crate::lightning::ln::msgs::AcceptChannel), - /// Handle an incoming funding_created message from the given peer. + /// Handle an incoming `open_channel` message from the given peer. + pub handle_open_channel: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::OpenChannel), + /// Handle an incoming `accept_channel` message from the given peer. + pub handle_accept_channel: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::AcceptChannel), + /// Handle an incoming `funding_created` message from the given peer. pub handle_funding_created: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::FundingCreated), - /// Handle an incoming funding_signed message from the given peer. + /// Handle an incoming `funding_signed` message from the given peer. pub handle_funding_signed: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::FundingSigned), - /// Handle an incoming channel_ready message from the given peer. + /// Handle an incoming `channel_ready` message from the given peer. pub handle_channel_ready: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::ChannelReady), - /// Handle an incoming shutdown message from the given peer. - pub handle_shutdown: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, their_features: &crate::lightning::ln::features::InitFeatures, msg: &crate::lightning::ln::msgs::Shutdown), - /// Handle an incoming closing_signed message from the given peer. + /// Handle an incoming `shutdown` message from the given peer. + pub handle_shutdown: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::Shutdown), + /// Handle an incoming `closing_signed` message from the given peer. pub handle_closing_signed: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::ClosingSigned), - /// Handle an incoming update_add_htlc message from the given peer. + /// Handle an incoming `update_add_htlc` message from the given peer. pub handle_update_add_htlc: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::UpdateAddHTLC), - /// Handle an incoming update_fulfill_htlc message from the given peer. + /// Handle an incoming `update_fulfill_htlc` message from the given peer. pub handle_update_fulfill_htlc: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::UpdateFulfillHTLC), - /// Handle an incoming update_fail_htlc message from the given peer. + /// Handle an incoming `update_fail_htlc` message from the given peer. pub handle_update_fail_htlc: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::UpdateFailHTLC), - /// Handle an incoming update_fail_malformed_htlc message from the given peer. + /// Handle an incoming `update_fail_malformed_htlc` message from the given peer. pub handle_update_fail_malformed_htlc: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::UpdateFailMalformedHTLC), - /// Handle an incoming commitment_signed message from the given peer. + /// Handle an incoming `commitment_signed` message from the given peer. pub handle_commitment_signed: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::CommitmentSigned), - /// Handle an incoming revoke_and_ack message from the given peer. + /// Handle an incoming `revoke_and_ack` message from the given peer. pub handle_revoke_and_ack: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::RevokeAndACK), - /// Handle an incoming update_fee message from the given peer. + /// Handle an incoming `update_fee` message from the given peer. pub handle_update_fee: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::UpdateFee), - /// Handle an incoming announcement_signatures message from the given peer. + /// Handle an incoming `announcement_signatures` message from the given peer. pub handle_announcement_signatures: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::AnnouncementSignatures), - /// Indicates a connection to the peer failed/an existing connection was lost. If no connection - /// is believed to be possible in the future (eg they're sending us messages we don't - /// understand or indicate they require unknown feature bits), no_connection_possible is set - /// and any outstanding channels should be failed. - pub peer_disconnected: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, no_connection_possible: bool), - /// Handle a peer reconnecting, possibly generating channel_reestablish message(s). - pub peer_connected: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::Init), - /// Handle an incoming channel_reestablish message from the given peer. + /// Indicates a connection to the peer failed/an existing connection was lost. + pub peer_disconnected: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey), + /// Handle a peer reconnecting, possibly generating `channel_reestablish` message(s). + /// + /// May return an `Err(())` if the features the peer supports are not sufficient to communicate + /// with us. Implementors should be somewhat conservative about doing so, however, as other + /// message handlers may still wish to communicate with this peer. + #[must_use] + pub peer_connected: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::Init, inbound: bool) -> crate::c_types::derived::CResult_NoneNoneZ, + /// Handle an incoming `channel_reestablish` message from the given peer. pub handle_channel_reestablish: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::ChannelReestablish), - /// Handle an incoming channel update from the given peer. + /// Handle an incoming `channel_update` message from the given peer. pub handle_channel_update: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::ChannelUpdate), - /// Handle an incoming error message from the given peer. + /// Handle an incoming `error` message from the given peer. pub handle_error: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::ErrorMessage), + /// Gets the node feature flags which this handler itself supports. All available handlers are + /// queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`] + /// which are broadcasted in our [`NodeAnnouncement`] message. + #[must_use] + pub provided_node_features: extern "C" fn (this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures, + /// Gets the init feature flags which should be sent to the given peer. All available handlers + /// are queried similarly and their feature flags are OR'd together to form the [`InitFeatures`] + /// which are sent in our [`Init`] message. + /// + /// Note that this method is called before [`Self::peer_connected`]. + #[must_use] + pub provided_init_features: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey) -> crate::lightning::ln::features::InitFeatures, /// Implementation of MessageSendEventsProvider for this object. pub MessageSendEventsProvider: crate::lightning::util::events::MessageSendEventsProvider, /// Frees any resources associated with this object given its this_arg pointer. @@ -5196,6 +5976,8 @@ pub(crate) extern "C" fn ChannelMessageHandler_clone_fields(orig: &ChannelMessag handle_channel_reestablish: Clone::clone(&orig.handle_channel_reestablish), handle_channel_update: Clone::clone(&orig.handle_channel_update), handle_error: Clone::clone(&orig.handle_error), + provided_node_features: Clone::clone(&orig.provided_node_features), + provided_init_features: Clone::clone(&orig.provided_init_features), MessageSendEventsProvider: crate::lightning::util::events::MessageSendEventsProvider_clone_fields(&orig.MessageSendEventsProvider), free: Clone::clone(&orig.free), } @@ -5210,11 +5992,11 @@ impl lightning::util::events::MessageSendEventsProvider for ChannelMessageHandle use lightning::ln::msgs::ChannelMessageHandler as rustChannelMessageHandler; impl rustChannelMessageHandler for ChannelMessageHandler { - fn handle_open_channel(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut their_features: lightning::ln::features::InitFeatures, mut msg: &lightning::ln::msgs::OpenChannel) { - (self.handle_open_channel)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(their_features), is_owned: true }, &crate::lightning::ln::msgs::OpenChannel { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::OpenChannel<>) as *mut _) }, is_owned: false }) + fn handle_open_channel(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::OpenChannel) { + (self.handle_open_channel)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::OpenChannel { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::OpenChannel<>) as *mut _) }, is_owned: false }) } - fn handle_accept_channel(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut their_features: lightning::ln::features::InitFeatures, mut msg: &lightning::ln::msgs::AcceptChannel) { - (self.handle_accept_channel)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(their_features), is_owned: true }, &crate::lightning::ln::msgs::AcceptChannel { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::AcceptChannel<>) as *mut _) }, is_owned: false }) + fn handle_accept_channel(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::AcceptChannel) { + (self.handle_accept_channel)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::AcceptChannel { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::AcceptChannel<>) as *mut _) }, is_owned: false }) } fn handle_funding_created(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::FundingCreated) { (self.handle_funding_created)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::FundingCreated { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::FundingCreated<>) as *mut _) }, is_owned: false }) @@ -5225,8 +6007,8 @@ impl rustChannelMessageHandler for ChannelMessageHandler { fn handle_channel_ready(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::ChannelReady) { (self.handle_channel_ready)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::ChannelReady { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::ChannelReady<>) as *mut _) }, is_owned: false }) } - fn handle_shutdown(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut their_features: &lightning::ln::features::InitFeatures, mut msg: &lightning::ln::msgs::Shutdown) { - (self.handle_shutdown)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::features::InitFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((their_features as *const lightning::ln::features::InitFeatures<>) as *mut _) }, is_owned: false }, &crate::lightning::ln::msgs::Shutdown { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::Shutdown<>) as *mut _) }, is_owned: false }) + fn handle_shutdown(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::Shutdown) { + (self.handle_shutdown)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::Shutdown { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::Shutdown<>) as *mut _) }, is_owned: false }) } fn handle_closing_signed(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::ClosingSigned) { (self.handle_closing_signed)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::ClosingSigned { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::ClosingSigned<>) as *mut _) }, is_owned: false }) @@ -5255,11 +6037,13 @@ impl rustChannelMessageHandler for ChannelMessageHandler { fn handle_announcement_signatures(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::AnnouncementSignatures) { (self.handle_announcement_signatures)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::AnnouncementSignatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::AnnouncementSignatures<>) as *mut _) }, is_owned: false }) } - fn peer_disconnected(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut no_connection_possible: bool) { - (self.peer_disconnected)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), no_connection_possible) + fn peer_disconnected(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey) { + (self.peer_disconnected)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id)) } - fn peer_connected(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::Init) { - (self.peer_connected)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::Init { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::Init<>) as *mut _) }, is_owned: false }) + fn peer_connected(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::Init, mut inbound: bool) -> Result<(), ()> { + let mut ret = (self.peer_connected)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::Init { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::Init<>) as *mut _) }, is_owned: false }, inbound); + let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })}; + local_ret } fn handle_channel_reestablish(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::ChannelReestablish) { (self.handle_channel_reestablish)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::ChannelReestablish { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::ChannelReestablish<>) as *mut _) }, is_owned: false }) @@ -5270,6 +6054,14 @@ impl rustChannelMessageHandler for ChannelMessageHandler { fn handle_error(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::ErrorMessage) { (self.handle_error)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::ErrorMessage { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::ErrorMessage<>) as *mut _) }, is_owned: false }) } + fn provided_node_features(&self) -> lightning::ln::features::NodeFeatures { + let mut ret = (self.provided_node_features)(self.this_arg); + *unsafe { Box::from_raw(ret.take_inner()) } + } + fn provided_init_features(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey) -> lightning::ln::features::InitFeatures { + let mut ret = (self.provided_init_features)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id)); + *unsafe { Box::from_raw(ret.take_inner()) } + } } // We're essentially a pointer already, or at least a set of pointers, so allow us to be used @@ -5294,43 +6086,49 @@ impl Drop for ChannelMessageHandler { /// /// # Implementor DoS Warnings /// -/// For `gossip_queries` messages there are potential DoS vectors when handling -/// inbound queries. Implementors using an on-disk network graph should be aware of +/// For messages enabled with the `gossip_queries` feature there are potential DoS vectors when +/// handling inbound queries. Implementors using an on-disk network graph should be aware of /// repeated disk I/O for queries accessing different parts of the network graph. #[repr(C)] pub struct RoutingMessageHandler { /// An opaque pointer which is passed to your function implementations as an argument. /// This has no meaning in the LDK, and can be NULL or any other value. pub this_arg: *mut c_void, - /// Handle an incoming node_announcement message, returning true if it should be forwarded on, - /// false or returning an Err otherwise. + /// Handle an incoming `node_announcement` message, returning `true` if it should be forwarded on, + /// `false` or returning an `Err` otherwise. #[must_use] pub handle_node_announcement: extern "C" fn (this_arg: *const c_void, msg: &crate::lightning::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CResult_boolLightningErrorZ, - /// Handle a channel_announcement message, returning true if it should be forwarded on, false - /// or returning an Err otherwise. + /// Handle a `channel_announcement` message, returning `true` if it should be forwarded on, `false` + /// or returning an `Err` otherwise. #[must_use] pub handle_channel_announcement: extern "C" fn (this_arg: *const c_void, msg: &crate::lightning::ln::msgs::ChannelAnnouncement) -> crate::c_types::derived::CResult_boolLightningErrorZ, - /// Handle an incoming channel_update message, returning true if it should be forwarded on, - /// false or returning an Err otherwise. + /// Handle an incoming `channel_update` message, returning true if it should be forwarded on, + /// `false` or returning an `Err` otherwise. #[must_use] pub handle_channel_update: extern "C" fn (this_arg: *const c_void, msg: &crate::lightning::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CResult_boolLightningErrorZ, - /// Gets a subset of the channel announcements and updates required to dump our routing table - /// to a remote node, starting at the short_channel_id indicated by starting_point and - /// including the batch_amount entries immediately higher in numerical value than starting_point. + /// Gets channel announcements and updates required to dump our routing table to a remote node, + /// starting at the `short_channel_id` indicated by `starting_point` and including announcements + /// for a single channel. #[must_use] - pub get_next_channel_announcements: extern "C" fn (this_arg: *const c_void, starting_point: u64, batch_amount: u8) -> crate::c_types::derived::CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ, - /// Gets a subset of the node announcements required to dump our routing table to a remote node, - /// starting at the node *after* the provided publickey and including batch_amount entries - /// immediately higher (as defined by ::cmp) than starting_point. - /// If None is provided for starting_point, we start at the first node. + pub get_next_channel_announcement: extern "C" fn (this_arg: *const c_void, starting_point: u64) -> crate::c_types::derived::COption_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ, + /// Gets a node announcement required to dump our routing table to a remote node, starting at + /// the node *after* the provided pubkey and including up to one announcement immediately + /// higher (as defined by `::cmp`) than `starting_point`. + /// If `None` is provided for `starting_point`, we start at the first node. /// /// Note that starting_point (or a relevant inner pointer) may be NULL or all-0s to represent None + /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None #[must_use] - pub get_next_node_announcements: extern "C" fn (this_arg: *const c_void, starting_point: crate::c_types::PublicKey, batch_amount: u8) -> crate::c_types::derived::CVec_NodeAnnouncementZ, + pub get_next_node_announcement: extern "C" fn (this_arg: *const c_void, starting_point: crate::lightning::routing::gossip::NodeId) -> crate::lightning::ln::msgs::NodeAnnouncement, /// Called when a connection is established with a peer. This can be used to /// perform routing table synchronization using a strategy defined by the /// implementor. - pub peer_connected: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, init: &crate::lightning::ln::msgs::Init), + /// + /// May return an `Err(())` if the features the peer supports are not sufficient to communicate + /// with us. Implementors should be somewhat conservative about doing so, however, as other + /// message handlers may still wish to communicate with this peer. + #[must_use] + pub peer_connected: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, init: &crate::lightning::ln::msgs::Init, inbound: bool) -> crate::c_types::derived::CResult_NoneNoneZ, /// Handles the reply of a query we initiated to learn about channels /// for a given range of blocks. We can expect to receive one or more /// replies to a single query. @@ -5342,14 +6140,32 @@ pub struct RoutingMessageHandler { /// gossip messages. #[must_use] pub handle_reply_short_channel_ids_end: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::ReplyShortChannelIdsEnd) -> crate::c_types::derived::CResult_NoneLightningErrorZ, - /// Handles when a peer asks us to send a list of short_channel_ids + /// Handles when a peer asks us to send a list of `short_channel_id`s /// for the requested range of blocks. #[must_use] pub handle_query_channel_range: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::QueryChannelRange) -> crate::c_types::derived::CResult_NoneLightningErrorZ, /// Handles when a peer asks us to send routing gossip messages for a - /// list of short_channel_ids. + /// list of `short_channel_id`s. #[must_use] pub handle_query_short_channel_ids: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: crate::lightning::ln::msgs::QueryShortChannelIds) -> crate::c_types::derived::CResult_NoneLightningErrorZ, + /// Indicates that there are a large number of [`ChannelAnnouncement`] (or other) messages + /// pending some async action. While there is no guarantee of the rate of future messages, the + /// caller should seek to reduce the rate of new gossip messages handled, especially + /// [`ChannelAnnouncement`]s. + #[must_use] + pub processing_queue_high: extern "C" fn (this_arg: *const c_void) -> bool, + /// Gets the node feature flags which this handler itself supports. All available handlers are + /// queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`] + /// which are broadcasted in our [`NodeAnnouncement`] message. + #[must_use] + pub provided_node_features: extern "C" fn (this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures, + /// Gets the init feature flags which should be sent to the given peer. All available handlers + /// are queried similarly and their feature flags are OR'd together to form the [`InitFeatures`] + /// which are sent in our [`Init`] message. + /// + /// Note that this method is called before [`Self::peer_connected`]. + #[must_use] + pub provided_init_features: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey) -> crate::lightning::ln::features::InitFeatures, /// Implementation of MessageSendEventsProvider for this object. pub MessageSendEventsProvider: crate::lightning::util::events::MessageSendEventsProvider, /// Frees any resources associated with this object given its this_arg pointer. @@ -5365,13 +6181,16 @@ pub(crate) extern "C" fn RoutingMessageHandler_clone_fields(orig: &RoutingMessag handle_node_announcement: Clone::clone(&orig.handle_node_announcement), handle_channel_announcement: Clone::clone(&orig.handle_channel_announcement), handle_channel_update: Clone::clone(&orig.handle_channel_update), - get_next_channel_announcements: Clone::clone(&orig.get_next_channel_announcements), - get_next_node_announcements: Clone::clone(&orig.get_next_node_announcements), + get_next_channel_announcement: Clone::clone(&orig.get_next_channel_announcement), + get_next_node_announcement: Clone::clone(&orig.get_next_node_announcement), peer_connected: Clone::clone(&orig.peer_connected), handle_reply_channel_range: Clone::clone(&orig.handle_reply_channel_range), handle_reply_short_channel_ids_end: Clone::clone(&orig.handle_reply_short_channel_ids_end), handle_query_channel_range: Clone::clone(&orig.handle_query_channel_range), handle_query_short_channel_ids: Clone::clone(&orig.handle_query_short_channel_ids), + processing_queue_high: Clone::clone(&orig.processing_queue_high), + provided_node_features: Clone::clone(&orig.provided_node_features), + provided_init_features: Clone::clone(&orig.provided_init_features), MessageSendEventsProvider: crate::lightning::util::events::MessageSendEventsProvider_clone_fields(&orig.MessageSendEventsProvider), free: Clone::clone(&orig.free), } @@ -5401,19 +6220,21 @@ impl rustRoutingMessageHandler for RoutingMessageHandler { let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }) }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).take_inner()) } })}; local_ret } - fn get_next_channel_announcements(&self, mut starting_point: u64, mut batch_amount: u8) -> Vec<(lightning::ln::msgs::ChannelAnnouncement, Option, Option)> { - let mut ret = (self.get_next_channel_announcements)(self.this_arg, starting_point, batch_amount); - let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1, mut orig_ret_0_2) = item.to_rust(); let mut local_orig_ret_0_1 = if orig_ret_0_1.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(orig_ret_0_1.take_inner()) } }) }; let mut local_orig_ret_0_2 = if orig_ret_0_2.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(orig_ret_0_2.take_inner()) } }) }; let mut local_ret_0 = (*unsafe { Box::from_raw(orig_ret_0_0.take_inner()) }, local_orig_ret_0_1, local_orig_ret_0_2); local_ret_0 }); }; + fn get_next_channel_announcement(&self, mut starting_point: u64) -> Option<(lightning::ln::msgs::ChannelAnnouncement, Option, Option)> { + let mut ret = (self.get_next_channel_announcement)(self.this_arg, starting_point); + let mut local_ret = if ret.is_some() { Some( { let (mut orig_ret_0_0, mut orig_ret_0_1, mut orig_ret_0_2) = ret.take().to_rust(); let mut local_orig_ret_0_1 = if orig_ret_0_1.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(orig_ret_0_1.take_inner()) } }) }; let mut local_orig_ret_0_2 = if orig_ret_0_2.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(orig_ret_0_2.take_inner()) } }) }; let mut local_ret_0 = (*unsafe { Box::from_raw(orig_ret_0_0.take_inner()) }, local_orig_ret_0_1, local_orig_ret_0_2); local_ret_0 }) } else { None }; local_ret } - fn get_next_node_announcements(&self, mut starting_point: Option<&bitcoin::secp256k1::PublicKey>, mut batch_amount: u8) -> Vec { - let mut local_starting_point = if starting_point.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(starting_point.unwrap())) } }; - let mut ret = (self.get_next_node_announcements)(self.this_arg, local_starting_point, batch_amount); - let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { *unsafe { Box::from_raw(item.take_inner()) } }); }; + fn get_next_node_announcement(&self, mut starting_point: Option<&lightning::routing::gossip::NodeId>) -> Option { + let mut local_starting_point = crate::lightning::routing::gossip::NodeId { inner: unsafe { (if starting_point.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (starting_point.unwrap()) }) } as *const lightning::routing::gossip::NodeId<>) as *mut _ }, is_owned: false }; + let mut ret = (self.get_next_node_announcement)(self.this_arg, local_starting_point); + let mut local_ret = if ret.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(ret.take_inner()) } }) }; local_ret } - fn peer_connected(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut init: &lightning::ln::msgs::Init) { - (self.peer_connected)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::Init { inner: unsafe { ObjOps::nonnull_ptr_to_inner((init as *const lightning::ln::msgs::Init<>) as *mut _) }, is_owned: false }) + fn peer_connected(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut init: &lightning::ln::msgs::Init, mut inbound: bool) -> Result<(), ()> { + let mut ret = (self.peer_connected)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::Init { inner: unsafe { ObjOps::nonnull_ptr_to_inner((init as *const lightning::ln::msgs::Init<>) as *mut _) }, is_owned: false }, inbound); + let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })}; + local_ret } fn handle_reply_channel_range(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: lightning::ln::msgs::ReplyChannelRange) -> Result<(), lightning::ln::msgs::LightningError> { let mut ret = (self.handle_reply_channel_range)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), crate::lightning::ln::msgs::ReplyChannelRange { inner: ObjOps::heap_alloc(msg), is_owned: true }); @@ -5435,6 +6256,18 @@ impl rustRoutingMessageHandler for RoutingMessageHandler { let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).take_inner()) } })}; local_ret } + fn processing_queue_high(&self) -> bool { + let mut ret = (self.processing_queue_high)(self.this_arg); + ret + } + fn provided_node_features(&self) -> lightning::ln::features::NodeFeatures { + let mut ret = (self.provided_node_features)(self.this_arg); + *unsafe { Box::from_raw(ret.take_inner()) } + } + fn provided_init_features(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey) -> lightning::ln::features::InitFeatures { + let mut ret = (self.provided_init_features)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id)); + *unsafe { Box::from_raw(ret.take_inner()) } + } } // We're essentially a pointer already, or at least a set of pointers, so allow us to be used @@ -5455,6 +6288,107 @@ impl Drop for RoutingMessageHandler { } } } +/// A trait to describe an object that can receive onion messages. +#[repr(C)] +pub struct OnionMessageHandler { + /// An opaque pointer which is passed to your function implementations as an argument. + /// This has no meaning in the LDK, and can be NULL or any other value. + pub this_arg: *mut c_void, + /// Handle an incoming `onion_message` message from the given peer. + pub handle_onion_message: extern "C" fn (this_arg: *const c_void, peer_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::OnionMessage), + /// Called when a connection is established with a peer. Can be used to track which peers + /// advertise onion message support and are online. + /// + /// May return an `Err(())` if the features the peer supports are not sufficient to communicate + /// with us. Implementors should be somewhat conservative about doing so, however, as other + /// message handlers may still wish to communicate with this peer. + #[must_use] + pub peer_connected: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, init: &crate::lightning::ln::msgs::Init, inbound: bool) -> crate::c_types::derived::CResult_NoneNoneZ, + /// Indicates a connection to the peer failed/an existing connection was lost. Allows handlers to + /// drop and refuse to forward onion messages to this peer. + pub peer_disconnected: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey), + /// Gets the node feature flags which this handler itself supports. All available handlers are + /// queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`] + /// which are broadcasted in our [`NodeAnnouncement`] message. + #[must_use] + pub provided_node_features: extern "C" fn (this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures, + /// Gets the init feature flags which should be sent to the given peer. All available handlers + /// are queried similarly and their feature flags are OR'd together to form the [`InitFeatures`] + /// which are sent in our [`Init`] message. + /// + /// Note that this method is called before [`Self::peer_connected`]. + #[must_use] + pub provided_init_features: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey) -> crate::lightning::ln::features::InitFeatures, + /// Implementation of OnionMessageProvider for this object. + pub OnionMessageProvider: crate::lightning::util::events::OnionMessageProvider, + /// Frees any resources associated with this object given its this_arg pointer. + /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed. + pub free: Option, +} +unsafe impl Send for OnionMessageHandler {} +unsafe impl Sync for OnionMessageHandler {} +#[no_mangle] +pub(crate) extern "C" fn OnionMessageHandler_clone_fields(orig: &OnionMessageHandler) -> OnionMessageHandler { + OnionMessageHandler { + this_arg: orig.this_arg, + handle_onion_message: Clone::clone(&orig.handle_onion_message), + peer_connected: Clone::clone(&orig.peer_connected), + peer_disconnected: Clone::clone(&orig.peer_disconnected), + provided_node_features: Clone::clone(&orig.provided_node_features), + provided_init_features: Clone::clone(&orig.provided_init_features), + OnionMessageProvider: crate::lightning::util::events::OnionMessageProvider_clone_fields(&orig.OnionMessageProvider), + free: Clone::clone(&orig.free), + } +} +impl lightning::util::events::OnionMessageProvider for OnionMessageHandler { + fn next_onion_message_for_peer(&self, mut peer_node_id: bitcoin::secp256k1::PublicKey) -> Option { + let mut ret = (self.OnionMessageProvider.next_onion_message_for_peer)(self.OnionMessageProvider.this_arg, crate::c_types::PublicKey::from_rust(&peer_node_id)); + let mut local_ret = if ret.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(ret.take_inner()) } }) }; + local_ret + } +} + +use lightning::ln::msgs::OnionMessageHandler as rustOnionMessageHandler; +impl rustOnionMessageHandler for OnionMessageHandler { + fn handle_onion_message(&self, mut peer_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::OnionMessage) { + (self.handle_onion_message)(self.this_arg, crate::c_types::PublicKey::from_rust(&peer_node_id), &crate::lightning::ln::msgs::OnionMessage { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::OnionMessage<>) as *mut _) }, is_owned: false }) + } + fn peer_connected(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut init: &lightning::ln::msgs::Init, mut inbound: bool) -> Result<(), ()> { + let mut ret = (self.peer_connected)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::Init { inner: unsafe { ObjOps::nonnull_ptr_to_inner((init as *const lightning::ln::msgs::Init<>) as *mut _) }, is_owned: false }, inbound); + let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })}; + local_ret + } + fn peer_disconnected(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey) { + (self.peer_disconnected)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id)) + } + fn provided_node_features(&self) -> lightning::ln::features::NodeFeatures { + let mut ret = (self.provided_node_features)(self.this_arg); + *unsafe { Box::from_raw(ret.take_inner()) } + } + fn provided_init_features(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey) -> lightning::ln::features::InitFeatures { + let mut ret = (self.provided_init_features)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id)); + *unsafe { Box::from_raw(ret.take_inner()) } + } +} + +// We're essentially a pointer already, or at least a set of pointers, so allow us to be used +// directly as a Deref trait in higher-level structs: +impl core::ops::Deref for OnionMessageHandler { + type Target = Self; + fn deref(&self) -> &Self { + self + } +} +/// Calls the free function if one is set +#[no_mangle] +pub extern "C" fn OnionMessageHandler_free(this_ptr: OnionMessageHandler) { } +impl Drop for OnionMessageHandler { + fn drop(&mut self) { + if let Some(f) = self.free { + f(self.this_arg); + } + } +} mod fuzzy_internal_msgs { use alloc::str::FromStr; @@ -5479,7 +6413,7 @@ pub(crate) extern "C" fn AcceptChannel_write_void(obj: *const c_void) -> crate:: /// Read a AcceptChannel from a byte array, created by AcceptChannel_write pub extern "C" fn AcceptChannel_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_AcceptChannelDecodeErrorZ { let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::AcceptChannel { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::AcceptChannel { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; local_res } #[no_mangle] @@ -5495,7 +6429,7 @@ pub(crate) extern "C" fn AnnouncementSignatures_write_void(obj: *const c_void) - /// Read a AnnouncementSignatures from a byte array, created by AnnouncementSignatures_write pub extern "C" fn AnnouncementSignatures_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_AnnouncementSignaturesDecodeErrorZ { let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::AnnouncementSignatures { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::AnnouncementSignatures { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; local_res } #[no_mangle] @@ -5511,7 +6445,7 @@ pub(crate) extern "C" fn ChannelReestablish_write_void(obj: *const c_void) -> cr /// Read a ChannelReestablish from a byte array, created by ChannelReestablish_write pub extern "C" fn ChannelReestablish_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelReestablishDecodeErrorZ { let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::ChannelReestablish { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::ChannelReestablish { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; local_res } #[no_mangle] @@ -5527,7 +6461,7 @@ pub(crate) extern "C" fn ClosingSigned_write_void(obj: *const c_void) -> crate:: /// Read a ClosingSigned from a byte array, created by ClosingSigned_write pub extern "C" fn ClosingSigned_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ClosingSignedDecodeErrorZ { let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::ClosingSigned { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::ClosingSigned { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; local_res } #[no_mangle] @@ -5543,7 +6477,7 @@ pub(crate) extern "C" fn ClosingSignedFeeRange_write_void(obj: *const c_void) -> /// Read a ClosingSignedFeeRange from a byte array, created by ClosingSignedFeeRange_write pub extern "C" fn ClosingSignedFeeRange_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ClosingSignedFeeRangeDecodeErrorZ { let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::ClosingSignedFeeRange { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::ClosingSignedFeeRange { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; local_res } #[no_mangle] @@ -5559,7 +6493,7 @@ pub(crate) extern "C" fn CommitmentSigned_write_void(obj: *const c_void) -> crat /// Read a CommitmentSigned from a byte array, created by CommitmentSigned_write pub extern "C" fn CommitmentSigned_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_CommitmentSignedDecodeErrorZ { let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::CommitmentSigned { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::CommitmentSigned { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; local_res } #[no_mangle] @@ -5575,7 +6509,7 @@ pub(crate) extern "C" fn FundingCreated_write_void(obj: *const c_void) -> crate: /// Read a FundingCreated from a byte array, created by FundingCreated_write pub extern "C" fn FundingCreated_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_FundingCreatedDecodeErrorZ { let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::FundingCreated { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::FundingCreated { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; local_res } #[no_mangle] @@ -5591,7 +6525,7 @@ pub(crate) extern "C" fn FundingSigned_write_void(obj: *const c_void) -> crate:: /// Read a FundingSigned from a byte array, created by FundingSigned_write pub extern "C" fn FundingSigned_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_FundingSignedDecodeErrorZ { let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::FundingSigned { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::FundingSigned { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; local_res } #[no_mangle] @@ -5607,7 +6541,7 @@ pub(crate) extern "C" fn ChannelReady_write_void(obj: *const c_void) -> crate::c /// Read a ChannelReady from a byte array, created by ChannelReady_write pub extern "C" fn ChannelReady_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelReadyDecodeErrorZ { let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::ChannelReady { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::ChannelReady { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; local_res } #[no_mangle] @@ -5623,7 +6557,7 @@ pub(crate) extern "C" fn Init_write_void(obj: *const c_void) -> crate::c_types:: /// Read a Init from a byte array, created by Init_write pub extern "C" fn Init_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_InitDecodeErrorZ { let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::Init { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::Init { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; local_res } #[no_mangle] @@ -5639,7 +6573,7 @@ pub(crate) extern "C" fn OpenChannel_write_void(obj: *const c_void) -> crate::c_ /// Read a OpenChannel from a byte array, created by OpenChannel_write pub extern "C" fn OpenChannel_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_OpenChannelDecodeErrorZ { let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::OpenChannel { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::OpenChannel { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; local_res } #[no_mangle] @@ -5655,7 +6589,7 @@ pub(crate) extern "C" fn RevokeAndACK_write_void(obj: *const c_void) -> crate::c /// Read a RevokeAndACK from a byte array, created by RevokeAndACK_write pub extern "C" fn RevokeAndACK_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RevokeAndACKDecodeErrorZ { let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::RevokeAndACK { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::RevokeAndACK { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; local_res } #[no_mangle] @@ -5671,7 +6605,7 @@ pub(crate) extern "C" fn Shutdown_write_void(obj: *const c_void) -> crate::c_typ /// Read a Shutdown from a byte array, created by Shutdown_write pub extern "C" fn Shutdown_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ShutdownDecodeErrorZ { let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::Shutdown { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::Shutdown { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; local_res } #[no_mangle] @@ -5687,7 +6621,7 @@ pub(crate) extern "C" fn UpdateFailHTLC_write_void(obj: *const c_void) -> crate: /// Read a UpdateFailHTLC from a byte array, created by UpdateFailHTLC_write pub extern "C" fn UpdateFailHTLC_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_UpdateFailHTLCDecodeErrorZ { let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::UpdateFailHTLC { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::UpdateFailHTLC { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; local_res } #[no_mangle] @@ -5703,7 +6637,7 @@ pub(crate) extern "C" fn UpdateFailMalformedHTLC_write_void(obj: *const c_void) /// Read a UpdateFailMalformedHTLC from a byte array, created by UpdateFailMalformedHTLC_write pub extern "C" fn UpdateFailMalformedHTLC_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_UpdateFailMalformedHTLCDecodeErrorZ { let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::UpdateFailMalformedHTLC { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::UpdateFailMalformedHTLC { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; local_res } #[no_mangle] @@ -5719,7 +6653,7 @@ pub(crate) extern "C" fn UpdateFee_write_void(obj: *const c_void) -> crate::c_ty /// Read a UpdateFee from a byte array, created by UpdateFee_write pub extern "C" fn UpdateFee_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_UpdateFeeDecodeErrorZ { let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::UpdateFee { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::UpdateFee { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; local_res } #[no_mangle] @@ -5735,7 +6669,7 @@ pub(crate) extern "C" fn UpdateFulfillHTLC_write_void(obj: *const c_void) -> cra /// Read a UpdateFulfillHTLC from a byte array, created by UpdateFulfillHTLC_write pub extern "C" fn UpdateFulfillHTLC_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_UpdateFulfillHTLCDecodeErrorZ { let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::UpdateFulfillHTLC { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::UpdateFulfillHTLC { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; local_res } #[no_mangle] @@ -5751,10 +6685,26 @@ pub(crate) extern "C" fn UpdateAddHTLC_write_void(obj: *const c_void) -> crate:: /// Read a UpdateAddHTLC from a byte array, created by UpdateAddHTLC_write pub extern "C" fn UpdateAddHTLC_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_UpdateAddHTLCDecodeErrorZ { let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::UpdateAddHTLC { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::UpdateAddHTLC { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; + local_res +} +#[no_mangle] +/// Read a OnionMessage from a byte array, created by OnionMessage_write +pub extern "C" fn OnionMessage_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_OnionMessageDecodeErrorZ { + let res: Result = crate::c_types::deserialize_obj(ser); + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::OnionMessage { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; local_res } #[no_mangle] +/// Serialize the OnionMessage object into a byte array which can be read by OnionMessage_read +pub extern "C" fn OnionMessage_write(obj: &crate::lightning::ln::msgs::OnionMessage) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) +} +#[no_mangle] +pub(crate) extern "C" fn OnionMessage_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeOnionMessage) }) +} +#[no_mangle] /// Serialize the Ping object into a byte array which can be read by Ping_read pub extern "C" fn Ping_write(obj: &crate::lightning::ln::msgs::Ping) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) @@ -5767,7 +6717,7 @@ pub(crate) extern "C" fn Ping_write_void(obj: *const c_void) -> crate::c_types:: /// Read a Ping from a byte array, created by Ping_write pub extern "C" fn Ping_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_PingDecodeErrorZ { let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::Ping { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::Ping { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; local_res } #[no_mangle] @@ -5783,7 +6733,7 @@ pub(crate) extern "C" fn Pong_write_void(obj: *const c_void) -> crate::c_types:: /// Read a Pong from a byte array, created by Pong_write pub extern "C" fn Pong_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_PongDecodeErrorZ { let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::Pong { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::Pong { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; local_res } #[no_mangle] @@ -5799,7 +6749,7 @@ pub(crate) extern "C" fn UnsignedChannelAnnouncement_write_void(obj: *const c_vo /// Read a UnsignedChannelAnnouncement from a byte array, created by UnsignedChannelAnnouncement_write pub extern "C" fn UnsignedChannelAnnouncement_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_UnsignedChannelAnnouncementDecodeErrorZ { let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::UnsignedChannelAnnouncement { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::UnsignedChannelAnnouncement { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; local_res } #[no_mangle] @@ -5815,7 +6765,7 @@ pub(crate) extern "C" fn ChannelAnnouncement_write_void(obj: *const c_void) -> c /// Read a ChannelAnnouncement from a byte array, created by ChannelAnnouncement_write pub extern "C" fn ChannelAnnouncement_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelAnnouncementDecodeErrorZ { let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::ChannelAnnouncement { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; local_res } #[no_mangle] @@ -5831,7 +6781,7 @@ pub(crate) extern "C" fn UnsignedChannelUpdate_write_void(obj: *const c_void) -> /// Read a UnsignedChannelUpdate from a byte array, created by UnsignedChannelUpdate_write pub extern "C" fn UnsignedChannelUpdate_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_UnsignedChannelUpdateDecodeErrorZ { let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::UnsignedChannelUpdate { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::UnsignedChannelUpdate { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; local_res } #[no_mangle] @@ -5847,7 +6797,7 @@ pub(crate) extern "C" fn ChannelUpdate_write_void(obj: *const c_void) -> crate:: /// Read a ChannelUpdate from a byte array, created by ChannelUpdate_write pub extern "C" fn ChannelUpdate_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelUpdateDecodeErrorZ { let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::ChannelUpdate { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; local_res } #[no_mangle] @@ -5863,7 +6813,7 @@ pub(crate) extern "C" fn ErrorMessage_write_void(obj: *const c_void) -> crate::c /// Read a ErrorMessage from a byte array, created by ErrorMessage_write pub extern "C" fn ErrorMessage_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ErrorMessageDecodeErrorZ { let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::ErrorMessage { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::ErrorMessage { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; local_res } #[no_mangle] @@ -5879,7 +6829,7 @@ pub(crate) extern "C" fn WarningMessage_write_void(obj: *const c_void) -> crate: /// Read a WarningMessage from a byte array, created by WarningMessage_write pub extern "C" fn WarningMessage_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_WarningMessageDecodeErrorZ { let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::WarningMessage { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::WarningMessage { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; local_res } #[no_mangle] @@ -5895,7 +6845,7 @@ pub(crate) extern "C" fn UnsignedNodeAnnouncement_write_void(obj: *const c_void) /// Read a UnsignedNodeAnnouncement from a byte array, created by UnsignedNodeAnnouncement_write pub extern "C" fn UnsignedNodeAnnouncement_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_UnsignedNodeAnnouncementDecodeErrorZ { let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::UnsignedNodeAnnouncement { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::UnsignedNodeAnnouncement { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; local_res } #[no_mangle] @@ -5911,14 +6861,14 @@ pub(crate) extern "C" fn NodeAnnouncement_write_void(obj: *const c_void) -> crat /// Read a NodeAnnouncement from a byte array, created by NodeAnnouncement_write pub extern "C" fn NodeAnnouncement_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeAnnouncementDecodeErrorZ { let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::NodeAnnouncement { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::NodeAnnouncement { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; local_res } #[no_mangle] /// Read a QueryShortChannelIds from a byte array, created by QueryShortChannelIds_write pub extern "C" fn QueryShortChannelIds_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_QueryShortChannelIdsDecodeErrorZ { let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::QueryShortChannelIds { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::QueryShortChannelIds { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; local_res } #[no_mangle] @@ -5943,10 +6893,12 @@ pub(crate) extern "C" fn ReplyShortChannelIdsEnd_write_void(obj: *const c_void) /// Read a ReplyShortChannelIdsEnd from a byte array, created by ReplyShortChannelIdsEnd_write pub extern "C" fn ReplyShortChannelIdsEnd_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ReplyShortChannelIdsEndDecodeErrorZ { let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::ReplyShortChannelIdsEnd { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::ReplyShortChannelIdsEnd { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; local_res } -///\n\t * Calculates the overflow safe ending block height for the query.\n\t * Overflow returns `0xffffffff`, otherwise returns `first_blocknum + number_of_blocks`\n\t +/// Calculates the overflow safe ending block height for the query. +/// +/// Overflow returns `0xffffffff`, otherwise returns `first_blocknum + number_of_blocks`. #[must_use] #[no_mangle] pub extern "C" fn QueryChannelRange_end_blocknum(this_arg: &crate::lightning::ln::msgs::QueryChannelRange) -> u32 { @@ -5967,14 +6919,14 @@ pub(crate) extern "C" fn QueryChannelRange_write_void(obj: *const c_void) -> cra /// Read a QueryChannelRange from a byte array, created by QueryChannelRange_write pub extern "C" fn QueryChannelRange_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_QueryChannelRangeDecodeErrorZ { let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::QueryChannelRange { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::QueryChannelRange { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; local_res } #[no_mangle] /// Read a ReplyChannelRange from a byte array, created by ReplyChannelRange_write pub extern "C" fn ReplyChannelRange_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ReplyChannelRangeDecodeErrorZ { let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::ReplyChannelRange { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::ReplyChannelRange { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; local_res } #[no_mangle] @@ -5999,6 +6951,6 @@ pub(crate) extern "C" fn GossipTimestampFilter_write_void(obj: *const c_void) -> /// Read a GossipTimestampFilter from a byte array, created by GossipTimestampFilter_write pub extern "C" fn GossipTimestampFilter_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_GossipTimestampFilterDecodeErrorZ { let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::GossipTimestampFilter { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::msgs::GossipTimestampFilter { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; local_res }