1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
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.
9 /// Error types that these functions can return
11 use alloc::str::FromStr;
12 use alloc::string::String;
13 use core::ffi::c_void;
14 use core::convert::Infallible;
15 use bitcoin::hashes::Hash;
16 use crate::c_types::*;
17 #[cfg(feature="no-std")]
18 use alloc::{vec::Vec, boxed::Box};
20 /// All-encompassing standard error type that processing can return
24 pub enum GraphSyncError {
25 /// Error trying to read the update data, typically due to an erroneous data length indication
26 /// that is greater than the actual amount of data provided
28 crate::lightning::ln::msgs::DecodeError),
29 /// Error applying the patch to the network graph, usually the result of updates that are too
30 /// old or missing prerequisite data to the application of updates out of order
32 crate::lightning::ln::msgs::LightningError),
34 use lightning_rapid_gossip_sync::error::GraphSyncError as GraphSyncErrorImport;
35 pub(crate) type nativeGraphSyncError = GraphSyncErrorImport;
39 pub(crate) fn to_native(&self) -> nativeGraphSyncError {
41 GraphSyncError::DecodeError (ref a, ) => {
42 let mut a_nonref = Clone::clone(a);
43 nativeGraphSyncError::DecodeError (
44 a_nonref.into_native(),
47 GraphSyncError::LightningError (ref a, ) => {
48 let mut a_nonref = Clone::clone(a);
49 nativeGraphSyncError::LightningError (
50 *unsafe { Box::from_raw(a_nonref.take_inner()) },
56 pub(crate) fn into_native(self) -> nativeGraphSyncError {
58 GraphSyncError::DecodeError (mut a, ) => {
59 nativeGraphSyncError::DecodeError (
63 GraphSyncError::LightningError (mut a, ) => {
64 nativeGraphSyncError::LightningError (
65 *unsafe { Box::from_raw(a.take_inner()) },
71 pub(crate) fn from_native(native: &nativeGraphSyncError) -> Self {
73 nativeGraphSyncError::DecodeError (ref a, ) => {
74 let mut a_nonref = Clone::clone(a);
75 GraphSyncError::DecodeError (
76 crate::lightning::ln::msgs::DecodeError::native_into(a_nonref),
79 nativeGraphSyncError::LightningError (ref a, ) => {
80 let mut a_nonref = Clone::clone(a);
81 GraphSyncError::LightningError (
82 crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
88 pub(crate) fn native_into(native: nativeGraphSyncError) -> Self {
90 nativeGraphSyncError::DecodeError (mut a, ) => {
91 GraphSyncError::DecodeError (
92 crate::lightning::ln::msgs::DecodeError::native_into(a),
95 nativeGraphSyncError::LightningError (mut a, ) => {
96 GraphSyncError::LightningError (
97 crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(a), is_owned: true },
103 /// Frees any resources used by the GraphSyncError
105 pub extern "C" fn GraphSyncError_free(this_ptr: GraphSyncError) { }
106 /// Creates a copy of the GraphSyncError
108 pub extern "C" fn GraphSyncError_clone(orig: &GraphSyncError) -> GraphSyncError {
112 /// Utility method to constructs a new DecodeError-variant GraphSyncError
113 pub extern "C" fn GraphSyncError_decode_error(a: crate::lightning::ln::msgs::DecodeError) -> GraphSyncError {
114 GraphSyncError::DecodeError(a, )
117 /// Utility method to constructs a new LightningError-variant GraphSyncError
118 pub extern "C" fn GraphSyncError_lightning_error(a: crate::lightning::ln::msgs::LightningError) -> GraphSyncError {
119 GraphSyncError::LightningError(a, )