X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-c-bindings%2Fsrc%2Flightning%2Futil%2Ferrors.rs;h=ff0f416bd499fb15c0fcd9d68a5661bdad8a0553;hb=11b997c3a0452ea1da5b7b352e7887798105db29;hp=fffe44fe462440b66338c7ccab1273ac68b3294b;hpb=ae39d0e5a34ef021db50b12a7be96f0694fd1b18;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 fffe44f..ff0f416 100644 --- a/lightning-c-bindings/src/lightning/util/errors.rs +++ b/lightning-c-bindings/src/lightning/util/errors.rs @@ -39,7 +39,7 @@ pub enum APIError { }, /// A malformed Route was provided (eg overflowed value, node id mismatch, overly-looped route, /// too-many-hops, etc). - RouteError { + InvalidRoute { /// A human-readable error message err: crate::c_types::Str, }, @@ -50,16 +50,22 @@ 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, - /// [`KeysInterface::get_shutdown_scriptpubkey`] returned a shutdown scriptpubkey incompatible + /// 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, + /// [`SignerProvider::get_shutdown_scriptpubkey`] returned a shutdown scriptpubkey incompatible /// with the channel counterparty as negotiated in [`InitFeatures`]. /// /// Using a SegWit v0 script should resolve this issue. If you cannot, you won't be able to open /// a channel or cooperatively close one with this peer (and will have to force-close instead). /// - /// [`KeysInterface::get_shutdown_scriptpubkey`]: crate::chain::keysinterface::KeysInterface::get_shutdown_scriptpubkey + /// [`SignerProvider::get_shutdown_scriptpubkey`]: crate::chain::keysinterface::SignerProvider::get_shutdown_scriptpubkey /// [`InitFeatures`]: crate::ln::features::InitFeatures IncompatibleShutdownScript { /// The incompatible shutdown script. @@ -74,34 +80,34 @@ impl APIError { pub(crate) fn to_native(&self) -> nativeAPIError { match self { APIError::APIMisuseError {ref err, } => { - let mut err_nonref = (*err).clone(); + let mut err_nonref = Clone::clone(err); nativeAPIError::APIMisuseError { err: err_nonref.into_string(), } }, APIError::FeeRateTooHigh {ref err, ref feerate, } => { - let mut err_nonref = (*err).clone(); - let mut feerate_nonref = (*feerate).clone(); + let mut err_nonref = Clone::clone(err); + let mut feerate_nonref = Clone::clone(feerate); nativeAPIError::FeeRateTooHigh { err: err_nonref.into_string(), feerate: feerate_nonref, } }, - APIError::RouteError {ref err, } => { - let mut err_nonref = (*err).clone(); - nativeAPIError::RouteError { - err: err_nonref.into_str(), + APIError::InvalidRoute {ref err, } => { + let mut err_nonref = Clone::clone(err); + nativeAPIError::InvalidRoute { + err: err_nonref.into_string(), } }, APIError::ChannelUnavailable {ref err, } => { - let mut err_nonref = (*err).clone(); + let mut err_nonref = Clone::clone(err); nativeAPIError::ChannelUnavailable { err: err_nonref.into_string(), } }, - APIError::MonitorUpdateFailed => nativeAPIError::MonitorUpdateFailed, + APIError::MonitorUpdateInProgress => nativeAPIError::MonitorUpdateInProgress, APIError::IncompatibleShutdownScript {ref script, } => { - let mut script_nonref = (*script).clone(); + let mut script_nonref = Clone::clone(script); nativeAPIError::IncompatibleShutdownScript { script: *unsafe { Box::from_raw(script_nonref.take_inner()) }, } @@ -122,9 +128,9 @@ impl APIError { feerate: feerate, } }, - APIError::RouteError {mut err, } => { - nativeAPIError::RouteError { - err: err.into_str(), + APIError::InvalidRoute {mut err, } => { + nativeAPIError::InvalidRoute { + err: err.into_string(), } }, APIError::ChannelUnavailable {mut err, } => { @@ -132,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()) }, @@ -144,34 +150,34 @@ impl APIError { pub(crate) fn from_native(native: &nativeAPIError) -> Self { match native { nativeAPIError::APIMisuseError {ref err, } => { - let mut err_nonref = (*err).clone(); + let mut err_nonref = Clone::clone(err); APIError::APIMisuseError { err: err_nonref.into(), } }, nativeAPIError::FeeRateTooHigh {ref err, ref feerate, } => { - let mut err_nonref = (*err).clone(); - let mut feerate_nonref = (*feerate).clone(); + let mut err_nonref = Clone::clone(err); + let mut feerate_nonref = Clone::clone(feerate); APIError::FeeRateTooHigh { err: err_nonref.into(), feerate: feerate_nonref, } }, - nativeAPIError::RouteError {ref err, } => { - let mut err_nonref = (*err).clone(); - APIError::RouteError { + nativeAPIError::InvalidRoute {ref err, } => { + let mut err_nonref = Clone::clone(err); + APIError::InvalidRoute { err: err_nonref.into(), } }, nativeAPIError::ChannelUnavailable {ref err, } => { - let mut err_nonref = (*err).clone(); + let mut err_nonref = Clone::clone(err); APIError::ChannelUnavailable { err: err_nonref.into(), } }, - nativeAPIError::MonitorUpdateFailed => APIError::MonitorUpdateFailed, + nativeAPIError::MonitorUpdateInProgress => APIError::MonitorUpdateInProgress, nativeAPIError::IncompatibleShutdownScript {ref script, } => { - let mut script_nonref = (*script).clone(); + let mut script_nonref = Clone::clone(script); APIError::IncompatibleShutdownScript { script: crate::lightning::ln::script::ShutdownScript { inner: ObjOps::heap_alloc(script_nonref), is_owned: true }, } @@ -192,8 +198,8 @@ impl APIError { feerate: feerate, } }, - nativeAPIError::RouteError {mut err, } => { - APIError::RouteError { + nativeAPIError::InvalidRoute {mut err, } => { + APIError::InvalidRoute { err: err.into(), } }, @@ -202,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 }, @@ -235,9 +241,9 @@ pub extern "C" fn APIError_fee_rate_too_high(err: crate::c_types::Str, feerate: } } #[no_mangle] -/// Utility method to constructs a new RouteError-variant APIError -pub extern "C" fn APIError_route_error(err: crate::c_types::Str) -> APIError { - APIError::RouteError { +/// Utility method to constructs a new InvalidRoute-variant APIError +pub extern "C" fn APIError_invalid_route(err: crate::c_types::Str) -> APIError { + APIError::InvalidRoute { err, } } @@ -249,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 { @@ -259,3 +265,21 @@ 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 } +} +#[no_mangle] +/// Serialize the APIError object into a byte array which can be read by APIError_read +pub extern "C" fn APIError_write(obj: &crate::lightning::util::errors::APIError) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(&unsafe { &*obj }.to_native()) +} +#[no_mangle] +/// Read a APIError from a byte array, created by APIError_write +pub extern "C" fn APIError_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_COption_APIErrorZDecodeErrorZ { + let res: Result, lightning::ln::msgs::DecodeError> = crate::c_types::maybe_deserialize_obj(ser); + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { let mut local_res_0 = if o.is_none() { crate::c_types::derived::COption_APIErrorZ::None } else { crate::c_types::derived::COption_APIErrorZ::Some( { crate::lightning::util::errors::APIError::native_into(o.unwrap()) }) }; local_res_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; + local_res +}