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
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
31 crate::lightning::ln::msgs::LightningError),
33 use lightning_rapid_gossip_sync::error::GraphSyncError as GraphSyncErrorImport;
34 pub(crate) type nativeGraphSyncError = GraphSyncErrorImport;
38 pub(crate) fn to_native(&self) -> nativeGraphSyncError {
40 GraphSyncError::DecodeError (ref a, ) => {
41 let mut a_nonref = Clone::clone(a);
42 nativeGraphSyncError::DecodeError (
43 a_nonref.into_native(),
46 GraphSyncError::LightningError (ref a, ) => {
47 let mut a_nonref = Clone::clone(a);
48 nativeGraphSyncError::LightningError (
49 *unsafe { Box::from_raw(a_nonref.take_inner()) },
55 pub(crate) fn into_native(self) -> nativeGraphSyncError {
57 GraphSyncError::DecodeError (mut a, ) => {
58 nativeGraphSyncError::DecodeError (
62 GraphSyncError::LightningError (mut a, ) => {
63 nativeGraphSyncError::LightningError (
64 *unsafe { Box::from_raw(a.take_inner()) },
70 pub(crate) fn from_native(native: &nativeGraphSyncError) -> Self {
72 nativeGraphSyncError::DecodeError (ref a, ) => {
73 let mut a_nonref = Clone::clone(a);
74 GraphSyncError::DecodeError (
75 crate::lightning::ln::msgs::DecodeError::native_into(a_nonref),
78 nativeGraphSyncError::LightningError (ref a, ) => {
79 let mut a_nonref = Clone::clone(a);
80 GraphSyncError::LightningError (
81 crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(a_nonref), is_owned: true },
87 pub(crate) fn native_into(native: nativeGraphSyncError) -> Self {
89 nativeGraphSyncError::DecodeError (mut a, ) => {
90 GraphSyncError::DecodeError (
91 crate::lightning::ln::msgs::DecodeError::native_into(a),
94 nativeGraphSyncError::LightningError (mut a, ) => {
95 GraphSyncError::LightningError (
96 crate::lightning::ln::msgs::LightningError { inner: ObjOps::heap_alloc(a), is_owned: true },
102 /// Frees any resources used by the GraphSyncError
104 pub extern "C" fn GraphSyncError_free(this_ptr: GraphSyncError) { }
105 /// Creates a copy of the GraphSyncError
107 pub extern "C" fn GraphSyncError_clone(orig: &GraphSyncError) -> GraphSyncError {
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, )
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, )