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 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};
19 /// All-encompassing standard error type that processing can return
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(crate::lightning::ln::msgs::DecodeError),
27 /// Error applying the patch to the network graph, usually the result of updates that are too
28 /// old or missing prerequisite data to the application of updates out of order
29 LightningError(crate::lightning::ln::msgs::LightningError),
31 use lightning_rapid_gossip_sync::error::GraphSyncError as GraphSyncErrorImport;
32 pub(crate) type nativeGraphSyncError = GraphSyncErrorImport;
36 pub(crate) fn to_native(&self) -> nativeGraphSyncError {
38 GraphSyncError::DecodeError (ref a, ) => {
39 let mut a_nonref = (*a).clone();
40 nativeGraphSyncError::DecodeError (
41 *unsafe { Box::from_raw(a_nonref.take_inner()) },
44 GraphSyncError::LightningError (ref a, ) => {
45 let mut a_nonref = (*a).clone();
46 nativeGraphSyncError::LightningError (
47 *unsafe { Box::from_raw(a_nonref.take_inner()) },
53 pub(crate) fn into_native(self) -> nativeGraphSyncError {
55 GraphSyncError::DecodeError (mut a, ) => {
56 nativeGraphSyncError::DecodeError (
57 *unsafe { Box::from_raw(a.take_inner()) },
60 GraphSyncError::LightningError (mut a, ) => {
61 nativeGraphSyncError::LightningError (
62 *unsafe { Box::from_raw(a.take_inner()) },
68 pub(crate) fn from_native(native: &nativeGraphSyncError) -> Self {
70 nativeGraphSyncError::DecodeError (ref a, ) => {
71 let mut a_nonref = (*a).clone();
72 GraphSyncError::DecodeError (
73 crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
76 nativeGraphSyncError::LightningError (ref a, ) => {
77 let mut a_nonref = (*a).clone();
78 GraphSyncError::LightningError (
79 crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
85 pub(crate) fn native_into(native: nativeGraphSyncError) -> Self {
87 nativeGraphSyncError::DecodeError (mut a, ) => {
88 GraphSyncError::DecodeError (
89 crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(a), is_owned: true },
92 nativeGraphSyncError::LightningError (mut a, ) => {
93 GraphSyncError::LightningError (
94 crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(a), is_owned: true },
100 /// Frees any resources used by the GraphSyncError
102 pub extern "C" fn GraphSyncError_free(this_ptr: GraphSyncError) { }
103 /// Creates a copy of the GraphSyncError
105 pub extern "C" fn GraphSyncError_clone(orig: &GraphSyncError) -> GraphSyncError {
109 /// Utility method to constructs a new DecodeError-variant GraphSyncError
110 pub extern "C" fn GraphSyncError_decode_error(a: crate::lightning::ln::msgs::DecodeError) -> GraphSyncError {
111 GraphSyncError::DecodeError(a, )
114 /// Utility method to constructs a new LightningError-variant GraphSyncError
115 pub extern "C" fn GraphSyncError_lightning_error(a: crate::lightning::ln::msgs::LightningError) -> GraphSyncError {
116 GraphSyncError::LightningError(a, )