X-Git-Url: http://git.bitcoin.ninja/index.cgi?p=ldk-c-bindings;a=blobdiff_plain;f=lightning-c-bindings%2Fsrc%2Flightning%2Futil%2Ferrors.rs;h=a3933b9b5591e7ed3412d6f71cd62134afd135c3;hp=81faa98f461e08b9e4f2091e9cf28229dbf960bd;hb=1eaf50a3d9f777b462ff1817678473567a00eb75;hpb=9e34ca7e68bc8caca0b76f29efbac903ce5b9d2b diff --git a/lightning-c-bindings/src/lightning/util/errors.rs b/lightning-c-bindings/src/lightning/util/errors.rs index 81faa98..a3933b9 100644 --- a/lightning-c-bindings/src/lightning/util/errors.rs +++ b/lightning-c-bindings/src/lightning/util/errors.rs @@ -8,10 +8,13 @@ //! 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) @@ -50,6 +53,18 @@ pub enum APIError { /// 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 + /// 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 + /// [`InitFeatures`]: crate::ln::features::InitFeatures + IncompatibleShutdownScript { + /// The incompatible shutdown script. + script: crate::lightning::ln::script::ShutdownScript, + }, } use lightning::util::errors::APIError as nativeAPIError; impl APIError { @@ -83,6 +98,12 @@ impl APIError { } }, APIError::MonitorUpdateFailed => nativeAPIError::MonitorUpdateFailed, + APIError::IncompatibleShutdownScript {ref script, } => { + let mut script_nonref = (*script).clone(); + nativeAPIError::IncompatibleShutdownScript { + script: *unsafe { Box::from_raw(script_nonref.take_inner()) }, + } + }, } } #[allow(unused)] @@ -110,6 +131,11 @@ impl APIError { } }, APIError::MonitorUpdateFailed => nativeAPIError::MonitorUpdateFailed, + APIError::IncompatibleShutdownScript {mut script, } => { + nativeAPIError::IncompatibleShutdownScript { + script: *unsafe { Box::from_raw(script.take_inner()) }, + } + }, } } #[allow(unused)] @@ -142,6 +168,12 @@ impl APIError { } }, nativeAPIError::MonitorUpdateFailed => APIError::MonitorUpdateFailed, + nativeAPIError::IncompatibleShutdownScript {ref script, } => { + let mut script_nonref = (*script).clone(); + APIError::IncompatibleShutdownScript { + script: crate::lightning::ln::script::ShutdownScript { inner: ObjOps::heap_alloc(script_nonref), is_owned: true }, + } + }, } } #[allow(unused)] @@ -169,6 +201,11 @@ impl APIError { } }, nativeAPIError::MonitorUpdateFailed => APIError::MonitorUpdateFailed, + nativeAPIError::IncompatibleShutdownScript {mut script, } => { + APIError::IncompatibleShutdownScript { + script: crate::lightning::ln::script::ShutdownScript { inner: ObjOps::heap_alloc(script), is_owned: true }, + } + }, } } } @@ -180,3 +217,43 @@ pub extern "C" fn APIError_free(this_ptr: APIError) { } pub extern "C" fn APIError_clone(orig: &APIError) -> APIError { orig.clone() } +#[no_mangle] +/// Utility method to constructs a new APIMisuseError-variant APIError +pub extern "C" fn APIError_apimisuse_error(err: crate::c_types::Str) -> APIError { + APIError::APIMisuseError { + err, + } +} +#[no_mangle] +/// Utility method to constructs a new FeeRateTooHigh-variant APIError +pub extern "C" fn APIError_fee_rate_too_high(err: crate::c_types::Str, feerate: u32) -> APIError { + APIError::FeeRateTooHigh { + err, + 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 { + err, + } +} +#[no_mangle] +/// Utility method to constructs a new ChannelUnavailable-variant APIError +pub extern "C" fn APIError_channel_unavailable(err: crate::c_types::Str) -> APIError { + APIError::ChannelUnavailable { + err, + } +} +#[no_mangle] +/// Utility method to constructs a new MonitorUpdateFailed-variant APIError +pub extern "C" fn APIError_monitor_update_failed() -> APIError { + APIError::MonitorUpdateFailed} +#[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 { + APIError::IncompatibleShutdownScript { + script, + } +}