0fe5716afaeaa3d6e95e0b5148cc18112aba7a26
[ldk-c-bindings] / lightning-c-bindings / src / lightning_rapid_gossip_sync / error.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 /// Error types that these functions can return
10
11 use alloc::str::FromStr;
12 use core::ffi::c_void;
13 use core::convert::Infallible;
14 use bitcoin::hashes::Hash;
15 use crate::c_types::*;
16 #[cfg(feature="no-std")]
17 use alloc::{vec::Vec, boxed::Box};
18
19 /// All-encompassing standard error type that processing can return
20 #[derive(Clone)]
21 #[must_use]
22 #[repr(C)]
23 pub enum GraphSyncError {
24         /// Error trying to read the update data, typically due to an erroneous data length indication
25         /// that is greater than the actual amount of data provided
26         DecodeError(
27                 crate::lightning::ln::msgs::DecodeError),
28         /// Error applying the patch to the network graph, usually the result of updates that are too
29         /// old or missing prerequisite data to the application of updates out of order
30         LightningError(
31                 crate::lightning::ln::msgs::LightningError),
32 }
33 use lightning_rapid_gossip_sync::error::GraphSyncError as GraphSyncErrorImport;
34 pub(crate) type nativeGraphSyncError = GraphSyncErrorImport;
35
36 impl GraphSyncError {
37         #[allow(unused)]
38         pub(crate) fn to_native(&self) -> nativeGraphSyncError {
39                 match self {
40                         GraphSyncError::DecodeError (ref a, ) => {
41                                 let mut a_nonref = (*a).clone();
42                                 nativeGraphSyncError::DecodeError (
43                                         a_nonref.into_native(),
44                                 )
45                         },
46                         GraphSyncError::LightningError (ref a, ) => {
47                                 let mut a_nonref = (*a).clone();
48                                 nativeGraphSyncError::LightningError (
49                                         *unsafe { Box::from_raw(a_nonref.take_inner()) },
50                                 )
51                         },
52                 }
53         }
54         #[allow(unused)]
55         pub(crate) fn into_native(self) -> nativeGraphSyncError {
56                 match self {
57                         GraphSyncError::DecodeError (mut a, ) => {
58                                 nativeGraphSyncError::DecodeError (
59                                         a.into_native(),
60                                 )
61                         },
62                         GraphSyncError::LightningError (mut a, ) => {
63                                 nativeGraphSyncError::LightningError (
64                                         *unsafe { Box::from_raw(a.take_inner()) },
65                                 )
66                         },
67                 }
68         }
69         #[allow(unused)]
70         pub(crate) fn from_native(native: &nativeGraphSyncError) -> Self {
71                 match native {
72                         nativeGraphSyncError::DecodeError (ref a, ) => {
73                                 let mut a_nonref = (*a).clone();
74                                 GraphSyncError::DecodeError (
75                                         crate::lightning::ln::msgs::DecodeError::native_into(a_nonref),
76                                 )
77                         },
78                         nativeGraphSyncError::LightningError (ref a, ) => {
79                                 let mut a_nonref = (*a).clone();
80                                 GraphSyncError::LightningError (
81                                         crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
82                                 )
83                         },
84                 }
85         }
86         #[allow(unused)]
87         pub(crate) fn native_into(native: nativeGraphSyncError) -> Self {
88                 match native {
89                         nativeGraphSyncError::DecodeError (mut a, ) => {
90                                 GraphSyncError::DecodeError (
91                                         crate::lightning::ln::msgs::DecodeError::native_into(a),
92                                 )
93                         },
94                         nativeGraphSyncError::LightningError (mut a, ) => {
95                                 GraphSyncError::LightningError (
96                                         crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(a), is_owned: true },
97                                 )
98                         },
99                 }
100         }
101 }
102 /// Frees any resources used by the GraphSyncError
103 #[no_mangle]
104 pub extern "C" fn GraphSyncError_free(this_ptr: GraphSyncError) { }
105 /// Creates a copy of the GraphSyncError
106 #[no_mangle]
107 pub extern "C" fn GraphSyncError_clone(orig: &GraphSyncError) -> GraphSyncError {
108         orig.clone()
109 }
110 #[no_mangle]
111 /// Utility method to constructs a new DecodeError-variant GraphSyncError
112 pub extern "C" fn GraphSyncError_decode_error(a: crate::lightning::ln::msgs::DecodeError) -> GraphSyncError {
113         GraphSyncError::DecodeError(a, )
114 }
115 #[no_mangle]
116 /// Utility method to constructs a new LightningError-variant GraphSyncError
117 pub extern "C" fn GraphSyncError_lightning_error(a: crate::lightning::ln::msgs::LightningError) -> GraphSyncError {
118         GraphSyncError::LightningError(a, )
119 }