Merge pull request #36 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 #[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( { () /*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( { () /*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( { () /*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( { () /*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 /// Checks if two RoutingFeess contain equal inner contents.
808 /// This ignores pointers and is_owned flags and looks at the values in fields.
809 /// Two objects with NULL inner values will be considered "equal" here.
810 #[no_mangle]
811 pub extern "C" fn RoutingFees_eq(a: &RoutingFees, b: &RoutingFees) -> bool {
812         if a.inner == b.inner { return true; }
813         if a.inner.is_null() || b.inner.is_null() { return false; }
814         if unsafe { &*a.inner } == unsafe { &*b.inner } { true } else { false }
815 }
816 impl Clone for RoutingFees {
817         fn clone(&self) -> Self {
818                 Self {
819                         inner: if <*mut nativeRoutingFees>::is_null(self.inner) { std::ptr::null_mut() } else {
820                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
821                         is_owned: true,
822                 }
823         }
824 }
825 #[allow(unused)]
826 /// Used only if an object of this type is returned as a trait impl by a method
827 pub(crate) extern "C" fn RoutingFees_clone_void(this_ptr: *const c_void) -> *mut c_void {
828         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRoutingFees)).clone() })) as *mut c_void
829 }
830 #[no_mangle]
831 /// Creates a copy of the RoutingFees
832 pub extern "C" fn RoutingFees_clone(orig: &RoutingFees) -> RoutingFees {
833         orig.clone()
834 }
835 #[no_mangle]
836 /// Serialize the RoutingFees object into a byte array which can be read by RoutingFees_read
837 pub extern "C" fn RoutingFees_write(obj: &RoutingFees) -> crate::c_types::derived::CVec_u8Z {
838         crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
839 }
840 #[no_mangle]
841 pub(crate) extern "C" fn RoutingFees_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
842         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRoutingFees) })
843 }
844 #[no_mangle]
845 /// Read a RoutingFees from a byte array, created by RoutingFees_write
846 pub extern "C" fn RoutingFees_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RoutingFeesDecodeErrorZ {
847         let res = crate::c_types::deserialize_obj(ser);
848         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() };
849         local_res
850 }
851
852 use lightning::routing::network_graph::NodeAnnouncementInfo as nativeNodeAnnouncementInfoImport;
853 type nativeNodeAnnouncementInfo = nativeNodeAnnouncementInfoImport;
854
855 /// Information received in the latest node_announcement from this node.
856 #[must_use]
857 #[repr(C)]
858 pub struct NodeAnnouncementInfo {
859         /// A pointer to the opaque Rust object.
860
861         /// Nearly everywhere, inner must be non-null, however in places where
862         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
863         pub inner: *mut nativeNodeAnnouncementInfo,
864         /// Indicates that this is the only struct which contains the same pointer.
865
866         /// Rust functions which take ownership of an object provided via an argument require
867         /// this to be true and invalidate the object pointed to by inner.
868         pub is_owned: bool,
869 }
870
871 impl Drop for NodeAnnouncementInfo {
872         fn drop(&mut self) {
873                 if self.is_owned && !<*mut nativeNodeAnnouncementInfo>::is_null(self.inner) {
874                         let _ = unsafe { Box::from_raw(self.inner) };
875                 }
876         }
877 }
878 /// Frees any resources used by the NodeAnnouncementInfo, if is_owned is set and inner is non-NULL.
879 #[no_mangle]
880 pub extern "C" fn NodeAnnouncementInfo_free(this_obj: NodeAnnouncementInfo) { }
881 #[allow(unused)]
882 /// Used only if an object of this type is returned as a trait impl by a method
883 extern "C" fn NodeAnnouncementInfo_free_void(this_ptr: *mut c_void) {
884         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeAnnouncementInfo); }
885 }
886 #[allow(unused)]
887 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
888 impl NodeAnnouncementInfo {
889         pub(crate) fn take_inner(mut self) -> *mut nativeNodeAnnouncementInfo {
890                 assert!(self.is_owned);
891                 let ret = self.inner;
892                 self.inner = std::ptr::null_mut();
893                 ret
894         }
895 }
896 /// Protocol features the node announced support for
897 #[no_mangle]
898 pub extern "C" fn NodeAnnouncementInfo_get_features(this_ptr: &NodeAnnouncementInfo) -> crate::lightning::ln::features::NodeFeatures {
899         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.features;
900         crate::lightning::ln::features::NodeFeatures { inner: unsafe { ( (&(*inner_val) as *const _) as *mut _) }, is_owned: false }
901 }
902 /// Protocol features the node announced support for
903 #[no_mangle]
904 pub extern "C" fn NodeAnnouncementInfo_set_features(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::lightning::ln::features::NodeFeatures) {
905         unsafe { &mut *this_ptr.inner }.features = *unsafe { Box::from_raw(val.take_inner()) };
906 }
907 /// When the last known update to the node state was issued.
908 /// Value is opaque, as set in the announcement.
909 #[no_mangle]
910 pub extern "C" fn NodeAnnouncementInfo_get_last_update(this_ptr: &NodeAnnouncementInfo) -> u32 {
911         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.last_update;
912         *inner_val
913 }
914 /// When the last known update to the node state was issued.
915 /// Value is opaque, as set in the announcement.
916 #[no_mangle]
917 pub extern "C" fn NodeAnnouncementInfo_set_last_update(this_ptr: &mut NodeAnnouncementInfo, mut val: u32) {
918         unsafe { &mut *this_ptr.inner }.last_update = val;
919 }
920 /// Color assigned to the node
921 #[no_mangle]
922 pub extern "C" fn NodeAnnouncementInfo_get_rgb(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 3] {
923         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.rgb;
924         inner_val
925 }
926 /// Color assigned to the node
927 #[no_mangle]
928 pub extern "C" fn NodeAnnouncementInfo_set_rgb(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThreeBytes) {
929         unsafe { &mut *this_ptr.inner }.rgb = val.data;
930 }
931 /// Moniker assigned to the node.
932 /// May be invalid or malicious (eg control chars),
933 /// should not be exposed to the user.
934 #[no_mangle]
935 pub extern "C" fn NodeAnnouncementInfo_get_alias(this_ptr: &NodeAnnouncementInfo) -> *const [u8; 32] {
936         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.alias;
937         inner_val
938 }
939 /// Moniker assigned to the node.
940 /// May be invalid or malicious (eg control chars),
941 /// should not be exposed to the user.
942 #[no_mangle]
943 pub extern "C" fn NodeAnnouncementInfo_set_alias(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::ThirtyTwoBytes) {
944         unsafe { &mut *this_ptr.inner }.alias = val.data;
945 }
946 /// Internet-level addresses via which one can connect to the node
947 #[no_mangle]
948 pub extern "C" fn NodeAnnouncementInfo_set_addresses(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::c_types::derived::CVec_NetAddressZ) {
949         let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item.into_native() }); };
950         unsafe { &mut *this_ptr.inner }.addresses = local_val;
951 }
952 /// An initial announcement of the node
953 /// Mostly redundant with the data we store in fields explicitly.
954 /// Everything else is useful only for sending out for initial routing sync.
955 /// Not stored if contains excess data to prevent DoS.
956 #[no_mangle]
957 pub extern "C" fn NodeAnnouncementInfo_get_announcement_message(this_ptr: &NodeAnnouncementInfo) -> crate::lightning::ln::msgs::NodeAnnouncement {
958         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.announcement_message;
959         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 };
960         local_inner_val
961 }
962 /// An initial announcement of the node
963 /// Mostly redundant with the data we store in fields explicitly.
964 /// Everything else is useful only for sending out for initial routing sync.
965 /// Not stored if contains excess data to prevent DoS.
966 #[no_mangle]
967 pub extern "C" fn NodeAnnouncementInfo_set_announcement_message(this_ptr: &mut NodeAnnouncementInfo, mut val: crate::lightning::ln::msgs::NodeAnnouncement) {
968         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
969         unsafe { &mut *this_ptr.inner }.announcement_message = local_val;
970 }
971 /// Constructs a new NodeAnnouncementInfo given each field
972 #[must_use]
973 #[no_mangle]
974 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 {
975         let mut local_addresses_arg = Vec::new(); for mut item in addresses_arg.into_rust().drain(..) { local_addresses_arg.push( { item.into_native() }); };
976         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()) } }) };
977         NodeAnnouncementInfo { inner: Box::into_raw(Box::new(nativeNodeAnnouncementInfo {
978                 features: *unsafe { Box::from_raw(features_arg.take_inner()) },
979                 last_update: last_update_arg,
980                 rgb: rgb_arg.data,
981                 alias: alias_arg.data,
982                 addresses: local_addresses_arg,
983                 announcement_message: local_announcement_message_arg,
984         })), is_owned: true }
985 }
986 impl Clone for NodeAnnouncementInfo {
987         fn clone(&self) -> Self {
988                 Self {
989                         inner: if <*mut nativeNodeAnnouncementInfo>::is_null(self.inner) { std::ptr::null_mut() } else {
990                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
991                         is_owned: true,
992                 }
993         }
994 }
995 #[allow(unused)]
996 /// Used only if an object of this type is returned as a trait impl by a method
997 pub(crate) extern "C" fn NodeAnnouncementInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
998         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeAnnouncementInfo)).clone() })) as *mut c_void
999 }
1000 #[no_mangle]
1001 /// Creates a copy of the NodeAnnouncementInfo
1002 pub extern "C" fn NodeAnnouncementInfo_clone(orig: &NodeAnnouncementInfo) -> NodeAnnouncementInfo {
1003         orig.clone()
1004 }
1005 #[no_mangle]
1006 /// Serialize the NodeAnnouncementInfo object into a byte array which can be read by NodeAnnouncementInfo_read
1007 pub extern "C" fn NodeAnnouncementInfo_write(obj: &NodeAnnouncementInfo) -> crate::c_types::derived::CVec_u8Z {
1008         crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
1009 }
1010 #[no_mangle]
1011 pub(crate) extern "C" fn NodeAnnouncementInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1012         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeAnnouncementInfo) })
1013 }
1014 #[no_mangle]
1015 /// Read a NodeAnnouncementInfo from a byte array, created by NodeAnnouncementInfo_write
1016 pub extern "C" fn NodeAnnouncementInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeAnnouncementInfoDecodeErrorZ {
1017         let res = crate::c_types::deserialize_obj(ser);
1018         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() };
1019         local_res
1020 }
1021
1022 use lightning::routing::network_graph::NodeInfo as nativeNodeInfoImport;
1023 type nativeNodeInfo = nativeNodeInfoImport;
1024
1025 /// Details about a node in the network, known from the network announcement.
1026 #[must_use]
1027 #[repr(C)]
1028 pub struct NodeInfo {
1029         /// A pointer to the opaque Rust object.
1030
1031         /// Nearly everywhere, inner must be non-null, however in places where
1032         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
1033         pub inner: *mut nativeNodeInfo,
1034         /// Indicates that this is the only struct which contains the same pointer.
1035
1036         /// Rust functions which take ownership of an object provided via an argument require
1037         /// this to be true and invalidate the object pointed to by inner.
1038         pub is_owned: bool,
1039 }
1040
1041 impl Drop for NodeInfo {
1042         fn drop(&mut self) {
1043                 if self.is_owned && !<*mut nativeNodeInfo>::is_null(self.inner) {
1044                         let _ = unsafe { Box::from_raw(self.inner) };
1045                 }
1046         }
1047 }
1048 /// Frees any resources used by the NodeInfo, if is_owned is set and inner is non-NULL.
1049 #[no_mangle]
1050 pub extern "C" fn NodeInfo_free(this_obj: NodeInfo) { }
1051 #[allow(unused)]
1052 /// Used only if an object of this type is returned as a trait impl by a method
1053 extern "C" fn NodeInfo_free_void(this_ptr: *mut c_void) {
1054         unsafe { let _ = Box::from_raw(this_ptr as *mut nativeNodeInfo); }
1055 }
1056 #[allow(unused)]
1057 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
1058 impl NodeInfo {
1059         pub(crate) fn take_inner(mut self) -> *mut nativeNodeInfo {
1060                 assert!(self.is_owned);
1061                 let ret = self.inner;
1062                 self.inner = std::ptr::null_mut();
1063                 ret
1064         }
1065 }
1066 /// All valid channels a node has announced
1067 #[no_mangle]
1068 pub extern "C" fn NodeInfo_set_channels(this_ptr: &mut NodeInfo, mut val: crate::c_types::derived::CVec_u64Z) {
1069         let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); };
1070         unsafe { &mut *this_ptr.inner }.channels = local_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_get_lowest_inbound_channel_fees(this_ptr: &NodeInfo) -> crate::lightning::routing::network_graph::RoutingFees {
1077         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.lowest_inbound_channel_fees;
1078         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 };
1079         local_inner_val
1080 }
1081 /// Lowest fees enabling routing via any of the enabled, known channels to a node.
1082 /// The two fields (flat and proportional fee) are independent,
1083 /// meaning they don't have to refer to the same channel.
1084 #[no_mangle]
1085 pub extern "C" fn NodeInfo_set_lowest_inbound_channel_fees(this_ptr: &mut NodeInfo, mut val: crate::lightning::routing::network_graph::RoutingFees) {
1086         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1087         unsafe { &mut *this_ptr.inner }.lowest_inbound_channel_fees = local_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_get_announcement_info(this_ptr: &NodeInfo) -> crate::lightning::routing::network_graph::NodeAnnouncementInfo {
1094         let mut inner_val = &mut unsafe { &mut *this_ptr.inner }.announcement_info;
1095         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 };
1096         local_inner_val
1097 }
1098 /// More information about a node from node_announcement.
1099 /// Optional because we store a Node entry after learning about it from
1100 /// a channel announcement, but before receiving a node announcement.
1101 #[no_mangle]
1102 pub extern "C" fn NodeInfo_set_announcement_info(this_ptr: &mut NodeInfo, mut val: crate::lightning::routing::network_graph::NodeAnnouncementInfo) {
1103         let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) };
1104         unsafe { &mut *this_ptr.inner }.announcement_info = local_val;
1105 }
1106 /// Constructs a new NodeInfo given each field
1107 #[must_use]
1108 #[no_mangle]
1109 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 {
1110         let mut local_channels_arg = Vec::new(); for mut item in channels_arg.into_rust().drain(..) { local_channels_arg.push( { item }); };
1111         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()) } }) };
1112         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()) } }) };
1113         NodeInfo { inner: Box::into_raw(Box::new(nativeNodeInfo {
1114                 channels: local_channels_arg,
1115                 lowest_inbound_channel_fees: local_lowest_inbound_channel_fees_arg,
1116                 announcement_info: local_announcement_info_arg,
1117         })), is_owned: true }
1118 }
1119 impl Clone for NodeInfo {
1120         fn clone(&self) -> Self {
1121                 Self {
1122                         inner: if <*mut nativeNodeInfo>::is_null(self.inner) { std::ptr::null_mut() } else {
1123                                 Box::into_raw(Box::new(unsafe { &*self.inner }.clone())) },
1124                         is_owned: true,
1125                 }
1126         }
1127 }
1128 #[allow(unused)]
1129 /// Used only if an object of this type is returned as a trait impl by a method
1130 pub(crate) extern "C" fn NodeInfo_clone_void(this_ptr: *const c_void) -> *mut c_void {
1131         Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeInfo)).clone() })) as *mut c_void
1132 }
1133 #[no_mangle]
1134 /// Creates a copy of the NodeInfo
1135 pub extern "C" fn NodeInfo_clone(orig: &NodeInfo) -> NodeInfo {
1136         orig.clone()
1137 }
1138 #[no_mangle]
1139 /// Serialize the NodeInfo object into a byte array which can be read by NodeInfo_read
1140 pub extern "C" fn NodeInfo_write(obj: &NodeInfo) -> crate::c_types::derived::CVec_u8Z {
1141         crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
1142 }
1143 #[no_mangle]
1144 pub(crate) extern "C" fn NodeInfo_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1145         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeInfo) })
1146 }
1147 #[no_mangle]
1148 /// Read a NodeInfo from a byte array, created by NodeInfo_write
1149 pub extern "C" fn NodeInfo_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NodeInfoDecodeErrorZ {
1150         let res = crate::c_types::deserialize_obj(ser);
1151         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() };
1152         local_res
1153 }
1154 #[no_mangle]
1155 /// Serialize the NetworkGraph object into a byte array which can be read by NetworkGraph_read
1156 pub extern "C" fn NetworkGraph_write(obj: &NetworkGraph) -> crate::c_types::derived::CVec_u8Z {
1157         crate::c_types::serialize_obj(unsafe { &*unsafe { &*obj }.inner })
1158 }
1159 #[no_mangle]
1160 pub(crate) extern "C" fn NetworkGraph_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
1161         crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNetworkGraph) })
1162 }
1163 #[no_mangle]
1164 /// Read a NetworkGraph from a byte array, created by NetworkGraph_write
1165 pub extern "C" fn NetworkGraph_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_NetworkGraphDecodeErrorZ {
1166         let res = crate::c_types::deserialize_obj(ser);
1167         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() };
1168         local_res
1169 }
1170 /// Creates a new, empty, network graph.
1171 #[must_use]
1172 #[no_mangle]
1173 pub extern "C" fn NetworkGraph_new(mut genesis_hash: crate::c_types::ThirtyTwoBytes) -> crate::lightning::routing::network_graph::NetworkGraph {
1174         let mut ret = lightning::routing::network_graph::NetworkGraph::new(::bitcoin::hash_types::BlockHash::from_slice(&genesis_hash.data[..]).unwrap());
1175         crate::lightning::routing::network_graph::NetworkGraph { inner: Box::into_raw(Box::new(ret)), is_owned: true }
1176 }
1177
1178 /// For an already known node (from channel announcements), update its stored properties from a
1179 /// given node announcement.
1180 ///
1181 /// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
1182 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1183 /// routing messages from a source using a protocol other than the lightning P2P protocol.
1184 #[must_use]
1185 #[no_mangle]
1186 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 {
1187         let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_node_from_announcement(unsafe { &*msg.inner }, secp256k1::SECP256K1);
1188         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() };
1189         local_ret
1190 }
1191
1192 /// For an already known node (from channel announcements), update its stored properties from a
1193 /// given node announcement without verifying the associated signatures. Because we aren't
1194 /// given the associated signatures here we cannot relay the node announcement to any of our
1195 /// peers.
1196 #[must_use]
1197 #[no_mangle]
1198 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 {
1199         let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_node_from_unsigned_announcement(unsafe { &*msg.inner });
1200         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() };
1201         local_ret
1202 }
1203
1204 /// Store or update channel info from a channel announcement.
1205 ///
1206 /// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
1207 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1208 /// routing messages from a source using a protocol other than the lightning P2P protocol.
1209 ///
1210 /// If a `chain::Access` object is provided via `chain_access`, it will be called to verify
1211 /// the corresponding UTXO exists on chain and is correctly-formatted.
1212 #[must_use]
1213 #[no_mangle]
1214 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 {
1215         let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) };
1216         let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_channel_from_announcement(unsafe { &*msg.inner }, &local_chain_access, secp256k1::SECP256K1);
1217         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() };
1218         local_ret
1219 }
1220
1221 /// Store or update channel info from a channel announcement without verifying the associated
1222 /// signatures. Because we aren't given the associated signatures here we cannot relay the
1223 /// channel announcement to any of our peers.
1224 ///
1225 /// If a `chain::Access` object is provided via `chain_access`, it will be called to verify
1226 /// the corresponding UTXO exists on chain and is correctly-formatted.
1227 #[must_use]
1228 #[no_mangle]
1229 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 {
1230         let mut local_chain_access = if chain_access == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_access) } }) };
1231         let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_channel_from_unsigned_announcement(unsafe { &*msg.inner }, &local_chain_access);
1232         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() };
1233         local_ret
1234 }
1235
1236 /// Close a channel if a corresponding HTLC fail was sent.
1237 /// If permanent, removes a channel from the local storage.
1238 /// May cause the removal of nodes too, if this was their last channel.
1239 /// If not permanent, makes channels unavailable for routing.
1240 #[no_mangle]
1241 pub extern "C" fn NetworkGraph_close_channel_from_update(this_arg: &mut NetworkGraph, mut short_channel_id: u64, mut is_permanent: bool) {
1242         unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.close_channel_from_update(short_channel_id, is_permanent)
1243 }
1244
1245 /// For an already known (from announcement) channel, update info about one of the directions
1246 /// of the channel.
1247 ///
1248 /// You probably don't want to call this directly, instead relying on a NetGraphMsgHandler's
1249 /// RoutingMessageHandler implementation to call it indirectly. This may be useful to accept
1250 /// routing messages from a source using a protocol other than the lightning P2P protocol.
1251 #[must_use]
1252 #[no_mangle]
1253 pub extern "C" fn NetworkGraph_update_channel(this_arg: &mut NetworkGraph, msg: &crate::lightning::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1254         let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_channel(unsafe { &*msg.inner }, secp256k1::SECP256K1);
1255         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() };
1256         local_ret
1257 }
1258
1259 /// For an already known (from announcement) channel, update info about one of the directions
1260 /// of the channel without verifying the associated signatures. Because we aren't given the
1261 /// associated signatures here we cannot relay the channel update to any of our peers.
1262 #[must_use]
1263 #[no_mangle]
1264 pub extern "C" fn NetworkGraph_update_channel_unsigned(this_arg: &mut NetworkGraph, msg: &crate::lightning::ln::msgs::UnsignedChannelUpdate) -> crate::c_types::derived::CResult_NoneLightningErrorZ {
1265         let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeNetworkGraph)) }.update_channel_unsigned(unsafe { &*msg.inner });
1266         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() };
1267         local_ret
1268 }
1269