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