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