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