Update auto-generated bindings with new module structure
[ldk-c-bindings] / lightning-c-bindings / src / lightning / ln / features.rs
1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
3 //
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.
8
9 //! Feature flag definitions for the Lightning protocol according to [BOLT #9].
10 //!
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).
15 //!
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.
20 //!
21 //! [BOLT #9]: https://github.com/lightningnetwork/lightning-rfc/blob/master/09-features.md
22 //! [messages]: crate::ln::msgs
23
24 use std::ffi::c_void;
25 use bitcoin::hashes::Hash;
26 use crate::c_types::*;
27
28 impl Clone for InitFeatures {
29         fn clone(&self) -> Self {
30                 Self {
31                         inner: if <*mut nativeInitFeatures>::is_null(self.inner) { std::ptr::null_mut() } else {
32                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
33                         is_owned: true,
34                 }
35         }
36 }
37 #[allow(unused)]
38 /// Used only if an object of this type is returned as a trait impl by a method
39 pub(crate) extern "C" fn InitFeatures_clone_void(this_ptr: *const c_void) -> *mut c_void {
40         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInitFeatures)).clone() })) as *mut c_void
41 }
42 #[no_mangle]
43 /// Creates a copy of the InitFeatures
44 pub extern "C" fn InitFeatures_clone(orig: &InitFeatures) -> InitFeatures {
45         orig.clone()
46 }
47 impl Clone for NodeFeatures {
48         fn clone(&self) -> Self {
49                 Self {
50                         inner: if <*mut nativeNodeFeatures>::is_null(self.inner) { std::ptr::null_mut() } else {
51                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
52                         is_owned: true,
53                 }
54         }
55 }
56 #[allow(unused)]
57 /// Used only if an object of this type is returned as a trait impl by a method
58 pub(crate) extern "C" fn NodeFeatures_clone_void(this_ptr: *const c_void) -> *mut c_void {
59         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeFeatures)).clone() })) as *mut c_void
60 }
61 #[no_mangle]
62 /// Creates a copy of the NodeFeatures
63 pub extern "C" fn NodeFeatures_clone(orig: &NodeFeatures) -> NodeFeatures {
64         orig.clone()
65 }
66 impl Clone for ChannelFeatures {
67         fn clone(&self) -> Self {
68                 Self {
69                         inner: if <*mut nativeChannelFeatures>::is_null(self.inner) { std::ptr::null_mut() } else {
70                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
71                         is_owned: true,
72                 }
73         }
74 }
75 #[allow(unused)]
76 /// Used only if an object of this type is returned as a trait impl by a method
77 pub(crate) extern "C" fn ChannelFeatures_clone_void(this_ptr: *const c_void) -> *mut c_void {
78         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelFeatures)).clone() })) as *mut c_void
79 }
80 #[no_mangle]
81 /// Creates a copy of the ChannelFeatures
82 pub extern "C" fn ChannelFeatures_clone(orig: &ChannelFeatures) -> ChannelFeatures {
83         orig.clone()
84 }
85 impl Clone for InvoiceFeatures {
86         fn clone(&self) -> Self {
87                 Self {
88                         inner: if <*mut nativeInvoiceFeatures>::is_null(self.inner) { std::ptr::null_mut() } else {
89                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
90                         is_owned: true,
91                 }
92         }
93 }
94 #[allow(unused)]
95 /// Used only if an object of this type is returned as a trait impl by a method
96 pub(crate) extern "C" fn InvoiceFeatures_clone_void(this_ptr: *const c_void) -> *mut c_void {
97         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInvoiceFeatures)).clone() })) as *mut c_void
98 }
99 #[no_mangle]
100 /// Creates a copy of the InvoiceFeatures
101 pub extern "C" fn InvoiceFeatures_clone(orig: &InvoiceFeatures) -> InvoiceFeatures {
102         orig.clone()
103 }
104
105 use lightning::ln::features::InitFeatures as nativeInitFeaturesImport;
106 type nativeInitFeatures = nativeInitFeaturesImport;
107
108 /// Features used within an `init` message.
109 #[must_use]
110 #[repr(C)]
111 pub struct InitFeatures {
112         /// A pointer to the opaque Rust object.
113
114         /// Nearly everywhere, inner must be non-null, however in places where
115         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
116         pub inner: *mut nativeInitFeatures,
117         /// Indicates that this is the only struct which contains the same pointer.
118
119         /// Rust functions which take ownership of an object provided via an argument require
120         /// this to be true and invalidate the object pointed to by inner.
121         pub is_owned: bool,
122 }
123
124 impl Drop for InitFeatures {
125         fn drop(&mut self) {
126                 if self.is_owned && !<*mut nativeInitFeatures>::is_null(self.inner) {
127                         let _ = unsafe { Box::from_raw(self.inner) };
128                 }
129         }
130 }
131 /// Frees any resources used by the InitFeatures, if is_owned is set and inner is non-NULL.
132 #[no_mangle]
133 pub extern "C" fn InitFeatures_free(this_obj: InitFeatures) { }
134 #[allow(unused)]
135 /// Used only if an object of this type is returned as a trait impl by a method
136 extern "C" fn InitFeatures_free_void(this_ptr: *mut c_void) {
137         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInitFeatures); }
138 }
139 #[allow(unused)]
140 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
141 impl InitFeatures {
142         pub(crate) fn take_inner(mut self) -> *mut nativeInitFeatures {
143                 assert!(self.is_owned);
144                 let ret = self.inner;
145                 self.inner = std::ptr::null_mut();
146                 ret
147         }
148 }
149
150 use lightning::ln::features::NodeFeatures as nativeNodeFeaturesImport;
151 type nativeNodeFeatures = nativeNodeFeaturesImport;
152
153 /// Features used within a `node_announcement` message.
154 #[must_use]
155 #[repr(C)]
156 pub struct NodeFeatures {
157         /// A pointer to the opaque Rust object.
158
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 nativeNodeFeatures,
162         /// Indicates that this is the only struct which contains the same pointer.
163
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.
166         pub is_owned: bool,
167 }
168
169 impl Drop for NodeFeatures {
170         fn drop(&mut self) {
171                 if self.is_owned && !<*mut nativeNodeFeatures>::is_null(self.inner) {
172                         let _ = unsafe { Box::from_raw(self.inner) };
173                 }
174         }
175 }
176 /// Frees any resources used by the NodeFeatures, if is_owned is set and inner is non-NULL.
177 #[no_mangle]
178 pub extern "C" fn NodeFeatures_free(this_obj: NodeFeatures) { }
179 #[allow(unused)]
180 /// Used only if an object of this type is returned as a trait impl by a method
181 extern "C" fn NodeFeatures_free_void(this_ptr: *mut c_void) {
182         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeFeatures); }
183 }
184 #[allow(unused)]
185 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
186 impl NodeFeatures {
187         pub(crate) fn take_inner(mut self) -> *mut nativeNodeFeatures {
188                 assert!(self.is_owned);
189                 let ret = self.inner;
190                 self.inner = std::ptr::null_mut();
191                 ret
192         }
193 }
194
195 use lightning::ln::features::ChannelFeatures as nativeChannelFeaturesImport;
196 type nativeChannelFeatures = nativeChannelFeaturesImport;
197
198 /// Features used within a `channel_announcement` message.
199 #[must_use]
200 #[repr(C)]
201 pub struct ChannelFeatures {
202         /// A pointer to the opaque Rust object.
203
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 nativeChannelFeatures,
207         /// Indicates that this is the only struct which contains the same pointer.
208
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.
211         pub is_owned: bool,
212 }
213
214 impl Drop for ChannelFeatures {
215         fn drop(&mut self) {
216                 if self.is_owned && !<*mut nativeChannelFeatures>::is_null(self.inner) {
217                         let _ = unsafe { Box::from_raw(self.inner) };
218                 }
219         }
220 }
221 /// Frees any resources used by the ChannelFeatures, if is_owned is set and inner is non-NULL.
222 #[no_mangle]
223 pub extern "C" fn ChannelFeatures_free(this_obj: ChannelFeatures) { }
224 #[allow(unused)]
225 /// Used only if an object of this type is returned as a trait impl by a method
226 extern "C" fn ChannelFeatures_free_void(this_ptr: *mut c_void) {
227         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelFeatures); }
228 }
229 #[allow(unused)]
230 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
231 impl ChannelFeatures {
232         pub(crate) fn take_inner(mut self) -> *mut nativeChannelFeatures {
233                 assert!(self.is_owned);
234                 let ret = self.inner;
235                 self.inner = std::ptr::null_mut();
236                 ret
237         }
238 }
239
240 use lightning::ln::features::InvoiceFeatures as nativeInvoiceFeaturesImport;
241 type nativeInvoiceFeatures = nativeInvoiceFeaturesImport;
242
243 /// Features used within an invoice.
244 #[must_use]
245 #[repr(C)]
246 pub struct InvoiceFeatures {
247         /// A pointer to the opaque Rust object.
248
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 nativeInvoiceFeatures,
252         /// Indicates that this is the only struct which contains the same pointer.
253
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.
256         pub is_owned: bool,
257 }
258
259 impl Drop for InvoiceFeatures {
260         fn drop(&mut self) {
261                 if self.is_owned && !<*mut nativeInvoiceFeatures>::is_null(self.inner) {
262                         let _ = unsafe { Box::from_raw(self.inner) };
263                 }
264         }
265 }
266 /// Frees any resources used by the InvoiceFeatures, if is_owned is set and inner is non-NULL.
267 #[no_mangle]
268 pub extern "C" fn InvoiceFeatures_free(this_obj: InvoiceFeatures) { }
269 #[allow(unused)]
270 /// Used only if an object of this type is returned as a trait impl by a method
271 extern "C" fn InvoiceFeatures_free_void(this_ptr: *mut c_void) {
272         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeInvoiceFeatures); }
273 }
274 #[allow(unused)]
275 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
276 impl InvoiceFeatures {
277         pub(crate) fn take_inner(mut self) -> *mut nativeInvoiceFeatures {
278                 assert!(self.is_owned);
279                 let ret = self.inner;
280                 self.inner = std::ptr::null_mut();
281                 ret
282         }
283 }
284 /// Create a blank Features with no features set
285 #[must_use]
286 #[no_mangle]
287 pub extern "C" fn InitFeatures_empty() -> InitFeatures {
288         let mut ret = lightning::ln::features::InitFeatures::empty();
289         InitFeatures { inner: Box::into_raw(Box::new(ret)), is_owned: true }
290 }
291
292 /// Creates a Features with the bits set which are known by the implementation
293 #[must_use]
294 #[no_mangle]
295 pub extern "C" fn InitFeatures_known() -> InitFeatures {
296         let mut ret = lightning::ln::features::InitFeatures::known();
297         InitFeatures { inner: Box::into_raw(Box::new(ret)), is_owned: true }
298 }
299
300 /// Create a blank Features with no features set
301 #[must_use]
302 #[no_mangle]
303 pub extern "C" fn NodeFeatures_empty() -> NodeFeatures {
304         let mut ret = lightning::ln::features::NodeFeatures::empty();
305         NodeFeatures { inner: Box::into_raw(Box::new(ret)), is_owned: true }
306 }
307
308 /// Creates a Features with the bits set which are known by the implementation
309 #[must_use]
310 #[no_mangle]
311 pub extern "C" fn NodeFeatures_known() -> NodeFeatures {
312         let mut ret = lightning::ln::features::NodeFeatures::known();
313         NodeFeatures { inner: Box::into_raw(Box::new(ret)), is_owned: true }
314 }
315
316 /// Create a blank Features with no features set
317 #[must_use]
318 #[no_mangle]
319 pub extern "C" fn ChannelFeatures_empty() -> ChannelFeatures {
320         let mut ret = lightning::ln::features::ChannelFeatures::empty();
321         ChannelFeatures { inner: Box::into_raw(Box::new(ret)), is_owned: true }
322 }
323
324 /// Creates a Features with the bits set which are known by the implementation
325 #[must_use]
326 #[no_mangle]
327 pub extern "C" fn ChannelFeatures_known() -> ChannelFeatures {
328         let mut ret = lightning::ln::features::ChannelFeatures::known();
329         ChannelFeatures { inner: Box::into_raw(Box::new(ret)), is_owned: true }
330 }
331
332 /// Create a blank Features with no features set
333 #[must_use]
334 #[no_mangle]
335 pub extern "C" fn InvoiceFeatures_empty() -> InvoiceFeatures {
336         let mut ret = lightning::ln::features::InvoiceFeatures::empty();
337         InvoiceFeatures { inner: Box::into_raw(Box::new(ret)), is_owned: true }
338 }
339
340 /// Creates a Features with the bits set which are known by the implementation
341 #[must_use]
342 #[no_mangle]
343 pub extern "C" fn InvoiceFeatures_known() -> InvoiceFeatures {
344         let mut ret = lightning::ln::features::InvoiceFeatures::known();
345         InvoiceFeatures { inner: Box::into_raw(Box::new(ret)), is_owned: true }
346 }
347
348 #[no_mangle]
349 /// Serialize the InitFeatures object into a byte array which can be read by InitFeatures_read
350 pub extern "C" fn InitFeatures_write(obj: &InitFeatures) -> crate::c_types::derived::CVec_u8Z {
351         crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
352 }
353 #[no_mangle]
354 pub(crate) extern "C" fn InitFeatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
355         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInitFeatures) })
356 }
357 #[no_mangle]
358 /// Serialize the NodeFeatures object into a byte array which can be read by NodeFeatures_read
359 pub extern "C" fn NodeFeatures_write(obj: &NodeFeatures) -> crate::c_types::derived::CVec_u8Z {
360         crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
361 }
362 #[no_mangle]
363 pub(crate) extern "C" fn NodeFeatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
364         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeFeatures) })
365 }
366 #[no_mangle]
367 /// Serialize the ChannelFeatures object into a byte array which can be read by ChannelFeatures_read
368 pub extern "C" fn ChannelFeatures_write(obj: &ChannelFeatures) -> crate::c_types::derived::CVec_u8Z {
369         crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
370 }
371 #[no_mangle]
372 pub(crate) extern "C" fn ChannelFeatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
373         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelFeatures) })
374 }
375 #[no_mangle]
376 /// Serialize the InvoiceFeatures object into a byte array which can be read by InvoiceFeatures_read
377 pub extern "C" fn InvoiceFeatures_write(obj: &InvoiceFeatures) -> crate::c_types::derived::CVec_u8Z {
378         crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
379 }
380 #[no_mangle]
381 pub(crate) extern "C" fn InvoiceFeatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
382         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInvoiceFeatures) })
383 }
384 #[no_mangle]
385 /// Read a InitFeatures from a byte array, created by InitFeatures_write
386 pub extern "C" fn InitFeatures_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_InitFeaturesDecodeErrorZ {
387         let res = crate::c_types::deserialize_obj(ser);
388         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() };
389         local_res
390 }
391 #[no_mangle]
392 /// Read a NodeFeatures from a byte array, created by NodeFeatures_write
393 pub extern "C" fn NodeFeatures_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeFeaturesDecodeErrorZ {
394         let res = crate::c_types::deserialize_obj(ser);
395         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() };
396         local_res
397 }
398 #[no_mangle]
399 /// Read a ChannelFeatures from a byte array, created by ChannelFeatures_write
400 pub extern "C" fn ChannelFeatures_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelFeaturesDecodeErrorZ {
401         let res = crate::c_types::deserialize_obj(ser);
402         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() };
403         local_res
404 }
405 #[no_mangle]
406 /// Read a InvoiceFeatures from a byte array, created by InvoiceFeatures_write
407 pub extern "C" fn InvoiceFeatures_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_InvoiceFeaturesDecodeErrorZ {
408         let res = crate::c_types::deserialize_obj(ser);
409         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() };
410         local_res
411 }