Merge pull request #18 from TheBlueMatt/2021-04-invoice-incl
[ldk-c-bindings] / lightning-c-bindings / src / lightning / routing / network_graph.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 //! The top-level network map tracking logic lives here.
10
11 use std::str::FromStr;
12 use std::ffi::c_void;
13 use bitcoin::hashes::Hash;
14 use crate::c_types::*;
15
16
17 use lightning::routing::network_graph::NetworkGraph as nativeNetworkGraphImport;
18 type nativeNetworkGraph = nativeNetworkGraphImport;
19
20 /// Represents the network as nodes and channels between them
21 #[must_use]
22 #[repr(C)]
23 pub struct NetworkGraph {
24         /// A pointer to the opaque Rust object.
25
26         /// Nearly everywhere, inner must be non-null, however in places where
27         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
28         pub inner: *mut nativeNetworkGraph,
29         /// Indicates that this is the only struct which contains the same pointer.
30
31         /// Rust functions which take ownership of an object provided via an argument require
32         /// this to be true and invalidate the object pointed to by inner.
33         pub is_owned: bool,
34 }
35
36 impl Drop for NetworkGraph {
37         fn drop(&mut self) {
38                 if self.is_owned && !<*mut nativeNetworkGraph>::is_null(self.inner) {
39                         let _ = unsafe { Box::from_raw(self.inner) };
40                 }
41         }
42 }
43 /// Frees any resources used by the NetworkGraph, if is_owned is set and inner is non-NULL.
44 #[no_mangle]
45 pub extern "C" fn NetworkGraph_free(this_obj: NetworkGraph) { }
46 #[allow(unused)]
47 /// Used only if an object of this type is returned as a trait impl by a method
48 extern "C" fn NetworkGraph_free_void(this_ptr: *mut c_void) {
49         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNetworkGraph); }
50 }
51 #[allow(unused)]
52 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
53 impl NetworkGraph {
54         pub(crate) fn take_inner(mut self) -> *mut nativeNetworkGraph {
55                 assert!(self.is_owned);
56                 let ret = self.inner;
57                 self.inner = std::ptr::null_mut();
58                 ret
59         }
60 }
61 impl Clone for NetworkGraph {
62         fn clone(&self) -> Self {
63                 Self {
64                         inner: if <*mut nativeNetworkGraph>::is_null(self.inner) { std::ptr::null_mut() } else {
65                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
66                         is_owned: true,
67                 }
68         }
69 }
70 #[allow(unused)]
71 /// Used only if an object of this type is returned as a trait impl by a method
72 pub(crate) extern "C" fn NetworkGraph_clone_void(this_ptr: *const c_void) -> *mut c_void {
73         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNetworkGraph)).clone() })) as *mut c_void
74 }
75 #[no_mangle]
76 /// Creates a copy of the NetworkGraph
77 pub extern "C" fn NetworkGraph_clone(orig: &NetworkGraph) -> NetworkGraph {
78         orig.clone()
79 }
80
81 use lightning::routing::network_graph::LockedNetworkGraph as nativeLockedNetworkGraphImport;
82 type nativeLockedNetworkGraph = nativeLockedNetworkGraphImport<'static>;
83
84 /// A simple newtype for RwLockReadGuard<'a, NetworkGraph>.
85 /// This exists only to make accessing a RwLock<NetworkGraph> possible from
86 /// the C bindings, as it can be done directly in Rust code.
87 #[must_use]
88 #[repr(C)]
89 pub struct LockedNetworkGraph {
90         /// A pointer to the opaque Rust object.
91
92         /// Nearly everywhere, inner must be non-null, however in places where
93         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
94         pub inner: *mut nativeLockedNetworkGraph,
95         /// Indicates that this is the only struct which contains the same pointer.
96
97         /// Rust functions which take ownership of an object provided via an argument require
98         /// this to be true and invalidate the object pointed to by inner.
99         pub is_owned: bool,
100 }
101
102 impl Drop for LockedNetworkGraph {
103         fn drop(&mut self) {
104                 if self.is_owned && !<*mut nativeLockedNetworkGraph>::is_null(self.inner) {
105                         let _ = unsafe { Box::from_raw(self.inner) };
106                 }
107         }
108 }
109 /// Frees any resources used by the LockedNetworkGraph, if is_owned is set and inner is non-NULL.
110 #[no_mangle]
111 pub extern "C" fn LockedNetworkGraph_free(this_obj: LockedNetworkGraph) { }
112 #[allow(unused)]
113 /// Used only if an object of this type is returned as a trait impl by a method
114 extern "C" fn LockedNetworkGraph_free_void(this_ptr: *mut c_void) {
115         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeLockedNetworkGraph); }
116 }
117 #[allow(unused)]
118 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
119 impl LockedNetworkGraph {
120         pub(crate) fn take_inner(mut self) -> *mut nativeLockedNetworkGraph {
121                 assert!(self.is_owned);
122                 let ret = self.inner;
123                 self.inner = std::ptr::null_mut();
124                 ret
125         }
126 }
127
128 use lightning::routing::network_graph::NetGraphMsgHandler as nativeNetGraphMsgHandlerImport;
129 type nativeNetGraphMsgHandler = nativeNetGraphMsgHandlerImport<crate::lightning::chain::Access, crate::lightning::util::logger::Logger>;
130
131 /// Receives and validates network updates from peers,
132 /// stores authentic and relevant data as a network graph.
133 /// This network graph is then used for routing payments.
134 /// Provides interface to help with initial routing sync by
135 /// serving historical announcements.
136 #[must_use]
137 #[repr(C)]
138 pub struct NetGraphMsgHandler {
139         /// A pointer to the opaque Rust object.
140
141         /// Nearly everywhere, inner must be non-null, however in places where
142         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
143         pub inner: *mut nativeNetGraphMsgHandler,
144         /// Indicates that this is the only struct which contains the same pointer.
145
146         /// Rust functions which take ownership of an object provided via an argument require
147         /// this to be true and invalidate the object pointed to by inner.
148         pub is_owned: bool,
149 }
150
151 impl Drop for NetGraphMsgHandler {
152         fn drop(&mut self) {
153                 if self.is_owned && !<*mut nativeNetGraphMsgHandler>::is_null(self.inner) {
154                         let _ = unsafe { Box::from_raw(self.inner) };
155                 }
156         }
157 }
158 /// Frees any resources used by the NetGraphMsgHandler, if is_owned is set and inner is non-NULL.
159 #[no_mangle]
160 pub extern "C" fn NetGraphMsgHandler_free(this_obj: NetGraphMsgHandler) { }
161 #[allow(unused)]
162 /// Used only if an object of this type is returned as a trait impl by a method
163 extern "C" fn NetGraphMsgHandler_free_void(this_ptr: *mut c_void) {
164         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNetGraphMsgHandler); }
165 }
166 #[allow(unused)]
167 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
168 impl NetGraphMsgHandler {
169         pub(crate) fn take_inner(mut self) -> *mut nativeNetGraphMsgHandler {
170                 assert!(self.is_owned);
171                 let ret = self.inner;
172                 self.inner = std::ptr::null_mut();
173                 ret
174         }
175 }
176 /// Creates a new tracker of the actual state of the network of channels and nodes,
177 /// assuming a fresh network graph.
178 /// Chain monitor is used to make sure announced channels exist on-chain,
179 /// channel data is correct, and that the announcement is signed with
180 /// channel owners' keys.
181 #[must_use]
182 #[no_mangle]
183 pub extern "C" fn NetGraphMsgHandler_new(mut genesis_hash: crate::c_types::ThirtyTwoBytes, chain_access: *mut crate::lightning::chain::Access, mut logger: crate::lightning::util::logger::Logger) -> NetGraphMsgHandler {
184         let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) };
185         let mut ret = lightning::routing::network_graph::NetGraphMsgHandler::new(::bitcoin::hash_types::BlockHash::from_slice(&genesis_hash.data[..]).unwrap(), local_chain_access, logger);
186         NetGraphMsgHandler { inner: Box::into_raw(Box::new(ret)), is_owned: true }
187 }
188
189 /// Creates a new tracker of the actual state of the network of channels and nodes,
190 /// assuming an existing Network Graph.
191 #[must_use]
192 #[no_mangle]
193 pub extern "C" fn NetGraphMsgHandler_from_net_graph(chain_access: *mut crate::lightning::chain::Access, mut logger: crate::lightning::util::logger::Logger, mut network_graph: crate::lightning::routing::network_graph::NetworkGraph) -> NetGraphMsgHandler {
194         let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) };
195         let mut ret = lightning::routing::network_graph::NetGraphMsgHandler::from_net_graph(local_chain_access, logger, *unsafe { Box::from_raw(network_graph.take_inner()) });
196         NetGraphMsgHandler { inner: Box::into_raw(Box::new(ret)), is_owned: true }
197 }
198
199 /// Adds a provider used to check new announcements. Does not affect
200 /// existing announcements unless they are updated.
201 /// Add, update or remove the provider would replace the current one.
202 #[no_mangle]
203 pub extern "C" fn NetGraphMsgHandler_add_chain_access(this_arg: &mut NetGraphMsgHandler, chain_access: *mut crate::lightning::chain::Access) {
204         let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) };
205         unsafe { &mut (*(this_arg.inner as *mut nativeNetGraphMsgHandler)) }.add_chain_access(local_chain_access)
206 }
207
208 /// Take a read lock on the network_graph and return it in the C-bindings
209 /// newtype helper. This is likely only useful when called via the C
210 /// bindings as you can call `self.network_graph.read().unwrap()` in Rust
211 /// yourself.
212 #[must_use]
213 #[no_mangle]
214 pub extern "C" fn NetGraphMsgHandler_read_locked_graph(this_arg: &NetGraphMsgHandler) -> crate::lightning::routing::network_graph::LockedNetworkGraph {
215         let mut ret = unsafe { &*this_arg.inner }.read_locked_graph();
216         crate::lightning::routing::network_graph::LockedNetworkGraph { inner: Box::into_raw(Box::new(ret)), is_owned: true }
217 }
218
219 /// Get a reference to the NetworkGraph which this read-lock contains.
220 #[must_use]
221 #[no_mangle]
222 pub extern "C" fn LockedNetworkGraph_graph(this_arg: &LockedNetworkGraph) -> crate::lightning::routing::network_graph::NetworkGraph {
223         let mut ret = unsafe { &*this_arg.inner }.graph();
224         crate::lightning::routing::network_graph::NetworkGraph { inner: unsafe { ( (&(*ret) as *const _) as *mut _) }, is_owned: false }
225 }
226
227 impl From<nativeNetGraphMsgHandler> for crate::lightning::ln::msgs::RoutingMessageHandler {
228         fn from(obj: nativeNetGraphMsgHandler) -> Self {
229                 let mut rust_obj = NetGraphMsgHandler { inner: Box::into_raw(Box::new(obj)), is_owned: true };
230                 let mut ret = NetGraphMsgHandler_as_RoutingMessageHandler(&rust_obj);
231                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
232                 rust_obj.inner = std::ptr::null_mut();
233                 ret.free = Some(NetGraphMsgHandler_free_void);
234                 ret
235         }
236 }
237 /// Constructs a new RoutingMessageHandler which calls the relevant methods on this_arg.
238 /// This copies the `inner` pointer in this_arg and thus the returned RoutingMessageHandler must be freed before this_arg is
239 #[no_mangle]
240 pub extern "C" fn NetGraphMsgHandler_as_RoutingMessageHandler(this_arg: &NetGraphMsgHandler) -> crate::lightning::ln::msgs::RoutingMessageHandler {
241         crate::lightning::ln::msgs::RoutingMessageHandler {
242                 this_arg: unsafe { (*this_arg).inner as *mut c_void },
243                 free: None,
244                 handle_node_announcement: NetGraphMsgHandler_RoutingMessageHandler_handle_node_announcement,
245                 handle_channel_announcement: NetGraphMsgHandler_RoutingMessageHandler_handle_channel_announcement,
246                 handle_channel_update: NetGraphMsgHandler_RoutingMessageHandler_handle_channel_update,
247                 handle_htlc_fail_channel_update: NetGraphMsgHandler_RoutingMessageHandler_handle_htlc_fail_channel_update,
248                 get_next_channel_announcements: NetGraphMsgHandler_RoutingMessageHandler_get_next_channel_announcements,
249                 get_next_node_announcements: NetGraphMsgHandler_RoutingMessageHandler_get_next_node_announcements,
250                 sync_routing_table: NetGraphMsgHandler_RoutingMessageHandler_sync_routing_table,
251                 handle_reply_channel_range: NetGraphMsgHandler_RoutingMessageHandler_handle_reply_channel_range,
252                 handle_reply_short_channel_ids_end: NetGraphMsgHandler_RoutingMessageHandler_handle_reply_short_channel_ids_end,
253                 handle_query_channel_range: NetGraphMsgHandler_RoutingMessageHandler_handle_query_channel_range,
254                 handle_query_short_channel_ids: NetGraphMsgHandler_RoutingMessageHandler_handle_query_short_channel_ids,
255                 MessageSendEventsProvider: crate::lightning::util::events::MessageSendEventsProvider {
256                         this_arg: unsafe { (*this_arg).inner as *mut c_void },
257                         free: None,
258                         get_and_clear_pending_msg_events: NetGraphMsgHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
259                 },
260         }
261 }
262
263 #[must_use]
264 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_node_announcement(this_arg: *const c_void, msg: &crate::lightning::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CResult_boolLightningErrorZ {
265         let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_node_announcement(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, unsafe { &*msg.inner });
266         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
267         local_ret
268 }
269 #[must_use]
270 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_channel_announcement(this_arg: *const c_void, msg: &crate::lightning::ln::msgs::ChannelAnnouncement) -> crate::c_types::derived::CResult_boolLightningErrorZ {
271         let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_announcement(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, unsafe { &*msg.inner });
272         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
273         local_ret
274 }
275 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_htlc_fail_channel_update(this_arg: *const c_void, update: &crate::lightning::ln::msgs::HTLCFailChannelUpdate) {
276         <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_htlc_fail_channel_update(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, &update.to_native())
277 }
278 #[must_use]
279 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_channel_update(this_arg: *const c_void, msg: &crate::lightning::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CResult_boolLightningErrorZ {
280         let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_channel_update(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, unsafe { &*msg.inner });
281         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { o }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
282         local_ret
283 }
284 #[must_use]
285 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_get_next_channel_announcements(this_arg: *const c_void, mut starting_point: u64, mut batch_amount: u8) -> crate::c_types::derived::CVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ {
286         let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::get_next_channel_announcements(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, starting_point, batch_amount);
287         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { let (mut orig_ret_0_0, mut orig_ret_0_1, mut orig_ret_0_2) = item; let mut local_orig_ret_0_1 = crate::lightning::ln::msgs::ChannelUpdate { inner: if orig_ret_0_1.is_none() { std::ptr::null_mut() } else {  { Box::into_raw(Box::new((orig_ret_0_1.unwrap()))) } }, is_owned: true }; let mut local_orig_ret_0_2 = crate::lightning::ln::msgs::ChannelUpdate { inner: if orig_ret_0_2.is_none() { std::ptr::null_mut() } else {  { Box::into_raw(Box::new((orig_ret_0_2.unwrap()))) } }, is_owned: true }; let mut local_ret_0 = (crate::lightning::ln::msgs::ChannelAnnouncement { inner: Box::into_raw(Box::new(orig_ret_0_0)), is_owned: true }, local_orig_ret_0_1, local_orig_ret_0_2).into(); local_ret_0 }); };
288         local_ret.into()
289 }
290 #[must_use]
291 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_get_next_node_announcements(this_arg: *const c_void, mut starting_point: crate::c_types::PublicKey, mut batch_amount: u8) -> crate::c_types::derived::CVec_NodeAnnouncementZ {
292         let mut local_starting_point_base = if starting_point.is_null() { None } else { Some( { starting_point.into_rust() }) }; let mut local_starting_point = local_starting_point_base.as_ref();
293         let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::get_next_node_announcements(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, local_starting_point, batch_amount);
294         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::ln::msgs::NodeAnnouncement { inner: Box::into_raw(Box::new(item)), is_owned: true } }); };
295         local_ret.into()
296 }
297 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_sync_routing_table(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, init_msg: &crate::lightning::ln::msgs::Init) {
298         <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::sync_routing_table(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, &their_node_id.into_rust(), unsafe { &*init_msg.inner })
299 }
300 #[must_use]
301 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_reply_channel_range(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, mut msg: crate::lightning::ln::msgs::ReplyChannelRange) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
302         let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_reply_channel_range(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, &their_node_id.into_rust(), *unsafe { Box::from_raw(msg.take_inner()) });
303         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
304         local_ret
305 }
306 #[must_use]
307 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_reply_short_channel_ids_end(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, mut msg: crate::lightning::ln::msgs::ReplyShortChannelIdsEnd) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
308         let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_reply_short_channel_ids_end(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, &their_node_id.into_rust(), *unsafe { Box::from_raw(msg.take_inner()) });
309         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
310         local_ret
311 }
312 #[must_use]
313 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_query_channel_range(this_arg: *const c_void, mut their_node_id: crate::c_types::PublicKey, mut msg: crate::lightning::ln::msgs::QueryChannelRange) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
314         let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_query_channel_range(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, &their_node_id.into_rust(), *unsafe { Box::from_raw(msg.take_inner()) });
315         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
316         local_ret
317 }
318 #[must_use]
319 extern "C" fn NetGraphMsgHandler_RoutingMessageHandler_handle_query_short_channel_ids(this_arg: *const c_void, mut _their_node_id: crate::c_types::PublicKey, mut _msg: crate::lightning::ln::msgs::QueryShortChannelIds) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
320         let mut ret = <nativeNetGraphMsgHandler as lightning::ln::msgs::RoutingMessageHandler<>>::handle_query_short_channel_ids(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, &_their_node_id.into_rust(), *unsafe { Box::from_raw(_msg.take_inner()) });
321         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
322         local_ret
323 }
324
325 impl From<nativeNetGraphMsgHandler> for crate::lightning::util::events::MessageSendEventsProvider {
326         fn from(obj: nativeNetGraphMsgHandler) -> Self {
327                 let mut rust_obj = NetGraphMsgHandler { inner: Box::into_raw(Box::new(obj)), is_owned: true };
328                 let mut ret = NetGraphMsgHandler_as_MessageSendEventsProvider(&rust_obj);
329                 // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
330                 rust_obj.inner = std::ptr::null_mut();
331                 ret.free = Some(NetGraphMsgHandler_free_void);
332                 ret
333         }
334 }
335 /// Constructs a new MessageSendEventsProvider which calls the relevant methods on this_arg.
336 /// This copies the `inner` pointer in this_arg and thus the returned MessageSendEventsProvider must be freed before this_arg is
337 #[no_mangle]
338 pub extern "C" fn NetGraphMsgHandler_as_MessageSendEventsProvider(this_arg: &NetGraphMsgHandler) -> crate::lightning::util::events::MessageSendEventsProvider {
339         crate::lightning::util::events::MessageSendEventsProvider {
340                 this_arg: unsafe { (*this_arg).inner as *mut c_void },
341                 free: None,
342                 get_and_clear_pending_msg_events: NetGraphMsgHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events,
343         }
344 }
345
346 #[must_use]
347 extern "C" fn NetGraphMsgHandler_MessageSendEventsProvider_get_and_clear_pending_msg_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_MessageSendEventZ {
348         let mut ret = <nativeNetGraphMsgHandler as lightning::util::events::MessageSendEventsProvider<>>::get_and_clear_pending_msg_events(unsafe { &mut *(this_arg as *mut nativeNetGraphMsgHandler) }, );
349         let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::util::events::MessageSendEvent::native_into(item) }); };
350         local_ret.into()
351 }
352
353
354 use lightning::routing::network_graph::DirectionalChannelInfo as nativeDirectionalChannelInfoImport;
355 type nativeDirectionalChannelInfo = nativeDirectionalChannelInfoImport;
356
357 /// Details about one direction of a channel. Received
358 /// within a channel update.
359 #[must_use]
360 #[repr(C)]
361 pub struct DirectionalChannelInfo {
362         /// A pointer to the opaque Rust object.
363
364         /// Nearly everywhere, inner must be non-null, however in places where
365         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
366         pub inner: *mut nativeDirectionalChannelInfo,
367         /// Indicates that this is the only struct which contains the same pointer.
368
369         /// Rust functions which take ownership of an object provided via an argument require
370         /// this to be true and invalidate the object pointed to by inner.
371         pub is_owned: bool,
372 }
373
374 impl Drop for DirectionalChannelInfo {
375         fn drop(&mut self) {
376                 if self.is_owned && !<*mut nativeDirectionalChannelInfo>::is_null(self.inner) {
377                         let _ = unsafe { Box::from_raw(self.inner) };
378                 }
379         }
380 }
381 /// Frees any resources used by the DirectionalChannelInfo, if is_owned is set and inner is non-NULL.
382 #[no_mangle]
383 pub extern "C" fn DirectionalChannelInfo_free(this_obj: DirectionalChannelInfo) { }
384 #[allow(unused)]
385 /// Used only if an object of this type is returned as a trait impl by a method
386 extern "C" fn DirectionalChannelInfo_free_void(this_ptr: *mut c_void) {
387         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeDirectionalChannelInfo); }
388 }
389 #[allow(unused)]
390 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
391 impl DirectionalChannelInfo {
392         pub(crate) fn take_inner(mut self) -> *mut nativeDirectionalChannelInfo {
393                 assert!(self.is_owned);
394                 let ret = self.inner;
395                 self.inner = std::ptr::null_mut();
396                 ret
397         }
398 }
399 /// When the last update to the channel direction was issued.
400 /// Value is opaque, as set in the announcement.
401 #[no_mangle]
402 pub extern "C" fn DirectionalChannelInfo_get_last_update(this_ptr: &DirectionalChannelInfo) -> u32 {
403         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.last_update;
404         *inner_val
405 }
406 /// When the last update to the channel direction was issued.
407 /// Value is opaque, as set in the announcement.
408 #[no_mangle]
409 pub extern "C" fn DirectionalChannelInfo_set_last_update(this_ptr: &mut DirectionalChannelInfo, mut val: u32) {
410         unsafe { &mut *this_ptr.inner }.last_update = val;
411 }
412 /// Whether the channel can be currently used for payments (in this one direction).
413 #[no_mangle]
414 pub extern "C" fn DirectionalChannelInfo_get_enabled(this_ptr: &DirectionalChannelInfo) -> bool {
415         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.enabled;
416         *inner_val
417 }
418 /// Whether the channel can be currently used for payments (in this one direction).
419 #[no_mangle]
420 pub extern "C" fn DirectionalChannelInfo_set_enabled(this_ptr: &mut DirectionalChannelInfo, mut val: bool) {
421         unsafe { &mut *this_ptr.inner }.enabled = val;
422 }
423 /// The difference in CLTV values that you must have when routing through this channel.
424 #[no_mangle]
425 pub extern "C" fn DirectionalChannelInfo_get_cltv_expiry_delta(this_ptr: &DirectionalChannelInfo) -> u16 {
426         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.cltv_expiry_delta;
427         *inner_val
428 }
429 /// The difference in CLTV values that you must have when routing through this channel.
430 #[no_mangle]
431 pub extern "C" fn DirectionalChannelInfo_set_cltv_expiry_delta(this_ptr: &mut DirectionalChannelInfo, mut val: u16) {
432         unsafe { &mut *this_ptr.inner }.cltv_expiry_delta = val;
433 }
434 /// The minimum value, which must be relayed to the next hop via the channel
435 #[no_mangle]
436 pub extern "C" fn DirectionalChannelInfo_get_htlc_minimum_msat(this_ptr: &DirectionalChannelInfo) -> u64 {
437         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.htlc_minimum_msat;
438         *inner_val
439 }
440 /// The minimum value, which must be relayed to the next hop via the channel
441 #[no_mangle]
442 pub extern "C" fn DirectionalChannelInfo_set_htlc_minimum_msat(this_ptr: &mut DirectionalChannelInfo, mut val: u64) {
443         unsafe { &mut *this_ptr.inner }.htlc_minimum_msat = val;
444 }
445 /// The maximum value which may be relayed to the next hop via the channel.
446 #[no_mangle]
447 pub extern "C" fn DirectionalChannelInfo_get_htlc_maximum_msat(this_ptr: &DirectionalChannelInfo) -> crate::c_types::derived::COption_u64Z {
448         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.htlc_maximum_msat;
449         let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u64Z::None } else {  { crate::c_types::derived::COption_u64Z::Some(inner_val.unwrap()) } };
450         local_inner_val
451 }
452 /// The maximum value which may be relayed to the next hop via the channel.
453 #[no_mangle]
454 pub extern "C" fn DirectionalChannelInfo_set_htlc_maximum_msat(this_ptr: &mut DirectionalChannelInfo, mut val: crate::c_types::derived::COption_u64Z) {
455         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
456         unsafe { &mut *this_ptr.inner }.htlc_maximum_msat = local_val;
457 }
458 /// Fees charged when the channel is used for routing
459 #[no_mangle]
460 pub extern "C" fn DirectionalChannelInfo_get_fees(this_ptr: &DirectionalChannelInfo) -> crate::lightning::routing::network_graph::RoutingFees {
461         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.fees;
462         crate::lightning::routing::network_graph::RoutingFees { inner: unsafe { ( (&(*inner_val) as *const _) as *mut _) }, is_owned: false }
463 }
464 /// Fees charged when the channel is used for routing
465 #[no_mangle]
466 pub extern "C" fn DirectionalChannelInfo_set_fees(this_ptr: &mut DirectionalChannelInfo, mut val: crate::lightning::routing::network_graph::RoutingFees) {
467         unsafe { &mut *this_ptr.inner }.fees = *unsafe { Box::from_raw(val.take_inner()) };
468 }
469 /// Most recent update for the channel received from the network
470 /// Mostly redundant with the data we store in fields explicitly.
471 /// Everything else is useful only for sending out for initial routing sync.
472 /// Not stored if contains excess data to prevent DoS.
473 #[no_mangle]
474 pub extern "C" fn DirectionalChannelInfo_get_last_update_message(this_ptr: &DirectionalChannelInfo) -> crate::lightning::ln::msgs::ChannelUpdate {
475         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.last_update_message;
476         let mut local_inner_val = crate::lightning::ln::msgs::ChannelUpdate { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else {  { (inner_val.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false };
477         local_inner_val
478 }
479 /// Most recent update for the channel received from the network
480 /// Mostly redundant with the data we store in fields explicitly.
481 /// Everything else is useful only for sending out for initial routing sync.
482 /// Not stored if contains excess data to prevent DoS.
483 #[no_mangle]
484 pub extern "C" fn DirectionalChannelInfo_set_last_update_message(this_ptr: &mut DirectionalChannelInfo, mut val: crate::lightning::ln::msgs::ChannelUpdate) {
485         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
486         unsafe { &mut *this_ptr.inner }.last_update_message = local_val;
487 }
488 /// Constructs a new DirectionalChannelInfo given each field
489 #[must_use]
490 #[no_mangle]
491 pub extern "C" fn DirectionalChannelInfo_new(mut last_update_arg: u32, mut enabled_arg: bool, mut cltv_expiry_delta_arg: u16, mut htlc_minimum_msat_arg: u64, mut htlc_maximum_msat_arg: crate::c_types::derived::COption_u64Z, mut fees_arg: crate::lightning::routing::network_graph::RoutingFees, mut last_update_message_arg: crate::lightning::ln::msgs::ChannelUpdate) -> DirectionalChannelInfo {
492         let mut local_htlc_maximum_msat_arg = if htlc_maximum_msat_arg.is_some() { Some( { htlc_maximum_msat_arg.take() }) } else { None };
493         let mut local_last_update_message_arg = if last_update_message_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(last_update_message_arg.take_inner()) } }) };
494         DirectionalChannelInfo { inner: Box::into_raw(Box::new(nativeDirectionalChannelInfo {
495                 last_update: last_update_arg,
496                 enabled: enabled_arg,
497                 cltv_expiry_delta: cltv_expiry_delta_arg,
498                 htlc_minimum_msat: htlc_minimum_msat_arg,
499                 htlc_maximum_msat: local_htlc_maximum_msat_arg,
500                 fees: *unsafe { Box::from_raw(fees_arg.take_inner()) },
501                 last_update_message: local_last_update_message_arg,
502         })), is_owned: true }
503 }
504 impl Clone for DirectionalChannelInfo {
505         fn clone(&self) -> Self {
506                 Self {
507                         inner: if <*mut nativeDirectionalChannelInfo>::is_null(self.inner) { std::ptr::null_mut() } else {
508                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
509                         is_owned: true,
510                 }
511         }
512 }
513 #[allow(unused)]
514 /// Used only if an object of this type is returned as a trait impl by a method
515 pub(crate) extern "C" fn DirectionalChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
516         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeDirectionalChannelInfo)).clone() })) as *mut c_void
517 }
518 #[no_mangle]
519 /// Creates a copy of the DirectionalChannelInfo
520 pub extern "C" fn DirectionalChannelInfo_clone(orig: &DirectionalChannelInfo) -> DirectionalChannelInfo {
521         orig.clone()
522 }
523 #[no_mangle]
524 /// Serialize the DirectionalChannelInfo object into a byte array which can be read by DirectionalChannelInfo_read
525 pub extern "C" fn DirectionalChannelInfo_write(obj: &DirectionalChannelInfo) -> crate::c_types::derived::CVec_u8Z {
526         crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
527 }
528 #[no_mangle]
529 pub(crate) extern "C" fn DirectionalChannelInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
530         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeDirectionalChannelInfo) })
531 }
532 #[no_mangle]
533 /// Read a DirectionalChannelInfo from a byte array, created by DirectionalChannelInfo_write
534 pub extern "C" fn DirectionalChannelInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_DirectionalChannelInfoDecodeErrorZ {
535         let res = crate::c_types::deserialize_obj(ser);
536         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::network_graph::DirectionalChannelInfo { 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() };
537         local_res
538 }
539
540 use lightning::routing::network_graph::ChannelInfo as nativeChannelInfoImport;
541 type nativeChannelInfo = nativeChannelInfoImport;
542
543 /// Details about a channel (both directions).
544 /// Received within a channel announcement.
545 #[must_use]
546 #[repr(C)]
547 pub struct ChannelInfo {
548         /// A pointer to the opaque Rust object.
549
550         /// Nearly everywhere, inner must be non-null, however in places where
551         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
552         pub inner: *mut nativeChannelInfo,
553         /// Indicates that this is the only struct which contains the same pointer.
554
555         /// Rust functions which take ownership of an object provided via an argument require
556         /// this to be true and invalidate the object pointed to by inner.
557         pub is_owned: bool,
558 }
559
560 impl Drop for ChannelInfo {
561         fn drop(&mut self) {
562                 if self.is_owned && !<*mut nativeChannelInfo>::is_null(self.inner) {
563                         let _ = unsafe { Box::from_raw(self.inner) };
564                 }
565         }
566 }
567 /// Frees any resources used by the ChannelInfo, if is_owned is set and inner is non-NULL.
568 #[no_mangle]
569 pub extern "C" fn ChannelInfo_free(this_obj: ChannelInfo) { }
570 #[allow(unused)]
571 /// Used only if an object of this type is returned as a trait impl by a method
572 extern "C" fn ChannelInfo_free_void(this_ptr: *mut c_void) {
573         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelInfo); }
574 }
575 #[allow(unused)]
576 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
577 impl ChannelInfo {
578         pub(crate) fn take_inner(mut self) -> *mut nativeChannelInfo {
579                 assert!(self.is_owned);
580                 let ret = self.inner;
581                 self.inner = std::ptr::null_mut();
582                 ret
583         }
584 }
585 /// Protocol features of a channel communicated during its announcement
586 #[no_mangle]
587 pub extern "C" fn ChannelInfo_get_features(this_ptr: &ChannelInfo) -> crate::lightning::ln::features::ChannelFeatures {
588         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.features;
589         crate::lightning::ln::features::ChannelFeatures { inner: unsafe { ( (&(*inner_val) as *const _) as *mut _) }, is_owned: false }
590 }
591 /// Protocol features of a channel communicated during its announcement
592 #[no_mangle]
593 pub extern "C" fn ChannelInfo_set_features(this_ptr: &mut ChannelInfo, mut val: crate::lightning::ln::features::ChannelFeatures) {
594         unsafe { &mut *this_ptr.inner }.features = *unsafe { Box::from_raw(val.take_inner()) };
595 }
596 /// Source node of the first direction of a channel
597 #[no_mangle]
598 pub extern "C" fn ChannelInfo_get_node_one(this_ptr: &ChannelInfo) -> crate::c_types::PublicKey {
599         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.node_one;
600         crate::c_types::PublicKey::from_rust(&inner_val)
601 }
602 /// Source node of the first direction of a channel
603 #[no_mangle]
604 pub extern "C" fn ChannelInfo_set_node_one(this_ptr: &mut ChannelInfo, mut val: crate::c_types::PublicKey) {
605         unsafe { &mut *this_ptr.inner }.node_one = val.into_rust();
606 }
607 /// Details about the first direction of a channel
608 #[no_mangle]
609 pub extern "C" fn ChannelInfo_get_one_to_two(this_ptr: &ChannelInfo) -> crate::lightning::routing::network_graph::DirectionalChannelInfo {
610         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.one_to_two;
611         let mut local_inner_val = crate::lightning::routing::network_graph::DirectionalChannelInfo { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else {  { (inner_val.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false };
612         local_inner_val
613 }
614 /// Details about the first direction of a channel
615 #[no_mangle]
616 pub extern "C" fn ChannelInfo_set_one_to_two(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::network_graph::DirectionalChannelInfo) {
617         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
618         unsafe { &mut *this_ptr.inner }.one_to_two = local_val;
619 }
620 /// Source node of the second direction of a channel
621 #[no_mangle]
622 pub extern "C" fn ChannelInfo_get_node_two(this_ptr: &ChannelInfo) -> crate::c_types::PublicKey {
623         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.node_two;
624         crate::c_types::PublicKey::from_rust(&inner_val)
625 }
626 /// Source node of the second direction of a channel
627 #[no_mangle]
628 pub extern "C" fn ChannelInfo_set_node_two(this_ptr: &mut ChannelInfo, mut val: crate::c_types::PublicKey) {
629         unsafe { &mut *this_ptr.inner }.node_two = val.into_rust();
630 }
631 /// Details about the second direction of a channel
632 #[no_mangle]
633 pub extern "C" fn ChannelInfo_get_two_to_one(this_ptr: &ChannelInfo) -> crate::lightning::routing::network_graph::DirectionalChannelInfo {
634         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.two_to_one;
635         let mut local_inner_val = crate::lightning::routing::network_graph::DirectionalChannelInfo { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else {  { (inner_val.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false };
636         local_inner_val
637 }
638 /// Details about the second direction of a channel
639 #[no_mangle]
640 pub extern "C" fn ChannelInfo_set_two_to_one(this_ptr: &mut ChannelInfo, mut val: crate::lightning::routing::network_graph::DirectionalChannelInfo) {
641         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
642         unsafe { &mut *this_ptr.inner }.two_to_one = local_val;
643 }
644 /// The channel capacity as seen on-chain, if chain lookup is available.
645 #[no_mangle]
646 pub extern "C" fn ChannelInfo_get_capacity_sats(this_ptr: &ChannelInfo) -> crate::c_types::derived::COption_u64Z {
647         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.capacity_sats;
648         let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u64Z::None } else {  { crate::c_types::derived::COption_u64Z::Some(inner_val.unwrap()) } };
649         local_inner_val
650 }
651 /// The channel capacity as seen on-chain, if chain lookup is available.
652 #[no_mangle]
653 pub extern "C" fn ChannelInfo_set_capacity_sats(this_ptr: &mut ChannelInfo, mut val: crate::c_types::derived::COption_u64Z) {
654         let mut local_val = if val.is_some() { Some( { val.take() }) } else { None };
655         unsafe { &mut *this_ptr.inner }.capacity_sats = local_val;
656 }
657 /// An initial announcement of the channel
658 /// Mostly redundant with the data we store in fields explicitly.
659 /// Everything else is useful only for sending out for initial routing sync.
660 /// Not stored if contains excess data to prevent DoS.
661 #[no_mangle]
662 pub extern "C" fn ChannelInfo_get_announcement_message(this_ptr: &ChannelInfo) -> crate::lightning::ln::msgs::ChannelAnnouncement {
663         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.announcement_message;
664         let mut local_inner_val = crate::lightning::ln::msgs::ChannelAnnouncement { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else {  { (inner_val.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false };
665         local_inner_val
666 }
667 /// An initial announcement of the channel
668 /// Mostly redundant with the data we store in fields explicitly.
669 /// Everything else is useful only for sending out for initial routing sync.
670 /// Not stored if contains excess data to prevent DoS.
671 #[no_mangle]
672 pub extern "C" fn ChannelInfo_set_announcement_message(this_ptr: &mut ChannelInfo, mut val: crate::lightning::ln::msgs::ChannelAnnouncement) {
673         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
674         unsafe { &mut *this_ptr.inner }.announcement_message = local_val;
675 }
676 /// Constructs a new ChannelInfo given each field
677 #[must_use]
678 #[no_mangle]
679 pub extern "C" fn ChannelInfo_new(mut features_arg: crate::lightning::ln::features::ChannelFeatures, mut node_one_arg: crate::c_types::PublicKey, mut one_to_two_arg: crate::lightning::routing::network_graph::DirectionalChannelInfo, mut node_two_arg: crate::c_types::PublicKey, mut two_to_one_arg: crate::lightning::routing::network_graph::DirectionalChannelInfo, mut capacity_sats_arg: crate::c_types::derived::COption_u64Z, mut announcement_message_arg: crate::lightning::ln::msgs::ChannelAnnouncement) -> ChannelInfo {
680         let mut local_one_to_two_arg = if one_to_two_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(one_to_two_arg.take_inner()) } }) };
681         let mut local_two_to_one_arg = if two_to_one_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(two_to_one_arg.take_inner()) } }) };
682         let mut local_capacity_sats_arg = if capacity_sats_arg.is_some() { Some( { capacity_sats_arg.take() }) } else { None };
683         let mut local_announcement_message_arg = if announcement_message_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(announcement_message_arg.take_inner()) } }) };
684         ChannelInfo { inner: Box::into_raw(Box::new(nativeChannelInfo {
685                 features: *unsafe { Box::from_raw(features_arg.take_inner()) },
686                 node_one: node_one_arg.into_rust(),
687                 one_to_two: local_one_to_two_arg,
688                 node_two: node_two_arg.into_rust(),
689                 two_to_one: local_two_to_one_arg,
690                 capacity_sats: local_capacity_sats_arg,
691                 announcement_message: local_announcement_message_arg,
692         })), is_owned: true }
693 }
694 impl Clone for ChannelInfo {
695         fn clone(&self) -> Self {
696                 Self {
697                         inner: if <*mut nativeChannelInfo>::is_null(self.inner) { std::ptr::null_mut() } else {
698                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
699                         is_owned: true,
700                 }
701         }
702 }
703 #[allow(unused)]
704 /// Used only if an object of this type is returned as a trait impl by a method
705 pub(crate) extern "C" fn ChannelInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
706         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelInfo)).clone() })) as *mut c_void
707 }
708 #[no_mangle]
709 /// Creates a copy of the ChannelInfo
710 pub extern "C" fn ChannelInfo_clone(orig: &ChannelInfo) -> ChannelInfo {
711         orig.clone()
712 }
713 #[no_mangle]
714 /// Serialize the ChannelInfo object into a byte array which can be read by ChannelInfo_read
715 pub extern "C" fn ChannelInfo_write(obj: &ChannelInfo) -> crate::c_types::derived::CVec_u8Z {
716         crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
717 }
718 #[no_mangle]
719 pub(crate) extern "C" fn ChannelInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
720         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelInfo) })
721 }
722 #[no_mangle]
723 /// Read a ChannelInfo from a byte array, created by ChannelInfo_write
724 pub extern "C" fn ChannelInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelInfoDecodeErrorZ {
725         let res = crate::c_types::deserialize_obj(ser);
726         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::network_graph::ChannelInfo { 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() };
727         local_res
728 }
729
730 use lightning::routing::network_graph::RoutingFees as nativeRoutingFeesImport;
731 type nativeRoutingFees = nativeRoutingFeesImport;
732
733 /// Fees for routing via a given channel or a node
734 #[must_use]
735 #[repr(C)]
736 pub struct RoutingFees {
737         /// A pointer to the opaque Rust object.
738
739         /// Nearly everywhere, inner must be non-null, however in places where
740         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
741         pub inner: *mut nativeRoutingFees,
742         /// Indicates that this is the only struct which contains the same pointer.
743
744         /// Rust functions which take ownership of an object provided via an argument require
745         /// this to be true and invalidate the object pointed to by inner.
746         pub is_owned: bool,
747 }
748
749 impl Drop for RoutingFees {
750         fn drop(&mut self) {
751                 if self.is_owned && !<*mut nativeRoutingFees>::is_null(self.inner) {
752                         let _ = unsafe { Box::from_raw(self.inner) };
753                 }
754         }
755 }
756 /// Frees any resources used by the RoutingFees, if is_owned is set and inner is non-NULL.
757 #[no_mangle]
758 pub extern "C" fn RoutingFees_free(this_obj: RoutingFees) { }
759 #[allow(unused)]
760 /// Used only if an object of this type is returned as a trait impl by a method
761 extern "C" fn RoutingFees_free_void(this_ptr: *mut c_void) {
762         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeRoutingFees); }
763 }
764 #[allow(unused)]
765 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
766 impl RoutingFees {
767         pub(crate) fn take_inner(mut self) -> *mut nativeRoutingFees {
768                 assert!(self.is_owned);
769                 let ret = self.inner;
770                 self.inner = std::ptr::null_mut();
771                 ret
772         }
773 }
774 /// Flat routing fee in satoshis
775 #[no_mangle]
776 pub extern "C" fn RoutingFees_get_base_msat(this_ptr: &RoutingFees) -> u32 {
777         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.base_msat;
778         *inner_val
779 }
780 /// Flat routing fee in satoshis
781 #[no_mangle]
782 pub extern "C" fn RoutingFees_set_base_msat(this_ptr: &mut RoutingFees, mut val: u32) {
783         unsafe { &mut *this_ptr.inner }.base_msat = val;
784 }
785 /// Liquidity-based routing fee in millionths of a routed amount.
786 /// In other words, 10000 is 1%.
787 #[no_mangle]
788 pub extern "C" fn RoutingFees_get_proportional_millionths(this_ptr: &RoutingFees) -> u32 {
789         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.proportional_millionths;
790         *inner_val
791 }
792 /// Liquidity-based routing fee in millionths of a routed amount.
793 /// In other words, 10000 is 1%.
794 #[no_mangle]
795 pub extern "C" fn RoutingFees_set_proportional_millionths(this_ptr: &mut RoutingFees, mut val: u32) {
796         unsafe { &mut *this_ptr.inner }.proportional_millionths = val;
797 }
798 /// Constructs a new RoutingFees given each field
799 #[must_use]
800 #[no_mangle]
801 pub extern "C" fn RoutingFees_new(mut base_msat_arg: u32, mut proportional_millionths_arg: u32) -> RoutingFees {
802         RoutingFees { inner: Box::into_raw(Box::new(nativeRoutingFees {
803                 base_msat: base_msat_arg,
804                 proportional_millionths: proportional_millionths_arg,
805         })), is_owned: true }
806 }
807 impl Clone for RoutingFees {
808         fn clone(&self) -> Self {
809                 Self {
810                         inner: if <*mut nativeRoutingFees>::is_null(self.inner) { std::ptr::null_mut() } else {
811                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
812                         is_owned: true,
813                 }
814         }
815 }
816 #[allow(unused)]
817 /// Used only if an object of this type is returned as a trait impl by a method
818 pub(crate) extern "C" fn RoutingFees_clone_void(this_ptr: *const c_void) -> *mut c_void {
819         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRoutingFees)).clone() })) as *mut c_void
820 }
821 #[no_mangle]
822 /// Creates a copy of the RoutingFees
823 pub extern "C" fn RoutingFees_clone(orig: &RoutingFees) -> RoutingFees {
824         orig.clone()
825 }
826 #[no_mangle]
827 /// Read a RoutingFees from a byte array, created by RoutingFees_write
828 pub extern "C" fn RoutingFees_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RoutingFeesDecodeErrorZ {
829         let res = crate::c_types::deserialize_obj(ser);
830         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::network_graph::RoutingFees { 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() };
831         local_res
832 }
833 #[no_mangle]
834 /// Serialize the RoutingFees object into a byte array which can be read by RoutingFees_read
835 pub extern "C" fn RoutingFees_write(obj: &RoutingFees) -> crate::c_types::derived::CVec_u8Z {
836         crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
837 }
838 #[no_mangle]
839 pub(crate) extern "C" fn RoutingFees_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
840         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRoutingFees) })
841 }
842
843 use lightning::routing::network_graph::NodeAnnouncementInfo as nativeNodeAnnouncementInfoImport;
844 type nativeNodeAnnouncementInfo = nativeNodeAnnouncementInfoImport;
845
846 /// Information received in the latest node_announcement from this node.
847 #[must_use]
848 #[repr(C)]
849 pub struct NodeAnnouncementInfo {
850         /// A pointer to the opaque Rust object.
851
852         /// Nearly everywhere, inner must be non-null, however in places where
853         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
854         pub inner: *mut nativeNodeAnnouncementInfo,
855         /// Indicates that this is the only struct which contains the same pointer.
856
857         /// Rust functions which take ownership of an object provided via an argument require
858         /// this to be true and invalidate the object pointed to by inner.
859         pub is_owned: bool,
860 }
861
862 impl Drop for NodeAnnouncementInfo {
863         fn drop(&mut self) {
864                 if self.is_owned && !<*mut nativeNodeAnnouncementInfo>::is_null(self.inner) {
865                         let _ = unsafe { Box::from_raw(self.inner) };
866                 }
867         }
868 }
869 /// Frees any resources used by the NodeAnnouncementInfo, if is_owned is set and inner is non-NULL.
870 #[no_mangle]
871 pub extern "C" fn NodeAnnouncementInfo_free(this_obj: NodeAnnouncementInfo) { }
872 #[allow(unused)]
873 /// Used only if an object of this type is returned as a trait impl by a method
874 extern "C" fn NodeAnnouncementInfo_free_void(this_ptr: *mut c_void) {
875         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeAnnouncementInfo); }
876 }
877 #[allow(unused)]
878 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
879 impl NodeAnnouncementInfo {
880         pub(crate) fn take_inner(mut self) -> *mut nativeNodeAnnouncementInfo {
881                 assert!(self.is_owned);
882                 let ret = self.inner;
883                 self.inner = std::ptr::null_mut();
884                 ret
885         }
886 }
887 /// Protocol features the node announced support for
888 #[no_mangle]
889 pub extern "C" fn NodeAnnouncementInfo_get_features(this_ptr: &NodeAnnouncementInfo) -> crate::lightning::ln::features::NodeFeatures {
890         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.features;
891         crate::lightning::ln::features::NodeFeatures { inner: unsafe { ( (&(*inner_val) as *const _) as *mut _) }, is_owned: false }
892 }
893 /// Protocol features the node announced support for
894 #[no_mangle]
895 pub extern "C" fn NodeAnnouncementInfo_set_features(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::lightning::ln::features::NodeFeatures) {
896         unsafe { &mut *this_ptr.inner }.features = *unsafe { Box::from_raw(val.take_inner()) };
897 }
898 /// When the last known update to the node state was issued.
899 /// Value is opaque, as set in the announcement.
900 #[no_mangle]
901 pub extern "C" fn NodeAnnouncementInfo_get_last_update(this_ptr: &NodeAnnouncementInfo) -> u32 {
902         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.last_update;
903         *inner_val
904 }
905 /// When the last known update to the node state was issued.
906 /// Value is opaque, as set in the announcement.
907 #[no_mangle]
908 pub extern "C" fn NodeAnnouncementInfo_set_last_update(this_ptr: &mut NodeAnnouncementInfo, mut val: u32) {
909         unsafe { &mut *this_ptr.inner }.last_update = val;
910 }
911 /// Color assigned to the node
912 #[no_mangle]
913 pub extern "C" fn NodeAnnouncementInfo_get_rgb(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 3] {
914         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.rgb;
915         inner_val
916 }
917 /// Color assigned to the node
918 #[no_mangle]
919 pub extern "C" fn NodeAnnouncementInfo_set_rgb(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThreeBytes) {
920         unsafe { &mut *this_ptr.inner }.rgb = val.data;
921 }
922 /// Moniker assigned to the node.
923 /// May be invalid or malicious (eg control chars),
924 /// should not be exposed to the user.
925 #[no_mangle]
926 pub extern "C" fn NodeAnnouncementInfo_get_alias(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 32] {
927         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.alias;
928         inner_val
929 }
930 /// Moniker assigned to the node.
931 /// May be invalid or malicious (eg control chars),
932 /// should not be exposed to the user.
933 #[no_mangle]
934 pub extern "C" fn NodeAnnouncementInfo_set_alias(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThirtyTwoBytes) {
935         unsafe { &mut *this_ptr.inner }.alias = val.data;
936 }
937 /// Internet-level addresses via which one can connect to the node
938 #[no_mangle]
939 pub extern "C" fn NodeAnnouncementInfo_set_addresses(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::derived::CVec_NetAddressZ) {
940         let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item.into_native() }); };
941         unsafe { &mut *this_ptr.inner }.addresses = local_val;
942 }
943 /// An initial announcement of the node
944 /// Mostly redundant with the data we store in fields explicitly.
945 /// Everything else is useful only for sending out for initial routing sync.
946 /// Not stored if contains excess data to prevent DoS.
947 #[no_mangle]
948 pub extern "C" fn NodeAnnouncementInfo_get_announcement_message(this_ptr: &NodeAnnouncementInfo) -> crate::lightning::ln::msgs::NodeAnnouncement {
949         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.announcement_message;
950         let mut local_inner_val = crate::lightning::ln::msgs::NodeAnnouncement { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else {  { (inner_val.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false };
951         local_inner_val
952 }
953 /// An initial announcement of the node
954 /// Mostly redundant with the data we store in fields explicitly.
955 /// Everything else is useful only for sending out for initial routing sync.
956 /// Not stored if contains excess data to prevent DoS.
957 #[no_mangle]
958 pub extern "C" fn NodeAnnouncementInfo_set_announcement_message(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::lightning::ln::msgs::NodeAnnouncement) {
959         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
960         unsafe { &mut *this_ptr.inner }.announcement_message = local_val;
961 }
962 /// Constructs a new NodeAnnouncementInfo given each field
963 #[must_use]
964 #[no_mangle]
965 pub extern "C" fn NodeAnnouncementInfo_new(mut features_arg: crate::lightning::ln::features::NodeFeatures, mut last_update_arg: u32, mut rgb_arg: crate::c_types::ThreeBytes, mut alias_arg: crate::c_types::ThirtyTwoBytes, mut addresses_arg: crate::c_types::derived::CVec_NetAddressZ, mut announcement_message_arg: crate::lightning::ln::msgs::NodeAnnouncement) -> NodeAnnouncementInfo {
966         let mut local_addresses_arg = Vec::new(); for mut item in addresses_arg.into_rust().drain(..) { local_addresses_arg.push( { item.into_native() }); };
967         let mut local_announcement_message_arg = if announcement_message_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(announcement_message_arg.take_inner()) } }) };
968         NodeAnnouncementInfo { inner: Box::into_raw(Box::new(nativeNodeAnnouncementInfo {
969                 features: *unsafe { Box::from_raw(features_arg.take_inner()) },
970                 last_update: last_update_arg,
971                 rgb: rgb_arg.data,
972                 alias: alias_arg.data,
973                 addresses: local_addresses_arg,
974                 announcement_message: local_announcement_message_arg,
975         })), is_owned: true }
976 }
977 impl Clone for NodeAnnouncementInfo {
978         fn clone(&self) -> Self {
979                 Self {
980                         inner: if <*mut nativeNodeAnnouncementInfo>::is_null(self.inner) { std::ptr::null_mut() } else {
981                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
982                         is_owned: true,
983                 }
984         }
985 }
986 #[allow(unused)]
987 /// Used only if an object of this type is returned as a trait impl by a method
988 pub(crate) extern "C" fn NodeAnnouncementInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
989         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeAnnouncementInfo)).clone() })) as *mut c_void
990 }
991 #[no_mangle]
992 /// Creates a copy of the NodeAnnouncementInfo
993 pub extern "C" fn NodeAnnouncementInfo_clone(orig: &NodeAnnouncementInfo) -> NodeAnnouncementInfo {
994         orig.clone()
995 }
996 #[no_mangle]
997 /// Serialize the NodeAnnouncementInfo object into a byte array which can be read by NodeAnnouncementInfo_read
998 pub extern "C" fn NodeAnnouncementInfo_write(obj: &NodeAnnouncementInfo) -> crate::c_types::derived::CVec_u8Z {
999         crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
1000 }
1001 #[no_mangle]
1002 pub(crate) extern "C" fn NodeAnnouncementInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1003         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeAnnouncementInfo) })
1004 }
1005 #[no_mangle]
1006 /// Read a NodeAnnouncementInfo from a byte array, created by NodeAnnouncementInfo_write
1007 pub extern "C" fn NodeAnnouncementInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeAnnouncementInfoDecodeErrorZ {
1008         let res = crate::c_types::deserialize_obj(ser);
1009         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::network_graph::NodeAnnouncementInfo { 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() };
1010         local_res
1011 }
1012
1013 use lightning::routing::network_graph::NodeInfo as nativeNodeInfoImport;
1014 type nativeNodeInfo = nativeNodeInfoImport;
1015
1016 /// Details about a node in the network, known from the network announcement.
1017 #[must_use]
1018 #[repr(C)]
1019 pub struct NodeInfo {
1020         /// A pointer to the opaque Rust object.
1021
1022         /// Nearly everywhere, inner must be non-null, however in places where
1023         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1024         pub inner: *mut nativeNodeInfo,
1025         /// Indicates that this is the only struct which contains the same pointer.
1026
1027         /// Rust functions which take ownership of an object provided via an argument require
1028         /// this to be true and invalidate the object pointed to by inner.
1029         pub is_owned: bool,
1030 }
1031
1032 impl Drop for NodeInfo {
1033         fn drop(&mut self) {
1034                 if self.is_owned && !<*mut nativeNodeInfo>::is_null(self.inner) {
1035                         let _ = unsafe { Box::from_raw(self.inner) };
1036                 }
1037         }
1038 }
1039 /// Frees any resources used by the NodeInfo, if is_owned is set and inner is non-NULL.
1040 #[no_mangle]
1041 pub extern "C" fn NodeInfo_free(this_obj: NodeInfo) { }
1042 #[allow(unused)]
1043 /// Used only if an object of this type is returned as a trait impl by a method
1044 extern "C" fn NodeInfo_free_void(this_ptr: *mut c_void) {
1045         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeInfo); }
1046 }
1047 #[allow(unused)]
1048 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1049 impl NodeInfo {
1050         pub(crate) fn take_inner(mut self) -> *mut nativeNodeInfo {
1051                 assert!(self.is_owned);
1052                 let ret = self.inner;
1053                 self.inner = std::ptr::null_mut();
1054                 ret
1055         }
1056 }
1057 /// All valid channels a node has announced
1058 #[no_mangle]
1059 pub extern "C" fn NodeInfo_set_channels(this_ptr: &mut NodeInfo, mut val: crate::c_types::derived::CVec_u64Z) {
1060         let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); };
1061         unsafe { &mut *this_ptr.inner }.channels = local_val;
1062 }
1063 /// Lowest fees enabling routing via any of the enabled, known channels to a node.
1064 /// The two fields (flat and proportional fee) are independent,
1065 /// meaning they don't have to refer to the same channel.
1066 #[no_mangle]
1067 pub extern "C" fn NodeInfo_get_lowest_inbound_channel_fees(this_ptr: &NodeInfo) -> crate::lightning::routing::network_graph::RoutingFees {
1068         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.lowest_inbound_channel_fees;
1069         let mut local_inner_val = crate::lightning::routing::network_graph::RoutingFees { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else {  { (inner_val.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false };
1070         local_inner_val
1071 }
1072 /// Lowest fees enabling routing via any of the enabled, known channels to a node.
1073 /// The two fields (flat and proportional fee) are independent,
1074 /// meaning they don't have to refer to the same channel.
1075 #[no_mangle]
1076 pub extern "C" fn NodeInfo_set_lowest_inbound_channel_fees(this_ptr: &mut NodeInfo, mut val: crate::lightning::routing::network_graph::RoutingFees) {
1077         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1078         unsafe { &mut *this_ptr.inner }.lowest_inbound_channel_fees = local_val;
1079 }
1080 /// More information about a node from node_announcement.
1081 /// Optional because we store a Node entry after learning about it from
1082 /// a channel announcement, but before receiving a node announcement.
1083 #[no_mangle]
1084 pub extern "C" fn NodeInfo_get_announcement_info(this_ptr: &NodeInfo) -> crate::lightning::routing::network_graph::NodeAnnouncementInfo {
1085         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.announcement_info;
1086         let mut local_inner_val = crate::lightning::routing::network_graph::NodeAnnouncementInfo { inner: unsafe { (if inner_val.is_none() { std::ptr::null() } else {  { (inner_val.as_ref().unwrap()) } } as *const _) as *mut _ }, is_owned: false };
1087         local_inner_val
1088 }
1089 /// More information about a node from node_announcement.
1090 /// Optional because we store a Node entry after learning about it from
1091 /// a channel announcement, but before receiving a node announcement.
1092 #[no_mangle]
1093 pub extern "C" fn NodeInfo_set_announcement_info(this_ptr: &mut NodeInfo, mut val: crate::lightning::routing::network_graph::NodeAnnouncementInfo) {
1094         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1095         unsafe { &mut *this_ptr.inner }.announcement_info = local_val;
1096 }
1097 /// Constructs a new NodeInfo given each field
1098 #[must_use]
1099 #[no_mangle]
1100 pub extern "C" fn NodeInfo_new(mut channels_arg: crate::c_types::derived::CVec_u64Z, mut lowest_inbound_channel_fees_arg: crate::lightning::routing::network_graph::RoutingFees, mut announcement_info_arg: crate::lightning::routing::network_graph::NodeAnnouncementInfo) -> NodeInfo {
1101         let mut local_channels_arg = Vec::new(); for mut item in channels_arg.into_rust().drain(..) { local_channels_arg.push( { item }); };
1102         let mut local_lowest_inbound_channel_fees_arg = if lowest_inbound_channel_fees_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(lowest_inbound_channel_fees_arg.take_inner()) } }) };
1103         let mut local_announcement_info_arg = if announcement_info_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(announcement_info_arg.take_inner()) } }) };
1104         NodeInfo { inner: Box::into_raw(Box::new(nativeNodeInfo {
1105                 channels: local_channels_arg,
1106                 lowest_inbound_channel_fees: local_lowest_inbound_channel_fees_arg,
1107                 announcement_info: local_announcement_info_arg,
1108         })), is_owned: true }
1109 }
1110 impl Clone for NodeInfo {
1111         fn clone(&self) -> Self {
1112                 Self {
1113                         inner: if <*mut nativeNodeInfo>::is_null(self.inner) { std::ptr::null_mut() } else {
1114                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
1115                         is_owned: true,
1116                 }
1117         }
1118 }
1119 #[allow(unused)]
1120 /// Used only if an object of this type is returned as a trait impl by a method
1121 pub(crate) extern "C" fn NodeInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1122         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeInfo)).clone() })) as *mut c_void
1123 }
1124 #[no_mangle]
1125 /// Creates a copy of the NodeInfo
1126 pub extern "C" fn NodeInfo_clone(orig: &NodeInfo) -> NodeInfo {
1127         orig.clone()
1128 }
1129 #[no_mangle]
1130 /// Serialize the NodeInfo object into a byte array which can be read by NodeInfo_read
1131 pub extern "C" fn NodeInfo_write(obj: &NodeInfo) -> crate::c_types::derived::CVec_u8Z {
1132         crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
1133 }
1134 #[no_mangle]
1135 pub(crate) extern "C" fn NodeInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1136         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeInfo) })
1137 }
1138 #[no_mangle]
1139 /// Read a NodeInfo from a byte array, created by NodeInfo_write
1140 pub extern "C" fn NodeInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeInfoDecodeErrorZ {
1141         let res = crate::c_types::deserialize_obj(ser);
1142         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::network_graph::NodeInfo { 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() };
1143         local_res
1144 }
1145 #[no_mangle]
1146 /// Serialize the NetworkGraph object into a byte array which can be read by NetworkGraph_read
1147 pub extern "C" fn NetworkGraph_write(obj: &NetworkGraph) -> crate::c_types::derived::CVec_u8Z {
1148         crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
1149 }
1150 #[no_mangle]
1151 pub(crate) extern "C" fn NetworkGraph_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1152         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNetworkGraph) })
1153 }
1154 #[no_mangle]
1155 /// Read a NetworkGraph from a byte array, created by NetworkGraph_write
1156 pub extern "C" fn NetworkGraph_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NetworkGraphDecodeErrorZ {
1157         let res = crate::c_types::deserialize_obj(ser);
1158         let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::routing::network_graph::NetworkGraph { 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() };
1159         local_res
1160 }
1161 /// Creates a new, empty, network graph.
1162 #[must_use]
1163 #[no_mangle]
1164 pub extern "C" fn NetworkGraph_new(mut genesis_hash: crate::c_types::ThirtyTwoBytes) -> crate::lightning::routing::network_graph::NetworkGraph {
1165         let mut ret = lightning::routing::network_graph::NetworkGraph::new(::bitcoin::hash_types::BlockHash::from_slice(&genesis_hash.data[..]).unwrap());
1166         crate::lightning::routing::network_graph::NetworkGraph { inner: Box::into_raw(Box::new(ret)), is_owned: true }
1167 }
1168
1169 /// For an already known node (from channel announcements), update its stored properties from a
1170 /// given node announcement.
1171 ///
1172 /// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
1173 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1174 /// routing messages from a source using a protocol other than the lightning P2P protocol.
1175 #[must_use]
1176 #[no_mangle]
1177 pub extern "C" fn NetworkGraph_update_node_from_announcement(this_arg: &mut NetworkGraph, msg: &crate::lightning::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1178         let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_node_from_announcement(unsafe { &*msg.inner }, secp256k1::SECP256K1);
1179         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
1180         local_ret
1181 }
1182
1183 /// For an already known node (from channel announcements), update its stored properties from a
1184 /// given node announcement without verifying the associated signatures. Because we aren't
1185 /// given the associated signatures here we cannot relay the node announcement to any of our
1186 /// peers.
1187 #[must_use]
1188 #[no_mangle]
1189 pub extern "C" fn NetworkGraph_update_node_from_unsigned_announcement(this_arg: &mut NetworkGraph, msg: &crate::lightning::ln::msgs::UnsignedNodeAnnouncement) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1190         let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_node_from_unsigned_announcement(unsafe { &*msg.inner });
1191         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
1192         local_ret
1193 }
1194
1195 /// Store or update channel info from a channel announcement.
1196 ///
1197 /// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
1198 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1199 /// routing messages from a source using a protocol other than the lightning P2P protocol.
1200 ///
1201 /// If a `chain::Access` object is provided via `chain_access`, it will be called to verify
1202 /// the corresponding UTXO exists on chain and is correctly-formatted.
1203 #[must_use]
1204 #[no_mangle]
1205 pub extern "C" fn NetworkGraph_update_channel_from_announcement(this_arg: &mut NetworkGraph, msg: &crate::lightning::ln::msgs::ChannelAnnouncement, chain_access: *mut crate::lightning::chain::Access) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1206         let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) };
1207         let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_channel_from_announcement(unsafe { &*msg.inner }, &local_chain_access, secp256k1::SECP256K1);
1208         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
1209         local_ret
1210 }
1211
1212 /// Store or update channel info from a channel announcement without verifying the associated
1213 /// signatures. Because we aren't given the associated signatures here we cannot relay the
1214 /// channel announcement to any of our peers.
1215 ///
1216 /// If a `chain::Access` object is provided via `chain_access`, it will be called to verify
1217 /// the corresponding UTXO exists on chain and is correctly-formatted.
1218 #[must_use]
1219 #[no_mangle]
1220 pub extern "C" fn NetworkGraph_update_channel_from_unsigned_announcement(this_arg: &mut NetworkGraph, msg: &crate::lightning::ln::msgs::UnsignedChannelAnnouncement, chain_access: *mut crate::lightning::chain::Access) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1221         let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) };
1222         let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_channel_from_unsigned_announcement(unsafe { &*msg.inner }, &local_chain_access);
1223         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
1224         local_ret
1225 }
1226
1227 /// Close a channel if a corresponding HTLC fail was sent.
1228 /// If permanent, removes a channel from the local storage.
1229 /// May cause the removal of nodes too, if this was their last channel.
1230 /// If not permanent, makes channels unavailable for routing.
1231 #[no_mangle]
1232 pub extern "C" fn NetworkGraph_close_channel_from_update(this_arg: &mut NetworkGraph, mut short_channel_id: u64, mut is_permanent: bool) {
1233         unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.close_channel_from_update(short_channel_id, is_permanent)
1234 }
1235
1236 /// For an already known (from announcement) channel, update info about one of the directions
1237 /// of the channel.
1238 ///
1239 /// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
1240 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1241 /// routing messages from a source using a protocol other than the lightning P2P protocol.
1242 #[must_use]
1243 #[no_mangle]
1244 pub extern "C" fn NetworkGraph_update_channel(this_arg: &mut NetworkGraph, msg: &crate::lightning::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1245         let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_channel(unsafe { &*msg.inner }, secp256k1::SECP256K1);
1246         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
1247         local_ret
1248 }
1249
1250 /// For an already known (from announcement) channel, update info about one of the directions
1251 /// of the channel without verifying the associated signatures. Because we aren't given the
1252 /// associated signatures here we cannot relay the channel update to any of our peers.
1253 #[must_use]
1254 #[no_mangle]
1255 pub extern "C" fn NetworkGraph_update_channel_unsigned(this_arg: &mut NetworkGraph, msg: &crate::lightning::ln::msgs::UnsignedChannelUpdate) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1256         let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_channel_unsigned(unsafe { &*msg.inner });
1257         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::LightningError { inner: Box::into_raw(Box::new(e)), is_owned: true } }).into() };
1258         local_ret
1259 }
1260