X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-c-bindings%2Fsrc%2Flightning%2Futil%2Ferrors.rs;h=4c911a5f2ddd9ce3b6ddfde0e60886a0bbfe33a0;hb=a21177846ed75d66f68a1603f768410f07a65791;hp=4764a70c106b9d34f43e2e2e0a8502dc347fcbbc;hpb=696382c9fbc707aa5226f73910625136adb724fd;p=ldk-c-bindings diff --git a/lightning-c-bindings/src/lightning/util/errors.rs b/lightning-c-bindings/src/lightning/util/errors.rs index 4764a70..4c911a5 100644 --- a/lightning-c-bindings/src/lightning/util/errors.rs +++ b/lightning-c-bindings/src/lightning/util/errors.rs @@ -8,15 +8,18 @@ //! Error types live here. -use std::str::FromStr; -use std::ffi::c_void; +use alloc::str::FromStr; +use core::ffi::c_void; +use core::convert::Infallible; use bitcoin::hashes::Hash; use crate::c_types::*; +#[cfg(feature="no-std")] +use alloc::{vec::Vec, boxed::Box}; /// Indicates an error on the client's part (usually some variant of attempting to use too-low or /// too-high values) -#[must_use] #[derive(Clone)] +#[must_use] #[repr(C)] pub enum APIError { /// Indicates the API was wholly misused (see err for more). Cases where these can be returned @@ -47,9 +50,15 @@ pub enum APIError { /// A human-readable error message err: crate::c_types::Str, }, - /// An attempt to call watch/update_channel returned an Err (ie you did this!), causing the - /// attempted action to fail. - MonitorUpdateFailed, + /// An attempt to call [`chain::Watch::watch_channel`]/[`chain::Watch::update_channel`] + /// returned a [`ChannelMonitorUpdateStatus::InProgress`] indicating the persistence of a + /// monitor update is awaiting async resolution. Once it resolves the attempted action should + /// complete automatically. + /// + /// [`chain::Watch::watch_channel`]: crate::chain::Watch::watch_channel + /// [`chain::Watch::update_channel`]: crate::chain::Watch::update_channel + /// [`ChannelMonitorUpdateStatus::InProgress`]: crate::chain::ChannelMonitorUpdateStatus::InProgress + MonitorUpdateInProgress, /// [`KeysInterface::get_shutdown_scriptpubkey`] returned a shutdown scriptpubkey incompatible /// with the channel counterparty as negotiated in [`InitFeatures`]. /// @@ -63,7 +72,9 @@ pub enum APIError { script: crate::lightning::ln::script::ShutdownScript, }, } -use lightning::util::errors::APIError as nativeAPIError; +use lightning::util::errors::APIError as APIErrorImport; +pub(crate) type nativeAPIError = APIErrorImport; + impl APIError { #[allow(unused)] pub(crate) fn to_native(&self) -> nativeAPIError { @@ -94,7 +105,7 @@ impl APIError { err: err_nonref.into_string(), } }, - APIError::MonitorUpdateFailed => nativeAPIError::MonitorUpdateFailed, + APIError::MonitorUpdateInProgress => nativeAPIError::MonitorUpdateInProgress, APIError::IncompatibleShutdownScript {ref script, } => { let mut script_nonref = (*script).clone(); nativeAPIError::IncompatibleShutdownScript { @@ -127,7 +138,7 @@ impl APIError { err: err.into_string(), } }, - APIError::MonitorUpdateFailed => nativeAPIError::MonitorUpdateFailed, + APIError::MonitorUpdateInProgress => nativeAPIError::MonitorUpdateInProgress, APIError::IncompatibleShutdownScript {mut script, } => { nativeAPIError::IncompatibleShutdownScript { script: *unsafe { Box::from_raw(script.take_inner()) }, @@ -164,7 +175,7 @@ impl APIError { err: err_nonref.into(), } }, - nativeAPIError::MonitorUpdateFailed => APIError::MonitorUpdateFailed, + nativeAPIError::MonitorUpdateInProgress => APIError::MonitorUpdateInProgress, nativeAPIError::IncompatibleShutdownScript {ref script, } => { let mut script_nonref = (*script).clone(); APIError::IncompatibleShutdownScript { @@ -197,7 +208,7 @@ impl APIError { err: err.into(), } }, - nativeAPIError::MonitorUpdateFailed => APIError::MonitorUpdateFailed, + nativeAPIError::MonitorUpdateInProgress => APIError::MonitorUpdateInProgress, nativeAPIError::IncompatibleShutdownScript {mut script, } => { APIError::IncompatibleShutdownScript { script: crate::lightning::ln::script::ShutdownScript { inner: ObjOps::heap_alloc(script), is_owned: true }, @@ -244,9 +255,9 @@ pub extern "C" fn APIError_channel_unavailable(err: crate::c_types::Str) -> APIE } } #[no_mangle] -/// Utility method to constructs a new MonitorUpdateFailed-variant APIError -pub extern "C" fn APIError_monitor_update_failed() -> APIError { - APIError::MonitorUpdateFailed} +/// Utility method to constructs a new MonitorUpdateInProgress-variant APIError +pub extern "C" fn APIError_monitor_update_in_progress() -> APIError { + APIError::MonitorUpdateInProgress} #[no_mangle] /// Utility method to constructs a new IncompatibleShutdownScript-variant APIError pub extern "C" fn APIError_incompatible_shutdown_script(script: crate::lightning::ln::script::ShutdownScript) -> APIError { @@ -254,3 +265,9 @@ pub extern "C" fn APIError_incompatible_shutdown_script(script: crate::lightning script, } } +/// Checks if two APIErrors contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +#[no_mangle] +pub extern "C" fn APIError_eq(a: &APIError, b: &APIError) -> bool { + if &a.to_native() == &b.to_native() { true } else { false } +}