X-Git-Url: http://git.bitcoin.ninja/index.cgi?p=ldk-c-bindings;a=blobdiff_plain;f=lightning-c-bindings%2Fsrc%2Flightning%2Fln%2Ffeatures.rs;h=c0a52b3ee74f39e7df9800b8278ad0614020bdc3;hp=591173e31cf12f5161a30208ccc1a7b2b353b5cf;hb=23b946be5cf633afdba94e12fd71380cafdf49be;hpb=b33cce1a6255564b88e0615eb5c7941bd7b15759 diff --git a/lightning-c-bindings/src/lightning/ln/features.rs b/lightning-c-bindings/src/lightning/ln/features.rs index 591173e..c0a52b3 100644 --- a/lightning-c-bindings/src/lightning/ln/features.rs +++ b/lightning-c-bindings/src/lightning/ln/features.rs @@ -72,6 +72,15 @@ pub extern "C" fn InvoiceFeatures_eq(a: &InvoiceFeatures, b: &InvoiceFeatures) - if a.inner.is_null() || b.inner.is_null() { return false; } if a.get_native_ref() == b.get_native_ref() { true } else { false } } +/// Checks if two ChannelTypeFeaturess contain equal inner contents. +/// This ignores pointers and is_owned flags and looks at the values in fields. +/// Two objects with NULL inner values will be considered "equal" here. +#[no_mangle] +pub extern "C" fn ChannelTypeFeatures_eq(a: &ChannelTypeFeatures, b: &ChannelTypeFeatures) -> bool { + if a.inner == b.inner { return true; } + if a.inner.is_null() || b.inner.is_null() { return false; } + if a.get_native_ref() == b.get_native_ref() { true } else { false } +} impl Clone for InitFeatures { fn clone(&self) -> Self { Self { @@ -148,6 +157,25 @@ pub(crate) extern "C" fn InvoiceFeatures_clone_void(this_ptr: *const c_void) -> pub extern "C" fn InvoiceFeatures_clone(orig: &InvoiceFeatures) -> InvoiceFeatures { orig.clone() } +impl Clone for ChannelTypeFeatures { + fn clone(&self) -> Self { + Self { + inner: if <*mut nativeChannelTypeFeatures>::is_null(self.inner) { std::ptr::null_mut() } else { + ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, + is_owned: true, + } + } +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn ChannelTypeFeatures_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelTypeFeatures)).clone() })) as *mut c_void +} +#[no_mangle] +/// Creates a copy of the ChannelTypeFeatures +pub extern "C" fn ChannelTypeFeatures_clone(orig: &ChannelTypeFeatures) -> ChannelTypeFeatures { + orig.clone() +} use lightning::ln::features::InitFeatures as nativeInitFeaturesImport; pub(crate) type nativeInitFeatures = nativeInitFeaturesImport; @@ -352,6 +380,66 @@ impl InvoiceFeatures { ret } } + +use lightning::ln::features::ChannelTypeFeatures as nativeChannelTypeFeaturesImport; +pub(crate) type nativeChannelTypeFeatures = nativeChannelTypeFeaturesImport; + +/// Features used within the channel_type field in an OpenChannel message. +/// +/// A channel is always of some known \"type\", describing the transaction formats used and the exact +/// semantics of our interaction with our peer. +/// +/// Note that because a channel is a specific type which is proposed by the opener and accepted by +/// the counterparty, only required features are allowed here. +/// +/// This is serialized differently from other feature types - it is not prefixed by a length, and +/// thus must only appear inside a TLV where its length is known in advance. +#[must_use] +#[repr(C)] +pub struct ChannelTypeFeatures { + /// A pointer to the opaque Rust object. + + /// Nearly everywhere, inner must be non-null, however in places where + /// the Rust equivalent takes an Option, it may be set to null to indicate None. + pub inner: *mut nativeChannelTypeFeatures, + /// Indicates that this is the only struct which contains the same pointer. + + /// Rust functions which take ownership of an object provided via an argument require + /// this to be true and invalidate the object pointed to by inner. + pub is_owned: bool, +} + +impl Drop for ChannelTypeFeatures { + fn drop(&mut self) { + if self.is_owned && !<*mut nativeChannelTypeFeatures>::is_null(self.inner) { + let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; + } + } +} +/// Frees any resources used by the ChannelTypeFeatures, if is_owned is set and inner is non-NULL. +#[no_mangle] +pub extern "C" fn ChannelTypeFeatures_free(this_obj: ChannelTypeFeatures) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn ChannelTypeFeatures_free_void(this_ptr: *mut c_void) { + unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChannelTypeFeatures); } +} +#[allow(unused)] +impl ChannelTypeFeatures { + pub(crate) fn get_native_ref(&self) -> &'static nativeChannelTypeFeatures { + unsafe { &*ObjOps::untweak_ptr(self.inner) } + } + pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelTypeFeatures { + unsafe { &mut *ObjOps::untweak_ptr(self.inner) } + } + /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy + pub(crate) fn take_inner(mut self) -> *mut nativeChannelTypeFeatures { + assert!(self.is_owned); + let ret = ObjOps::untweak_ptr(self.inner); + self.inner = std::ptr::null_mut(); + ret + } +} /// Create a blank Features with no features set #[must_use] #[no_mangle] @@ -452,27 +540,28 @@ pub extern "C" fn InvoiceFeatures_requires_unknown_bits(this_arg: &InvoiceFeatur ret } -/// Returns whether the `payment_secret` feature is supported. +/// Create a blank Features with no features set #[must_use] #[no_mangle] -pub extern "C" fn InitFeatures_supports_payment_secret(this_arg: &InitFeatures) -> bool { - let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.supports_payment_secret(); - ret +pub extern "C" fn ChannelTypeFeatures_empty() -> ChannelTypeFeatures { + let mut ret = lightning::ln::features::ChannelTypeFeatures::empty(); + ChannelTypeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true } } -/// Returns whether the `payment_secret` feature is supported. +/// Creates a Features with the bits set which are known by the implementation #[must_use] #[no_mangle] -pub extern "C" fn NodeFeatures_supports_payment_secret(this_arg: &NodeFeatures) -> bool { - let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.supports_payment_secret(); - ret +pub extern "C" fn ChannelTypeFeatures_known() -> ChannelTypeFeatures { + let mut ret = lightning::ln::features::ChannelTypeFeatures::known(); + ChannelTypeFeatures { inner: ObjOps::heap_alloc(ret), is_owned: true } } -/// Returns whether the `payment_secret` feature is supported. +/// Returns true if this `Features` object contains unknown feature flags which are set as +/// \"required\". #[must_use] #[no_mangle] -pub extern "C" fn InvoiceFeatures_supports_payment_secret(this_arg: &InvoiceFeatures) -> bool { - let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.supports_payment_secret(); +pub extern "C" fn ChannelTypeFeatures_requires_unknown_bits(this_arg: &ChannelTypeFeatures) -> bool { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.requires_unknown_bits(); ret } @@ -486,13 +575,11 @@ pub(crate) extern "C" fn InitFeatures_write_void(obj: *const c_void) -> crate::c crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInitFeatures) }) } #[no_mangle] -/// Serialize the NodeFeatures object into a byte array which can be read by NodeFeatures_read -pub extern "C" fn NodeFeatures_write(obj: &NodeFeatures) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) -} -#[no_mangle] -pub(crate) extern "C" fn NodeFeatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeFeatures) }) +/// Read a InitFeatures from a byte array, created by InitFeatures_write +pub extern "C" fn InitFeatures_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_InitFeaturesDecodeErrorZ { + let res: Result = crate::c_types::deserialize_obj(ser); + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + local_res } #[no_mangle] /// Serialize the ChannelFeatures object into a byte array which can be read by ChannelFeatures_read @@ -504,20 +591,20 @@ pub(crate) extern "C" fn ChannelFeatures_write_void(obj: *const c_void) -> crate crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelFeatures) }) } #[no_mangle] -/// Serialize the InvoiceFeatures object into a byte array which can be read by InvoiceFeatures_read -pub extern "C" fn InvoiceFeatures_write(obj: &InvoiceFeatures) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) +/// Read a ChannelFeatures from a byte array, created by ChannelFeatures_write +pub extern "C" fn ChannelFeatures_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelFeaturesDecodeErrorZ { + let res: Result = crate::c_types::deserialize_obj(ser); + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::features::ChannelFeatures { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + local_res } #[no_mangle] -pub(crate) extern "C" fn InvoiceFeatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInvoiceFeatures) }) +/// Serialize the NodeFeatures object into a byte array which can be read by NodeFeatures_read +pub extern "C" fn NodeFeatures_write(obj: &NodeFeatures) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } #[no_mangle] -/// Read a InitFeatures from a byte array, created by InitFeatures_write -pub extern "C" fn InitFeatures_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_InitFeaturesDecodeErrorZ { - let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::features::InitFeatures { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; - local_res +pub(crate) extern "C" fn NodeFeatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeFeatures) }) } #[no_mangle] /// Read a NodeFeatures from a byte array, created by NodeFeatures_write @@ -527,11 +614,13 @@ pub extern "C" fn NodeFeatures_read(ser: crate::c_types::u8slice) -> crate::c_ty local_res } #[no_mangle] -/// Read a ChannelFeatures from a byte array, created by ChannelFeatures_write -pub extern "C" fn ChannelFeatures_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelFeaturesDecodeErrorZ { - let res: Result = crate::c_types::deserialize_obj(ser); - let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::features::ChannelFeatures { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; - local_res +/// Serialize the InvoiceFeatures object into a byte array which can be read by InvoiceFeatures_read +pub extern "C" fn InvoiceFeatures_write(obj: &InvoiceFeatures) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) +} +#[no_mangle] +pub(crate) extern "C" fn InvoiceFeatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInvoiceFeatures) }) } #[no_mangle] /// Read a InvoiceFeatures from a byte array, created by InvoiceFeatures_write @@ -540,3 +629,19 @@ pub extern "C" fn InvoiceFeatures_read(ser: crate::c_types::u8slice) -> crate::c let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::features::InvoiceFeatures { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; local_res } +#[no_mangle] +/// Serialize the ChannelTypeFeatures object into a byte array which can be read by ChannelTypeFeatures_read +pub extern "C" fn ChannelTypeFeatures_write(obj: &ChannelTypeFeatures) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) +} +#[no_mangle] +pub(crate) extern "C" fn ChannelTypeFeatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelTypeFeatures) }) +} +#[no_mangle] +/// Read a ChannelTypeFeatures from a byte array, created by ChannelTypeFeatures_write +pub extern "C" fn ChannelTypeFeatures_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_ChannelTypeFeaturesDecodeErrorZ { + let res: Result = crate::c_types::deserialize_obj(ser); + let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::features::ChannelTypeFeatures { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError { inner: ObjOps::heap_alloc(e), is_owned: true } }).into() }; + local_res +}