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 core::convert::Infallible;
27 use bitcoin::hashes::Hash;
28 use crate::c_types::*;
32 use std::str::FromStr;
34 use core::convert::Infallible;
35 use bitcoin::hashes::Hash;
36 use crate::c_types::*;
39 /// Checks if two InitFeaturess contain equal inner contents.
40 /// This ignores pointers and is_owned flags and looks at the values in fields.
41 /// Two objects with NULL inner values will be considered "equal" here.
43 pub extern "C" fn InitFeatures_eq(a: &InitFeatures, b: &InitFeatures) -> bool {
44 if a.inner == b.inner { return true; }
45 if a.inner.is_null() || b.inner.is_null() { return false; }
46 if a.get_native_ref() == b.get_native_ref() { true } else { false }
48 /// Checks if two NodeFeaturess contain equal inner contents.
49 /// This ignores pointers and is_owned flags and looks at the values in fields.
50 /// Two objects with NULL inner values will be considered "equal" here.
52 pub extern "C" fn NodeFeatures_eq(a: &NodeFeatures, b: &NodeFeatures) -> bool {
53 if a.inner == b.inner { return true; }
54 if a.inner.is_null() || b.inner.is_null() { return false; }
55 if a.get_native_ref() == b.get_native_ref() { true } else { false }
57 /// Checks if two ChannelFeaturess contain equal inner contents.
58 /// This ignores pointers and is_owned flags and looks at the values in fields.
59 /// Two objects with NULL inner values will be considered "equal" here.
61 pub extern "C" fn ChannelFeatures_eq(a: &ChannelFeatures, b: &ChannelFeatures) -> bool {
62 if a.inner == b.inner { return true; }
63 if a.inner.is_null() || b.inner.is_null() { return false; }
64 if a.get_native_ref() == b.get_native_ref() { true } else { false }
66 /// Checks if two InvoiceFeaturess contain equal inner contents.
67 /// This ignores pointers and is_owned flags and looks at the values in fields.
68 /// Two objects with NULL inner values will be considered "equal" here.
70 pub extern "C" fn InvoiceFeatures_eq(a: &InvoiceFeatures, b: &InvoiceFeatures) -> bool {
71 if a.inner == b.inner { return true; }
72 if a.inner.is_null() || b.inner.is_null() { return false; }
73 if a.get_native_ref() == b.get_native_ref() { true } else { false }
75 impl Clone for InitFeatures {
76 fn clone(&self) -> Self {
78 inner: if <*mut nativeInitFeatures>::is_null(self.inner) { std::ptr::null_mut() } else {
79 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
85 /// Used only if an object of this type is returned as a trait impl by a method
86 pub(crate) extern "C" fn InitFeatures_clone_void(this_ptr: *const c_void) -> *mut c_void {
87 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInitFeatures)).clone() })) as *mut c_void
90 /// Creates a copy of the InitFeatures
91 pub extern "C" fn InitFeatures_clone(orig: &InitFeatures) -> InitFeatures {
94 impl Clone for NodeFeatures {
95 fn clone(&self) -> Self {
97 inner: if <*mut nativeNodeFeatures>::is_null(self.inner) { std::ptr::null_mut() } else {
98 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
104 /// Used only if an object of this type is returned as a trait impl by a method
105 pub(crate) extern "C" fn NodeFeatures_clone_void(this_ptr: *const c_void) -> *mut c_void {
106 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeFeatures)).clone() })) as *mut c_void
109 /// Creates a copy of the NodeFeatures
110 pub extern "C" fn NodeFeatures_clone(orig: &NodeFeatures) -> NodeFeatures {
113 impl Clone for ChannelFeatures {
114 fn clone(&self) -> Self {
116 inner: if <*mut nativeChannelFeatures>::is_null(self.inner) { std::ptr::null_mut() } else {
117 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
123 /// Used only if an object of this type is returned as a trait impl by a method
124 pub(crate) extern "C" fn ChannelFeatures_clone_void(this_ptr: *const c_void) -> *mut c_void {
125 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelFeatures)).clone() })) as *mut c_void
128 /// Creates a copy of the ChannelFeatures
129 pub extern "C" fn ChannelFeatures_clone(orig: &ChannelFeatures) -> ChannelFeatures {
132 impl Clone for InvoiceFeatures {
133 fn clone(&self) -> Self {
135 inner: if <*mut nativeInvoiceFeatures>::is_null(self.inner) { std::ptr::null_mut() } else {
136 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
142 /// Used only if an object of this type is returned as a trait impl by a method
143 pub(crate) extern "C" fn InvoiceFeatures_clone_void(this_ptr: *const c_void) -> *mut c_void {
144 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoiceFeatures)).clone() })) as *mut c_void
147 /// Creates a copy of the InvoiceFeatures
148 pub extern "C" fn InvoiceFeatures_clone(orig: &InvoiceFeatures) -> InvoiceFeatures {
152 use lightning::ln::features::InitFeatures as nativeInitFeaturesImport;
153 pub(crate) type nativeInitFeatures = nativeInitFeaturesImport;
155 /// Features used within an `init` message.
158 pub struct InitFeatures {
159 /// A pointer to the opaque Rust object.
161 /// Nearly everywhere, inner must be non-null, however in places where
162 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
163 pub inner: *mut nativeInitFeatures,
164 /// Indicates that this is the only struct which contains the same pointer.
166 /// Rust functions which take ownership of an object provided via an argument require
167 /// this to be true and invalidate the object pointed to by inner.
171 impl Drop for InitFeatures {
173 if self.is_owned && !<*mut nativeInitFeatures>::is_null(self.inner) {
174 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
178 /// Frees any resources used by the InitFeatures, if is_owned is set and inner is non-NULL.
180 pub extern "C" fn InitFeatures_free(this_obj: InitFeatures) { }
182 /// Used only if an object of this type is returned as a trait impl by a method
183 pub(crate) extern "C" fn InitFeatures_free_void(this_ptr: *mut c_void) {
184 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInitFeatures); }
188 pub(crate) fn get_native_ref(&self) -> &'static nativeInitFeatures {
189 unsafe { &*ObjOps::untweak_ptr(self.inner) }
191 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInitFeatures {
192 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
194 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
195 pub(crate) fn take_inner(mut self) -> *mut nativeInitFeatures {
196 assert!(self.is_owned);
197 let ret = ObjOps::untweak_ptr(self.inner);
198 self.inner = std::ptr::null_mut();
203 use lightning::ln::features::NodeFeatures as nativeNodeFeaturesImport;
204 pub(crate) type nativeNodeFeatures = nativeNodeFeaturesImport;
206 /// Features used within a `node_announcement` message.
209 pub struct NodeFeatures {
210 /// A pointer to the opaque Rust object.
212 /// Nearly everywhere, inner must be non-null, however in places where
213 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
214 pub inner: *mut nativeNodeFeatures,
215 /// Indicates that this is the only struct which contains the same pointer.
217 /// Rust functions which take ownership of an object provided via an argument require
218 /// this to be true and invalidate the object pointed to by inner.
222 impl Drop for NodeFeatures {
224 if self.is_owned && !<*mut nativeNodeFeatures>::is_null(self.inner) {
225 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
229 /// Frees any resources used by the NodeFeatures, if is_owned is set and inner is non-NULL.
231 pub extern "C" fn NodeFeatures_free(this_obj: NodeFeatures) { }
233 /// Used only if an object of this type is returned as a trait impl by a method
234 pub(crate) extern "C" fn NodeFeatures_free_void(this_ptr: *mut c_void) {
235 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeFeatures); }
239 pub(crate) fn get_native_ref(&self) -> &'static nativeNodeFeatures {
240 unsafe { &*ObjOps::untweak_ptr(self.inner) }
242 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeNodeFeatures {
243 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
245 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
246 pub(crate) fn take_inner(mut self) -> *mut nativeNodeFeatures {
247 assert!(self.is_owned);
248 let ret = ObjOps::untweak_ptr(self.inner);
249 self.inner = std::ptr::null_mut();
254 use lightning::ln::features::ChannelFeatures as nativeChannelFeaturesImport;
255 pub(crate) type nativeChannelFeatures = nativeChannelFeaturesImport;
257 /// Features used within a `channel_announcement` message.
260 pub struct ChannelFeatures {
261 /// A pointer to the opaque Rust object.
263 /// Nearly everywhere, inner must be non-null, however in places where
264 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
265 pub inner: *mut nativeChannelFeatures,
266 /// Indicates that this is the only struct which contains the same pointer.
268 /// Rust functions which take ownership of an object provided via an argument require
269 /// this to be true and invalidate the object pointed to by inner.
273 impl Drop for ChannelFeatures {
275 if self.is_owned && !<*mut nativeChannelFeatures>::is_null(self.inner) {
276 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
280 /// Frees any resources used by the ChannelFeatures, if is_owned is set and inner is non-NULL.
282 pub extern "C" fn ChannelFeatures_free(this_obj: ChannelFeatures) { }
284 /// Used only if an object of this type is returned as a trait impl by a method
285 pub(crate) extern "C" fn ChannelFeatures_free_void(this_ptr: *mut c_void) {
286 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelFeatures); }
289 impl ChannelFeatures {
290 pub(crate) fn get_native_ref(&self) -> &'static nativeChannelFeatures {
291 unsafe { &*ObjOps::untweak_ptr(self.inner) }
293 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelFeatures {
294 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
296 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
297 pub(crate) fn take_inner(mut self) -> *mut nativeChannelFeatures {
298 assert!(self.is_owned);
299 let ret = ObjOps::untweak_ptr(self.inner);
300 self.inner = std::ptr::null_mut();
305 use lightning::ln::features::InvoiceFeatures as nativeInvoiceFeaturesImport;
306 pub(crate) type nativeInvoiceFeatures = nativeInvoiceFeaturesImport;
308 /// Features used within an invoice.
311 pub struct InvoiceFeatures {
312 /// A pointer to the opaque Rust object.
314 /// Nearly everywhere, inner must be non-null, however in places where
315 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
316 pub inner: *mut nativeInvoiceFeatures,
317 /// Indicates that this is the only struct which contains the same pointer.
319 /// Rust functions which take ownership of an object provided via an argument require
320 /// this to be true and invalidate the object pointed to by inner.
324 impl Drop for InvoiceFeatures {
326 if self.is_owned && !<*mut nativeInvoiceFeatures>::is_null(self.inner) {
327 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
331 /// Frees any resources used by the InvoiceFeatures, if is_owned is set and inner is non-NULL.
333 pub extern "C" fn InvoiceFeatures_free(this_obj: InvoiceFeatures) { }
335 /// Used only if an object of this type is returned as a trait impl by a method
336 pub(crate) extern "C" fn InvoiceFeatures_free_void(this_ptr: *mut c_void) {
337 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoiceFeatures); }
340 impl InvoiceFeatures {
341 pub(crate) fn get_native_ref(&self) -> &'static nativeInvoiceFeatures {
342 unsafe { &*ObjOps::untweak_ptr(self.inner) }
344 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeInvoiceFeatures {
345 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
347 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
348 pub(crate) fn take_inner(mut self) -> *mut nativeInvoiceFeatures {
349 assert!(self.is_owned);
350 let ret = ObjOps::untweak_ptr(self.inner);
351 self.inner = std::ptr::null_mut();
355 /// Create a blank Features with no features set
358 pub extern "C" fn InitFeatures_empty() -> InitFeatures {
359 let mut ret = lightning::ln::features::InitFeatures::empty();
360 InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
363 /// Creates a Features with the bits set which are known by the implementation
366 pub extern "C" fn InitFeatures_known() -> InitFeatures {
367 let mut ret = lightning::ln::features::InitFeatures::known();
368 InitFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
371 /// Returns true if this `Features` object contains unknown feature flags which are set as
375 pub extern "C" fn InitFeatures_requires_unknown_bits(this_arg: &InitFeatures) -> bool {
376 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.requires_unknown_bits();
380 /// Create a blank Features with no features set
383 pub extern "C" fn NodeFeatures_empty() -> NodeFeatures {
384 let mut ret = lightning::ln::features::NodeFeatures::empty();
385 NodeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
388 /// Creates a Features with the bits set which are known by the implementation
391 pub extern "C" fn NodeFeatures_known() -> NodeFeatures {
392 let mut ret = lightning::ln::features::NodeFeatures::known();
393 NodeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
396 /// Returns true if this `Features` object contains unknown feature flags which are set as
400 pub extern "C" fn NodeFeatures_requires_unknown_bits(this_arg: &NodeFeatures) -> bool {
401 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.requires_unknown_bits();
405 /// Create a blank Features with no features set
408 pub extern "C" fn ChannelFeatures_empty() -> ChannelFeatures {
409 let mut ret = lightning::ln::features::ChannelFeatures::empty();
410 ChannelFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
413 /// Creates a Features with the bits set which are known by the implementation
416 pub extern "C" fn ChannelFeatures_known() -> ChannelFeatures {
417 let mut ret = lightning::ln::features::ChannelFeatures::known();
418 ChannelFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
421 /// Returns true if this `Features` object contains unknown feature flags which are set as
425 pub extern "C" fn ChannelFeatures_requires_unknown_bits(this_arg: &ChannelFeatures) -> bool {
426 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.requires_unknown_bits();
430 /// Create a blank Features with no features set
433 pub extern "C" fn InvoiceFeatures_empty() -> InvoiceFeatures {
434 let mut ret = lightning::ln::features::InvoiceFeatures::empty();
435 InvoiceFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
438 /// Creates a Features with the bits set which are known by the implementation
441 pub extern "C" fn InvoiceFeatures_known() -> InvoiceFeatures {
442 let mut ret = lightning::ln::features::InvoiceFeatures::known();
443 InvoiceFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true }
446 /// Returns true if this `Features` object contains unknown feature flags which are set as
450 pub extern "C" fn InvoiceFeatures_requires_unknown_bits(this_arg: &InvoiceFeatures) -> bool {
451 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.requires_unknown_bits();
455 /// Returns whether the `payment_secret` feature is supported.
458 pub extern "C" fn InitFeatures_supports_payment_secret(this_arg: &InitFeatures) -> bool {
459 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.supports_payment_secret();
463 /// Returns whether the `payment_secret` feature is supported.
466 pub extern "C" fn NodeFeatures_supports_payment_secret(this_arg: &NodeFeatures) -> bool {
467 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.supports_payment_secret();
471 /// Returns whether the `payment_secret` feature is supported.
474 pub extern "C" fn InvoiceFeatures_supports_payment_secret(this_arg: &InvoiceFeatures) -> bool {
475 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.supports_payment_secret();
480 /// Serialize the InitFeatures object into a byte array which can be read by InitFeatures_read
481 pub extern "C" fn InitFeatures_write(obj: &InitFeatures) -> crate::c_types::derived::CVec_u8Z {
482 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
485 pub(crate) extern "C" fn InitFeatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
486 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInitFeatures) })
489 /// Serialize the NodeFeatures object into a byte array which can be read by NodeFeatures_read
490 pub extern "C" fn NodeFeatures_write(obj: &NodeFeatures) -> crate::c_types::derived::CVec_u8Z {
491 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
494 pub(crate) extern "C" fn NodeFeatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
495 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeFeatures) })
498 /// Serialize the ChannelFeatures object into a byte array which can be read by ChannelFeatures_read
499 pub extern "C" fn ChannelFeatures_write(obj: &ChannelFeatures) -> crate::c_types::derived::CVec_u8Z {
500 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
503 pub(crate) extern "C" fn ChannelFeatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
504 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelFeatures) })
507 /// Serialize the InvoiceFeatures object into a byte array which can be read by InvoiceFeatures_read
508 pub extern "C" fn InvoiceFeatures_write(obj: &InvoiceFeatures) -> crate::c_types::derived::CVec_u8Z {
509 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
512 pub(crate) extern "C" fn InvoiceFeatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
513 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInvoiceFeatures) })
516 /// Read a InitFeatures from a byte array, created by InitFeatures_write
517 pub extern "C" fn InitFeatures_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_InitFeaturesDecodeErrorZ {
518 let res: Result<lightning::ln::features::InitFeatures, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
519 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::features::InitFeatures { 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() };
523 /// Read a NodeFeatures from a byte array, created by NodeFeatures_write
524 pub extern "C" fn NodeFeatures_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeFeaturesDecodeErrorZ {
525 let res: Result<lightning::ln::features::NodeFeatures, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
526 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::features::NodeFeatures { 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() };
530 /// Read a ChannelFeatures from a byte array, created by ChannelFeatures_write
531 pub extern "C" fn ChannelFeatures_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelFeaturesDecodeErrorZ {
532 let res: Result<lightning::ln::features::ChannelFeatures, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
533 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::features::ChannelFeatures { 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() };
537 /// Read a InvoiceFeatures from a byte array, created by InvoiceFeatures_write
538 pub extern "C" fn InvoiceFeatures_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_InvoiceFeaturesDecodeErrorZ {
539 let res: Result<lightning::ln::features::InvoiceFeatures, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
540 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::features::InvoiceFeatures { 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() };