Merge pull request #18 from TheBlueMatt/2021-04-invoice-incl
[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::str::FromStr;
25 use std::ffi::c_void;
26 use bitcoin::hashes::Hash;
27 use crate::c_types::*;
28
29 mod sealed {
30
31 use std::str::FromStr;
32 use std::ffi::c_void;
33 use bitcoin::hashes::Hash;
34 use crate::c_types::*;
35
36 }
37 impl Clone for InitFeatures {
38         fn clone(&self) -> Self {
39                 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())) },
42                         is_owned: true,
43                 }
44         }
45 }
46 #[allow(unused)]
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
50 }
51 #[no_mangle]
52 /// Creates a copy of the InitFeatures
53 pub extern "C" fn InitFeatures_clone(orig: &InitFeatures) -> InitFeatures {
54         orig.clone()
55 }
56 impl Clone for NodeFeatures {
57         fn clone(&self) -> Self {
58                 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())) },
61                         is_owned: true,
62                 }
63         }
64 }
65 #[allow(unused)]
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
69 }
70 #[no_mangle]
71 /// Creates a copy of the NodeFeatures
72 pub extern "C" fn NodeFeatures_clone(orig: &NodeFeatures) -> NodeFeatures {
73         orig.clone()
74 }
75 impl Clone for ChannelFeatures {
76         fn clone(&self) -> Self {
77                 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())) },
80                         is_owned: true,
81                 }
82         }
83 }
84 #[allow(unused)]
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
88 }
89 #[no_mangle]
90 /// Creates a copy of the ChannelFeatures
91 pub extern "C" fn ChannelFeatures_clone(orig: &ChannelFeatures) -> ChannelFeatures {
92         orig.clone()
93 }
94 impl Clone for InvoiceFeatures {
95         fn clone(&self) -> Self {
96                 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())) },
99                         is_owned: true,
100                 }
101         }
102 }
103 #[allow(unused)]
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
107 }
108 #[no_mangle]
109 /// Creates a copy of the InvoiceFeatures
110 pub extern "C" fn InvoiceFeatures_clone(orig: &InvoiceFeatures) -> InvoiceFeatures {
111         orig.clone()
112 }
113
114 use lightning::ln::features::InitFeatures as nativeInitFeaturesImport;
115 type nativeInitFeatures = nativeInitFeaturesImport;
116
117 /// Features used within an `init` message.
118 #[must_use]
119 #[repr(C)]
120 pub struct InitFeatures {
121         /// A pointer to the opaque Rust object.
122
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.
127
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.
130         pub is_owned: bool,
131 }
132
133 impl Drop for InitFeatures {
134         fn drop(&mut self) {
135                 if self.is_owned && !<*mut nativeInitFeatures>::is_null(self.inner) {
136                         let _ = unsafe { Box::from_raw(self.inner) };
137                 }
138         }
139 }
140 /// Frees any resources used by the InitFeatures, if is_owned is set and inner is non-NULL.
141 #[no_mangle]
142 pub extern "C" fn InitFeatures_free(this_obj: InitFeatures) { }
143 #[allow(unused)]
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); }
147 }
148 #[allow(unused)]
149 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
150 impl InitFeatures {
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();
155                 ret
156         }
157 }
158
159 use lightning::ln::features::NodeFeatures as nativeNodeFeaturesImport;
160 type nativeNodeFeatures = nativeNodeFeaturesImport;
161
162 /// Features used within a `node_announcement` message.
163 #[must_use]
164 #[repr(C)]
165 pub struct NodeFeatures {
166         /// A pointer to the opaque Rust object.
167
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.
172
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.
175         pub is_owned: bool,
176 }
177
178 impl Drop for NodeFeatures {
179         fn drop(&mut self) {
180                 if self.is_owned && !<*mut nativeNodeFeatures>::is_null(self.inner) {
181                         let _ = unsafe { Box::from_raw(self.inner) };
182                 }
183         }
184 }
185 /// Frees any resources used by the NodeFeatures, if is_owned is set and inner is non-NULL.
186 #[no_mangle]
187 pub extern "C" fn NodeFeatures_free(this_obj: NodeFeatures) { }
188 #[allow(unused)]
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); }
192 }
193 #[allow(unused)]
194 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
195 impl NodeFeatures {
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();
200                 ret
201         }
202 }
203
204 use lightning::ln::features::ChannelFeatures as nativeChannelFeaturesImport;
205 type nativeChannelFeatures = nativeChannelFeaturesImport;
206
207 /// Features used within a `channel_announcement` message.
208 #[must_use]
209 #[repr(C)]
210 pub struct ChannelFeatures {
211         /// A pointer to the opaque Rust object.
212
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.
217
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.
220         pub is_owned: bool,
221 }
222
223 impl Drop for ChannelFeatures {
224         fn drop(&mut self) {
225                 if self.is_owned && !<*mut nativeChannelFeatures>::is_null(self.inner) {
226                         let _ = unsafe { Box::from_raw(self.inner) };
227                 }
228         }
229 }
230 /// Frees any resources used by the ChannelFeatures, if is_owned is set and inner is non-NULL.
231 #[no_mangle]
232 pub extern "C" fn ChannelFeatures_free(this_obj: ChannelFeatures) { }
233 #[allow(unused)]
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); }
237 }
238 #[allow(unused)]
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();
245                 ret
246         }
247 }
248
249 use lightning::ln::features::InvoiceFeatures as nativeInvoiceFeaturesImport;
250 type nativeInvoiceFeatures = nativeInvoiceFeaturesImport;
251
252 /// Features used within an invoice.
253 #[must_use]
254 #[repr(C)]
255 pub struct InvoiceFeatures {
256         /// A pointer to the opaque Rust object.
257
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.
262
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.
265         pub is_owned: bool,
266 }
267
268 impl Drop for InvoiceFeatures {
269         fn drop(&mut self) {
270                 if self.is_owned && !<*mut nativeInvoiceFeatures>::is_null(self.inner) {
271                         let _ = unsafe { Box::from_raw(self.inner) };
272                 }
273         }
274 }
275 /// Frees any resources used by the InvoiceFeatures, if is_owned is set and inner is non-NULL.
276 #[no_mangle]
277 pub extern "C" fn InvoiceFeatures_free(this_obj: InvoiceFeatures) { }
278 #[allow(unused)]
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); }
282 }
283 #[allow(unused)]
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();
290                 ret
291         }
292 }
293 /// Create a blank Features with no features set
294 #[must_use]
295 #[no_mangle]
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 }
299 }
300
301 /// Creates a Features with the bits set which are known by the implementation
302 #[must_use]
303 #[no_mangle]
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 }
307 }
308
309 /// Create a blank Features with no features set
310 #[must_use]
311 #[no_mangle]
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 }
315 }
316
317 /// Creates a Features with the bits set which are known by the implementation
318 #[must_use]
319 #[no_mangle]
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 }
323 }
324
325 /// Create a blank Features with no features set
326 #[must_use]
327 #[no_mangle]
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 }
331 }
332
333 /// Creates a Features with the bits set which are known by the implementation
334 #[must_use]
335 #[no_mangle]
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 }
339 }
340
341 /// Create a blank Features with no features set
342 #[must_use]
343 #[no_mangle]
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 }
347 }
348
349 /// Creates a Features with the bits set which are known by the implementation
350 #[must_use]
351 #[no_mangle]
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 }
355 }
356
357 #[no_mangle]
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 })
361 }
362 #[no_mangle]
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) })
365 }
366 #[no_mangle]
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 })
370 }
371 #[no_mangle]
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) })
374 }
375 #[no_mangle]
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 })
379 }
380 #[no_mangle]
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) })
383 }
384 #[no_mangle]
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 })
388 }
389 #[no_mangle]
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) })
392 }
393 #[no_mangle]
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() };
398         local_res
399 }
400 #[no_mangle]
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() };
405         local_res
406 }
407 #[no_mangle]
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() };
412         local_res
413 }
414 #[no_mangle]
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() };
419         local_res
420 }