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