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 impl Clone for InitFeatures {
38 fn clone(&self) -> Self {
40 inner: if <*mut nativeInitFeatures>::is_null(self.inner) { std::ptr::null_mut() } else {
41 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
47 /// Used only if an object of this type is returned as a trait impl by a method
48 pub(crate) extern "C" fn InitFeatures_clone_void(this_ptr: *const c_void) -> *mut c_void {
49 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInitFeatures)).clone() })) as *mut c_void
52 /// Creates a copy of the InitFeatures
53 pub extern "C" fn InitFeatures_clone(orig: &InitFeatures) -> InitFeatures {
56 impl Clone for NodeFeatures {
57 fn clone(&self) -> Self {
59 inner: if <*mut nativeNodeFeatures>::is_null(self.inner) { std::ptr::null_mut() } else {
60 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
66 /// Used only if an object of this type is returned as a trait impl by a method
67 pub(crate) extern "C" fn NodeFeatures_clone_void(this_ptr: *const c_void) -> *mut c_void {
68 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeFeatures)).clone() })) as *mut c_void
71 /// Creates a copy of the NodeFeatures
72 pub extern "C" fn NodeFeatures_clone(orig: &NodeFeatures) -> NodeFeatures {
75 impl Clone for ChannelFeatures {
76 fn clone(&self) -> Self {
78 inner: if <*mut nativeChannelFeatures>::is_null(self.inner) { std::ptr::null_mut() } else {
79 Box::into_raw(Box::new(unsafe { &*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 ChannelFeatures_clone_void(this_ptr: *const c_void) -> *mut c_void {
87 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelFeatures)).clone() })) as *mut c_void
90 /// Creates a copy of the ChannelFeatures
91 pub extern "C" fn ChannelFeatures_clone(orig: &ChannelFeatures) -> ChannelFeatures {
94 impl Clone for InvoiceFeatures {
95 fn clone(&self) -> Self {
97 inner: if <*mut nativeInvoiceFeatures>::is_null(self.inner) { std::ptr::null_mut() } else {
98 Box::into_raw(Box::new(unsafe { &*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 InvoiceFeatures_clone_void(this_ptr: *const c_void) -> *mut c_void {
106 Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoiceFeatures)).clone() })) as *mut c_void
109 /// Creates a copy of the InvoiceFeatures
110 pub extern "C" fn InvoiceFeatures_clone(orig: &InvoiceFeatures) -> InvoiceFeatures {
114 use lightning::ln::features::InitFeatures as nativeInitFeaturesImport;
115 type nativeInitFeatures = nativeInitFeaturesImport;
117 /// Features used within an `init` message.
120 pub struct InitFeatures {
121 /// A pointer to the opaque Rust object.
123 /// Nearly everywhere, inner must be non-null, however in places where
124 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
125 pub inner: *mut nativeInitFeatures,
126 /// Indicates that this is the only struct which contains the same pointer.
128 /// Rust functions which take ownership of an object provided via an argument require
129 /// this to be true and invalidate the object pointed to by inner.
133 impl Drop for InitFeatures {
135 if self.is_owned && !<*mut nativeInitFeatures>::is_null(self.inner) {
136 let _ = unsafe { Box::from_raw(self.inner) };
140 /// Frees any resources used by the InitFeatures, if is_owned is set and inner is non-NULL.
142 pub extern "C" fn InitFeatures_free(this_obj: InitFeatures) { }
144 /// Used only if an object of this type is returned as a trait impl by a method
145 extern "C" fn InitFeatures_free_void(this_ptr: *mut c_void) {
146 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInitFeatures); }
149 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
151 pub(crate) fn take_inner(mut self) -> *mut nativeInitFeatures {
152 assert!(self.is_owned);
153 let ret = self.inner;
154 self.inner = std::ptr::null_mut();
159 use lightning::ln::features::NodeFeatures as nativeNodeFeaturesImport;
160 type nativeNodeFeatures = nativeNodeFeaturesImport;
162 /// Features used within a `node_announcement` message.
165 pub struct NodeFeatures {
166 /// A pointer to the opaque Rust object.
168 /// Nearly everywhere, inner must be non-null, however in places where
169 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
170 pub inner: *mut nativeNodeFeatures,
171 /// Indicates that this is the only struct which contains the same pointer.
173 /// Rust functions which take ownership of an object provided via an argument require
174 /// this to be true and invalidate the object pointed to by inner.
178 impl Drop for NodeFeatures {
180 if self.is_owned && !<*mut nativeNodeFeatures>::is_null(self.inner) {
181 let _ = unsafe { Box::from_raw(self.inner) };
185 /// Frees any resources used by the NodeFeatures, if is_owned is set and inner is non-NULL.
187 pub extern "C" fn NodeFeatures_free(this_obj: NodeFeatures) { }
189 /// Used only if an object of this type is returned as a trait impl by a method
190 extern "C" fn NodeFeatures_free_void(this_ptr: *mut c_void) {
191 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeFeatures); }
194 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
196 pub(crate) fn take_inner(mut self) -> *mut nativeNodeFeatures {
197 assert!(self.is_owned);
198 let ret = self.inner;
199 self.inner = std::ptr::null_mut();
204 use lightning::ln::features::ChannelFeatures as nativeChannelFeaturesImport;
205 type nativeChannelFeatures = nativeChannelFeaturesImport;
207 /// Features used within a `channel_announcement` message.
210 pub struct ChannelFeatures {
211 /// A pointer to the opaque Rust object.
213 /// Nearly everywhere, inner must be non-null, however in places where
214 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
215 pub inner: *mut nativeChannelFeatures,
216 /// Indicates that this is the only struct which contains the same pointer.
218 /// Rust functions which take ownership of an object provided via an argument require
219 /// this to be true and invalidate the object pointed to by inner.
223 impl Drop for ChannelFeatures {
225 if self.is_owned && !<*mut nativeChannelFeatures>::is_null(self.inner) {
226 let _ = unsafe { Box::from_raw(self.inner) };
230 /// Frees any resources used by the ChannelFeatures, if is_owned is set and inner is non-NULL.
232 pub extern "C" fn ChannelFeatures_free(this_obj: ChannelFeatures) { }
234 /// Used only if an object of this type is returned as a trait impl by a method
235 extern "C" fn ChannelFeatures_free_void(this_ptr: *mut c_void) {
236 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelFeatures); }
239 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
240 impl ChannelFeatures {
241 pub(crate) fn take_inner(mut self) -> *mut nativeChannelFeatures {
242 assert!(self.is_owned);
243 let ret = self.inner;
244 self.inner = std::ptr::null_mut();
249 use lightning::ln::features::InvoiceFeatures as nativeInvoiceFeaturesImport;
250 type nativeInvoiceFeatures = nativeInvoiceFeaturesImport;
252 /// Features used within an invoice.
255 pub struct InvoiceFeatures {
256 /// A pointer to the opaque Rust object.
258 /// Nearly everywhere, inner must be non-null, however in places where
259 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
260 pub inner: *mut nativeInvoiceFeatures,
261 /// Indicates that this is the only struct which contains the same pointer.
263 /// Rust functions which take ownership of an object provided via an argument require
264 /// this to be true and invalidate the object pointed to by inner.
268 impl Drop for InvoiceFeatures {
270 if self.is_owned && !<*mut nativeInvoiceFeatures>::is_null(self.inner) {
271 let _ = unsafe { Box::from_raw(self.inner) };
275 /// Frees any resources used by the InvoiceFeatures, if is_owned is set and inner is non-NULL.
277 pub extern "C" fn InvoiceFeatures_free(this_obj: InvoiceFeatures) { }
279 /// Used only if an object of this type is returned as a trait impl by a method
280 extern "C" fn InvoiceFeatures_free_void(this_ptr: *mut c_void) {
281 unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoiceFeatures); }
284 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
285 impl InvoiceFeatures {
286 pub(crate) fn take_inner(mut self) -> *mut nativeInvoiceFeatures {
287 assert!(self.is_owned);
288 let ret = self.inner;
289 self.inner = std::ptr::null_mut();
293 /// Create a blank Features with no features set
296 pub extern "C" fn InitFeatures_empty() -> InitFeatures {
297 let mut ret = lightning::ln::features::InitFeatures::empty();
298 InitFeatures { inner: Box::into_raw(Box::new(ret)), is_owned: true }
301 /// Creates a Features with the bits set which are known by the implementation
304 pub extern "C" fn InitFeatures_known() -> InitFeatures {
305 let mut ret = lightning::ln::features::InitFeatures::known();
306 InitFeatures { inner: Box::into_raw(Box::new(ret)), is_owned: true }
309 /// Create a blank Features with no features set
312 pub extern "C" fn NodeFeatures_empty() -> NodeFeatures {
313 let mut ret = lightning::ln::features::NodeFeatures::empty();
314 NodeFeatures { inner: Box::into_raw(Box::new(ret)), is_owned: true }
317 /// Creates a Features with the bits set which are known by the implementation
320 pub extern "C" fn NodeFeatures_known() -> NodeFeatures {
321 let mut ret = lightning::ln::features::NodeFeatures::known();
322 NodeFeatures { inner: Box::into_raw(Box::new(ret)), is_owned: true }
325 /// Create a blank Features with no features set
328 pub extern "C" fn ChannelFeatures_empty() -> ChannelFeatures {
329 let mut ret = lightning::ln::features::ChannelFeatures::empty();
330 ChannelFeatures { inner: Box::into_raw(Box::new(ret)), is_owned: true }
333 /// Creates a Features with the bits set which are known by the implementation
336 pub extern "C" fn ChannelFeatures_known() -> ChannelFeatures {
337 let mut ret = lightning::ln::features::ChannelFeatures::known();
338 ChannelFeatures { inner: Box::into_raw(Box::new(ret)), is_owned: true }
341 /// Create a blank Features with no features set
344 pub extern "C" fn InvoiceFeatures_empty() -> InvoiceFeatures {
345 let mut ret = lightning::ln::features::InvoiceFeatures::empty();
346 InvoiceFeatures { inner: Box::into_raw(Box::new(ret)), is_owned: true }
349 /// Creates a Features with the bits set which are known by the implementation
352 pub extern "C" fn InvoiceFeatures_known() -> InvoiceFeatures {
353 let mut ret = lightning::ln::features::InvoiceFeatures::known();
354 InvoiceFeatures { inner: Box::into_raw(Box::new(ret)), is_owned: true }
358 /// Serialize the InitFeatures object into a byte array which can be read by InitFeatures_read
359 pub extern "C" fn InitFeatures_write(obj: &InitFeatures) -> crate::c_types::derived::CVec_u8Z {
360 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
363 pub(crate) extern "C" fn InitFeatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
364 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInitFeatures) })
367 /// Serialize the NodeFeatures object into a byte array which can be read by NodeFeatures_read
368 pub extern "C" fn NodeFeatures_write(obj: &NodeFeatures) -> crate::c_types::derived::CVec_u8Z {
369 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
372 pub(crate) extern "C" fn NodeFeatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
373 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeFeatures) })
376 /// Serialize the ChannelFeatures object into a byte array which can be read by ChannelFeatures_read
377 pub extern "C" fn ChannelFeatures_write(obj: &ChannelFeatures) -> crate::c_types::derived::CVec_u8Z {
378 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
381 pub(crate) extern "C" fn ChannelFeatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
382 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelFeatures) })
385 /// Serialize the InvoiceFeatures object into a byte array which can be read by InvoiceFeatures_read
386 pub extern "C" fn InvoiceFeatures_write(obj: &InvoiceFeatures) -> crate::c_types::derived::CVec_u8Z {
387 crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
390 pub(crate) extern "C" fn InvoiceFeatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
391 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInvoiceFeatures) })
394 /// Read a InitFeatures from a byte array, created by InitFeatures_write
395 pub extern "C" fn InitFeatures_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_InitFeaturesDecodeErrorZ {
396 let res = crate::c_types::deserialize_obj(ser);
397 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() };
401 /// Read a NodeFeatures from a byte array, created by NodeFeatures_write
402 pub extern "C" fn NodeFeatures_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeFeaturesDecodeErrorZ {
403 let res = crate::c_types::deserialize_obj(ser);
404 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() };
408 /// Read a ChannelFeatures from a byte array, created by ChannelFeatures_write
409 pub extern "C" fn ChannelFeatures_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelFeaturesDecodeErrorZ {
410 let res = crate::c_types::deserialize_obj(ser);
411 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() };
415 /// Read a InvoiceFeatures from a byte array, created by InvoiceFeatures_write
416 pub extern "C" fn InvoiceFeatures_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_InvoiceFeaturesDecodeErrorZ {
417 let res = crate::c_types::deserialize_obj(ser);
418 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() };