1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
4 // This file is licensed under the license available in the LICENSE or LICENSE.md
5 // file in the root of this repository or, if no such file exists, the same
6 // license as that which applies to the original source files from which this
7 // source was automatically generated.
9 //! Feature flag definitions for the Lightning protocol according to [BOLT #9].
11 //! Lightning nodes advertise a supported set of operation through feature flags. Features are
12 //! applicable for a specific context as indicated in some [messages]. [`Features`] encapsulates
13 //! behavior for specifying and checking feature flags for a particular context. Each feature is
14 //! defined internally by a trait specifying the corresponding flags (i.e., even and odd bits).
16 //! Whether a feature is considered \"known\" or \"unknown\" is relative to the implementation, whereas
17 //! the term \"supports\" is used in reference to a particular set of [`Features`]. That is, a node
18 //! supports a feature if it advertises the feature (as either required or optional) to its peers.
19 //! And the implementation can interpret a feature if the feature is known to it.
21 //! [BOLT #9]: https://github.com/lightningnetwork/lightning-rfc/blob/master/09-features.md
22 //! [messages]: crate::ln::msgs
24 use std::str::FromStr;
26 use bitcoin::hashes::Hash;
27 use crate::c_types::*;
31 use std::str::FromStr;
33 use bitcoin::hashes::Hash;
34 use crate::c_types::*;
37 /// Checks if two InitFeaturess contain equal inner contents.
38 /// This ignores pointers and is_owned flags and looks at the values in fields.
39 /// Two objects with NULL inner values will be considered "equal" here.
41 pub extern "C" fn InitFeatures_eq(a: &InitFeatures, b: &InitFeatures) -> bool {
42 if a.inner == b.inner { return true; }
43 if a.inner.is_null() || b.inner.is_null() { return false; }
44 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
46 /// Checks if two NodeFeaturess contain equal inner contents.
47 /// This ignores pointers and is_owned flags and looks at the values in fields.
48 /// Two objects with NULL inner values will be considered "equal" here.
50 pub extern "C" fn NodeFeatures_eq(a: &NodeFeatures, b: &NodeFeatures) -> bool {
51 if a.inner == b.inner { return true; }
52 if a.inner.is_null() || b.inner.is_null() { return false; }
53 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
55 /// Checks if two ChannelFeaturess contain equal inner contents.
56 /// This ignores pointers and is_owned flags and looks at the values in fields.
57 /// Two objects with NULL inner values will be considered "equal" here.
59 pub extern "C" fn ChannelFeatures_eq(a: &ChannelFeatures, b: &ChannelFeatures) -> bool {
60 if a.inner == b.inner { return true; }
61 if a.inner.is_null() || b.inner.is_null() { return false; }
62 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
64 /// Checks if two InvoiceFeaturess contain equal inner contents.
65 /// This ignores pointers and is_owned flags and looks at the values in fields.
66 /// Two objects with NULL inner values will be considered "equal" here.
68 pub extern "C" fn InvoiceFeatures_eq(a: &InvoiceFeatures, b: &InvoiceFeatures) -> bool {
69 if a.inner == b.inner { return true; }
70 if a.inner.is_null() || b.inner.is_null() { return false; }
71 if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
73 impl Clone for InitFeatures {
74 fn clone(&self) -> Self {
76 inner: if <*mut nativeInitFeatures>::is_null(self.inner) { std::ptr::null_mut() } else {
77 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
83 /// Used only if an object of this type is returned as a trait impl by a method
84 pub(crate) extern "C" fn InitFeatures_clone_void(this_ptr: *const c_void) -> *mut c_void {
85 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInitFeatures)).clone() })) as *mut c_void
88 /// Creates a copy of the InitFeatures
89 pub extern "C" fn InitFeatures_clone(orig: &InitFeatures) -> InitFeatures {
92 impl Clone for NodeFeatures {
93 fn clone(&self) -> Self {
95 inner: if <*mut nativeNodeFeatures>::is_null(self.inner) { std::ptr::null_mut() } else {
96 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
102 /// Used only if an object of this type is returned as a trait impl by a method
103 pub(crate) extern "C" fn NodeFeatures_clone_void(this_ptr: *const c_void) -> *mut c_void {
104 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeFeatures)).clone() })) as *mut c_void
107 /// Creates a copy of the NodeFeatures
108 pub extern "C" fn NodeFeatures_clone(orig: &NodeFeatures) -> NodeFeatures {
111 impl Clone for ChannelFeatures {
112 fn clone(&self) -> Self {
114 inner: if <*mut nativeChannelFeatures>::is_null(self.inner) { std::ptr::null_mut() } else {
115 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
121 /// Used only if an object of this type is returned as a trait impl by a method
122 pub(crate) extern "C" fn ChannelFeatures_clone_void(this_ptr: *const c_void) -> *mut c_void {
123 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelFeatures)).clone() })) as *mut c_void
126 /// Creates a copy of the ChannelFeatures
127 pub extern "C" fn ChannelFeatures_clone(orig: &ChannelFeatures) -> ChannelFeatures {
130 impl Clone for InvoiceFeatures {
131 fn clone(&self) -> Self {
133 inner: if <*mut nativeInvoiceFeatures>::is_null(self.inner) { std::ptr::null_mut() } else {
134 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
140 /// Used only if an object of this type is returned as a trait impl by a method
141 pub(crate) extern "C" fn InvoiceFeatures_clone_void(this_ptr: *const c_void) -> *mut c_void {
142 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoiceFeatures)).clone() })) as *mut c_void
145 /// Creates a copy of the InvoiceFeatures
146 pub extern "C" fn InvoiceFeatures_clone(orig: &InvoiceFeatures) -> InvoiceFeatures {
150 use lightning::ln::features::InitFeatures as nativeInitFeaturesImport;
151 type nativeInitFeatures = nativeInitFeaturesImport;
153 /// Features used within an `init` message.
156 pub struct InitFeatures {
157 /// A pointer to the opaque Rust object.
159 /// Nearly everywhere, inner must be non-null, however in places where
160 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
161 pub inner: *mut nativeInitFeatures,
162 /// Indicates that this is the only struct which contains the same pointer.
164 /// Rust functions which take ownership of an object provided via an argument require
165 /// this to be true and invalidate the object pointed to by inner.
169 impl Drop for InitFeatures {
171 if self.is_owned && !<*mut nativeInitFeatures>::is_null(self.inner) {
172 let _ = unsafe { Box::from_raw(self.inner) };
176 /// Frees any resources used by the InitFeatures, if is_owned is set and inner is non-NULL.
178 pub extern "C" fn InitFeatures_free(this_obj: InitFeatures) { }
180 /// Used only if an object of this type is returned as a trait impl by a method
181 extern "C" fn InitFeatures_free_void(this_ptr: *mut c_void) {
182 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInitFeatures); }
185 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
187 pub(crate) fn take_inner(mut self) -> *mut nativeInitFeatures {
188 assert!(self.is_owned);
189 let ret = self.inner;
190 self.inner = std::ptr::null_mut();
195 use lightning::ln::features::NodeFeatures as nativeNodeFeaturesImport;
196 type nativeNodeFeatures = nativeNodeFeaturesImport;
198 /// Features used within a `node_announcement` message.
201 pub struct NodeFeatures {
202 /// A pointer to the opaque Rust object.
204 /// Nearly everywhere, inner must be non-null, however in places where
205 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
206 pub inner: *mut nativeNodeFeatures,
207 /// Indicates that this is the only struct which contains the same pointer.
209 /// Rust functions which take ownership of an object provided via an argument require
210 /// this to be true and invalidate the object pointed to by inner.
214 impl Drop for NodeFeatures {
216 if self.is_owned && !<*mut nativeNodeFeatures>::is_null(self.inner) {
217 let _ = unsafe { Box::from_raw(self.inner) };
221 /// Frees any resources used by the NodeFeatures, if is_owned is set and inner is non-NULL.
223 pub extern "C" fn NodeFeatures_free(this_obj: NodeFeatures) { }
225 /// Used only if an object of this type is returned as a trait impl by a method
226 extern "C" fn NodeFeatures_free_void(this_ptr: *mut c_void) {
227 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeFeatures); }
230 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
232 pub(crate) fn take_inner(mut self) -> *mut nativeNodeFeatures {
233 assert!(self.is_owned);
234 let ret = self.inner;
235 self.inner = std::ptr::null_mut();
240 use lightning::ln::features::ChannelFeatures as nativeChannelFeaturesImport;
241 type nativeChannelFeatures = nativeChannelFeaturesImport;
243 /// Features used within a `channel_announcement` message.
246 pub struct ChannelFeatures {
247 /// A pointer to the opaque Rust object.
249 /// Nearly everywhere, inner must be non-null, however in places where
250 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
251 pub inner: *mut nativeChannelFeatures,
252 /// Indicates that this is the only struct which contains the same pointer.
254 /// Rust functions which take ownership of an object provided via an argument require
255 /// this to be true and invalidate the object pointed to by inner.
259 impl Drop for ChannelFeatures {
261 if self.is_owned && !<*mut nativeChannelFeatures>::is_null(self.inner) {
262 let _ = unsafe { Box::from_raw(self.inner) };
266 /// Frees any resources used by the ChannelFeatures, if is_owned is set and inner is non-NULL.
268 pub extern "C" fn ChannelFeatures_free(this_obj: ChannelFeatures) { }
270 /// Used only if an object of this type is returned as a trait impl by a method
271 extern "C" fn ChannelFeatures_free_void(this_ptr: *mut c_void) {
272 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelFeatures); }
275 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
276 impl ChannelFeatures {
277 pub(crate) fn take_inner(mut self) -> *mut nativeChannelFeatures {
278 assert!(self.is_owned);
279 let ret = self.inner;
280 self.inner = std::ptr::null_mut();
285 use lightning::ln::features::InvoiceFeatures as nativeInvoiceFeaturesImport;
286 type nativeInvoiceFeatures = nativeInvoiceFeaturesImport;
288 /// Features used within an invoice.
291 pub struct InvoiceFeatures {
292 /// A pointer to the opaque Rust object.
294 /// Nearly everywhere, inner must be non-null, however in places where
295 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
296 pub inner: *mut nativeInvoiceFeatures,
297 /// Indicates that this is the only struct which contains the same pointer.
299 /// Rust functions which take ownership of an object provided via an argument require
300 /// this to be true and invalidate the object pointed to by inner.
304 impl Drop for InvoiceFeatures {
306 if self.is_owned && !<*mut nativeInvoiceFeatures>::is_null(self.inner) {
307 let _ = unsafe { Box::from_raw(self.inner) };
311 /// Frees any resources used by the InvoiceFeatures, if is_owned is set and inner is non-NULL.
313 pub extern "C" fn InvoiceFeatures_free(this_obj: InvoiceFeatures) { }
315 /// Used only if an object of this type is returned as a trait impl by a method
316 extern "C" fn InvoiceFeatures_free_void(this_ptr: *mut c_void) {
317 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoiceFeatures); }
320 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
321 impl InvoiceFeatures {
322 pub(crate) fn take_inner(mut self) -> *mut nativeInvoiceFeatures {
323 assert!(self.is_owned);
324 let ret = self.inner;
325 self.inner = std::ptr::null_mut();
329 /// Create a blank Features with no features set
332 pub extern "C" fn InitFeatures_empty() -> InitFeatures {
333 let mut ret = lightning::ln::features::InitFeatures::empty();
334 InitFeatures { inner: Box::into_raw(Box::new(ret)), is_owned: true }
337 /// Creates a Features with the bits set which are known by the implementation
340 pub extern "C" fn InitFeatures_known() -> InitFeatures {
341 let mut ret = lightning::ln::features::InitFeatures::known();
342 InitFeatures { inner: Box::into_raw(Box::new(ret)), is_owned: true }
345 /// Create a blank Features with no features set
348 pub extern "C" fn NodeFeatures_empty() -> NodeFeatures {
349 let mut ret = lightning::ln::features::NodeFeatures::empty();
350 NodeFeatures { inner: Box::into_raw(Box::new(ret)), is_owned: true }
353 /// Creates a Features with the bits set which are known by the implementation
356 pub extern "C" fn NodeFeatures_known() -> NodeFeatures {
357 let mut ret = lightning::ln::features::NodeFeatures::known();
358 NodeFeatures { inner: Box::into_raw(Box::new(ret)), is_owned: true }
361 /// Create a blank Features with no features set
364 pub extern "C" fn ChannelFeatures_empty() -> ChannelFeatures {
365 let mut ret = lightning::ln::features::ChannelFeatures::empty();
366 ChannelFeatures { inner: Box::into_raw(Box::new(ret)), is_owned: true }
369 /// Creates a Features with the bits set which are known by the implementation
372 pub extern "C" fn ChannelFeatures_known() -> ChannelFeatures {
373 let mut ret = lightning::ln::features::ChannelFeatures::known();
374 ChannelFeatures { inner: Box::into_raw(Box::new(ret)), is_owned: true }
377 /// Create a blank Features with no features set
380 pub extern "C" fn InvoiceFeatures_empty() -> InvoiceFeatures {
381 let mut ret = lightning::ln::features::InvoiceFeatures::empty();
382 InvoiceFeatures { inner: Box::into_raw(Box::new(ret)), is_owned: true }
385 /// Creates a Features with the bits set which are known by the implementation
388 pub extern "C" fn InvoiceFeatures_known() -> InvoiceFeatures {
389 let mut ret = lightning::ln::features::InvoiceFeatures::known();
390 InvoiceFeatures { inner: Box::into_raw(Box::new(ret)), is_owned: true }
393 /// Returns whether the `payment_secret` feature is supported.
396 pub extern "C" fn InitFeatures_supports_payment_secret(this_arg: &InitFeatures) -> bool {
397 let mut ret = unsafe { &*this_arg.inner }.supports_payment_secret();
401 /// Returns whether the `payment_secret` feature is supported.
404 pub extern "C" fn NodeFeatures_supports_payment_secret(this_arg: &NodeFeatures) -> bool {
405 let mut ret = unsafe { &*this_arg.inner }.supports_payment_secret();
409 /// Returns whether the `payment_secret` feature is supported.
412 pub extern "C" fn InvoiceFeatures_supports_payment_secret(this_arg: &InvoiceFeatures) -> bool {
413 let mut ret = unsafe { &*this_arg.inner }.supports_payment_secret();
418 /// Serialize the InitFeatures object into a byte array which can be read by InitFeatures_read
419 pub extern "C" fn InitFeatures_write(obj: &InitFeatures) -> crate::c_types::derived::CVec_u8Z {
420 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
423 pub(crate) extern "C" fn InitFeatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
424 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInitFeatures) })
427 /// Serialize the NodeFeatures object into a byte array which can be read by NodeFeatures_read
428 pub extern "C" fn NodeFeatures_write(obj: &NodeFeatures) -> crate::c_types::derived::CVec_u8Z {
429 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
432 pub(crate) extern "C" fn NodeFeatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
433 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeFeatures) })
436 /// Serialize the ChannelFeatures object into a byte array which can be read by ChannelFeatures_read
437 pub extern "C" fn ChannelFeatures_write(obj: &ChannelFeatures) -> crate::c_types::derived::CVec_u8Z {
438 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
441 pub(crate) extern "C" fn ChannelFeatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
442 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelFeatures) })
445 /// Serialize the InvoiceFeatures object into a byte array which can be read by InvoiceFeatures_read
446 pub extern "C" fn InvoiceFeatures_write(obj: &InvoiceFeatures) -> crate::c_types::derived::CVec_u8Z {
447 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
450 pub(crate) extern "C" fn InvoiceFeatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
451 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInvoiceFeatures) })
454 /// Read a InitFeatures from a byte array, created by InitFeatures_write
455 pub extern "C" fn InitFeatures_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_InitFeaturesDecodeErrorZ {
456 let res = crate::c_types::deserialize_obj(ser);
457 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::features::InitFeatures { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
461 /// Read a NodeFeatures from a byte array, created by NodeFeatures_write
462 pub extern "C" fn NodeFeatures_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeFeaturesDecodeErrorZ {
463 let res = crate::c_types::deserialize_obj(ser);
464 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::features::NodeFeatures { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
468 /// Read a ChannelFeatures from a byte array, created by ChannelFeatures_write
469 pub extern "C" fn ChannelFeatures_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelFeaturesDecodeErrorZ {
470 let res = crate::c_types::deserialize_obj(ser);
471 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::features::ChannelFeatures { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
475 /// Read a InvoiceFeatures from a byte array, created by InvoiceFeatures_write
476 pub extern "C" fn InvoiceFeatures_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_InvoiceFeaturesDecodeErrorZ {
477 let res = crate::c_types::deserialize_obj(ser);
478 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::features::InvoiceFeatures { inner: Box::into_raw(Box::new(o)), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };