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