X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=lightning-c-bindings%2Fsrc%2Flightning%2Fln%2Fmsgs.rs;h=279dcdf35be6a7d9fc02063580a874f91b12a91a;hb=HEAD;hp=dbc239726e4143fa9efdb3bcb6f0047aff46b69e;hpb=f7105f5bb3fdf379d58286eacd8e44edba686954;p=ldk-c-bindings diff --git a/lightning-c-bindings/src/lightning/ln/msgs.rs b/lightning-c-bindings/src/lightning/ln/msgs.rs index dbc2397..89c8181 100644 --- a/lightning-c-bindings/src/lightning/ln/msgs.rs +++ b/lightning-c-bindings/src/lightning/ln/msgs.rs @@ -58,6 +58,16 @@ pub enum DecodeError { crate::c_types::IOError), /// The message included zlib-compressed values, which we don't support. UnsupportedCompression, + /// Value is validly encoded but is dangerous to use. + /// + /// This is used for things like [`ChannelManager`] deserialization where we want to ensure + /// that we don't use a [`ChannelManager`] which is in out of sync with the [`ChannelMonitor`]. + /// This indicates that there is a critical implementation flaw in the storage implementation + /// and it's unsafe to continue. + /// + /// [`ChannelManager`]: crate::ln::channelmanager::ChannelManager + /// [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor + DangerousValue, } use lightning::ln::msgs::DecodeError as DecodeErrorImport; pub(crate) type nativeDecodeError = DecodeErrorImport; @@ -78,6 +88,7 @@ impl DecodeError { ) }, DecodeError::UnsupportedCompression => nativeDecodeError::UnsupportedCompression, + DecodeError::DangerousValue => nativeDecodeError::DangerousValue, } } #[allow(unused)] @@ -94,10 +105,12 @@ impl DecodeError { ) }, DecodeError::UnsupportedCompression => nativeDecodeError::UnsupportedCompression, + DecodeError::DangerousValue => nativeDecodeError::DangerousValue, } } #[allow(unused)] - pub(crate) fn from_native(native: &nativeDecodeError) -> Self { + pub(crate) fn from_native(native: &DecodeErrorImport) -> Self { + let native = unsafe { &*(native as *const _ as *const c_void as *const nativeDecodeError) }; match native { nativeDecodeError::UnknownVersion => DecodeError::UnknownVersion, nativeDecodeError::UnknownRequiredFeature => DecodeError::UnknownRequiredFeature, @@ -111,6 +124,7 @@ impl DecodeError { ) }, nativeDecodeError::UnsupportedCompression => DecodeError::UnsupportedCompression, + nativeDecodeError::DangerousValue => DecodeError::DangerousValue, } } #[allow(unused)] @@ -127,6 +141,7 @@ impl DecodeError { ) }, nativeDecodeError::UnsupportedCompression => DecodeError::UnsupportedCompression, + nativeDecodeError::DangerousValue => DecodeError::DangerousValue, } } } @@ -138,6 +153,16 @@ pub extern "C" fn DecodeError_free(this_ptr: DecodeError) { } pub extern "C" fn DecodeError_clone(orig: &DecodeError) -> DecodeError { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn DecodeError_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const DecodeError)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn DecodeError_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut DecodeError) }; +} #[no_mangle] /// Utility method to constructs a new UnknownVersion-variant DecodeError pub extern "C" fn DecodeError_unknown_version() -> DecodeError { @@ -167,6 +192,22 @@ pub extern "C" fn DecodeError_io(a: crate::c_types::IOError) -> DecodeError { /// Utility method to constructs a new UnsupportedCompression-variant DecodeError pub extern "C" fn DecodeError_unsupported_compression() -> DecodeError { DecodeError::UnsupportedCompression} +#[no_mangle] +/// Utility method to constructs a new DangerousValue-variant DecodeError +pub extern "C" fn DecodeError_dangerous_value() -> DecodeError { + DecodeError::DangerousValue} +/// Get a string which allows debug introspection of a DecodeError object +pub extern "C" fn DecodeError_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::DecodeError }).into()} +/// Generates a non-cryptographic 64-bit hash of the DecodeError. +#[no_mangle] +pub extern "C" fn DecodeError_hash(o: &DecodeError) -> u64 { + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(&o.to_native(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two DecodeErrors contain equal inner contents. /// This ignores pointers and is_owned flags and looks at the values in fields. #[no_mangle] @@ -195,6 +236,12 @@ pub struct Init { pub is_owned: bool, } +impl core::ops::Deref for Init { + type Target = nativeInit; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for Init { } +unsafe impl core::marker::Sync for Init { } impl Drop for Init { fn drop(&mut self) { if self.is_owned && !<*mut nativeInit>::is_null(self.inner) { @@ -225,16 +272,19 @@ impl Init { self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// The relevant features which the sender supports. #[no_mangle] -pub extern "C" fn Init_get_features(this_ptr: &Init) -> crate::lightning::ln::features::InitFeatures { +pub extern "C" fn Init_get_features(this_ptr: &Init) -> crate::lightning_types::features::InitFeatures { let mut inner_val = &mut this_ptr.get_native_mut_ref().features; - crate::lightning::ln::features::InitFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::features::InitFeatures<>) as *mut _) }, is_owned: false } + crate::lightning_types::features::InitFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning_types::features::InitFeatures<>) as *mut _) }, is_owned: false } } /// The relevant features which the sender supports. #[no_mangle] -pub extern "C" fn Init_set_features(this_ptr: &mut Init, mut val: crate::lightning::ln::features::InitFeatures) { +pub extern "C" fn Init_set_features(this_ptr: &mut Init, mut val: crate::lightning_types::features::InitFeatures) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) }; } /// Indicates chains the sender is interested in. @@ -245,7 +295,7 @@ pub extern "C" fn Init_set_features(this_ptr: &mut Init, mut val: crate::lightni #[no_mangle] pub extern "C" fn Init_get_networks(this_ptr: &Init) -> crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ { let mut inner_val = this_ptr.get_native_mut_ref().networks.clone(); - let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ::None } else { crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ::Some( { let mut local_inner_val_0 = Vec::new(); for mut item in inner_val.unwrap().drain(..) { local_inner_val_0.push( { crate::c_types::ThirtyTwoBytes { data: item.to_bytes() } }); }; local_inner_val_0.into() }) }; + let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ::None } else { crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ::Some( { let mut local_inner_val_0 = Vec::new(); for mut item in inner_val.unwrap().drain(..) { local_inner_val_0.push( { crate::c_types::ThirtyTwoBytes { data: *item.as_ref() } }); }; local_inner_val_0.into() }) }; local_inner_val } /// Indicates chains the sender is interested in. @@ -253,7 +303,7 @@ pub extern "C" fn Init_get_networks(this_ptr: &Init) -> crate::c_types::derived: /// If there are no common chains, the connection will be closed. #[no_mangle] pub extern "C" fn Init_set_networks(this_ptr: &mut Init, mut val: crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ) { - let mut local_val = { /*val*/ let val_opt = val; if val_opt.is_none() { None } else { Some({ { let mut local_val_0 = Vec::new(); for mut item in { val_opt.take() }.into_rust().drain(..) { local_val_0.push( { ::bitcoin::blockdata::constants::ChainHash::from(&item.data[..]) }); }; local_val_0 }})} }; + let mut local_val = { /*val*/ let val_opt = val; if val_opt.is_none() { None } else { Some({ { let mut local_val_0 = Vec::new(); for mut item in { val_opt.take() }.into_rust().drain(..) { local_val_0.push( { ::bitcoin::constants::ChainHash::from(&item.data) }); }; local_val_0 }})} }; unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.networks = local_val; } /// The receipient's network address. @@ -282,8 +332,8 @@ pub extern "C" fn Init_set_remote_network_address(this_ptr: &mut Init, mut val: /// Constructs a new Init given each field #[must_use] #[no_mangle] -pub extern "C" fn Init_new(mut features_arg: crate::lightning::ln::features::InitFeatures, mut networks_arg: crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ, mut remote_network_address_arg: crate::c_types::derived::COption_SocketAddressZ) -> Init { - let mut local_networks_arg = { /*networks_arg*/ let networks_arg_opt = networks_arg; if networks_arg_opt.is_none() { None } else { Some({ { let mut local_networks_arg_0 = Vec::new(); for mut item in { networks_arg_opt.take() }.into_rust().drain(..) { local_networks_arg_0.push( { ::bitcoin::blockdata::constants::ChainHash::from(&item.data[..]) }); }; local_networks_arg_0 }})} }; +pub extern "C" fn Init_new(mut features_arg: crate::lightning_types::features::InitFeatures, mut networks_arg: crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ, mut remote_network_address_arg: crate::c_types::derived::COption_SocketAddressZ) -> Init { + let mut local_networks_arg = { /*networks_arg*/ let networks_arg_opt = networks_arg; if networks_arg_opt.is_none() { None } else { Some({ { let mut local_networks_arg_0 = Vec::new(); for mut item in { networks_arg_opt.take() }.into_rust().drain(..) { local_networks_arg_0.push( { ::bitcoin::constants::ChainHash::from(&item.data) }); }; local_networks_arg_0 }})} }; let mut local_remote_network_address_arg = { /*remote_network_address_arg*/ let remote_network_address_arg_opt = remote_network_address_arg; if remote_network_address_arg_opt.is_none() { None } else { Some({ { { remote_network_address_arg_opt.take() }.into_native() }})} }; Init { inner: ObjOps::heap_alloc(nativeInit { features: *unsafe { Box::from_raw(features_arg.take_inner()) }, @@ -303,13 +353,26 @@ impl Clone for Init { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn Init_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeInit)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeInit)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the Init pub extern "C" fn Init_clone(orig: &Init) -> Init { orig.clone() } +/// Get a string which allows debug introspection of a Init object +pub extern "C" fn Init_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::Init }).into()} +/// Generates a non-cryptographic 64-bit hash of the Init. +#[no_mangle] +pub extern "C" fn Init_hash(o: &Init) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two Inits 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. @@ -341,6 +404,12 @@ pub struct ErrorMessage { pub is_owned: bool, } +impl core::ops::Deref for ErrorMessage { + type Target = nativeErrorMessage; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for ErrorMessage { } +unsafe impl core::marker::Sync for ErrorMessage { } impl Drop for ErrorMessage { fn drop(&mut self) { if self.is_owned && !<*mut nativeErrorMessage>::is_null(self.inner) { @@ -371,23 +440,26 @@ impl ErrorMessage { self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// The channel ID involved in the error. /// /// All-0s indicates a general error unrelated to a specific channel, after which all channels /// with the sending peer should be closed. #[no_mangle] -pub extern "C" fn ErrorMessage_get_channel_id(this_ptr: &ErrorMessage) -> *const [u8; 32] { +pub extern "C" fn ErrorMessage_get_channel_id(this_ptr: &ErrorMessage) -> crate::lightning::ln::types::ChannelId { let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_id; - &inner_val.0 + crate::lightning::ln::types::ChannelId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::types::ChannelId<>) as *mut _) }, is_owned: false } } /// The channel ID involved in the error. /// /// All-0s indicates a general error unrelated to a specific channel, after which all channels /// with the sending peer should be closed. #[no_mangle] -pub extern "C" fn ErrorMessage_set_channel_id(this_ptr: &mut ErrorMessage, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = ::lightning::ln::ChannelId(val.data); +pub extern "C" fn ErrorMessage_set_channel_id(this_ptr: &mut ErrorMessage, mut val: crate::lightning::ln::types::ChannelId) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = *unsafe { Box::from_raw(val.take_inner()) }; } /// A possibly human-readable error description. /// @@ -411,9 +483,9 @@ pub extern "C" fn ErrorMessage_set_data(this_ptr: &mut ErrorMessage, mut val: cr /// Constructs a new ErrorMessage given each field #[must_use] #[no_mangle] -pub extern "C" fn ErrorMessage_new(mut channel_id_arg: crate::c_types::ThirtyTwoBytes, mut data_arg: crate::c_types::Str) -> ErrorMessage { +pub extern "C" fn ErrorMessage_new(mut channel_id_arg: crate::lightning::ln::types::ChannelId, mut data_arg: crate::c_types::Str) -> ErrorMessage { ErrorMessage { inner: ObjOps::heap_alloc(nativeErrorMessage { - channel_id: ::lightning::ln::ChannelId(channel_id_arg.data), + channel_id: *unsafe { Box::from_raw(channel_id_arg.take_inner()) }, data: data_arg.into_string(), }), is_owned: true } } @@ -429,13 +501,26 @@ impl Clone for ErrorMessage { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ErrorMessage_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeErrorMessage)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeErrorMessage)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ErrorMessage pub extern "C" fn ErrorMessage_clone(orig: &ErrorMessage) -> ErrorMessage { orig.clone() } +/// Get a string which allows debug introspection of a ErrorMessage object +pub extern "C" fn ErrorMessage_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::ErrorMessage }).into()} +/// Generates a non-cryptographic 64-bit hash of the ErrorMessage. +#[no_mangle] +pub extern "C" fn ErrorMessage_hash(o: &ErrorMessage) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two ErrorMessages 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. @@ -467,6 +552,12 @@ pub struct WarningMessage { pub is_owned: bool, } +impl core::ops::Deref for WarningMessage { + type Target = nativeWarningMessage; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for WarningMessage { } +unsafe impl core::marker::Sync for WarningMessage { } impl Drop for WarningMessage { fn drop(&mut self) { if self.is_owned && !<*mut nativeWarningMessage>::is_null(self.inner) { @@ -497,21 +588,24 @@ impl WarningMessage { self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// The channel ID involved in the warning. /// /// All-0s indicates a warning unrelated to a specific channel. #[no_mangle] -pub extern "C" fn WarningMessage_get_channel_id(this_ptr: &WarningMessage) -> *const [u8; 32] { +pub extern "C" fn WarningMessage_get_channel_id(this_ptr: &WarningMessage) -> crate::lightning::ln::types::ChannelId { let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_id; - &inner_val.0 + crate::lightning::ln::types::ChannelId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::types::ChannelId<>) as *mut _) }, is_owned: false } } /// The channel ID involved in the warning. /// /// All-0s indicates a warning unrelated to a specific channel. #[no_mangle] -pub extern "C" fn WarningMessage_set_channel_id(this_ptr: &mut WarningMessage, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = ::lightning::ln::ChannelId(val.data); +pub extern "C" fn WarningMessage_set_channel_id(this_ptr: &mut WarningMessage, mut val: crate::lightning::ln::types::ChannelId) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = *unsafe { Box::from_raw(val.take_inner()) }; } /// A possibly human-readable warning description. /// @@ -535,9 +629,9 @@ pub extern "C" fn WarningMessage_set_data(this_ptr: &mut WarningMessage, mut val /// Constructs a new WarningMessage given each field #[must_use] #[no_mangle] -pub extern "C" fn WarningMessage_new(mut channel_id_arg: crate::c_types::ThirtyTwoBytes, mut data_arg: crate::c_types::Str) -> WarningMessage { +pub extern "C" fn WarningMessage_new(mut channel_id_arg: crate::lightning::ln::types::ChannelId, mut data_arg: crate::c_types::Str) -> WarningMessage { WarningMessage { inner: ObjOps::heap_alloc(nativeWarningMessage { - channel_id: ::lightning::ln::ChannelId(channel_id_arg.data), + channel_id: *unsafe { Box::from_raw(channel_id_arg.take_inner()) }, data: data_arg.into_string(), }), is_owned: true } } @@ -553,13 +647,26 @@ impl Clone for WarningMessage { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn WarningMessage_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeWarningMessage)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeWarningMessage)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the WarningMessage pub extern "C" fn WarningMessage_clone(orig: &WarningMessage) -> WarningMessage { orig.clone() } +/// Get a string which allows debug introspection of a WarningMessage object +pub extern "C" fn WarningMessage_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::WarningMessage }).into()} +/// Generates a non-cryptographic 64-bit hash of the WarningMessage. +#[no_mangle] +pub extern "C" fn WarningMessage_hash(o: &WarningMessage) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two WarningMessages 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. @@ -591,6 +698,12 @@ pub struct Ping { pub is_owned: bool, } +impl core::ops::Deref for Ping { + type Target = nativePing; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for Ping { } +unsafe impl core::marker::Sync for Ping { } impl Drop for Ping { fn drop(&mut self) { if self.is_owned && !<*mut nativePing>::is_null(self.inner) { @@ -621,6 +734,9 @@ impl Ping { self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// The desired response length. #[no_mangle] @@ -669,13 +785,26 @@ impl Clone for Ping { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn Ping_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePing)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePing)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the Ping pub extern "C" fn Ping_clone(orig: &Ping) -> Ping { orig.clone() } +/// Get a string which allows debug introspection of a Ping object +pub extern "C" fn Ping_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::Ping }).into()} +/// Generates a non-cryptographic 64-bit hash of the Ping. +#[no_mangle] +pub extern "C" fn Ping_hash(o: &Ping) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two Pings 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. @@ -707,6 +836,12 @@ pub struct Pong { pub is_owned: bool, } +impl core::ops::Deref for Pong { + type Target = nativePong; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for Pong { } +unsafe impl core::marker::Sync for Pong { } impl Drop for Pong { fn drop(&mut self) { if self.is_owned && !<*mut nativePong>::is_null(self.inner) { @@ -737,6 +872,9 @@ impl Pong { self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// The pong packet size. /// @@ -773,13 +911,26 @@ impl Clone for Pong { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn Pong_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativePong)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativePong)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the Pong pub extern "C" fn Pong_clone(orig: &Pong) -> Pong { orig.clone() } +/// Get a string which allows debug introspection of a Pong object +pub extern "C" fn Pong_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::Pong }).into()} +/// Generates a non-cryptographic 64-bit hash of the Pong. +#[no_mangle] +pub extern "C" fn Pong_hash(o: &Pong) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two Pongs 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. @@ -790,22 +941,20 @@ pub extern "C" fn Pong_eq(a: &Pong, b: &Pong) -> bool { if a.get_native_ref() == b.get_native_ref() { true } else { false } } -use lightning::ln::msgs::OpenChannel as nativeOpenChannelImport; -pub(crate) type nativeOpenChannel = nativeOpenChannelImport; +use lightning::ln::msgs::CommonOpenChannelFields as nativeCommonOpenChannelFieldsImport; +pub(crate) type nativeCommonOpenChannelFields = nativeCommonOpenChannelFieldsImport; -/// An [`open_channel`] message to be sent to or received from a peer. -/// -/// Used in V1 channel establishment +/// Contains fields that are both common to [`open_channel`] and `open_channel2` messages. /// /// [`open_channel`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#the-open_channel-message #[must_use] #[repr(C)] -pub struct OpenChannel { +pub struct CommonOpenChannelFields { /// 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 nativeOpenChannel, + pub inner: *mut nativeCommonOpenChannelFields, /// 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 @@ -813,250 +962,249 @@ pub struct OpenChannel { pub is_owned: bool, } -impl Drop for OpenChannel { +impl core::ops::Deref for CommonOpenChannelFields { + type Target = nativeCommonOpenChannelFields; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for CommonOpenChannelFields { } +unsafe impl core::marker::Sync for CommonOpenChannelFields { } +impl Drop for CommonOpenChannelFields { fn drop(&mut self) { - if self.is_owned && !<*mut nativeOpenChannel>::is_null(self.inner) { + if self.is_owned && !<*mut nativeCommonOpenChannelFields>::is_null(self.inner) { let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; } } } -/// Frees any resources used by the OpenChannel, if is_owned is set and inner is non-NULL. +/// Frees any resources used by the CommonOpenChannelFields, if is_owned is set and inner is non-NULL. #[no_mangle] -pub extern "C" fn OpenChannel_free(this_obj: OpenChannel) { } +pub extern "C" fn CommonOpenChannelFields_free(this_obj: CommonOpenChannelFields) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn OpenChannel_free_void(this_ptr: *mut c_void) { - let _ = unsafe { Box::from_raw(this_ptr as *mut nativeOpenChannel) }; +pub(crate) extern "C" fn CommonOpenChannelFields_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeCommonOpenChannelFields) }; } #[allow(unused)] -impl OpenChannel { - pub(crate) fn get_native_ref(&self) -> &'static nativeOpenChannel { +impl CommonOpenChannelFields { + pub(crate) fn get_native_ref(&self) -> &'static nativeCommonOpenChannelFields { unsafe { &*ObjOps::untweak_ptr(self.inner) } } - pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeOpenChannel { + pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeCommonOpenChannelFields { 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 nativeOpenChannel { + pub(crate) fn take_inner(mut self) -> *mut nativeCommonOpenChannelFields { assert!(self.is_owned); let ret = ObjOps::untweak_ptr(self.inner); self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// The genesis hash of the blockchain where the channel is to be opened #[no_mangle] -pub extern "C" fn OpenChannel_get_chain_hash(this_ptr: &OpenChannel) -> *const [u8; 32] { +pub extern "C" fn CommonOpenChannelFields_get_chain_hash(this_ptr: &CommonOpenChannelFields) -> *const [u8; 32] { let mut inner_val = &mut this_ptr.get_native_mut_ref().chain_hash; - inner_val.as_inner() + inner_val.as_ref() } /// The genesis hash of the blockchain where the channel is to be opened #[no_mangle] -pub extern "C" fn OpenChannel_set_chain_hash(this_ptr: &mut OpenChannel, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_hash = ::bitcoin::hash_types::BlockHash::from_slice(&val.data[..]).unwrap(); +pub extern "C" fn CommonOpenChannelFields_set_chain_hash(this_ptr: &mut CommonOpenChannelFields, mut val: crate::c_types::ThirtyTwoBytes) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_hash = ::bitcoin::constants::ChainHash::from(&val.data); } -/// A temporary channel ID, until the funding outpoint is announced +/// A temporary channel ID +/// For V2 channels: derived using a zeroed out value for the channel acceptor's revocation basepoint +/// For V1 channels: a temporary channel ID, until the funding outpoint is announced #[no_mangle] -pub extern "C" fn OpenChannel_get_temporary_channel_id(this_ptr: &OpenChannel) -> *const [u8; 32] { +pub extern "C" fn CommonOpenChannelFields_get_temporary_channel_id(this_ptr: &CommonOpenChannelFields) -> crate::lightning::ln::types::ChannelId { let mut inner_val = &mut this_ptr.get_native_mut_ref().temporary_channel_id; - &inner_val.0 + crate::lightning::ln::types::ChannelId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::types::ChannelId<>) as *mut _) }, is_owned: false } } -/// A temporary channel ID, until the funding outpoint is announced +/// A temporary channel ID +/// For V2 channels: derived using a zeroed out value for the channel acceptor's revocation basepoint +/// For V1 channels: a temporary channel ID, until the funding outpoint is announced #[no_mangle] -pub extern "C" fn OpenChannel_set_temporary_channel_id(this_ptr: &mut OpenChannel, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.temporary_channel_id = ::lightning::ln::ChannelId(val.data); +pub extern "C" fn CommonOpenChannelFields_set_temporary_channel_id(this_ptr: &mut CommonOpenChannelFields, mut val: crate::lightning::ln::types::ChannelId) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.temporary_channel_id = *unsafe { Box::from_raw(val.take_inner()) }; } -/// The channel value +/// For V1 channels: The channel value +/// For V2 channels: Part of the channel value contributed by the channel initiator #[no_mangle] -pub extern "C" fn OpenChannel_get_funding_satoshis(this_ptr: &OpenChannel) -> u64 { +pub extern "C" fn CommonOpenChannelFields_get_funding_satoshis(this_ptr: &CommonOpenChannelFields) -> u64 { let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_satoshis; *inner_val } -/// The channel value +/// For V1 channels: The channel value +/// For V2 channels: Part of the channel value contributed by the channel initiator #[no_mangle] -pub extern "C" fn OpenChannel_set_funding_satoshis(this_ptr: &mut OpenChannel, mut val: u64) { +pub extern "C" fn CommonOpenChannelFields_set_funding_satoshis(this_ptr: &mut CommonOpenChannelFields, mut val: u64) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_satoshis = val; } -/// The amount to push to the counterparty as part of the open, in milli-satoshi -#[no_mangle] -pub extern "C" fn OpenChannel_get_push_msat(this_ptr: &OpenChannel) -> u64 { - let mut inner_val = &mut this_ptr.get_native_mut_ref().push_msat; - *inner_val -} -/// The amount to push to the counterparty as part of the open, in milli-satoshi -#[no_mangle] -pub extern "C" fn OpenChannel_set_push_msat(this_ptr: &mut OpenChannel, mut val: u64) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.push_msat = val; -} -/// The threshold below which outputs on transactions broadcast by sender will be omitted +/// The threshold below which outputs on transactions broadcast by the channel initiator will be +/// omitted #[no_mangle] -pub extern "C" fn OpenChannel_get_dust_limit_satoshis(this_ptr: &OpenChannel) -> u64 { +pub extern "C" fn CommonOpenChannelFields_get_dust_limit_satoshis(this_ptr: &CommonOpenChannelFields) -> u64 { let mut inner_val = &mut this_ptr.get_native_mut_ref().dust_limit_satoshis; *inner_val } -/// The threshold below which outputs on transactions broadcast by sender will be omitted +/// The threshold below which outputs on transactions broadcast by the channel initiator will be +/// omitted #[no_mangle] -pub extern "C" fn OpenChannel_set_dust_limit_satoshis(this_ptr: &mut OpenChannel, mut val: u64) { +pub extern "C" fn CommonOpenChannelFields_set_dust_limit_satoshis(this_ptr: &mut CommonOpenChannelFields, mut val: u64) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.dust_limit_satoshis = val; } -/// The maximum inbound HTLC value in flight towards sender, in milli-satoshi +/// The maximum inbound HTLC value in flight towards channel initiator, in milli-satoshi #[no_mangle] -pub extern "C" fn OpenChannel_get_max_htlc_value_in_flight_msat(this_ptr: &OpenChannel) -> u64 { +pub extern "C" fn CommonOpenChannelFields_get_max_htlc_value_in_flight_msat(this_ptr: &CommonOpenChannelFields) -> u64 { let mut inner_val = &mut this_ptr.get_native_mut_ref().max_htlc_value_in_flight_msat; *inner_val } -/// The maximum inbound HTLC value in flight towards sender, in milli-satoshi +/// The maximum inbound HTLC value in flight towards channel initiator, in milli-satoshi #[no_mangle] -pub extern "C" fn OpenChannel_set_max_htlc_value_in_flight_msat(this_ptr: &mut OpenChannel, mut val: u64) { +pub extern "C" fn CommonOpenChannelFields_set_max_htlc_value_in_flight_msat(this_ptr: &mut CommonOpenChannelFields, mut val: u64) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_htlc_value_in_flight_msat = val; } -/// The minimum value unencumbered by HTLCs for the counterparty to keep in the channel -#[no_mangle] -pub extern "C" fn OpenChannel_get_channel_reserve_satoshis(this_ptr: &OpenChannel) -> u64 { - let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_reserve_satoshis; - *inner_val -} -/// The minimum value unencumbered by HTLCs for the counterparty to keep in the channel -#[no_mangle] -pub extern "C" fn OpenChannel_set_channel_reserve_satoshis(this_ptr: &mut OpenChannel, mut val: u64) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_reserve_satoshis = val; -} -/// The minimum HTLC size incoming to sender, in milli-satoshi +/// The minimum HTLC size incoming to channel initiator, in milli-satoshi #[no_mangle] -pub extern "C" fn OpenChannel_get_htlc_minimum_msat(this_ptr: &OpenChannel) -> u64 { +pub extern "C" fn CommonOpenChannelFields_get_htlc_minimum_msat(this_ptr: &CommonOpenChannelFields) -> u64 { let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_minimum_msat; *inner_val } -/// The minimum HTLC size incoming to sender, in milli-satoshi +/// The minimum HTLC size incoming to channel initiator, in milli-satoshi #[no_mangle] -pub extern "C" fn OpenChannel_set_htlc_minimum_msat(this_ptr: &mut OpenChannel, mut val: u64) { +pub extern "C" fn CommonOpenChannelFields_set_htlc_minimum_msat(this_ptr: &mut CommonOpenChannelFields, mut val: u64) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_minimum_msat = val; } -/// The feerate per 1000-weight of sender generated transactions, until updated by +/// The feerate for the commitment transaction set by the channel initiator until updated by /// [`UpdateFee`] #[no_mangle] -pub extern "C" fn OpenChannel_get_feerate_per_kw(this_ptr: &OpenChannel) -> u32 { - let mut inner_val = &mut this_ptr.get_native_mut_ref().feerate_per_kw; +pub extern "C" fn CommonOpenChannelFields_get_commitment_feerate_sat_per_1000_weight(this_ptr: &CommonOpenChannelFields) -> u32 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().commitment_feerate_sat_per_1000_weight; *inner_val } -/// The feerate per 1000-weight of sender generated transactions, until updated by +/// The feerate for the commitment transaction set by the channel initiator until updated by /// [`UpdateFee`] #[no_mangle] -pub extern "C" fn OpenChannel_set_feerate_per_kw(this_ptr: &mut OpenChannel, mut val: u32) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.feerate_per_kw = val; +pub extern "C" fn CommonOpenChannelFields_set_commitment_feerate_sat_per_1000_weight(this_ptr: &mut CommonOpenChannelFields, mut val: u32) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.commitment_feerate_sat_per_1000_weight = val; } -/// The number of blocks which the counterparty will have to wait to claim on-chain funds if -/// they broadcast a commitment transaction +/// The number of blocks which the counterparty will have to wait to claim on-chain funds if they +/// broadcast a commitment transaction #[no_mangle] -pub extern "C" fn OpenChannel_get_to_self_delay(this_ptr: &OpenChannel) -> u16 { +pub extern "C" fn CommonOpenChannelFields_get_to_self_delay(this_ptr: &CommonOpenChannelFields) -> u16 { let mut inner_val = &mut this_ptr.get_native_mut_ref().to_self_delay; *inner_val } -/// The number of blocks which the counterparty will have to wait to claim on-chain funds if -/// they broadcast a commitment transaction +/// The number of blocks which the counterparty will have to wait to claim on-chain funds if they +/// broadcast a commitment transaction #[no_mangle] -pub extern "C" fn OpenChannel_set_to_self_delay(this_ptr: &mut OpenChannel, mut val: u16) { +pub extern "C" fn CommonOpenChannelFields_set_to_self_delay(this_ptr: &mut CommonOpenChannelFields, mut val: u16) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.to_self_delay = val; } -/// The maximum number of inbound HTLCs towards sender +/// The maximum number of inbound HTLCs towards channel initiator #[no_mangle] -pub extern "C" fn OpenChannel_get_max_accepted_htlcs(this_ptr: &OpenChannel) -> u16 { +pub extern "C" fn CommonOpenChannelFields_get_max_accepted_htlcs(this_ptr: &CommonOpenChannelFields) -> u16 { let mut inner_val = &mut this_ptr.get_native_mut_ref().max_accepted_htlcs; *inner_val } -/// The maximum number of inbound HTLCs towards sender +/// The maximum number of inbound HTLCs towards channel initiator #[no_mangle] -pub extern "C" fn OpenChannel_set_max_accepted_htlcs(this_ptr: &mut OpenChannel, mut val: u16) { +pub extern "C" fn CommonOpenChannelFields_set_max_accepted_htlcs(this_ptr: &mut CommonOpenChannelFields, mut val: u16) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_accepted_htlcs = val; } -/// The sender's key controlling the funding transaction +/// The channel initiator's key controlling the funding transaction #[no_mangle] -pub extern "C" fn OpenChannel_get_funding_pubkey(this_ptr: &OpenChannel) -> crate::c_types::PublicKey { +pub extern "C" fn CommonOpenChannelFields_get_funding_pubkey(this_ptr: &CommonOpenChannelFields) -> crate::c_types::PublicKey { let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_pubkey; crate::c_types::PublicKey::from_rust(&inner_val) } -/// The sender's key controlling the funding transaction +/// The channel initiator's key controlling the funding transaction #[no_mangle] -pub extern "C" fn OpenChannel_set_funding_pubkey(this_ptr: &mut OpenChannel, mut val: crate::c_types::PublicKey) { +pub extern "C" fn CommonOpenChannelFields_set_funding_pubkey(this_ptr: &mut CommonOpenChannelFields, mut val: crate::c_types::PublicKey) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_pubkey = val.into_rust(); } /// Used to derive a revocation key for transactions broadcast by counterparty #[no_mangle] -pub extern "C" fn OpenChannel_get_revocation_basepoint(this_ptr: &OpenChannel) -> crate::c_types::PublicKey { +pub extern "C" fn CommonOpenChannelFields_get_revocation_basepoint(this_ptr: &CommonOpenChannelFields) -> crate::c_types::PublicKey { let mut inner_val = &mut this_ptr.get_native_mut_ref().revocation_basepoint; crate::c_types::PublicKey::from_rust(&inner_val) } /// Used to derive a revocation key for transactions broadcast by counterparty #[no_mangle] -pub extern "C" fn OpenChannel_set_revocation_basepoint(this_ptr: &mut OpenChannel, mut val: crate::c_types::PublicKey) { +pub extern "C" fn CommonOpenChannelFields_set_revocation_basepoint(this_ptr: &mut CommonOpenChannelFields, mut val: crate::c_types::PublicKey) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.revocation_basepoint = val.into_rust(); } -/// A payment key to sender for transactions broadcast by counterparty +/// A payment key to channel initiator for transactions broadcast by counterparty #[no_mangle] -pub extern "C" fn OpenChannel_get_payment_point(this_ptr: &OpenChannel) -> crate::c_types::PublicKey { - let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_point; +pub extern "C" fn CommonOpenChannelFields_get_payment_basepoint(this_ptr: &CommonOpenChannelFields) -> crate::c_types::PublicKey { + let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_basepoint; crate::c_types::PublicKey::from_rust(&inner_val) } -/// A payment key to sender for transactions broadcast by counterparty +/// A payment key to channel initiator for transactions broadcast by counterparty #[no_mangle] -pub extern "C" fn OpenChannel_set_payment_point(this_ptr: &mut OpenChannel, mut val: crate::c_types::PublicKey) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_point = val.into_rust(); +pub extern "C" fn CommonOpenChannelFields_set_payment_basepoint(this_ptr: &mut CommonOpenChannelFields, mut val: crate::c_types::PublicKey) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_basepoint = val.into_rust(); } -/// Used to derive a payment key to sender for transactions broadcast by sender +/// Used to derive a payment key to channel initiator for transactions broadcast by channel +/// initiator #[no_mangle] -pub extern "C" fn OpenChannel_get_delayed_payment_basepoint(this_ptr: &OpenChannel) -> crate::c_types::PublicKey { +pub extern "C" fn CommonOpenChannelFields_get_delayed_payment_basepoint(this_ptr: &CommonOpenChannelFields) -> crate::c_types::PublicKey { let mut inner_val = &mut this_ptr.get_native_mut_ref().delayed_payment_basepoint; crate::c_types::PublicKey::from_rust(&inner_val) } -/// Used to derive a payment key to sender for transactions broadcast by sender +/// Used to derive a payment key to channel initiator for transactions broadcast by channel +/// initiator #[no_mangle] -pub extern "C" fn OpenChannel_set_delayed_payment_basepoint(this_ptr: &mut OpenChannel, mut val: crate::c_types::PublicKey) { +pub extern "C" fn CommonOpenChannelFields_set_delayed_payment_basepoint(this_ptr: &mut CommonOpenChannelFields, mut val: crate::c_types::PublicKey) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.delayed_payment_basepoint = val.into_rust(); } -/// Used to derive an HTLC payment key to sender +/// Used to derive an HTLC payment key to channel initiator #[no_mangle] -pub extern "C" fn OpenChannel_get_htlc_basepoint(this_ptr: &OpenChannel) -> crate::c_types::PublicKey { +pub extern "C" fn CommonOpenChannelFields_get_htlc_basepoint(this_ptr: &CommonOpenChannelFields) -> crate::c_types::PublicKey { let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_basepoint; crate::c_types::PublicKey::from_rust(&inner_val) } -/// Used to derive an HTLC payment key to sender +/// Used to derive an HTLC payment key to channel initiator #[no_mangle] -pub extern "C" fn OpenChannel_set_htlc_basepoint(this_ptr: &mut OpenChannel, mut val: crate::c_types::PublicKey) { +pub extern "C" fn CommonOpenChannelFields_set_htlc_basepoint(this_ptr: &mut CommonOpenChannelFields, mut val: crate::c_types::PublicKey) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_basepoint = val.into_rust(); } -/// The first to-be-broadcast-by-sender transaction's per commitment point +/// The first to-be-broadcast-by-channel-initiator transaction's per commitment point #[no_mangle] -pub extern "C" fn OpenChannel_get_first_per_commitment_point(this_ptr: &OpenChannel) -> crate::c_types::PublicKey { +pub extern "C" fn CommonOpenChannelFields_get_first_per_commitment_point(this_ptr: &CommonOpenChannelFields) -> crate::c_types::PublicKey { let mut inner_val = &mut this_ptr.get_native_mut_ref().first_per_commitment_point; crate::c_types::PublicKey::from_rust(&inner_val) } -/// The first to-be-broadcast-by-sender transaction's per commitment point +/// The first to-be-broadcast-by-channel-initiator transaction's per commitment point #[no_mangle] -pub extern "C" fn OpenChannel_set_first_per_commitment_point(this_ptr: &mut OpenChannel, mut val: crate::c_types::PublicKey) { +pub extern "C" fn CommonOpenChannelFields_set_first_per_commitment_point(this_ptr: &mut CommonOpenChannelFields, mut val: crate::c_types::PublicKey) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.first_per_commitment_point = val.into_rust(); } /// The channel flags to be used #[no_mangle] -pub extern "C" fn OpenChannel_get_channel_flags(this_ptr: &OpenChannel) -> u8 { +pub extern "C" fn CommonOpenChannelFields_get_channel_flags(this_ptr: &CommonOpenChannelFields) -> u8 { let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_flags; *inner_val } /// The channel flags to be used #[no_mangle] -pub extern "C" fn OpenChannel_set_channel_flags(this_ptr: &mut OpenChannel, mut val: u8) { +pub extern "C" fn CommonOpenChannelFields_set_channel_flags(this_ptr: &mut CommonOpenChannelFields, mut val: u8) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_flags = val; } -/// A request to pre-set the to-sender output's `scriptPubkey` for when we collaboratively close +/// Optionally, a request to pre-set the to-channel-initiator output's scriptPubkey for when we +/// collaboratively close #[no_mangle] -pub extern "C" fn OpenChannel_get_shutdown_scriptpubkey(this_ptr: &OpenChannel) -> crate::c_types::derived::COption_CVec_u8ZZ { +pub extern "C" fn CommonOpenChannelFields_get_shutdown_scriptpubkey(this_ptr: &CommonOpenChannelFields) -> crate::c_types::derived::COption_CVec_u8ZZ { let mut inner_val = &mut this_ptr.get_native_mut_ref().shutdown_scriptpubkey; - let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_CVec_u8ZZ::None } else { crate::c_types::derived::COption_CVec_u8ZZ::Some(/* WARNING: CLONING CONVERSION HERE! &Option is otherwise un-expressable. */ { (*inner_val.as_ref().unwrap()).clone().into_bytes().into() }) }; + let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_CVec_u8ZZ::None } else { crate::c_types::derived::COption_CVec_u8ZZ::Some(/* WARNING: CLONING CONVERSION HERE! &Option is otherwise un-expressable. */ { (*inner_val.as_ref().unwrap()).clone().to_bytes().into() }) }; local_inner_val } -/// A request to pre-set the to-sender output's `scriptPubkey` for when we collaboratively close +/// Optionally, a request to pre-set the to-channel-initiator output's scriptPubkey for when we +/// collaboratively close #[no_mangle] -pub extern "C" fn OpenChannel_set_shutdown_scriptpubkey(this_ptr: &mut OpenChannel, mut val: crate::c_types::derived::COption_CVec_u8ZZ) { - let mut local_val = { /*val*/ let val_opt = val; if val_opt.is_none() { None } else { Some({ { ::bitcoin::blockdata::script::Script::from({ val_opt.take() }.into_rust()) }})} }; +pub extern "C" fn CommonOpenChannelFields_set_shutdown_scriptpubkey(this_ptr: &mut CommonOpenChannelFields, mut val: crate::c_types::derived::COption_CVec_u8ZZ) { + let mut local_val = { /*val*/ let val_opt = val; if val_opt.is_none() { None } else { Some({ { ::bitcoin::script::ScriptBuf::from({ val_opt.take() }.into_rust()) }})} }; unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.shutdown_scriptpubkey = local_val; } /// The channel type that this channel will represent @@ -1066,9 +1214,9 @@ pub extern "C" fn OpenChannel_set_shutdown_scriptpubkey(this_ptr: &mut OpenChann /// /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None #[no_mangle] -pub extern "C" fn OpenChannel_get_channel_type(this_ptr: &OpenChannel) -> crate::lightning::ln::features::ChannelTypeFeatures { +pub extern "C" fn CommonOpenChannelFields_get_channel_type(this_ptr: &CommonOpenChannelFields) -> crate::lightning_types::features::ChannelTypeFeatures { let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_type; - let mut local_inner_val = crate::lightning::ln::features::ChannelTypeFeatures { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::ln::features::ChannelTypeFeatures<>) as *mut _ }, is_owned: false }; + let mut local_inner_val = crate::lightning_types::features::ChannelTypeFeatures { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning_types::features::ChannelTypeFeatures<>) as *mut _ }, is_owned: false }; local_inner_val } /// The channel type that this channel will represent @@ -1078,33 +1226,31 @@ pub extern "C" fn OpenChannel_get_channel_type(this_ptr: &OpenChannel) -> crate: /// /// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None #[no_mangle] -pub extern "C" fn OpenChannel_set_channel_type(this_ptr: &mut OpenChannel, mut val: crate::lightning::ln::features::ChannelTypeFeatures) { +pub extern "C" fn CommonOpenChannelFields_set_channel_type(this_ptr: &mut CommonOpenChannelFields, mut val: crate::lightning_types::features::ChannelTypeFeatures) { let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) }; unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_type = local_val; } -/// Constructs a new OpenChannel given each field +/// Constructs a new CommonOpenChannelFields given each field /// /// Note that channel_type_arg (or a relevant inner pointer) may be NULL or all-0s to represent None #[must_use] #[no_mangle] -pub extern "C" fn OpenChannel_new(mut chain_hash_arg: crate::c_types::ThirtyTwoBytes, mut temporary_channel_id_arg: crate::c_types::ThirtyTwoBytes, mut funding_satoshis_arg: u64, mut push_msat_arg: u64, mut dust_limit_satoshis_arg: u64, mut max_htlc_value_in_flight_msat_arg: u64, mut channel_reserve_satoshis_arg: u64, mut htlc_minimum_msat_arg: u64, mut feerate_per_kw_arg: u32, mut to_self_delay_arg: u16, mut max_accepted_htlcs_arg: u16, mut funding_pubkey_arg: crate::c_types::PublicKey, mut revocation_basepoint_arg: crate::c_types::PublicKey, mut payment_point_arg: crate::c_types::PublicKey, mut delayed_payment_basepoint_arg: crate::c_types::PublicKey, mut htlc_basepoint_arg: crate::c_types::PublicKey, mut first_per_commitment_point_arg: crate::c_types::PublicKey, mut channel_flags_arg: u8, mut shutdown_scriptpubkey_arg: crate::c_types::derived::COption_CVec_u8ZZ, mut channel_type_arg: crate::lightning::ln::features::ChannelTypeFeatures) -> OpenChannel { - let mut local_shutdown_scriptpubkey_arg = { /*shutdown_scriptpubkey_arg*/ let shutdown_scriptpubkey_arg_opt = shutdown_scriptpubkey_arg; if shutdown_scriptpubkey_arg_opt.is_none() { None } else { Some({ { ::bitcoin::blockdata::script::Script::from({ shutdown_scriptpubkey_arg_opt.take() }.into_rust()) }})} }; +pub extern "C" fn CommonOpenChannelFields_new(mut chain_hash_arg: crate::c_types::ThirtyTwoBytes, mut temporary_channel_id_arg: crate::lightning::ln::types::ChannelId, mut funding_satoshis_arg: u64, mut dust_limit_satoshis_arg: u64, mut max_htlc_value_in_flight_msat_arg: u64, mut htlc_minimum_msat_arg: u64, mut commitment_feerate_sat_per_1000_weight_arg: u32, mut to_self_delay_arg: u16, mut max_accepted_htlcs_arg: u16, mut funding_pubkey_arg: crate::c_types::PublicKey, mut revocation_basepoint_arg: crate::c_types::PublicKey, mut payment_basepoint_arg: crate::c_types::PublicKey, mut delayed_payment_basepoint_arg: crate::c_types::PublicKey, mut htlc_basepoint_arg: crate::c_types::PublicKey, mut first_per_commitment_point_arg: crate::c_types::PublicKey, mut channel_flags_arg: u8, mut shutdown_scriptpubkey_arg: crate::c_types::derived::COption_CVec_u8ZZ, mut channel_type_arg: crate::lightning_types::features::ChannelTypeFeatures) -> CommonOpenChannelFields { + let mut local_shutdown_scriptpubkey_arg = { /*shutdown_scriptpubkey_arg*/ let shutdown_scriptpubkey_arg_opt = shutdown_scriptpubkey_arg; if shutdown_scriptpubkey_arg_opt.is_none() { None } else { Some({ { ::bitcoin::script::ScriptBuf::from({ shutdown_scriptpubkey_arg_opt.take() }.into_rust()) }})} }; let mut local_channel_type_arg = if channel_type_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(channel_type_arg.take_inner()) } }) }; - OpenChannel { inner: ObjOps::heap_alloc(nativeOpenChannel { - chain_hash: ::bitcoin::hash_types::BlockHash::from_slice(&chain_hash_arg.data[..]).unwrap(), - temporary_channel_id: ::lightning::ln::ChannelId(temporary_channel_id_arg.data), + CommonOpenChannelFields { inner: ObjOps::heap_alloc(nativeCommonOpenChannelFields { + chain_hash: ::bitcoin::constants::ChainHash::from(&chain_hash_arg.data), + temporary_channel_id: *unsafe { Box::from_raw(temporary_channel_id_arg.take_inner()) }, funding_satoshis: funding_satoshis_arg, - push_msat: push_msat_arg, dust_limit_satoshis: dust_limit_satoshis_arg, max_htlc_value_in_flight_msat: max_htlc_value_in_flight_msat_arg, - channel_reserve_satoshis: channel_reserve_satoshis_arg, htlc_minimum_msat: htlc_minimum_msat_arg, - feerate_per_kw: feerate_per_kw_arg, + commitment_feerate_sat_per_1000_weight: commitment_feerate_sat_per_1000_weight_arg, to_self_delay: to_self_delay_arg, max_accepted_htlcs: max_accepted_htlcs_arg, funding_pubkey: funding_pubkey_arg.into_rust(), revocation_basepoint: revocation_basepoint_arg.into_rust(), - payment_point: payment_point_arg.into_rust(), + payment_basepoint: payment_basepoint_arg.into_rust(), delayed_payment_basepoint: delayed_payment_basepoint_arg.into_rust(), htlc_basepoint: htlc_basepoint_arg.into_rust(), first_per_commitment_point: first_per_commitment_point_arg.into_rust(), @@ -1113,10 +1259,10 @@ pub extern "C" fn OpenChannel_new(mut chain_hash_arg: crate::c_types::ThirtyTwoB channel_type: local_channel_type_arg, }), is_owned: true } } -impl Clone for OpenChannel { +impl Clone for CommonOpenChannelFields { fn clone(&self) -> Self { Self { - inner: if <*mut nativeOpenChannel>::is_null(self.inner) { core::ptr::null_mut() } else { + inner: if <*mut nativeCommonOpenChannelFields>::is_null(self.inner) { core::ptr::null_mut() } else { ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, is_owned: true, } @@ -1124,39 +1270,58 @@ impl Clone for OpenChannel { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn OpenChannel_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeOpenChannel)).clone() })) as *mut c_void +pub(crate) extern "C" fn CommonOpenChannelFields_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeCommonOpenChannelFields)).clone() })) as *mut c_void } #[no_mangle] -/// Creates a copy of the OpenChannel -pub extern "C" fn OpenChannel_clone(orig: &OpenChannel) -> OpenChannel { +/// Creates a copy of the CommonOpenChannelFields +pub extern "C" fn CommonOpenChannelFields_clone(orig: &CommonOpenChannelFields) -> CommonOpenChannelFields { orig.clone() } -/// Checks if two OpenChannels contain equal inner contents. +/// Get a string which allows debug introspection of a CommonOpenChannelFields object +pub extern "C" fn CommonOpenChannelFields_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::CommonOpenChannelFields }).into()} +/// Generates a non-cryptographic 64-bit hash of the CommonOpenChannelFields. +#[no_mangle] +pub extern "C" fn CommonOpenChannelFields_hash(o: &CommonOpenChannelFields) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} +/// Checks if two CommonOpenChannelFieldss 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 OpenChannel_eq(a: &OpenChannel, b: &OpenChannel) -> bool { +pub extern "C" fn CommonOpenChannelFields_eq(a: &CommonOpenChannelFields, b: &CommonOpenChannelFields) -> 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 } } +/// The [`ChannelParameters`] for this channel. +#[must_use] +#[no_mangle] +pub extern "C" fn CommonOpenChannelFields_channel_parameters(this_arg: &crate::lightning::ln::msgs::CommonOpenChannelFields) -> crate::lightning::ln::msgs::ChannelParameters { + let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.channel_parameters(); + crate::lightning::ln::msgs::ChannelParameters { inner: ObjOps::heap_alloc(ret), is_owned: true } +} -use lightning::ln::msgs::OpenChannelV2 as nativeOpenChannelV2Import; -pub(crate) type nativeOpenChannelV2 = nativeOpenChannelV2Import; -/// An open_channel2 message to be sent by or received from the channel initiator. -/// -/// Used in V2 channel establishment -/// +use lightning::ln::msgs::ChannelParameters as nativeChannelParametersImport; +pub(crate) type nativeChannelParameters = nativeChannelParametersImport; + +/// A subset of [`CommonOpenChannelFields`], containing various parameters which are set by the +/// channel initiator and which are not part of the channel funding transaction. #[must_use] #[repr(C)] -pub struct OpenChannelV2 { +pub struct ChannelParameters { /// 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 nativeOpenChannelV2, + pub inner: *mut nativeChannelParameters, /// 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 @@ -1164,339 +1329,283 @@ pub struct OpenChannelV2 { pub is_owned: bool, } -impl Drop for OpenChannelV2 { +impl core::ops::Deref for ChannelParameters { + type Target = nativeChannelParameters; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for ChannelParameters { } +unsafe impl core::marker::Sync for ChannelParameters { } +impl Drop for ChannelParameters { fn drop(&mut self) { - if self.is_owned && !<*mut nativeOpenChannelV2>::is_null(self.inner) { + if self.is_owned && !<*mut nativeChannelParameters>::is_null(self.inner) { let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; } } } -/// Frees any resources used by the OpenChannelV2, if is_owned is set and inner is non-NULL. +/// Frees any resources used by the ChannelParameters, if is_owned is set and inner is non-NULL. #[no_mangle] -pub extern "C" fn OpenChannelV2_free(this_obj: OpenChannelV2) { } +pub extern "C" fn ChannelParameters_free(this_obj: ChannelParameters) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn OpenChannelV2_free_void(this_ptr: *mut c_void) { - let _ = unsafe { Box::from_raw(this_ptr as *mut nativeOpenChannelV2) }; +pub(crate) extern "C" fn ChannelParameters_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelParameters) }; } #[allow(unused)] -impl OpenChannelV2 { - pub(crate) fn get_native_ref(&self) -> &'static nativeOpenChannelV2 { +impl ChannelParameters { + pub(crate) fn get_native_ref(&self) -> &'static nativeChannelParameters { unsafe { &*ObjOps::untweak_ptr(self.inner) } } - pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeOpenChannelV2 { + pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelParameters { 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 nativeOpenChannelV2 { + pub(crate) fn take_inner(mut self) -> *mut nativeChannelParameters { assert!(self.is_owned); let ret = ObjOps::untweak_ptr(self.inner); self.inner = core::ptr::null_mut(); ret } -} -/// The genesis hash of the blockchain where the channel is to be opened -#[no_mangle] -pub extern "C" fn OpenChannelV2_get_chain_hash(this_ptr: &OpenChannelV2) -> *const [u8; 32] { - let mut inner_val = &mut this_ptr.get_native_mut_ref().chain_hash; - inner_val.as_inner() -} -/// The genesis hash of the blockchain where the channel is to be opened -#[no_mangle] -pub extern "C" fn OpenChannelV2_set_chain_hash(this_ptr: &mut OpenChannelV2, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_hash = ::bitcoin::hash_types::BlockHash::from_slice(&val.data[..]).unwrap(); -} -/// A temporary channel ID derived using a zeroed out value for the channel acceptor's revocation basepoint -#[no_mangle] -pub extern "C" fn OpenChannelV2_get_temporary_channel_id(this_ptr: &OpenChannelV2) -> *const [u8; 32] { - let mut inner_val = &mut this_ptr.get_native_mut_ref().temporary_channel_id; - &inner_val.0 -} -/// A temporary channel ID derived using a zeroed out value for the channel acceptor's revocation basepoint -#[no_mangle] -pub extern "C" fn OpenChannelV2_set_temporary_channel_id(this_ptr: &mut OpenChannelV2, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.temporary_channel_id = ::lightning::ln::ChannelId(val.data); -} -/// The feerate for the funding transaction set by the channel initiator -#[no_mangle] -pub extern "C" fn OpenChannelV2_get_funding_feerate_sat_per_1000_weight(this_ptr: &OpenChannelV2) -> u32 { - let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_feerate_sat_per_1000_weight; - *inner_val -} -/// The feerate for the funding transaction set by the channel initiator -#[no_mangle] -pub extern "C" fn OpenChannelV2_set_funding_feerate_sat_per_1000_weight(this_ptr: &mut OpenChannelV2, mut val: u32) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_feerate_sat_per_1000_weight = val; -} -/// The feerate for the commitment transaction set by the channel initiator -#[no_mangle] -pub extern "C" fn OpenChannelV2_get_commitment_feerate_sat_per_1000_weight(this_ptr: &OpenChannelV2) -> u32 { - let mut inner_val = &mut this_ptr.get_native_mut_ref().commitment_feerate_sat_per_1000_weight; - *inner_val -} -/// The feerate for the commitment transaction set by the channel initiator -#[no_mangle] -pub extern "C" fn OpenChannelV2_set_commitment_feerate_sat_per_1000_weight(this_ptr: &mut OpenChannelV2, mut val: u32) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.commitment_feerate_sat_per_1000_weight = val; -} -/// Part of the channel value contributed by the channel initiator -#[no_mangle] -pub extern "C" fn OpenChannelV2_get_funding_satoshis(this_ptr: &OpenChannelV2) -> u64 { - let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_satoshis; - *inner_val -} -/// Part of the channel value contributed by the channel initiator -#[no_mangle] -pub extern "C" fn OpenChannelV2_set_funding_satoshis(this_ptr: &mut OpenChannelV2, mut val: u64) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_satoshis = val; + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// The threshold below which outputs on transactions broadcast by the channel initiator will be -/// omitted +/// omitted. #[no_mangle] -pub extern "C" fn OpenChannelV2_get_dust_limit_satoshis(this_ptr: &OpenChannelV2) -> u64 { +pub extern "C" fn ChannelParameters_get_dust_limit_satoshis(this_ptr: &ChannelParameters) -> u64 { let mut inner_val = &mut this_ptr.get_native_mut_ref().dust_limit_satoshis; *inner_val } /// The threshold below which outputs on transactions broadcast by the channel initiator will be -/// omitted +/// omitted. #[no_mangle] -pub extern "C" fn OpenChannelV2_set_dust_limit_satoshis(this_ptr: &mut OpenChannelV2, mut val: u64) { +pub extern "C" fn ChannelParameters_set_dust_limit_satoshis(this_ptr: &mut ChannelParameters, mut val: u64) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.dust_limit_satoshis = val; } /// The maximum inbound HTLC value in flight towards channel initiator, in milli-satoshi #[no_mangle] -pub extern "C" fn OpenChannelV2_get_max_htlc_value_in_flight_msat(this_ptr: &OpenChannelV2) -> u64 { +pub extern "C" fn ChannelParameters_get_max_htlc_value_in_flight_msat(this_ptr: &ChannelParameters) -> u64 { let mut inner_val = &mut this_ptr.get_native_mut_ref().max_htlc_value_in_flight_msat; *inner_val } /// The maximum inbound HTLC value in flight towards channel initiator, in milli-satoshi #[no_mangle] -pub extern "C" fn OpenChannelV2_set_max_htlc_value_in_flight_msat(this_ptr: &mut OpenChannelV2, mut val: u64) { +pub extern "C" fn ChannelParameters_set_max_htlc_value_in_flight_msat(this_ptr: &mut ChannelParameters, mut val: u64) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_htlc_value_in_flight_msat = val; } -/// The minimum HTLC size incoming to channel initiator, in milli-satoshi +/// The minimum HTLC size for HTLCs towards the channel initiator, in milli-satoshi #[no_mangle] -pub extern "C" fn OpenChannelV2_get_htlc_minimum_msat(this_ptr: &OpenChannelV2) -> u64 { +pub extern "C" fn ChannelParameters_get_htlc_minimum_msat(this_ptr: &ChannelParameters) -> u64 { let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_minimum_msat; *inner_val } -/// The minimum HTLC size incoming to channel initiator, in milli-satoshi +/// The minimum HTLC size for HTLCs towards the channel initiator, in milli-satoshi #[no_mangle] -pub extern "C" fn OpenChannelV2_set_htlc_minimum_msat(this_ptr: &mut OpenChannelV2, mut val: u64) { +pub extern "C" fn ChannelParameters_set_htlc_minimum_msat(this_ptr: &mut ChannelParameters, mut val: u64) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_minimum_msat = val; } -/// The number of blocks which the counterparty will have to wait to claim on-chain funds if they -/// broadcast a commitment transaction +/// The feerate for the commitment transaction set by the channel initiator until updated by +/// [`UpdateFee`] #[no_mangle] -pub extern "C" fn OpenChannelV2_get_to_self_delay(this_ptr: &OpenChannelV2) -> u16 { - let mut inner_val = &mut this_ptr.get_native_mut_ref().to_self_delay; +pub extern "C" fn ChannelParameters_get_commitment_feerate_sat_per_1000_weight(this_ptr: &ChannelParameters) -> u32 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().commitment_feerate_sat_per_1000_weight; *inner_val } -/// The number of blocks which the counterparty will have to wait to claim on-chain funds if they -/// broadcast a commitment transaction +/// The feerate for the commitment transaction set by the channel initiator until updated by +/// [`UpdateFee`] #[no_mangle] -pub extern "C" fn OpenChannelV2_set_to_self_delay(this_ptr: &mut OpenChannelV2, mut val: u16) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.to_self_delay = val; +pub extern "C" fn ChannelParameters_set_commitment_feerate_sat_per_1000_weight(this_ptr: &mut ChannelParameters, mut val: u32) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.commitment_feerate_sat_per_1000_weight = val; } -/// The maximum number of inbound HTLCs towards channel initiator +/// The number of blocks which the non-channel-initator will have to wait to claim on-chain +/// funds if they broadcast a commitment transaction. #[no_mangle] -pub extern "C" fn OpenChannelV2_get_max_accepted_htlcs(this_ptr: &OpenChannelV2) -> u16 { - let mut inner_val = &mut this_ptr.get_native_mut_ref().max_accepted_htlcs; +pub extern "C" fn ChannelParameters_get_to_self_delay(this_ptr: &ChannelParameters) -> u16 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().to_self_delay; *inner_val } -/// The maximum number of inbound HTLCs towards channel initiator +/// The number of blocks which the non-channel-initator will have to wait to claim on-chain +/// funds if they broadcast a commitment transaction. #[no_mangle] -pub extern "C" fn OpenChannelV2_set_max_accepted_htlcs(this_ptr: &mut OpenChannelV2, mut val: u16) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_accepted_htlcs = val; +pub extern "C" fn ChannelParameters_set_to_self_delay(this_ptr: &mut ChannelParameters, mut val: u16) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.to_self_delay = val; } -/// The locktime for the funding transaction +/// The maximum number of pending HTLCs towards the channel initiator. #[no_mangle] -pub extern "C" fn OpenChannelV2_get_locktime(this_ptr: &OpenChannelV2) -> u32 { - let mut inner_val = &mut this_ptr.get_native_mut_ref().locktime; +pub extern "C" fn ChannelParameters_get_max_accepted_htlcs(this_ptr: &ChannelParameters) -> u16 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().max_accepted_htlcs; *inner_val } -/// The locktime for the funding transaction +/// The maximum number of pending HTLCs towards the channel initiator. #[no_mangle] -pub extern "C" fn OpenChannelV2_set_locktime(this_ptr: &mut OpenChannelV2, mut val: u32) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.locktime = val; +pub extern "C" fn ChannelParameters_set_max_accepted_htlcs(this_ptr: &mut ChannelParameters, mut val: u16) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_accepted_htlcs = val; } -/// The channel initiator's key controlling the funding transaction +/// Constructs a new ChannelParameters given each field +#[must_use] #[no_mangle] -pub extern "C" fn OpenChannelV2_get_funding_pubkey(this_ptr: &OpenChannelV2) -> crate::c_types::PublicKey { - let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_pubkey; - crate::c_types::PublicKey::from_rust(&inner_val) +pub extern "C" fn ChannelParameters_new(mut dust_limit_satoshis_arg: u64, mut max_htlc_value_in_flight_msat_arg: u64, mut htlc_minimum_msat_arg: u64, mut commitment_feerate_sat_per_1000_weight_arg: u32, mut to_self_delay_arg: u16, mut max_accepted_htlcs_arg: u16) -> ChannelParameters { + ChannelParameters { inner: ObjOps::heap_alloc(nativeChannelParameters { + dust_limit_satoshis: dust_limit_satoshis_arg, + max_htlc_value_in_flight_msat: max_htlc_value_in_flight_msat_arg, + htlc_minimum_msat: htlc_minimum_msat_arg, + commitment_feerate_sat_per_1000_weight: commitment_feerate_sat_per_1000_weight_arg, + to_self_delay: to_self_delay_arg, + max_accepted_htlcs: max_accepted_htlcs_arg, + }), is_owned: true } } -/// The channel initiator's key controlling the funding transaction -#[no_mangle] -pub extern "C" fn OpenChannelV2_set_funding_pubkey(this_ptr: &mut OpenChannelV2, mut val: crate::c_types::PublicKey) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_pubkey = val.into_rust(); +impl Clone for ChannelParameters { + fn clone(&self) -> Self { + Self { + inner: if <*mut nativeChannelParameters>::is_null(self.inner) { core::ptr::null_mut() } else { + ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, + is_owned: true, + } + } } -/// Used to derive a revocation key for transactions broadcast by counterparty -#[no_mangle] -pub extern "C" fn OpenChannelV2_get_revocation_basepoint(this_ptr: &OpenChannelV2) -> crate::c_types::PublicKey { - let mut inner_val = &mut this_ptr.get_native_mut_ref().revocation_basepoint; - crate::c_types::PublicKey::from_rust(&inner_val) +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn ChannelParameters_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelParameters)).clone() })) as *mut c_void } -/// Used to derive a revocation key for transactions broadcast by counterparty #[no_mangle] -pub extern "C" fn OpenChannelV2_set_revocation_basepoint(this_ptr: &mut OpenChannelV2, mut val: crate::c_types::PublicKey) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.revocation_basepoint = val.into_rust(); +/// Creates a copy of the ChannelParameters +pub extern "C" fn ChannelParameters_clone(orig: &ChannelParameters) -> ChannelParameters { + orig.clone() } -/// A payment key to channel initiator for transactions broadcast by counterparty +/// Get a string which allows debug introspection of a ChannelParameters object +pub extern "C" fn ChannelParameters_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::ChannelParameters }).into()} +/// Generates a non-cryptographic 64-bit hash of the ChannelParameters. #[no_mangle] -pub extern "C" fn OpenChannelV2_get_payment_basepoint(this_ptr: &OpenChannelV2) -> crate::c_types::PublicKey { - let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_basepoint; - crate::c_types::PublicKey::from_rust(&inner_val) +pub extern "C" fn ChannelParameters_hash(o: &ChannelParameters) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) } -/// A payment key to channel initiator for transactions broadcast by counterparty +/// Checks if two ChannelParameterss 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 OpenChannelV2_set_payment_basepoint(this_ptr: &mut OpenChannelV2, mut val: crate::c_types::PublicKey) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_basepoint = val.into_rust(); -} -/// Used to derive a payment key to channel initiator for transactions broadcast by channel -/// initiator -#[no_mangle] -pub extern "C" fn OpenChannelV2_get_delayed_payment_basepoint(this_ptr: &OpenChannelV2) -> crate::c_types::PublicKey { - let mut inner_val = &mut this_ptr.get_native_mut_ref().delayed_payment_basepoint; - crate::c_types::PublicKey::from_rust(&inner_val) +pub extern "C" fn ChannelParameters_eq(a: &ChannelParameters, b: &ChannelParameters) -> 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 } } -/// Used to derive a payment key to channel initiator for transactions broadcast by channel -/// initiator -#[no_mangle] -pub extern "C" fn OpenChannelV2_set_delayed_payment_basepoint(this_ptr: &mut OpenChannelV2, mut val: crate::c_types::PublicKey) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.delayed_payment_basepoint = val.into_rust(); + +use lightning::ln::msgs::OpenChannel as nativeOpenChannelImport; +pub(crate) type nativeOpenChannel = nativeOpenChannelImport; + +/// An [`open_channel`] message to be sent to or received from a peer. +/// +/// Used in V1 channel establishment +/// +/// [`open_channel`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#the-open_channel-message +#[must_use] +#[repr(C)] +pub struct OpenChannel { + /// 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 nativeOpenChannel, + /// 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, } -/// Used to derive an HTLC payment key to channel initiator -#[no_mangle] -pub extern "C" fn OpenChannelV2_get_htlc_basepoint(this_ptr: &OpenChannelV2) -> crate::c_types::PublicKey { - let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_basepoint; - crate::c_types::PublicKey::from_rust(&inner_val) + +impl core::ops::Deref for OpenChannel { + type Target = nativeOpenChannel; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } } -/// Used to derive an HTLC payment key to channel initiator -#[no_mangle] -pub extern "C" fn OpenChannelV2_set_htlc_basepoint(this_ptr: &mut OpenChannelV2, mut val: crate::c_types::PublicKey) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_basepoint = val.into_rust(); +unsafe impl core::marker::Send for OpenChannel { } +unsafe impl core::marker::Sync for OpenChannel { } +impl Drop for OpenChannel { + fn drop(&mut self) { + if self.is_owned && !<*mut nativeOpenChannel>::is_null(self.inner) { + let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; + } + } } -/// The first to-be-broadcast-by-channel-initiator transaction's per commitment point +/// Frees any resources used by the OpenChannel, if is_owned is set and inner is non-NULL. #[no_mangle] -pub extern "C" fn OpenChannelV2_get_first_per_commitment_point(this_ptr: &OpenChannelV2) -> crate::c_types::PublicKey { - let mut inner_val = &mut this_ptr.get_native_mut_ref().first_per_commitment_point; - crate::c_types::PublicKey::from_rust(&inner_val) +pub extern "C" fn OpenChannel_free(this_obj: OpenChannel) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn OpenChannel_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeOpenChannel) }; } -/// The first to-be-broadcast-by-channel-initiator transaction's per commitment point -#[no_mangle] -pub extern "C" fn OpenChannelV2_set_first_per_commitment_point(this_ptr: &mut OpenChannelV2, mut val: crate::c_types::PublicKey) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.first_per_commitment_point = val.into_rust(); +#[allow(unused)] +impl OpenChannel { + pub(crate) fn get_native_ref(&self) -> &'static nativeOpenChannel { + unsafe { &*ObjOps::untweak_ptr(self.inner) } + } + pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeOpenChannel { + 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 nativeOpenChannel { + assert!(self.is_owned); + let ret = ObjOps::untweak_ptr(self.inner); + self.inner = core::ptr::null_mut(); + ret + } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } -/// The second to-be-broadcast-by-channel-initiator transaction's per commitment point +/// Common fields of `open_channel(2)`-like messages #[no_mangle] -pub extern "C" fn OpenChannelV2_get_second_per_commitment_point(this_ptr: &OpenChannelV2) -> crate::c_types::PublicKey { - let mut inner_val = &mut this_ptr.get_native_mut_ref().second_per_commitment_point; - crate::c_types::PublicKey::from_rust(&inner_val) +pub extern "C" fn OpenChannel_get_common_fields(this_ptr: &OpenChannel) -> crate::lightning::ln::msgs::CommonOpenChannelFields { + let mut inner_val = &mut this_ptr.get_native_mut_ref().common_fields; + crate::lightning::ln::msgs::CommonOpenChannelFields { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::msgs::CommonOpenChannelFields<>) as *mut _) }, is_owned: false } } -/// The second to-be-broadcast-by-channel-initiator transaction's per commitment point +/// Common fields of `open_channel(2)`-like messages #[no_mangle] -pub extern "C" fn OpenChannelV2_set_second_per_commitment_point(this_ptr: &mut OpenChannelV2, mut val: crate::c_types::PublicKey) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.second_per_commitment_point = val.into_rust(); +pub extern "C" fn OpenChannel_set_common_fields(this_ptr: &mut OpenChannel, mut val: crate::lightning::ln::msgs::CommonOpenChannelFields) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.common_fields = *unsafe { Box::from_raw(val.take_inner()) }; } -/// Channel flags +/// The amount to push to the counterparty as part of the open, in milli-satoshi #[no_mangle] -pub extern "C" fn OpenChannelV2_get_channel_flags(this_ptr: &OpenChannelV2) -> u8 { - let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_flags; +pub extern "C" fn OpenChannel_get_push_msat(this_ptr: &OpenChannel) -> u64 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().push_msat; *inner_val } -/// Channel flags -#[no_mangle] -pub extern "C" fn OpenChannelV2_set_channel_flags(this_ptr: &mut OpenChannelV2, mut val: u8) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_flags = val; -} -/// Optionally, a request to pre-set the to-channel-initiator output's scriptPubkey for when we -/// collaboratively close -#[no_mangle] -pub extern "C" fn OpenChannelV2_get_shutdown_scriptpubkey(this_ptr: &OpenChannelV2) -> crate::c_types::derived::COption_CVec_u8ZZ { - let mut inner_val = &mut this_ptr.get_native_mut_ref().shutdown_scriptpubkey; - let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_CVec_u8ZZ::None } else { crate::c_types::derived::COption_CVec_u8ZZ::Some(/* WARNING: CLONING CONVERSION HERE! &Option is otherwise un-expressable. */ { (*inner_val.as_ref().unwrap()).clone().into_bytes().into() }) }; - local_inner_val -} -/// Optionally, a request to pre-set the to-channel-initiator output's scriptPubkey for when we -/// collaboratively close -#[no_mangle] -pub extern "C" fn OpenChannelV2_set_shutdown_scriptpubkey(this_ptr: &mut OpenChannelV2, mut val: crate::c_types::derived::COption_CVec_u8ZZ) { - let mut local_val = { /*val*/ let val_opt = val; if val_opt.is_none() { None } else { Some({ { ::bitcoin::blockdata::script::Script::from({ val_opt.take() }.into_rust()) }})} }; - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.shutdown_scriptpubkey = local_val; -} -/// The channel type that this channel will represent. If none is set, we derive the channel -/// type from the intersection of our feature bits with our counterparty's feature bits from -/// the Init message. -/// -/// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None -#[no_mangle] -pub extern "C" fn OpenChannelV2_get_channel_type(this_ptr: &OpenChannelV2) -> crate::lightning::ln::features::ChannelTypeFeatures { - let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_type; - let mut local_inner_val = crate::lightning::ln::features::ChannelTypeFeatures { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::ln::features::ChannelTypeFeatures<>) as *mut _ }, is_owned: false }; - local_inner_val -} -/// The channel type that this channel will represent. If none is set, we derive the channel -/// type from the intersection of our feature bits with our counterparty's feature bits from -/// the Init message. -/// -/// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None +/// The amount to push to the counterparty as part of the open, in milli-satoshi #[no_mangle] -pub extern "C" fn OpenChannelV2_set_channel_type(this_ptr: &mut OpenChannelV2, mut val: crate::lightning::ln::features::ChannelTypeFeatures) { - let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) }; - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_type = local_val; +pub extern "C" fn OpenChannel_set_push_msat(this_ptr: &mut OpenChannel, mut val: u64) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.push_msat = val; } -/// Optionally, a requirement that only confirmed inputs can be added +/// The minimum value unencumbered by HTLCs for the counterparty to keep in the channel #[no_mangle] -pub extern "C" fn OpenChannelV2_get_require_confirmed_inputs(this_ptr: &OpenChannelV2) -> crate::c_types::derived::COption_NoneZ { - let mut inner_val = &mut this_ptr.get_native_mut_ref().require_confirmed_inputs; - let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_NoneZ::None } else { crate::c_types::derived::COption_NoneZ::Some /* { () /**/ } */ }; - local_inner_val +pub extern "C" fn OpenChannel_get_channel_reserve_satoshis(this_ptr: &OpenChannel) -> u64 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_reserve_satoshis; + *inner_val } -/// Optionally, a requirement that only confirmed inputs can be added +/// The minimum value unencumbered by HTLCs for the counterparty to keep in the channel #[no_mangle] -pub extern "C" fn OpenChannelV2_set_require_confirmed_inputs(this_ptr: &mut OpenChannelV2, mut val: crate::c_types::derived::COption_NoneZ) { - let mut local_val = if val.is_some() { Some( { () /*val.take()*/ }) } else { None }; - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.require_confirmed_inputs = local_val; +pub extern "C" fn OpenChannel_set_channel_reserve_satoshis(this_ptr: &mut OpenChannel, mut val: u64) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_reserve_satoshis = val; } -/// Constructs a new OpenChannelV2 given each field -/// -/// Note that channel_type_arg (or a relevant inner pointer) may be NULL or all-0s to represent None +/// Constructs a new OpenChannel given each field #[must_use] #[no_mangle] -pub extern "C" fn OpenChannelV2_new(mut chain_hash_arg: crate::c_types::ThirtyTwoBytes, mut temporary_channel_id_arg: crate::c_types::ThirtyTwoBytes, mut funding_feerate_sat_per_1000_weight_arg: u32, mut commitment_feerate_sat_per_1000_weight_arg: u32, mut funding_satoshis_arg: u64, mut dust_limit_satoshis_arg: u64, mut max_htlc_value_in_flight_msat_arg: u64, mut htlc_minimum_msat_arg: u64, mut to_self_delay_arg: u16, mut max_accepted_htlcs_arg: u16, mut locktime_arg: u32, mut funding_pubkey_arg: crate::c_types::PublicKey, mut revocation_basepoint_arg: crate::c_types::PublicKey, mut payment_basepoint_arg: crate::c_types::PublicKey, mut delayed_payment_basepoint_arg: crate::c_types::PublicKey, mut htlc_basepoint_arg: crate::c_types::PublicKey, mut first_per_commitment_point_arg: crate::c_types::PublicKey, mut second_per_commitment_point_arg: crate::c_types::PublicKey, mut channel_flags_arg: u8, mut shutdown_scriptpubkey_arg: crate::c_types::derived::COption_CVec_u8ZZ, mut channel_type_arg: crate::lightning::ln::features::ChannelTypeFeatures, mut require_confirmed_inputs_arg: crate::c_types::derived::COption_NoneZ) -> OpenChannelV2 { - let mut local_shutdown_scriptpubkey_arg = { /*shutdown_scriptpubkey_arg*/ let shutdown_scriptpubkey_arg_opt = shutdown_scriptpubkey_arg; if shutdown_scriptpubkey_arg_opt.is_none() { None } else { Some({ { ::bitcoin::blockdata::script::Script::from({ shutdown_scriptpubkey_arg_opt.take() }.into_rust()) }})} }; - let mut local_channel_type_arg = if channel_type_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(channel_type_arg.take_inner()) } }) }; - let mut local_require_confirmed_inputs_arg = if require_confirmed_inputs_arg.is_some() { Some( { () /*require_confirmed_inputs_arg.take()*/ }) } else { None }; - OpenChannelV2 { inner: ObjOps::heap_alloc(nativeOpenChannelV2 { - chain_hash: ::bitcoin::hash_types::BlockHash::from_slice(&chain_hash_arg.data[..]).unwrap(), - temporary_channel_id: ::lightning::ln::ChannelId(temporary_channel_id_arg.data), - funding_feerate_sat_per_1000_weight: funding_feerate_sat_per_1000_weight_arg, - commitment_feerate_sat_per_1000_weight: commitment_feerate_sat_per_1000_weight_arg, - funding_satoshis: funding_satoshis_arg, - dust_limit_satoshis: dust_limit_satoshis_arg, - max_htlc_value_in_flight_msat: max_htlc_value_in_flight_msat_arg, - htlc_minimum_msat: htlc_minimum_msat_arg, - to_self_delay: to_self_delay_arg, - max_accepted_htlcs: max_accepted_htlcs_arg, - locktime: locktime_arg, - funding_pubkey: funding_pubkey_arg.into_rust(), - revocation_basepoint: revocation_basepoint_arg.into_rust(), - payment_basepoint: payment_basepoint_arg.into_rust(), - delayed_payment_basepoint: delayed_payment_basepoint_arg.into_rust(), - htlc_basepoint: htlc_basepoint_arg.into_rust(), - first_per_commitment_point: first_per_commitment_point_arg.into_rust(), - second_per_commitment_point: second_per_commitment_point_arg.into_rust(), - channel_flags: channel_flags_arg, - shutdown_scriptpubkey: local_shutdown_scriptpubkey_arg, - channel_type: local_channel_type_arg, - require_confirmed_inputs: local_require_confirmed_inputs_arg, +pub extern "C" fn OpenChannel_new(mut common_fields_arg: crate::lightning::ln::msgs::CommonOpenChannelFields, mut push_msat_arg: u64, mut channel_reserve_satoshis_arg: u64) -> OpenChannel { + OpenChannel { inner: ObjOps::heap_alloc(nativeOpenChannel { + common_fields: *unsafe { Box::from_raw(common_fields_arg.take_inner()) }, + push_msat: push_msat_arg, + channel_reserve_satoshis: channel_reserve_satoshis_arg, }), is_owned: true } } -impl Clone for OpenChannelV2 { +impl Clone for OpenChannel { fn clone(&self) -> Self { Self { - inner: if <*mut nativeOpenChannelV2>::is_null(self.inner) { core::ptr::null_mut() } else { + inner: if <*mut nativeOpenChannel>::is_null(self.inner) { core::ptr::null_mut() } else { ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, is_owned: true, } @@ -1504,40 +1613,52 @@ impl Clone for OpenChannelV2 { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn OpenChannelV2_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeOpenChannelV2)).clone() })) as *mut c_void +pub(crate) extern "C" fn OpenChannel_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeOpenChannel)).clone() })) as *mut c_void } #[no_mangle] -/// Creates a copy of the OpenChannelV2 -pub extern "C" fn OpenChannelV2_clone(orig: &OpenChannelV2) -> OpenChannelV2 { +/// Creates a copy of the OpenChannel +pub extern "C" fn OpenChannel_clone(orig: &OpenChannel) -> OpenChannel { orig.clone() } -/// Checks if two OpenChannelV2s contain equal inner contents. +/// Get a string which allows debug introspection of a OpenChannel object +pub extern "C" fn OpenChannel_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::OpenChannel }).into()} +/// Generates a non-cryptographic 64-bit hash of the OpenChannel. +#[no_mangle] +pub extern "C" fn OpenChannel_hash(o: &OpenChannel) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} +/// Checks if two OpenChannels 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 OpenChannelV2_eq(a: &OpenChannelV2, b: &OpenChannelV2) -> bool { +pub extern "C" fn OpenChannel_eq(a: &OpenChannel, b: &OpenChannel) -> 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 } } -use lightning::ln::msgs::AcceptChannel as nativeAcceptChannelImport; -pub(crate) type nativeAcceptChannel = nativeAcceptChannelImport; +use lightning::ln::msgs::OpenChannelV2 as nativeOpenChannelV2Import; +pub(crate) type nativeOpenChannelV2 = nativeOpenChannelV2Import; -/// An [`accept_channel`] message to be sent to or received from a peer. +/// An open_channel2 message to be sent by or received from the channel initiator. /// -/// Used in V1 channel establishment +/// Used in V2 channel establishment /// -/// [`accept_channel`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#the-accept_channel-message #[must_use] #[repr(C)] -pub struct AcceptChannel { +pub struct OpenChannelV2 { /// 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 nativeAcceptChannel, + pub inner: *mut nativeOpenChannelV2, /// 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 @@ -1545,260 +1666,120 @@ pub struct AcceptChannel { pub is_owned: bool, } -impl Drop for AcceptChannel { +impl core::ops::Deref for OpenChannelV2 { + type Target = nativeOpenChannelV2; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for OpenChannelV2 { } +unsafe impl core::marker::Sync for OpenChannelV2 { } +impl Drop for OpenChannelV2 { fn drop(&mut self) { - if self.is_owned && !<*mut nativeAcceptChannel>::is_null(self.inner) { + if self.is_owned && !<*mut nativeOpenChannelV2>::is_null(self.inner) { let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; } } } -/// Frees any resources used by the AcceptChannel, if is_owned is set and inner is non-NULL. +/// Frees any resources used by the OpenChannelV2, if is_owned is set and inner is non-NULL. #[no_mangle] -pub extern "C" fn AcceptChannel_free(this_obj: AcceptChannel) { } +pub extern "C" fn OpenChannelV2_free(this_obj: OpenChannelV2) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn AcceptChannel_free_void(this_ptr: *mut c_void) { - let _ = unsafe { Box::from_raw(this_ptr as *mut nativeAcceptChannel) }; +pub(crate) extern "C" fn OpenChannelV2_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeOpenChannelV2) }; } #[allow(unused)] -impl AcceptChannel { - pub(crate) fn get_native_ref(&self) -> &'static nativeAcceptChannel { +impl OpenChannelV2 { + pub(crate) fn get_native_ref(&self) -> &'static nativeOpenChannelV2 { unsafe { &*ObjOps::untweak_ptr(self.inner) } } - pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeAcceptChannel { + pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeOpenChannelV2 { 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 nativeAcceptChannel { + pub(crate) fn take_inner(mut self) -> *mut nativeOpenChannelV2 { assert!(self.is_owned); let ret = ObjOps::untweak_ptr(self.inner); self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } -/// A temporary channel ID, until the funding outpoint is announced +/// Common fields of `open_channel(2)`-like messages #[no_mangle] -pub extern "C" fn AcceptChannel_get_temporary_channel_id(this_ptr: &AcceptChannel) -> *const [u8; 32] { - let mut inner_val = &mut this_ptr.get_native_mut_ref().temporary_channel_id; - &inner_val.0 +pub extern "C" fn OpenChannelV2_get_common_fields(this_ptr: &OpenChannelV2) -> crate::lightning::ln::msgs::CommonOpenChannelFields { + let mut inner_val = &mut this_ptr.get_native_mut_ref().common_fields; + crate::lightning::ln::msgs::CommonOpenChannelFields { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::msgs::CommonOpenChannelFields<>) as *mut _) }, is_owned: false } } -/// A temporary channel ID, until the funding outpoint is announced +/// Common fields of `open_channel(2)`-like messages #[no_mangle] -pub extern "C" fn AcceptChannel_set_temporary_channel_id(this_ptr: &mut AcceptChannel, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.temporary_channel_id = ::lightning::ln::ChannelId(val.data); +pub extern "C" fn OpenChannelV2_set_common_fields(this_ptr: &mut OpenChannelV2, mut val: crate::lightning::ln::msgs::CommonOpenChannelFields) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.common_fields = *unsafe { Box::from_raw(val.take_inner()) }; } -/// The threshold below which outputs on transactions broadcast by sender will be omitted +/// The feerate for the funding transaction set by the channel initiator #[no_mangle] -pub extern "C" fn AcceptChannel_get_dust_limit_satoshis(this_ptr: &AcceptChannel) -> u64 { - let mut inner_val = &mut this_ptr.get_native_mut_ref().dust_limit_satoshis; +pub extern "C" fn OpenChannelV2_get_funding_feerate_sat_per_1000_weight(this_ptr: &OpenChannelV2) -> u32 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_feerate_sat_per_1000_weight; *inner_val } -/// The threshold below which outputs on transactions broadcast by sender will be omitted +/// The feerate for the funding transaction set by the channel initiator #[no_mangle] -pub extern "C" fn AcceptChannel_set_dust_limit_satoshis(this_ptr: &mut AcceptChannel, mut val: u64) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.dust_limit_satoshis = val; +pub extern "C" fn OpenChannelV2_set_funding_feerate_sat_per_1000_weight(this_ptr: &mut OpenChannelV2, mut val: u32) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_feerate_sat_per_1000_weight = val; } -/// The maximum inbound HTLC value in flight towards sender, in milli-satoshi +/// The locktime for the funding transaction #[no_mangle] -pub extern "C" fn AcceptChannel_get_max_htlc_value_in_flight_msat(this_ptr: &AcceptChannel) -> u64 { - let mut inner_val = &mut this_ptr.get_native_mut_ref().max_htlc_value_in_flight_msat; +pub extern "C" fn OpenChannelV2_get_locktime(this_ptr: &OpenChannelV2) -> u32 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().locktime; *inner_val } -/// The maximum inbound HTLC value in flight towards sender, in milli-satoshi +/// The locktime for the funding transaction #[no_mangle] -pub extern "C" fn AcceptChannel_set_max_htlc_value_in_flight_msat(this_ptr: &mut AcceptChannel, mut val: u64) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_htlc_value_in_flight_msat = val; +pub extern "C" fn OpenChannelV2_set_locktime(this_ptr: &mut OpenChannelV2, mut val: u32) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.locktime = val; } -/// The minimum value unencumbered by HTLCs for the counterparty to keep in the channel +/// The second to-be-broadcast-by-channel-initiator transaction's per commitment point #[no_mangle] -pub extern "C" fn AcceptChannel_get_channel_reserve_satoshis(this_ptr: &AcceptChannel) -> u64 { - let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_reserve_satoshis; - *inner_val +pub extern "C" fn OpenChannelV2_get_second_per_commitment_point(this_ptr: &OpenChannelV2) -> crate::c_types::PublicKey { + let mut inner_val = &mut this_ptr.get_native_mut_ref().second_per_commitment_point; + crate::c_types::PublicKey::from_rust(&inner_val) } -/// The minimum value unencumbered by HTLCs for the counterparty to keep in the channel +/// The second to-be-broadcast-by-channel-initiator transaction's per commitment point #[no_mangle] -pub extern "C" fn AcceptChannel_set_channel_reserve_satoshis(this_ptr: &mut AcceptChannel, mut val: u64) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_reserve_satoshis = val; +pub extern "C" fn OpenChannelV2_set_second_per_commitment_point(this_ptr: &mut OpenChannelV2, mut val: crate::c_types::PublicKey) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.second_per_commitment_point = val.into_rust(); } -/// The minimum HTLC size incoming to sender, in milli-satoshi +/// Optionally, a requirement that only confirmed inputs can be added #[no_mangle] -pub extern "C" fn AcceptChannel_get_htlc_minimum_msat(this_ptr: &AcceptChannel) -> u64 { - let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_minimum_msat; - *inner_val -} -/// The minimum HTLC size incoming to sender, in milli-satoshi -#[no_mangle] -pub extern "C" fn AcceptChannel_set_htlc_minimum_msat(this_ptr: &mut AcceptChannel, mut val: u64) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_minimum_msat = val; -} -/// Minimum depth of the funding transaction before the channel is considered open -#[no_mangle] -pub extern "C" fn AcceptChannel_get_minimum_depth(this_ptr: &AcceptChannel) -> u32 { - let mut inner_val = &mut this_ptr.get_native_mut_ref().minimum_depth; - *inner_val -} -/// Minimum depth of the funding transaction before the channel is considered open -#[no_mangle] -pub extern "C" fn AcceptChannel_set_minimum_depth(this_ptr: &mut AcceptChannel, mut val: u32) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.minimum_depth = val; -} -/// The number of blocks which the counterparty will have to wait to claim on-chain funds if they broadcast a commitment transaction -#[no_mangle] -pub extern "C" fn AcceptChannel_get_to_self_delay(this_ptr: &AcceptChannel) -> u16 { - let mut inner_val = &mut this_ptr.get_native_mut_ref().to_self_delay; - *inner_val -} -/// The number of blocks which the counterparty will have to wait to claim on-chain funds if they broadcast a commitment transaction -#[no_mangle] -pub extern "C" fn AcceptChannel_set_to_self_delay(this_ptr: &mut AcceptChannel, mut val: u16) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.to_self_delay = val; -} -/// The maximum number of inbound HTLCs towards sender -#[no_mangle] -pub extern "C" fn AcceptChannel_get_max_accepted_htlcs(this_ptr: &AcceptChannel) -> u16 { - let mut inner_val = &mut this_ptr.get_native_mut_ref().max_accepted_htlcs; - *inner_val -} -/// The maximum number of inbound HTLCs towards sender -#[no_mangle] -pub extern "C" fn AcceptChannel_set_max_accepted_htlcs(this_ptr: &mut AcceptChannel, mut val: u16) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_accepted_htlcs = val; -} -/// The sender's key controlling the funding transaction -#[no_mangle] -pub extern "C" fn AcceptChannel_get_funding_pubkey(this_ptr: &AcceptChannel) -> crate::c_types::PublicKey { - let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_pubkey; - crate::c_types::PublicKey::from_rust(&inner_val) -} -/// The sender's key controlling the funding transaction -#[no_mangle] -pub extern "C" fn AcceptChannel_set_funding_pubkey(this_ptr: &mut AcceptChannel, mut val: crate::c_types::PublicKey) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_pubkey = val.into_rust(); -} -/// Used to derive a revocation key for transactions broadcast by counterparty -#[no_mangle] -pub extern "C" fn AcceptChannel_get_revocation_basepoint(this_ptr: &AcceptChannel) -> crate::c_types::PublicKey { - let mut inner_val = &mut this_ptr.get_native_mut_ref().revocation_basepoint; - crate::c_types::PublicKey::from_rust(&inner_val) -} -/// Used to derive a revocation key for transactions broadcast by counterparty -#[no_mangle] -pub extern "C" fn AcceptChannel_set_revocation_basepoint(this_ptr: &mut AcceptChannel, mut val: crate::c_types::PublicKey) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.revocation_basepoint = val.into_rust(); -} -/// A payment key to sender for transactions broadcast by counterparty -#[no_mangle] -pub extern "C" fn AcceptChannel_get_payment_point(this_ptr: &AcceptChannel) -> crate::c_types::PublicKey { - let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_point; - crate::c_types::PublicKey::from_rust(&inner_val) -} -/// A payment key to sender for transactions broadcast by counterparty -#[no_mangle] -pub extern "C" fn AcceptChannel_set_payment_point(this_ptr: &mut AcceptChannel, mut val: crate::c_types::PublicKey) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_point = val.into_rust(); -} -/// Used to derive a payment key to sender for transactions broadcast by sender -#[no_mangle] -pub extern "C" fn AcceptChannel_get_delayed_payment_basepoint(this_ptr: &AcceptChannel) -> crate::c_types::PublicKey { - let mut inner_val = &mut this_ptr.get_native_mut_ref().delayed_payment_basepoint; - crate::c_types::PublicKey::from_rust(&inner_val) -} -/// Used to derive a payment key to sender for transactions broadcast by sender -#[no_mangle] -pub extern "C" fn AcceptChannel_set_delayed_payment_basepoint(this_ptr: &mut AcceptChannel, mut val: crate::c_types::PublicKey) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.delayed_payment_basepoint = val.into_rust(); -} -/// Used to derive an HTLC payment key to sender for transactions broadcast by counterparty -#[no_mangle] -pub extern "C" fn AcceptChannel_get_htlc_basepoint(this_ptr: &AcceptChannel) -> crate::c_types::PublicKey { - let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_basepoint; - crate::c_types::PublicKey::from_rust(&inner_val) -} -/// Used to derive an HTLC payment key to sender for transactions broadcast by counterparty -#[no_mangle] -pub extern "C" fn AcceptChannel_set_htlc_basepoint(this_ptr: &mut AcceptChannel, mut val: crate::c_types::PublicKey) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_basepoint = val.into_rust(); -} -/// The first to-be-broadcast-by-sender transaction's per commitment point -#[no_mangle] -pub extern "C" fn AcceptChannel_get_first_per_commitment_point(this_ptr: &AcceptChannel) -> crate::c_types::PublicKey { - let mut inner_val = &mut this_ptr.get_native_mut_ref().first_per_commitment_point; - crate::c_types::PublicKey::from_rust(&inner_val) -} -/// The first to-be-broadcast-by-sender transaction's per commitment point -#[no_mangle] -pub extern "C" fn AcceptChannel_set_first_per_commitment_point(this_ptr: &mut AcceptChannel, mut val: crate::c_types::PublicKey) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.first_per_commitment_point = val.into_rust(); -} -/// A request to pre-set the to-sender output's scriptPubkey for when we collaboratively close -#[no_mangle] -pub extern "C" fn AcceptChannel_get_shutdown_scriptpubkey(this_ptr: &AcceptChannel) -> crate::c_types::derived::COption_CVec_u8ZZ { - let mut inner_val = &mut this_ptr.get_native_mut_ref().shutdown_scriptpubkey; - let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_CVec_u8ZZ::None } else { crate::c_types::derived::COption_CVec_u8ZZ::Some(/* WARNING: CLONING CONVERSION HERE! &Option is otherwise un-expressable. */ { (*inner_val.as_ref().unwrap()).clone().into_bytes().into() }) }; - local_inner_val -} -/// A request to pre-set the to-sender output's scriptPubkey for when we collaboratively close -#[no_mangle] -pub extern "C" fn AcceptChannel_set_shutdown_scriptpubkey(this_ptr: &mut AcceptChannel, mut val: crate::c_types::derived::COption_CVec_u8ZZ) { - let mut local_val = { /*val*/ let val_opt = val; if val_opt.is_none() { None } else { Some({ { ::bitcoin::blockdata::script::Script::from({ val_opt.take() }.into_rust()) }})} }; - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.shutdown_scriptpubkey = local_val; -} -/// The channel type that this channel will represent. -/// -/// If this is `None`, we derive the channel type from the intersection of -/// our feature bits with our counterparty's feature bits from the [`Init`] message. -/// This is required to match the equivalent field in [`OpenChannel::channel_type`]. -/// -/// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None -#[no_mangle] -pub extern "C" fn AcceptChannel_get_channel_type(this_ptr: &AcceptChannel) -> crate::lightning::ln::features::ChannelTypeFeatures { - let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_type; - let mut local_inner_val = crate::lightning::ln::features::ChannelTypeFeatures { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::ln::features::ChannelTypeFeatures<>) as *mut _ }, is_owned: false }; +pub extern "C" fn OpenChannelV2_get_require_confirmed_inputs(this_ptr: &OpenChannelV2) -> crate::c_types::derived::COption_NoneZ { + let mut inner_val = &mut this_ptr.get_native_mut_ref().require_confirmed_inputs; + let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_NoneZ::None } else { crate::c_types::derived::COption_NoneZ::Some /* { () /**/ } */ }; local_inner_val } -/// The channel type that this channel will represent. -/// -/// If this is `None`, we derive the channel type from the intersection of -/// our feature bits with our counterparty's feature bits from the [`Init`] message. -/// This is required to match the equivalent field in [`OpenChannel::channel_type`]. -/// -/// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None +/// Optionally, a requirement that only confirmed inputs can be added #[no_mangle] -pub extern "C" fn AcceptChannel_set_channel_type(this_ptr: &mut AcceptChannel, mut val: crate::lightning::ln::features::ChannelTypeFeatures) { - let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) }; - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_type = local_val; +pub extern "C" fn OpenChannelV2_set_require_confirmed_inputs(this_ptr: &mut OpenChannelV2, mut val: crate::c_types::derived::COption_NoneZ) { + let mut local_val = if val.is_some() { Some( { () /*val.take()*/ }) } else { None }; + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.require_confirmed_inputs = local_val; } -/// Constructs a new AcceptChannel given each field -/// -/// Note that channel_type_arg (or a relevant inner pointer) may be NULL or all-0s to represent None +/// Constructs a new OpenChannelV2 given each field #[must_use] #[no_mangle] -pub extern "C" fn AcceptChannel_new(mut temporary_channel_id_arg: crate::c_types::ThirtyTwoBytes, mut dust_limit_satoshis_arg: u64, mut max_htlc_value_in_flight_msat_arg: u64, mut channel_reserve_satoshis_arg: u64, mut htlc_minimum_msat_arg: u64, mut minimum_depth_arg: u32, mut to_self_delay_arg: u16, mut max_accepted_htlcs_arg: u16, mut funding_pubkey_arg: crate::c_types::PublicKey, mut revocation_basepoint_arg: crate::c_types::PublicKey, mut payment_point_arg: crate::c_types::PublicKey, mut delayed_payment_basepoint_arg: crate::c_types::PublicKey, mut htlc_basepoint_arg: crate::c_types::PublicKey, mut first_per_commitment_point_arg: crate::c_types::PublicKey, mut shutdown_scriptpubkey_arg: crate::c_types::derived::COption_CVec_u8ZZ, mut channel_type_arg: crate::lightning::ln::features::ChannelTypeFeatures) -> AcceptChannel { - let mut local_shutdown_scriptpubkey_arg = { /*shutdown_scriptpubkey_arg*/ let shutdown_scriptpubkey_arg_opt = shutdown_scriptpubkey_arg; if shutdown_scriptpubkey_arg_opt.is_none() { None } else { Some({ { ::bitcoin::blockdata::script::Script::from({ shutdown_scriptpubkey_arg_opt.take() }.into_rust()) }})} }; - let mut local_channel_type_arg = if channel_type_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(channel_type_arg.take_inner()) } }) }; - AcceptChannel { inner: ObjOps::heap_alloc(nativeAcceptChannel { - temporary_channel_id: ::lightning::ln::ChannelId(temporary_channel_id_arg.data), - dust_limit_satoshis: dust_limit_satoshis_arg, - max_htlc_value_in_flight_msat: max_htlc_value_in_flight_msat_arg, - channel_reserve_satoshis: channel_reserve_satoshis_arg, - htlc_minimum_msat: htlc_minimum_msat_arg, - minimum_depth: minimum_depth_arg, - to_self_delay: to_self_delay_arg, - max_accepted_htlcs: max_accepted_htlcs_arg, - funding_pubkey: funding_pubkey_arg.into_rust(), - revocation_basepoint: revocation_basepoint_arg.into_rust(), - payment_point: payment_point_arg.into_rust(), - delayed_payment_basepoint: delayed_payment_basepoint_arg.into_rust(), - htlc_basepoint: htlc_basepoint_arg.into_rust(), - first_per_commitment_point: first_per_commitment_point_arg.into_rust(), - shutdown_scriptpubkey: local_shutdown_scriptpubkey_arg, - channel_type: local_channel_type_arg, +pub extern "C" fn OpenChannelV2_new(mut common_fields_arg: crate::lightning::ln::msgs::CommonOpenChannelFields, mut funding_feerate_sat_per_1000_weight_arg: u32, mut locktime_arg: u32, mut second_per_commitment_point_arg: crate::c_types::PublicKey, mut require_confirmed_inputs_arg: crate::c_types::derived::COption_NoneZ) -> OpenChannelV2 { + let mut local_require_confirmed_inputs_arg = if require_confirmed_inputs_arg.is_some() { Some( { () /*require_confirmed_inputs_arg.take()*/ }) } else { None }; + OpenChannelV2 { inner: ObjOps::heap_alloc(nativeOpenChannelV2 { + common_fields: *unsafe { Box::from_raw(common_fields_arg.take_inner()) }, + funding_feerate_sat_per_1000_weight: funding_feerate_sat_per_1000_weight_arg, + locktime: locktime_arg, + second_per_commitment_point: second_per_commitment_point_arg.into_rust(), + require_confirmed_inputs: local_require_confirmed_inputs_arg, }), is_owned: true } } -impl Clone for AcceptChannel { +impl Clone for OpenChannelV2 { fn clone(&self) -> Self { Self { - inner: if <*mut nativeAcceptChannel>::is_null(self.inner) { core::ptr::null_mut() } else { + inner: if <*mut nativeOpenChannelV2>::is_null(self.inner) { core::ptr::null_mut() } else { ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, is_owned: true, } @@ -1806,39 +1787,51 @@ impl Clone for AcceptChannel { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn AcceptChannel_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeAcceptChannel)).clone() })) as *mut c_void +pub(crate) extern "C" fn OpenChannelV2_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeOpenChannelV2)).clone() })) as *mut c_void } #[no_mangle] -/// Creates a copy of the AcceptChannel -pub extern "C" fn AcceptChannel_clone(orig: &AcceptChannel) -> AcceptChannel { +/// Creates a copy of the OpenChannelV2 +pub extern "C" fn OpenChannelV2_clone(orig: &OpenChannelV2) -> OpenChannelV2 { orig.clone() } -/// Checks if two AcceptChannels contain equal inner contents. +/// Get a string which allows debug introspection of a OpenChannelV2 object +pub extern "C" fn OpenChannelV2_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::OpenChannelV2 }).into()} +/// Generates a non-cryptographic 64-bit hash of the OpenChannelV2. +#[no_mangle] +pub extern "C" fn OpenChannelV2_hash(o: &OpenChannelV2) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} +/// Checks if two OpenChannelV2s 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 AcceptChannel_eq(a: &AcceptChannel, b: &AcceptChannel) -> bool { +pub extern "C" fn OpenChannelV2_eq(a: &OpenChannelV2, b: &OpenChannelV2) -> 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 } } -use lightning::ln::msgs::AcceptChannelV2 as nativeAcceptChannelV2Import; -pub(crate) type nativeAcceptChannelV2 = nativeAcceptChannelV2Import; +use lightning::ln::msgs::CommonAcceptChannelFields as nativeCommonAcceptChannelFieldsImport; +pub(crate) type nativeCommonAcceptChannelFields = nativeCommonAcceptChannelFieldsImport; -/// An accept_channel2 message to be sent by or received from the channel accepter. -/// -/// Used in V2 channel establishment +/// Contains fields that are both common to [`accept_channel`] and `accept_channel2` messages. /// +/// [`accept_channel`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#the-accept_channel-message #[must_use] #[repr(C)] -pub struct AcceptChannelV2 { +pub struct CommonAcceptChannelFields { /// 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 nativeAcceptChannelV2, + pub inner: *mut nativeCommonAcceptChannelFields, /// 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 @@ -1846,295 +1839,1149 @@ pub struct AcceptChannelV2 { pub is_owned: bool, } -impl Drop for AcceptChannelV2 { +impl core::ops::Deref for CommonAcceptChannelFields { + type Target = nativeCommonAcceptChannelFields; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for CommonAcceptChannelFields { } +unsafe impl core::marker::Sync for CommonAcceptChannelFields { } +impl Drop for CommonAcceptChannelFields { fn drop(&mut self) { - if self.is_owned && !<*mut nativeAcceptChannelV2>::is_null(self.inner) { + if self.is_owned && !<*mut nativeCommonAcceptChannelFields>::is_null(self.inner) { let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; } } } -/// Frees any resources used by the AcceptChannelV2, if is_owned is set and inner is non-NULL. +/// Frees any resources used by the CommonAcceptChannelFields, if is_owned is set and inner is non-NULL. #[no_mangle] -pub extern "C" fn AcceptChannelV2_free(this_obj: AcceptChannelV2) { } +pub extern "C" fn CommonAcceptChannelFields_free(this_obj: CommonAcceptChannelFields) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn AcceptChannelV2_free_void(this_ptr: *mut c_void) { - let _ = unsafe { Box::from_raw(this_ptr as *mut nativeAcceptChannelV2) }; +pub(crate) extern "C" fn CommonAcceptChannelFields_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeCommonAcceptChannelFields) }; } #[allow(unused)] -impl AcceptChannelV2 { - pub(crate) fn get_native_ref(&self) -> &'static nativeAcceptChannelV2 { +impl CommonAcceptChannelFields { + pub(crate) fn get_native_ref(&self) -> &'static nativeCommonAcceptChannelFields { unsafe { &*ObjOps::untweak_ptr(self.inner) } } - pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeAcceptChannelV2 { + pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeCommonAcceptChannelFields { 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 nativeAcceptChannelV2 { + pub(crate) fn take_inner(mut self) -> *mut nativeCommonAcceptChannelFields { assert!(self.is_owned); let ret = ObjOps::untweak_ptr(self.inner); self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } -/// The same `temporary_channel_id` received from the initiator's `open_channel2` message. +/// The same `temporary_channel_id` received from the initiator's `open_channel2` or `open_channel` message. #[no_mangle] -pub extern "C" fn AcceptChannelV2_get_temporary_channel_id(this_ptr: &AcceptChannelV2) -> *const [u8; 32] { +pub extern "C" fn CommonAcceptChannelFields_get_temporary_channel_id(this_ptr: &CommonAcceptChannelFields) -> crate::lightning::ln::types::ChannelId { let mut inner_val = &mut this_ptr.get_native_mut_ref().temporary_channel_id; - &inner_val.0 -} -/// The same `temporary_channel_id` received from the initiator's `open_channel2` message. -#[no_mangle] -pub extern "C" fn AcceptChannelV2_set_temporary_channel_id(this_ptr: &mut AcceptChannelV2, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.temporary_channel_id = ::lightning::ln::ChannelId(val.data); -} -/// Part of the channel value contributed by the channel acceptor -#[no_mangle] -pub extern "C" fn AcceptChannelV2_get_funding_satoshis(this_ptr: &AcceptChannelV2) -> u64 { - let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_satoshis; - *inner_val + crate::lightning::ln::types::ChannelId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::types::ChannelId<>) as *mut _) }, is_owned: false } } -/// Part of the channel value contributed by the channel acceptor +/// The same `temporary_channel_id` received from the initiator's `open_channel2` or `open_channel` message. #[no_mangle] -pub extern "C" fn AcceptChannelV2_set_funding_satoshis(this_ptr: &mut AcceptChannelV2, mut val: u64) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_satoshis = val; +pub extern "C" fn CommonAcceptChannelFields_set_temporary_channel_id(this_ptr: &mut CommonAcceptChannelFields, mut val: crate::lightning::ln::types::ChannelId) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.temporary_channel_id = *unsafe { Box::from_raw(val.take_inner()) }; } /// The threshold below which outputs on transactions broadcast by the channel acceptor will be /// omitted #[no_mangle] -pub extern "C" fn AcceptChannelV2_get_dust_limit_satoshis(this_ptr: &AcceptChannelV2) -> u64 { +pub extern "C" fn CommonAcceptChannelFields_get_dust_limit_satoshis(this_ptr: &CommonAcceptChannelFields) -> u64 { let mut inner_val = &mut this_ptr.get_native_mut_ref().dust_limit_satoshis; *inner_val } /// The threshold below which outputs on transactions broadcast by the channel acceptor will be /// omitted #[no_mangle] -pub extern "C" fn AcceptChannelV2_set_dust_limit_satoshis(this_ptr: &mut AcceptChannelV2, mut val: u64) { +pub extern "C" fn CommonAcceptChannelFields_set_dust_limit_satoshis(this_ptr: &mut CommonAcceptChannelFields, mut val: u64) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.dust_limit_satoshis = val; } -/// The maximum inbound HTLC value in flight towards channel acceptor, in milli-satoshi +/// The maximum inbound HTLC value in flight towards sender, in milli-satoshi #[no_mangle] -pub extern "C" fn AcceptChannelV2_get_max_htlc_value_in_flight_msat(this_ptr: &AcceptChannelV2) -> u64 { +pub extern "C" fn CommonAcceptChannelFields_get_max_htlc_value_in_flight_msat(this_ptr: &CommonAcceptChannelFields) -> u64 { let mut inner_val = &mut this_ptr.get_native_mut_ref().max_htlc_value_in_flight_msat; *inner_val } -/// The maximum inbound HTLC value in flight towards channel acceptor, in milli-satoshi +/// The maximum inbound HTLC value in flight towards sender, in milli-satoshi #[no_mangle] -pub extern "C" fn AcceptChannelV2_set_max_htlc_value_in_flight_msat(this_ptr: &mut AcceptChannelV2, mut val: u64) { +pub extern "C" fn CommonAcceptChannelFields_set_max_htlc_value_in_flight_msat(this_ptr: &mut CommonAcceptChannelFields, mut val: u64) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_htlc_value_in_flight_msat = val; } /// The minimum HTLC size incoming to channel acceptor, in milli-satoshi #[no_mangle] -pub extern "C" fn AcceptChannelV2_get_htlc_minimum_msat(this_ptr: &AcceptChannelV2) -> u64 { +pub extern "C" fn CommonAcceptChannelFields_get_htlc_minimum_msat(this_ptr: &CommonAcceptChannelFields) -> u64 { let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_minimum_msat; *inner_val } /// The minimum HTLC size incoming to channel acceptor, in milli-satoshi #[no_mangle] -pub extern "C" fn AcceptChannelV2_set_htlc_minimum_msat(this_ptr: &mut AcceptChannelV2, mut val: u64) { +pub extern "C" fn CommonAcceptChannelFields_set_htlc_minimum_msat(this_ptr: &mut CommonAcceptChannelFields, mut val: u64) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_minimum_msat = val; } /// Minimum depth of the funding transaction before the channel is considered open #[no_mangle] -pub extern "C" fn AcceptChannelV2_get_minimum_depth(this_ptr: &AcceptChannelV2) -> u32 { +pub extern "C" fn CommonAcceptChannelFields_get_minimum_depth(this_ptr: &CommonAcceptChannelFields) -> u32 { let mut inner_val = &mut this_ptr.get_native_mut_ref().minimum_depth; *inner_val } /// Minimum depth of the funding transaction before the channel is considered open #[no_mangle] -pub extern "C" fn AcceptChannelV2_set_minimum_depth(this_ptr: &mut AcceptChannelV2, mut val: u32) { +pub extern "C" fn CommonAcceptChannelFields_set_minimum_depth(this_ptr: &mut CommonAcceptChannelFields, mut val: u32) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.minimum_depth = val; } /// The number of blocks which the counterparty will have to wait to claim on-chain funds if they /// broadcast a commitment transaction #[no_mangle] -pub extern "C" fn AcceptChannelV2_get_to_self_delay(this_ptr: &AcceptChannelV2) -> u16 { +pub extern "C" fn CommonAcceptChannelFields_get_to_self_delay(this_ptr: &CommonAcceptChannelFields) -> u16 { let mut inner_val = &mut this_ptr.get_native_mut_ref().to_self_delay; *inner_val } /// The number of blocks which the counterparty will have to wait to claim on-chain funds if they /// broadcast a commitment transaction #[no_mangle] -pub extern "C" fn AcceptChannelV2_set_to_self_delay(this_ptr: &mut AcceptChannelV2, mut val: u16) { +pub extern "C" fn CommonAcceptChannelFields_set_to_self_delay(this_ptr: &mut CommonAcceptChannelFields, mut val: u16) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.to_self_delay = val; } /// The maximum number of inbound HTLCs towards channel acceptor #[no_mangle] -pub extern "C" fn AcceptChannelV2_get_max_accepted_htlcs(this_ptr: &AcceptChannelV2) -> u16 { +pub extern "C" fn CommonAcceptChannelFields_get_max_accepted_htlcs(this_ptr: &CommonAcceptChannelFields) -> u16 { let mut inner_val = &mut this_ptr.get_native_mut_ref().max_accepted_htlcs; *inner_val } /// The maximum number of inbound HTLCs towards channel acceptor #[no_mangle] -pub extern "C" fn AcceptChannelV2_set_max_accepted_htlcs(this_ptr: &mut AcceptChannelV2, mut val: u16) { +pub extern "C" fn CommonAcceptChannelFields_set_max_accepted_htlcs(this_ptr: &mut CommonAcceptChannelFields, mut val: u16) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.max_accepted_htlcs = val; } /// The channel acceptor's key controlling the funding transaction #[no_mangle] -pub extern "C" fn AcceptChannelV2_get_funding_pubkey(this_ptr: &AcceptChannelV2) -> crate::c_types::PublicKey { +pub extern "C" fn CommonAcceptChannelFields_get_funding_pubkey(this_ptr: &CommonAcceptChannelFields) -> crate::c_types::PublicKey { let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_pubkey; crate::c_types::PublicKey::from_rust(&inner_val) } /// The channel acceptor's key controlling the funding transaction #[no_mangle] -pub extern "C" fn AcceptChannelV2_set_funding_pubkey(this_ptr: &mut AcceptChannelV2, mut val: crate::c_types::PublicKey) { +pub extern "C" fn CommonAcceptChannelFields_set_funding_pubkey(this_ptr: &mut CommonAcceptChannelFields, mut val: crate::c_types::PublicKey) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_pubkey = val.into_rust(); } /// Used to derive a revocation key for transactions broadcast by counterparty #[no_mangle] -pub extern "C" fn AcceptChannelV2_get_revocation_basepoint(this_ptr: &AcceptChannelV2) -> crate::c_types::PublicKey { +pub extern "C" fn CommonAcceptChannelFields_get_revocation_basepoint(this_ptr: &CommonAcceptChannelFields) -> crate::c_types::PublicKey { let mut inner_val = &mut this_ptr.get_native_mut_ref().revocation_basepoint; crate::c_types::PublicKey::from_rust(&inner_val) } /// Used to derive a revocation key for transactions broadcast by counterparty #[no_mangle] -pub extern "C" fn AcceptChannelV2_set_revocation_basepoint(this_ptr: &mut AcceptChannelV2, mut val: crate::c_types::PublicKey) { +pub extern "C" fn CommonAcceptChannelFields_set_revocation_basepoint(this_ptr: &mut CommonAcceptChannelFields, mut val: crate::c_types::PublicKey) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.revocation_basepoint = val.into_rust(); } /// A payment key to channel acceptor for transactions broadcast by counterparty #[no_mangle] -pub extern "C" fn AcceptChannelV2_get_payment_basepoint(this_ptr: &AcceptChannelV2) -> crate::c_types::PublicKey { +pub extern "C" fn CommonAcceptChannelFields_get_payment_basepoint(this_ptr: &CommonAcceptChannelFields) -> crate::c_types::PublicKey { let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_basepoint; crate::c_types::PublicKey::from_rust(&inner_val) } /// A payment key to channel acceptor for transactions broadcast by counterparty #[no_mangle] -pub extern "C" fn AcceptChannelV2_set_payment_basepoint(this_ptr: &mut AcceptChannelV2, mut val: crate::c_types::PublicKey) { +pub extern "C" fn CommonAcceptChannelFields_set_payment_basepoint(this_ptr: &mut CommonAcceptChannelFields, mut val: crate::c_types::PublicKey) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_basepoint = val.into_rust(); } /// Used to derive a payment key to channel acceptor for transactions broadcast by channel /// acceptor #[no_mangle] -pub extern "C" fn AcceptChannelV2_get_delayed_payment_basepoint(this_ptr: &AcceptChannelV2) -> crate::c_types::PublicKey { +pub extern "C" fn CommonAcceptChannelFields_get_delayed_payment_basepoint(this_ptr: &CommonAcceptChannelFields) -> crate::c_types::PublicKey { let mut inner_val = &mut this_ptr.get_native_mut_ref().delayed_payment_basepoint; crate::c_types::PublicKey::from_rust(&inner_val) } /// Used to derive a payment key to channel acceptor for transactions broadcast by channel /// acceptor #[no_mangle] -pub extern "C" fn AcceptChannelV2_set_delayed_payment_basepoint(this_ptr: &mut AcceptChannelV2, mut val: crate::c_types::PublicKey) { +pub extern "C" fn CommonAcceptChannelFields_set_delayed_payment_basepoint(this_ptr: &mut CommonAcceptChannelFields, mut val: crate::c_types::PublicKey) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.delayed_payment_basepoint = val.into_rust(); } /// Used to derive an HTLC payment key to channel acceptor for transactions broadcast by counterparty #[no_mangle] -pub extern "C" fn AcceptChannelV2_get_htlc_basepoint(this_ptr: &AcceptChannelV2) -> crate::c_types::PublicKey { +pub extern "C" fn CommonAcceptChannelFields_get_htlc_basepoint(this_ptr: &CommonAcceptChannelFields) -> crate::c_types::PublicKey { let mut inner_val = &mut this_ptr.get_native_mut_ref().htlc_basepoint; crate::c_types::PublicKey::from_rust(&inner_val) } /// Used to derive an HTLC payment key to channel acceptor for transactions broadcast by counterparty #[no_mangle] -pub extern "C" fn AcceptChannelV2_set_htlc_basepoint(this_ptr: &mut AcceptChannelV2, mut val: crate::c_types::PublicKey) { +pub extern "C" fn CommonAcceptChannelFields_set_htlc_basepoint(this_ptr: &mut CommonAcceptChannelFields, mut val: crate::c_types::PublicKey) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_basepoint = val.into_rust(); } /// The first to-be-broadcast-by-channel-acceptor transaction's per commitment point #[no_mangle] -pub extern "C" fn AcceptChannelV2_get_first_per_commitment_point(this_ptr: &AcceptChannelV2) -> crate::c_types::PublicKey { +pub extern "C" fn CommonAcceptChannelFields_get_first_per_commitment_point(this_ptr: &CommonAcceptChannelFields) -> crate::c_types::PublicKey { let mut inner_val = &mut this_ptr.get_native_mut_ref().first_per_commitment_point; crate::c_types::PublicKey::from_rust(&inner_val) } /// The first to-be-broadcast-by-channel-acceptor transaction's per commitment point #[no_mangle] -pub extern "C" fn AcceptChannelV2_set_first_per_commitment_point(this_ptr: &mut AcceptChannelV2, mut val: crate::c_types::PublicKey) { +pub extern "C" fn CommonAcceptChannelFields_set_first_per_commitment_point(this_ptr: &mut CommonAcceptChannelFields, mut val: crate::c_types::PublicKey) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.first_per_commitment_point = val.into_rust(); } -/// The second to-be-broadcast-by-channel-acceptor transaction's per commitment point -#[no_mangle] -pub extern "C" fn AcceptChannelV2_get_second_per_commitment_point(this_ptr: &AcceptChannelV2) -> crate::c_types::PublicKey { - let mut inner_val = &mut this_ptr.get_native_mut_ref().second_per_commitment_point; - crate::c_types::PublicKey::from_rust(&inner_val) -} -/// The second to-be-broadcast-by-channel-acceptor transaction's per commitment point -#[no_mangle] -pub extern "C" fn AcceptChannelV2_set_second_per_commitment_point(this_ptr: &mut AcceptChannelV2, mut val: crate::c_types::PublicKey) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.second_per_commitment_point = val.into_rust(); -} /// Optionally, a request to pre-set the to-channel-acceptor output's scriptPubkey for when we /// collaboratively close #[no_mangle] -pub extern "C" fn AcceptChannelV2_get_shutdown_scriptpubkey(this_ptr: &AcceptChannelV2) -> crate::c_types::derived::COption_CVec_u8ZZ { +pub extern "C" fn CommonAcceptChannelFields_get_shutdown_scriptpubkey(this_ptr: &CommonAcceptChannelFields) -> crate::c_types::derived::COption_CVec_u8ZZ { let mut inner_val = &mut this_ptr.get_native_mut_ref().shutdown_scriptpubkey; - let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_CVec_u8ZZ::None } else { crate::c_types::derived::COption_CVec_u8ZZ::Some(/* WARNING: CLONING CONVERSION HERE! &Option is otherwise un-expressable. */ { (*inner_val.as_ref().unwrap()).clone().into_bytes().into() }) }; + let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_CVec_u8ZZ::None } else { crate::c_types::derived::COption_CVec_u8ZZ::Some(/* WARNING: CLONING CONVERSION HERE! &Option is otherwise un-expressable. */ { (*inner_val.as_ref().unwrap()).clone().to_bytes().into() }) }; local_inner_val } /// Optionally, a request to pre-set the to-channel-acceptor output's scriptPubkey for when we /// collaboratively close #[no_mangle] -pub extern "C" fn AcceptChannelV2_set_shutdown_scriptpubkey(this_ptr: &mut AcceptChannelV2, mut val: crate::c_types::derived::COption_CVec_u8ZZ) { - let mut local_val = { /*val*/ let val_opt = val; if val_opt.is_none() { None } else { Some({ { ::bitcoin::blockdata::script::Script::from({ val_opt.take() }.into_rust()) }})} }; +pub extern "C" fn CommonAcceptChannelFields_set_shutdown_scriptpubkey(this_ptr: &mut CommonAcceptChannelFields, mut val: crate::c_types::derived::COption_CVec_u8ZZ) { + let mut local_val = { /*val*/ let val_opt = val; if val_opt.is_none() { None } else { Some({ { ::bitcoin::script::ScriptBuf::from({ val_opt.take() }.into_rust()) }})} }; unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.shutdown_scriptpubkey = local_val; } -/// The channel type that this channel will represent. If none is set, we derive the channel -/// type from the intersection of our feature bits with our counterparty's feature bits from -/// the Init message. -/// -/// This is required to match the equivalent field in [`OpenChannelV2::channel_type`]. -/// -/// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None +/// The channel type that this channel will represent. If none is set, we derive the channel +/// type from the intersection of our feature bits with our counterparty's feature bits from +/// the Init message. +/// +/// This is required to match the equivalent field in [`OpenChannel`] or [`OpenChannelV2`]'s +/// [`CommonOpenChannelFields::channel_type`]. +/// +/// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None +#[no_mangle] +pub extern "C" fn CommonAcceptChannelFields_get_channel_type(this_ptr: &CommonAcceptChannelFields) -> crate::lightning_types::features::ChannelTypeFeatures { + let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_type; + let mut local_inner_val = crate::lightning_types::features::ChannelTypeFeatures { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning_types::features::ChannelTypeFeatures<>) as *mut _ }, is_owned: false }; + local_inner_val +} +/// The channel type that this channel will represent. If none is set, we derive the channel +/// type from the intersection of our feature bits with our counterparty's feature bits from +/// the Init message. +/// +/// This is required to match the equivalent field in [`OpenChannel`] or [`OpenChannelV2`]'s +/// [`CommonOpenChannelFields::channel_type`]. +/// +/// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None +#[no_mangle] +pub extern "C" fn CommonAcceptChannelFields_set_channel_type(this_ptr: &mut CommonAcceptChannelFields, mut val: crate::lightning_types::features::ChannelTypeFeatures) { + let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) }; + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_type = local_val; +} +/// Constructs a new CommonAcceptChannelFields given each field +/// +/// Note that channel_type_arg (or a relevant inner pointer) may be NULL or all-0s to represent None +#[must_use] +#[no_mangle] +pub extern "C" fn CommonAcceptChannelFields_new(mut temporary_channel_id_arg: crate::lightning::ln::types::ChannelId, mut dust_limit_satoshis_arg: u64, mut max_htlc_value_in_flight_msat_arg: u64, mut htlc_minimum_msat_arg: u64, mut minimum_depth_arg: u32, mut to_self_delay_arg: u16, mut max_accepted_htlcs_arg: u16, mut funding_pubkey_arg: crate::c_types::PublicKey, mut revocation_basepoint_arg: crate::c_types::PublicKey, mut payment_basepoint_arg: crate::c_types::PublicKey, mut delayed_payment_basepoint_arg: crate::c_types::PublicKey, mut htlc_basepoint_arg: crate::c_types::PublicKey, mut first_per_commitment_point_arg: crate::c_types::PublicKey, mut shutdown_scriptpubkey_arg: crate::c_types::derived::COption_CVec_u8ZZ, mut channel_type_arg: crate::lightning_types::features::ChannelTypeFeatures) -> CommonAcceptChannelFields { + let mut local_shutdown_scriptpubkey_arg = { /*shutdown_scriptpubkey_arg*/ let shutdown_scriptpubkey_arg_opt = shutdown_scriptpubkey_arg; if shutdown_scriptpubkey_arg_opt.is_none() { None } else { Some({ { ::bitcoin::script::ScriptBuf::from({ shutdown_scriptpubkey_arg_opt.take() }.into_rust()) }})} }; + let mut local_channel_type_arg = if channel_type_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(channel_type_arg.take_inner()) } }) }; + CommonAcceptChannelFields { inner: ObjOps::heap_alloc(nativeCommonAcceptChannelFields { + temporary_channel_id: *unsafe { Box::from_raw(temporary_channel_id_arg.take_inner()) }, + dust_limit_satoshis: dust_limit_satoshis_arg, + max_htlc_value_in_flight_msat: max_htlc_value_in_flight_msat_arg, + htlc_minimum_msat: htlc_minimum_msat_arg, + minimum_depth: minimum_depth_arg, + to_self_delay: to_self_delay_arg, + max_accepted_htlcs: max_accepted_htlcs_arg, + funding_pubkey: funding_pubkey_arg.into_rust(), + revocation_basepoint: revocation_basepoint_arg.into_rust(), + payment_basepoint: payment_basepoint_arg.into_rust(), + delayed_payment_basepoint: delayed_payment_basepoint_arg.into_rust(), + htlc_basepoint: htlc_basepoint_arg.into_rust(), + first_per_commitment_point: first_per_commitment_point_arg.into_rust(), + shutdown_scriptpubkey: local_shutdown_scriptpubkey_arg, + channel_type: local_channel_type_arg, + }), is_owned: true } +} +impl Clone for CommonAcceptChannelFields { + fn clone(&self) -> Self { + Self { + inner: if <*mut nativeCommonAcceptChannelFields>::is_null(self.inner) { core::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 CommonAcceptChannelFields_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeCommonAcceptChannelFields)).clone() })) as *mut c_void +} +#[no_mangle] +/// Creates a copy of the CommonAcceptChannelFields +pub extern "C" fn CommonAcceptChannelFields_clone(orig: &CommonAcceptChannelFields) -> CommonAcceptChannelFields { + orig.clone() +} +/// Get a string which allows debug introspection of a CommonAcceptChannelFields object +pub extern "C" fn CommonAcceptChannelFields_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::CommonAcceptChannelFields }).into()} +/// Generates a non-cryptographic 64-bit hash of the CommonAcceptChannelFields. +#[no_mangle] +pub extern "C" fn CommonAcceptChannelFields_hash(o: &CommonAcceptChannelFields) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} +/// Checks if two CommonAcceptChannelFieldss 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 CommonAcceptChannelFields_eq(a: &CommonAcceptChannelFields, b: &CommonAcceptChannelFields) -> 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 } +} + +use lightning::ln::msgs::AcceptChannel as nativeAcceptChannelImport; +pub(crate) type nativeAcceptChannel = nativeAcceptChannelImport; + +/// An [`accept_channel`] message to be sent to or received from a peer. +/// +/// Used in V1 channel establishment +/// +/// [`accept_channel`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#the-accept_channel-message +#[must_use] +#[repr(C)] +pub struct AcceptChannel { + /// 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 nativeAcceptChannel, + /// 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 core::ops::Deref for AcceptChannel { + type Target = nativeAcceptChannel; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for AcceptChannel { } +unsafe impl core::marker::Sync for AcceptChannel { } +impl Drop for AcceptChannel { + fn drop(&mut self) { + if self.is_owned && !<*mut nativeAcceptChannel>::is_null(self.inner) { + let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; + } + } +} +/// Frees any resources used by the AcceptChannel, if is_owned is set and inner is non-NULL. +#[no_mangle] +pub extern "C" fn AcceptChannel_free(this_obj: AcceptChannel) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn AcceptChannel_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeAcceptChannel) }; +} +#[allow(unused)] +impl AcceptChannel { + pub(crate) fn get_native_ref(&self) -> &'static nativeAcceptChannel { + unsafe { &*ObjOps::untweak_ptr(self.inner) } + } + pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeAcceptChannel { + 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 nativeAcceptChannel { + assert!(self.is_owned); + let ret = ObjOps::untweak_ptr(self.inner); + self.inner = core::ptr::null_mut(); + ret + } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } +} +/// Common fields of `accept_channel(2)`-like messages +#[no_mangle] +pub extern "C" fn AcceptChannel_get_common_fields(this_ptr: &AcceptChannel) -> crate::lightning::ln::msgs::CommonAcceptChannelFields { + let mut inner_val = &mut this_ptr.get_native_mut_ref().common_fields; + crate::lightning::ln::msgs::CommonAcceptChannelFields { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::msgs::CommonAcceptChannelFields<>) as *mut _) }, is_owned: false } +} +/// Common fields of `accept_channel(2)`-like messages +#[no_mangle] +pub extern "C" fn AcceptChannel_set_common_fields(this_ptr: &mut AcceptChannel, mut val: crate::lightning::ln::msgs::CommonAcceptChannelFields) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.common_fields = *unsafe { Box::from_raw(val.take_inner()) }; +} +/// The minimum value unencumbered by HTLCs for the counterparty to keep in the channel +#[no_mangle] +pub extern "C" fn AcceptChannel_get_channel_reserve_satoshis(this_ptr: &AcceptChannel) -> u64 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_reserve_satoshis; + *inner_val +} +/// The minimum value unencumbered by HTLCs for the counterparty to keep in the channel +#[no_mangle] +pub extern "C" fn AcceptChannel_set_channel_reserve_satoshis(this_ptr: &mut AcceptChannel, mut val: u64) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_reserve_satoshis = val; +} +/// Constructs a new AcceptChannel given each field +#[must_use] +#[no_mangle] +pub extern "C" fn AcceptChannel_new(mut common_fields_arg: crate::lightning::ln::msgs::CommonAcceptChannelFields, mut channel_reserve_satoshis_arg: u64) -> AcceptChannel { + AcceptChannel { inner: ObjOps::heap_alloc(nativeAcceptChannel { + common_fields: *unsafe { Box::from_raw(common_fields_arg.take_inner()) }, + channel_reserve_satoshis: channel_reserve_satoshis_arg, + }), is_owned: true } +} +impl Clone for AcceptChannel { + fn clone(&self) -> Self { + Self { + inner: if <*mut nativeAcceptChannel>::is_null(self.inner) { core::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 AcceptChannel_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeAcceptChannel)).clone() })) as *mut c_void +} +#[no_mangle] +/// Creates a copy of the AcceptChannel +pub extern "C" fn AcceptChannel_clone(orig: &AcceptChannel) -> AcceptChannel { + orig.clone() +} +/// Get a string which allows debug introspection of a AcceptChannel object +pub extern "C" fn AcceptChannel_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::AcceptChannel }).into()} +/// Generates a non-cryptographic 64-bit hash of the AcceptChannel. +#[no_mangle] +pub extern "C" fn AcceptChannel_hash(o: &AcceptChannel) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} +/// Checks if two AcceptChannels 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 AcceptChannel_eq(a: &AcceptChannel, b: &AcceptChannel) -> 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 } +} + +use lightning::ln::msgs::AcceptChannelV2 as nativeAcceptChannelV2Import; +pub(crate) type nativeAcceptChannelV2 = nativeAcceptChannelV2Import; + +/// An accept_channel2 message to be sent by or received from the channel accepter. +/// +/// Used in V2 channel establishment +/// +#[must_use] +#[repr(C)] +pub struct AcceptChannelV2 { + /// 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 nativeAcceptChannelV2, + /// 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 core::ops::Deref for AcceptChannelV2 { + type Target = nativeAcceptChannelV2; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for AcceptChannelV2 { } +unsafe impl core::marker::Sync for AcceptChannelV2 { } +impl Drop for AcceptChannelV2 { + fn drop(&mut self) { + if self.is_owned && !<*mut nativeAcceptChannelV2>::is_null(self.inner) { + let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; + } + } +} +/// Frees any resources used by the AcceptChannelV2, if is_owned is set and inner is non-NULL. +#[no_mangle] +pub extern "C" fn AcceptChannelV2_free(this_obj: AcceptChannelV2) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn AcceptChannelV2_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeAcceptChannelV2) }; +} +#[allow(unused)] +impl AcceptChannelV2 { + pub(crate) fn get_native_ref(&self) -> &'static nativeAcceptChannelV2 { + unsafe { &*ObjOps::untweak_ptr(self.inner) } + } + pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeAcceptChannelV2 { + 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 nativeAcceptChannelV2 { + assert!(self.is_owned); + let ret = ObjOps::untweak_ptr(self.inner); + self.inner = core::ptr::null_mut(); + ret + } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } +} +/// Common fields of `accept_channel(2)`-like messages +#[no_mangle] +pub extern "C" fn AcceptChannelV2_get_common_fields(this_ptr: &AcceptChannelV2) -> crate::lightning::ln::msgs::CommonAcceptChannelFields { + let mut inner_val = &mut this_ptr.get_native_mut_ref().common_fields; + crate::lightning::ln::msgs::CommonAcceptChannelFields { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::msgs::CommonAcceptChannelFields<>) as *mut _) }, is_owned: false } +} +/// Common fields of `accept_channel(2)`-like messages +#[no_mangle] +pub extern "C" fn AcceptChannelV2_set_common_fields(this_ptr: &mut AcceptChannelV2, mut val: crate::lightning::ln::msgs::CommonAcceptChannelFields) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.common_fields = *unsafe { Box::from_raw(val.take_inner()) }; +} +/// Part of the channel value contributed by the channel acceptor +#[no_mangle] +pub extern "C" fn AcceptChannelV2_get_funding_satoshis(this_ptr: &AcceptChannelV2) -> u64 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_satoshis; + *inner_val +} +/// Part of the channel value contributed by the channel acceptor +#[no_mangle] +pub extern "C" fn AcceptChannelV2_set_funding_satoshis(this_ptr: &mut AcceptChannelV2, mut val: u64) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_satoshis = val; +} +/// The second to-be-broadcast-by-channel-acceptor transaction's per commitment point +#[no_mangle] +pub extern "C" fn AcceptChannelV2_get_second_per_commitment_point(this_ptr: &AcceptChannelV2) -> crate::c_types::PublicKey { + let mut inner_val = &mut this_ptr.get_native_mut_ref().second_per_commitment_point; + crate::c_types::PublicKey::from_rust(&inner_val) +} +/// The second to-be-broadcast-by-channel-acceptor transaction's per commitment point +#[no_mangle] +pub extern "C" fn AcceptChannelV2_set_second_per_commitment_point(this_ptr: &mut AcceptChannelV2, mut val: crate::c_types::PublicKey) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.second_per_commitment_point = val.into_rust(); +} +/// Optionally, a requirement that only confirmed inputs can be added +#[no_mangle] +pub extern "C" fn AcceptChannelV2_get_require_confirmed_inputs(this_ptr: &AcceptChannelV2) -> crate::c_types::derived::COption_NoneZ { + let mut inner_val = &mut this_ptr.get_native_mut_ref().require_confirmed_inputs; + let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_NoneZ::None } else { crate::c_types::derived::COption_NoneZ::Some /* { () /**/ } */ }; + local_inner_val +} +/// Optionally, a requirement that only confirmed inputs can be added +#[no_mangle] +pub extern "C" fn AcceptChannelV2_set_require_confirmed_inputs(this_ptr: &mut AcceptChannelV2, mut val: crate::c_types::derived::COption_NoneZ) { + let mut local_val = if val.is_some() { Some( { () /*val.take()*/ }) } else { None }; + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.require_confirmed_inputs = local_val; +} +/// Constructs a new AcceptChannelV2 given each field +#[must_use] +#[no_mangle] +pub extern "C" fn AcceptChannelV2_new(mut common_fields_arg: crate::lightning::ln::msgs::CommonAcceptChannelFields, mut funding_satoshis_arg: u64, mut second_per_commitment_point_arg: crate::c_types::PublicKey, mut require_confirmed_inputs_arg: crate::c_types::derived::COption_NoneZ) -> AcceptChannelV2 { + let mut local_require_confirmed_inputs_arg = if require_confirmed_inputs_arg.is_some() { Some( { () /*require_confirmed_inputs_arg.take()*/ }) } else { None }; + AcceptChannelV2 { inner: ObjOps::heap_alloc(nativeAcceptChannelV2 { + common_fields: *unsafe { Box::from_raw(common_fields_arg.take_inner()) }, + funding_satoshis: funding_satoshis_arg, + second_per_commitment_point: second_per_commitment_point_arg.into_rust(), + require_confirmed_inputs: local_require_confirmed_inputs_arg, + }), is_owned: true } +} +impl Clone for AcceptChannelV2 { + fn clone(&self) -> Self { + Self { + inner: if <*mut nativeAcceptChannelV2>::is_null(self.inner) { core::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 AcceptChannelV2_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeAcceptChannelV2)).clone() })) as *mut c_void +} +#[no_mangle] +/// Creates a copy of the AcceptChannelV2 +pub extern "C" fn AcceptChannelV2_clone(orig: &AcceptChannelV2) -> AcceptChannelV2 { + orig.clone() +} +/// Get a string which allows debug introspection of a AcceptChannelV2 object +pub extern "C" fn AcceptChannelV2_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::AcceptChannelV2 }).into()} +/// Generates a non-cryptographic 64-bit hash of the AcceptChannelV2. +#[no_mangle] +pub extern "C" fn AcceptChannelV2_hash(o: &AcceptChannelV2) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} +/// Checks if two AcceptChannelV2s 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 AcceptChannelV2_eq(a: &AcceptChannelV2, b: &AcceptChannelV2) -> 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 } +} + +use lightning::ln::msgs::FundingCreated as nativeFundingCreatedImport; +pub(crate) type nativeFundingCreated = nativeFundingCreatedImport; + +/// A [`funding_created`] message to be sent to or received from a peer. +/// +/// Used in V1 channel establishment +/// +/// [`funding_created`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#the-funding_created-message +#[must_use] +#[repr(C)] +pub struct FundingCreated { + /// 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 nativeFundingCreated, + /// 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 core::ops::Deref for FundingCreated { + type Target = nativeFundingCreated; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for FundingCreated { } +unsafe impl core::marker::Sync for FundingCreated { } +impl Drop for FundingCreated { + fn drop(&mut self) { + if self.is_owned && !<*mut nativeFundingCreated>::is_null(self.inner) { + let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; + } + } +} +/// Frees any resources used by the FundingCreated, if is_owned is set and inner is non-NULL. +#[no_mangle] +pub extern "C" fn FundingCreated_free(this_obj: FundingCreated) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn FundingCreated_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeFundingCreated) }; +} +#[allow(unused)] +impl FundingCreated { + pub(crate) fn get_native_ref(&self) -> &'static nativeFundingCreated { + unsafe { &*ObjOps::untweak_ptr(self.inner) } + } + pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeFundingCreated { + 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 nativeFundingCreated { + assert!(self.is_owned); + let ret = ObjOps::untweak_ptr(self.inner); + self.inner = core::ptr::null_mut(); + ret + } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } +} +/// A temporary channel ID, until the funding is established +#[no_mangle] +pub extern "C" fn FundingCreated_get_temporary_channel_id(this_ptr: &FundingCreated) -> crate::lightning::ln::types::ChannelId { + let mut inner_val = &mut this_ptr.get_native_mut_ref().temporary_channel_id; + crate::lightning::ln::types::ChannelId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::types::ChannelId<>) as *mut _) }, is_owned: false } +} +/// A temporary channel ID, until the funding is established +#[no_mangle] +pub extern "C" fn FundingCreated_set_temporary_channel_id(this_ptr: &mut FundingCreated, mut val: crate::lightning::ln::types::ChannelId) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.temporary_channel_id = *unsafe { Box::from_raw(val.take_inner()) }; +} +/// The funding transaction ID +#[no_mangle] +pub extern "C" fn FundingCreated_get_funding_txid(this_ptr: &FundingCreated) -> *const [u8; 32] { + let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_txid; + inner_val.as_ref() +} +/// The funding transaction ID +#[no_mangle] +pub extern "C" fn FundingCreated_set_funding_txid(this_ptr: &mut FundingCreated, mut val: crate::c_types::ThirtyTwoBytes) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_txid = ::bitcoin::hash_types::Txid::from_slice(&val.data[..]).unwrap(); +} +/// The specific output index funding this channel +#[no_mangle] +pub extern "C" fn FundingCreated_get_funding_output_index(this_ptr: &FundingCreated) -> u16 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_output_index; + *inner_val +} +/// The specific output index funding this channel +#[no_mangle] +pub extern "C" fn FundingCreated_set_funding_output_index(this_ptr: &mut FundingCreated, mut val: u16) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_output_index = val; +} +/// The signature of the channel initiator (funder) on the initial commitment transaction +#[no_mangle] +pub extern "C" fn FundingCreated_get_signature(this_ptr: &FundingCreated) -> crate::c_types::ECDSASignature { + let mut inner_val = &mut this_ptr.get_native_mut_ref().signature; + crate::c_types::ECDSASignature::from_rust(&inner_val) +} +/// The signature of the channel initiator (funder) on the initial commitment transaction +#[no_mangle] +pub extern "C" fn FundingCreated_set_signature(this_ptr: &mut FundingCreated, mut val: crate::c_types::ECDSASignature) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.signature = val.into_rust(); +} +/// Constructs a new FundingCreated given each field +#[must_use] +#[no_mangle] +pub extern "C" fn FundingCreated_new(mut temporary_channel_id_arg: crate::lightning::ln::types::ChannelId, mut funding_txid_arg: crate::c_types::ThirtyTwoBytes, mut funding_output_index_arg: u16, mut signature_arg: crate::c_types::ECDSASignature) -> FundingCreated { + FundingCreated { inner: ObjOps::heap_alloc(nativeFundingCreated { + temporary_channel_id: *unsafe { Box::from_raw(temporary_channel_id_arg.take_inner()) }, + funding_txid: ::bitcoin::hash_types::Txid::from_slice(&funding_txid_arg.data[..]).unwrap(), + funding_output_index: funding_output_index_arg, + signature: signature_arg.into_rust(), + }), is_owned: true } +} +impl Clone for FundingCreated { + fn clone(&self) -> Self { + Self { + inner: if <*mut nativeFundingCreated>::is_null(self.inner) { core::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 FundingCreated_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeFundingCreated)).clone() })) as *mut c_void +} +#[no_mangle] +/// Creates a copy of the FundingCreated +pub extern "C" fn FundingCreated_clone(orig: &FundingCreated) -> FundingCreated { + orig.clone() +} +/// Get a string which allows debug introspection of a FundingCreated object +pub extern "C" fn FundingCreated_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::FundingCreated }).into()} +/// Generates a non-cryptographic 64-bit hash of the FundingCreated. +#[no_mangle] +pub extern "C" fn FundingCreated_hash(o: &FundingCreated) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} +/// Checks if two FundingCreateds 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 FundingCreated_eq(a: &FundingCreated, b: &FundingCreated) -> 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 } +} + +use lightning::ln::msgs::FundingSigned as nativeFundingSignedImport; +pub(crate) type nativeFundingSigned = nativeFundingSignedImport; + +/// A [`funding_signed`] message to be sent to or received from a peer. +/// +/// Used in V1 channel establishment +/// +/// [`funding_signed`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#the-funding_signed-message +#[must_use] +#[repr(C)] +pub struct FundingSigned { + /// 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 nativeFundingSigned, + /// 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 core::ops::Deref for FundingSigned { + type Target = nativeFundingSigned; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for FundingSigned { } +unsafe impl core::marker::Sync for FundingSigned { } +impl Drop for FundingSigned { + fn drop(&mut self) { + if self.is_owned && !<*mut nativeFundingSigned>::is_null(self.inner) { + let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; + } + } +} +/// Frees any resources used by the FundingSigned, if is_owned is set and inner is non-NULL. +#[no_mangle] +pub extern "C" fn FundingSigned_free(this_obj: FundingSigned) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn FundingSigned_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeFundingSigned) }; +} +#[allow(unused)] +impl FundingSigned { + pub(crate) fn get_native_ref(&self) -> &'static nativeFundingSigned { + unsafe { &*ObjOps::untweak_ptr(self.inner) } + } + pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeFundingSigned { + 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 nativeFundingSigned { + assert!(self.is_owned); + let ret = ObjOps::untweak_ptr(self.inner); + self.inner = core::ptr::null_mut(); + ret + } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } +} +/// The channel ID +#[no_mangle] +pub extern "C" fn FundingSigned_get_channel_id(this_ptr: &FundingSigned) -> crate::lightning::ln::types::ChannelId { + let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_id; + crate::lightning::ln::types::ChannelId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::types::ChannelId<>) as *mut _) }, is_owned: false } +} +/// The channel ID +#[no_mangle] +pub extern "C" fn FundingSigned_set_channel_id(this_ptr: &mut FundingSigned, mut val: crate::lightning::ln::types::ChannelId) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = *unsafe { Box::from_raw(val.take_inner()) }; +} +/// The signature of the channel acceptor (fundee) on the initial commitment transaction +#[no_mangle] +pub extern "C" fn FundingSigned_get_signature(this_ptr: &FundingSigned) -> crate::c_types::ECDSASignature { + let mut inner_val = &mut this_ptr.get_native_mut_ref().signature; + crate::c_types::ECDSASignature::from_rust(&inner_val) +} +/// The signature of the channel acceptor (fundee) on the initial commitment transaction +#[no_mangle] +pub extern "C" fn FundingSigned_set_signature(this_ptr: &mut FundingSigned, mut val: crate::c_types::ECDSASignature) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.signature = val.into_rust(); +} +/// Constructs a new FundingSigned given each field +#[must_use] +#[no_mangle] +pub extern "C" fn FundingSigned_new(mut channel_id_arg: crate::lightning::ln::types::ChannelId, mut signature_arg: crate::c_types::ECDSASignature) -> FundingSigned { + FundingSigned { inner: ObjOps::heap_alloc(nativeFundingSigned { + channel_id: *unsafe { Box::from_raw(channel_id_arg.take_inner()) }, + signature: signature_arg.into_rust(), + }), is_owned: true } +} +impl Clone for FundingSigned { + fn clone(&self) -> Self { + Self { + inner: if <*mut nativeFundingSigned>::is_null(self.inner) { core::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 FundingSigned_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeFundingSigned)).clone() })) as *mut c_void +} +#[no_mangle] +/// Creates a copy of the FundingSigned +pub extern "C" fn FundingSigned_clone(orig: &FundingSigned) -> FundingSigned { + orig.clone() +} +/// Get a string which allows debug introspection of a FundingSigned object +pub extern "C" fn FundingSigned_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::FundingSigned }).into()} +/// Generates a non-cryptographic 64-bit hash of the FundingSigned. +#[no_mangle] +pub extern "C" fn FundingSigned_hash(o: &FundingSigned) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} +/// Checks if two FundingSigneds 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 FundingSigned_eq(a: &FundingSigned, b: &FundingSigned) -> 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 } +} + +use lightning::ln::msgs::ChannelReady as nativeChannelReadyImport; +pub(crate) type nativeChannelReady = nativeChannelReadyImport; + +/// A [`channel_ready`] message to be sent to or received from a peer. +/// +/// [`channel_ready`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#the-channel_ready-message +#[must_use] +#[repr(C)] +pub struct ChannelReady { + /// 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 nativeChannelReady, + /// 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 core::ops::Deref for ChannelReady { + type Target = nativeChannelReady; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for ChannelReady { } +unsafe impl core::marker::Sync for ChannelReady { } +impl Drop for ChannelReady { + fn drop(&mut self) { + if self.is_owned && !<*mut nativeChannelReady>::is_null(self.inner) { + let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; + } + } +} +/// Frees any resources used by the ChannelReady, if is_owned is set and inner is non-NULL. +#[no_mangle] +pub extern "C" fn ChannelReady_free(this_obj: ChannelReady) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn ChannelReady_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelReady) }; +} +#[allow(unused)] +impl ChannelReady { + pub(crate) fn get_native_ref(&self) -> &'static nativeChannelReady { + unsafe { &*ObjOps::untweak_ptr(self.inner) } + } + pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelReady { + 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 nativeChannelReady { + assert!(self.is_owned); + let ret = ObjOps::untweak_ptr(self.inner); + self.inner = core::ptr::null_mut(); + ret + } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } +} +/// The channel ID +#[no_mangle] +pub extern "C" fn ChannelReady_get_channel_id(this_ptr: &ChannelReady) -> crate::lightning::ln::types::ChannelId { + let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_id; + crate::lightning::ln::types::ChannelId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::types::ChannelId<>) as *mut _) }, is_owned: false } +} +/// The channel ID +#[no_mangle] +pub extern "C" fn ChannelReady_set_channel_id(this_ptr: &mut ChannelReady, mut val: crate::lightning::ln::types::ChannelId) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = *unsafe { Box::from_raw(val.take_inner()) }; +} +/// The per-commitment point of the second commitment transaction +#[no_mangle] +pub extern "C" fn ChannelReady_get_next_per_commitment_point(this_ptr: &ChannelReady) -> crate::c_types::PublicKey { + let mut inner_val = &mut this_ptr.get_native_mut_ref().next_per_commitment_point; + crate::c_types::PublicKey::from_rust(&inner_val) +} +/// The per-commitment point of the second commitment transaction +#[no_mangle] +pub extern "C" fn ChannelReady_set_next_per_commitment_point(this_ptr: &mut ChannelReady, mut val: crate::c_types::PublicKey) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.next_per_commitment_point = val.into_rust(); +} +/// If set, provides a `short_channel_id` alias for this channel. +/// +/// The sender will accept payments to be forwarded over this SCID and forward them to this +/// messages' recipient. +#[no_mangle] +pub extern "C" fn ChannelReady_get_short_channel_id_alias(this_ptr: &ChannelReady) -> crate::c_types::derived::COption_u64Z { + let mut inner_val = &mut this_ptr.get_native_mut_ref().short_channel_id_alias; + let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { inner_val.unwrap() }) }; + local_inner_val +} +/// If set, provides a `short_channel_id` alias for this channel. +/// +/// The sender will accept payments to be forwarded over this SCID and forward them to this +/// messages' recipient. +#[no_mangle] +pub extern "C" fn ChannelReady_set_short_channel_id_alias(this_ptr: &mut ChannelReady, mut val: crate::c_types::derived::COption_u64Z) { + let mut local_val = if val.is_some() { Some( { val.take() }) } else { None }; + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.short_channel_id_alias = local_val; +} +/// Constructs a new ChannelReady given each field +#[must_use] +#[no_mangle] +pub extern "C" fn ChannelReady_new(mut channel_id_arg: crate::lightning::ln::types::ChannelId, mut next_per_commitment_point_arg: crate::c_types::PublicKey, mut short_channel_id_alias_arg: crate::c_types::derived::COption_u64Z) -> ChannelReady { + let mut local_short_channel_id_alias_arg = if short_channel_id_alias_arg.is_some() { Some( { short_channel_id_alias_arg.take() }) } else { None }; + ChannelReady { inner: ObjOps::heap_alloc(nativeChannelReady { + channel_id: *unsafe { Box::from_raw(channel_id_arg.take_inner()) }, + next_per_commitment_point: next_per_commitment_point_arg.into_rust(), + short_channel_id_alias: local_short_channel_id_alias_arg, + }), is_owned: true } +} +impl Clone for ChannelReady { + fn clone(&self) -> Self { + Self { + inner: if <*mut nativeChannelReady>::is_null(self.inner) { core::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 ChannelReady_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelReady)).clone() })) as *mut c_void +} +#[no_mangle] +/// Creates a copy of the ChannelReady +pub extern "C" fn ChannelReady_clone(orig: &ChannelReady) -> ChannelReady { + orig.clone() +} +/// Get a string which allows debug introspection of a ChannelReady object +pub extern "C" fn ChannelReady_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::ChannelReady }).into()} +/// Generates a non-cryptographic 64-bit hash of the ChannelReady. +#[no_mangle] +pub extern "C" fn ChannelReady_hash(o: &ChannelReady) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} +/// Checks if two ChannelReadys 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 ChannelReady_eq(a: &ChannelReady, b: &ChannelReady) -> 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 } +} + +use lightning::ln::msgs::Stfu as nativeStfuImport; +pub(crate) type nativeStfu = nativeStfuImport; + +/// An `stfu` (quiescence) message to be sent by or received from the stfu initiator. +/// +#[must_use] +#[repr(C)] +pub struct Stfu { + /// 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 nativeStfu, + /// 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 core::ops::Deref for Stfu { + type Target = nativeStfu; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for Stfu { } +unsafe impl core::marker::Sync for Stfu { } +impl Drop for Stfu { + fn drop(&mut self) { + if self.is_owned && !<*mut nativeStfu>::is_null(self.inner) { + let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; + } + } +} +/// Frees any resources used by the Stfu, if is_owned is set and inner is non-NULL. +#[no_mangle] +pub extern "C" fn Stfu_free(this_obj: Stfu) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn Stfu_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeStfu) }; +} +#[allow(unused)] +impl Stfu { + pub(crate) fn get_native_ref(&self) -> &'static nativeStfu { + unsafe { &*ObjOps::untweak_ptr(self.inner) } + } + pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeStfu { + 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 nativeStfu { + assert!(self.is_owned); + let ret = ObjOps::untweak_ptr(self.inner); + self.inner = core::ptr::null_mut(); + ret + } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } +} +/// The channel ID where quiescence is intended #[no_mangle] -pub extern "C" fn AcceptChannelV2_get_channel_type(this_ptr: &AcceptChannelV2) -> crate::lightning::ln::features::ChannelTypeFeatures { - let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_type; - let mut local_inner_val = crate::lightning::ln::features::ChannelTypeFeatures { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::ln::features::ChannelTypeFeatures<>) as *mut _ }, is_owned: false }; - local_inner_val +pub extern "C" fn Stfu_get_channel_id(this_ptr: &Stfu) -> crate::lightning::ln::types::ChannelId { + let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_id; + crate::lightning::ln::types::ChannelId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::types::ChannelId<>) as *mut _) }, is_owned: false } } -/// The channel type that this channel will represent. If none is set, we derive the channel -/// type from the intersection of our feature bits with our counterparty's feature bits from -/// the Init message. -/// -/// This is required to match the equivalent field in [`OpenChannelV2::channel_type`]. -/// -/// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None +/// The channel ID where quiescence is intended #[no_mangle] -pub extern "C" fn AcceptChannelV2_set_channel_type(this_ptr: &mut AcceptChannelV2, mut val: crate::lightning::ln::features::ChannelTypeFeatures) { - let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) }; - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_type = local_val; +pub extern "C" fn Stfu_set_channel_id(this_ptr: &mut Stfu, mut val: crate::lightning::ln::types::ChannelId) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = *unsafe { Box::from_raw(val.take_inner()) }; } -/// Optionally, a requirement that only confirmed inputs can be added +/// Initiator flag, 1 if initiating, 0 if replying to an stfu. #[no_mangle] -pub extern "C" fn AcceptChannelV2_get_require_confirmed_inputs(this_ptr: &AcceptChannelV2) -> crate::c_types::derived::COption_NoneZ { - let mut inner_val = &mut this_ptr.get_native_mut_ref().require_confirmed_inputs; - let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_NoneZ::None } else { crate::c_types::derived::COption_NoneZ::Some /* { () /**/ } */ }; - local_inner_val +pub extern "C" fn Stfu_get_initiator(this_ptr: &Stfu) -> u8 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().initiator; + *inner_val } -/// Optionally, a requirement that only confirmed inputs can be added +/// Initiator flag, 1 if initiating, 0 if replying to an stfu. #[no_mangle] -pub extern "C" fn AcceptChannelV2_set_require_confirmed_inputs(this_ptr: &mut AcceptChannelV2, mut val: crate::c_types::derived::COption_NoneZ) { - let mut local_val = if val.is_some() { Some( { () /*val.take()*/ }) } else { None }; - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.require_confirmed_inputs = local_val; +pub extern "C" fn Stfu_set_initiator(this_ptr: &mut Stfu, mut val: u8) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.initiator = val; } -/// Constructs a new AcceptChannelV2 given each field -/// -/// Note that channel_type_arg (or a relevant inner pointer) may be NULL or all-0s to represent None +/// Constructs a new Stfu given each field #[must_use] #[no_mangle] -pub extern "C" fn AcceptChannelV2_new(mut temporary_channel_id_arg: crate::c_types::ThirtyTwoBytes, mut funding_satoshis_arg: u64, mut dust_limit_satoshis_arg: u64, mut max_htlc_value_in_flight_msat_arg: u64, mut htlc_minimum_msat_arg: u64, mut minimum_depth_arg: u32, mut to_self_delay_arg: u16, mut max_accepted_htlcs_arg: u16, mut funding_pubkey_arg: crate::c_types::PublicKey, mut revocation_basepoint_arg: crate::c_types::PublicKey, mut payment_basepoint_arg: crate::c_types::PublicKey, mut delayed_payment_basepoint_arg: crate::c_types::PublicKey, mut htlc_basepoint_arg: crate::c_types::PublicKey, mut first_per_commitment_point_arg: crate::c_types::PublicKey, mut second_per_commitment_point_arg: crate::c_types::PublicKey, mut shutdown_scriptpubkey_arg: crate::c_types::derived::COption_CVec_u8ZZ, mut channel_type_arg: crate::lightning::ln::features::ChannelTypeFeatures, mut require_confirmed_inputs_arg: crate::c_types::derived::COption_NoneZ) -> AcceptChannelV2 { - let mut local_shutdown_scriptpubkey_arg = { /*shutdown_scriptpubkey_arg*/ let shutdown_scriptpubkey_arg_opt = shutdown_scriptpubkey_arg; if shutdown_scriptpubkey_arg_opt.is_none() { None } else { Some({ { ::bitcoin::blockdata::script::Script::from({ shutdown_scriptpubkey_arg_opt.take() }.into_rust()) }})} }; - let mut local_channel_type_arg = if channel_type_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(channel_type_arg.take_inner()) } }) }; - let mut local_require_confirmed_inputs_arg = if require_confirmed_inputs_arg.is_some() { Some( { () /*require_confirmed_inputs_arg.take()*/ }) } else { None }; - AcceptChannelV2 { inner: ObjOps::heap_alloc(nativeAcceptChannelV2 { - temporary_channel_id: ::lightning::ln::ChannelId(temporary_channel_id_arg.data), - funding_satoshis: funding_satoshis_arg, - dust_limit_satoshis: dust_limit_satoshis_arg, - max_htlc_value_in_flight_msat: max_htlc_value_in_flight_msat_arg, - htlc_minimum_msat: htlc_minimum_msat_arg, - minimum_depth: minimum_depth_arg, - to_self_delay: to_self_delay_arg, - max_accepted_htlcs: max_accepted_htlcs_arg, - funding_pubkey: funding_pubkey_arg.into_rust(), - revocation_basepoint: revocation_basepoint_arg.into_rust(), - payment_basepoint: payment_basepoint_arg.into_rust(), - delayed_payment_basepoint: delayed_payment_basepoint_arg.into_rust(), - htlc_basepoint: htlc_basepoint_arg.into_rust(), - first_per_commitment_point: first_per_commitment_point_arg.into_rust(), - second_per_commitment_point: second_per_commitment_point_arg.into_rust(), - shutdown_scriptpubkey: local_shutdown_scriptpubkey_arg, - channel_type: local_channel_type_arg, - require_confirmed_inputs: local_require_confirmed_inputs_arg, +pub extern "C" fn Stfu_new(mut channel_id_arg: crate::lightning::ln::types::ChannelId, mut initiator_arg: u8) -> Stfu { + Stfu { inner: ObjOps::heap_alloc(nativeStfu { + channel_id: *unsafe { Box::from_raw(channel_id_arg.take_inner()) }, + initiator: initiator_arg, }), is_owned: true } } -impl Clone for AcceptChannelV2 { +impl Clone for Stfu { fn clone(&self) -> Self { Self { - inner: if <*mut nativeAcceptChannelV2>::is_null(self.inner) { core::ptr::null_mut() } else { + inner: if <*mut nativeStfu>::is_null(self.inner) { core::ptr::null_mut() } else { ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, is_owned: true, } @@ -2142,40 +2989,40 @@ impl Clone for AcceptChannelV2 { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn AcceptChannelV2_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeAcceptChannelV2)).clone() })) as *mut c_void +pub(crate) extern "C" fn Stfu_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeStfu)).clone() })) as *mut c_void } #[no_mangle] -/// Creates a copy of the AcceptChannelV2 -pub extern "C" fn AcceptChannelV2_clone(orig: &AcceptChannelV2) -> AcceptChannelV2 { +/// Creates a copy of the Stfu +pub extern "C" fn Stfu_clone(orig: &Stfu) -> Stfu { orig.clone() } -/// Checks if two AcceptChannelV2s contain equal inner contents. +/// Get a string which allows debug introspection of a Stfu object +pub extern "C" fn Stfu_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::Stfu }).into()} +/// Checks if two Stfus 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 AcceptChannelV2_eq(a: &AcceptChannelV2, b: &AcceptChannelV2) -> bool { +pub extern "C" fn Stfu_eq(a: &Stfu, b: &Stfu) -> 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 } } -use lightning::ln::msgs::FundingCreated as nativeFundingCreatedImport; -pub(crate) type nativeFundingCreated = nativeFundingCreatedImport; +use lightning::ln::msgs::SpliceInit as nativeSpliceInitImport; +pub(crate) type nativeSpliceInit = nativeSpliceInitImport; -/// A [`funding_created`] message to be sent to or received from a peer. -/// -/// Used in V1 channel establishment +/// A `splice_init` message to be sent by or received from the stfu initiator (splice initiator). /// -/// [`funding_created`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#the-funding_created-message #[must_use] #[repr(C)] -pub struct FundingCreated { +pub struct SpliceInit { /// 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 nativeFundingCreated, + pub inner: *mut nativeSpliceInit, /// 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 @@ -2183,96 +3030,134 @@ pub struct FundingCreated { pub is_owned: bool, } -impl Drop for FundingCreated { +impl core::ops::Deref for SpliceInit { + type Target = nativeSpliceInit; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for SpliceInit { } +unsafe impl core::marker::Sync for SpliceInit { } +impl Drop for SpliceInit { fn drop(&mut self) { - if self.is_owned && !<*mut nativeFundingCreated>::is_null(self.inner) { + if self.is_owned && !<*mut nativeSpliceInit>::is_null(self.inner) { let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; } } } -/// Frees any resources used by the FundingCreated, if is_owned is set and inner is non-NULL. +/// Frees any resources used by the SpliceInit, if is_owned is set and inner is non-NULL. #[no_mangle] -pub extern "C" fn FundingCreated_free(this_obj: FundingCreated) { } +pub extern "C" fn SpliceInit_free(this_obj: SpliceInit) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn FundingCreated_free_void(this_ptr: *mut c_void) { - let _ = unsafe { Box::from_raw(this_ptr as *mut nativeFundingCreated) }; +pub(crate) extern "C" fn SpliceInit_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeSpliceInit) }; } #[allow(unused)] -impl FundingCreated { - pub(crate) fn get_native_ref(&self) -> &'static nativeFundingCreated { +impl SpliceInit { + pub(crate) fn get_native_ref(&self) -> &'static nativeSpliceInit { unsafe { &*ObjOps::untweak_ptr(self.inner) } } - pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeFundingCreated { + pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeSpliceInit { 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 nativeFundingCreated { + pub(crate) fn take_inner(mut self) -> *mut nativeSpliceInit { assert!(self.is_owned); let ret = ObjOps::untweak_ptr(self.inner); self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } -/// A temporary channel ID, until the funding is established +/// The channel ID where splicing is intended #[no_mangle] -pub extern "C" fn FundingCreated_get_temporary_channel_id(this_ptr: &FundingCreated) -> *const [u8; 32] { - let mut inner_val = &mut this_ptr.get_native_mut_ref().temporary_channel_id; - &inner_val.0 +pub extern "C" fn SpliceInit_get_channel_id(this_ptr: &SpliceInit) -> crate::lightning::ln::types::ChannelId { + let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_id; + crate::lightning::ln::types::ChannelId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::types::ChannelId<>) as *mut _) }, is_owned: false } } -/// A temporary channel ID, until the funding is established +/// The channel ID where splicing is intended #[no_mangle] -pub extern "C" fn FundingCreated_set_temporary_channel_id(this_ptr: &mut FundingCreated, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.temporary_channel_id = ::lightning::ln::ChannelId(val.data); +pub extern "C" fn SpliceInit_set_channel_id(this_ptr: &mut SpliceInit, mut val: crate::lightning::ln::types::ChannelId) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = *unsafe { Box::from_raw(val.take_inner()) }; } -/// The funding transaction ID +/// The amount the splice initiator is intending to add to its channel balance (splice-in) +/// or remove from its channel balance (splice-out). #[no_mangle] -pub extern "C" fn FundingCreated_get_funding_txid(this_ptr: &FundingCreated) -> *const [u8; 32] { - let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_txid; - inner_val.as_inner() +pub extern "C" fn SpliceInit_get_funding_contribution_satoshis(this_ptr: &SpliceInit) -> i64 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_contribution_satoshis; + *inner_val } -/// The funding transaction ID +/// The amount the splice initiator is intending to add to its channel balance (splice-in) +/// or remove from its channel balance (splice-out). #[no_mangle] -pub extern "C" fn FundingCreated_set_funding_txid(this_ptr: &mut FundingCreated, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_txid = ::bitcoin::hash_types::Txid::from_slice(&val.data[..]).unwrap(); +pub extern "C" fn SpliceInit_set_funding_contribution_satoshis(this_ptr: &mut SpliceInit, mut val: i64) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_contribution_satoshis = val; } -/// The specific output index funding this channel +/// The feerate for the new funding transaction, set by the splice initiator #[no_mangle] -pub extern "C" fn FundingCreated_get_funding_output_index(this_ptr: &FundingCreated) -> u16 { - let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_output_index; +pub extern "C" fn SpliceInit_get_funding_feerate_perkw(this_ptr: &SpliceInit) -> u32 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_feerate_perkw; *inner_val } -/// The specific output index funding this channel +/// The feerate for the new funding transaction, set by the splice initiator #[no_mangle] -pub extern "C" fn FundingCreated_set_funding_output_index(this_ptr: &mut FundingCreated, mut val: u16) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_output_index = val; +pub extern "C" fn SpliceInit_set_funding_feerate_perkw(this_ptr: &mut SpliceInit, mut val: u32) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_feerate_perkw = val; } -/// The signature of the channel initiator (funder) on the initial commitment transaction +/// The locktime for the new funding transaction #[no_mangle] -pub extern "C" fn FundingCreated_get_signature(this_ptr: &FundingCreated) -> crate::c_types::ECDSASignature { - let mut inner_val = &mut this_ptr.get_native_mut_ref().signature; - crate::c_types::ECDSASignature::from_rust(&inner_val) +pub extern "C" fn SpliceInit_get_locktime(this_ptr: &SpliceInit) -> u32 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().locktime; + *inner_val } -/// The signature of the channel initiator (funder) on the initial commitment transaction +/// The locktime for the new funding transaction #[no_mangle] -pub extern "C" fn FundingCreated_set_signature(this_ptr: &mut FundingCreated, mut val: crate::c_types::ECDSASignature) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.signature = val.into_rust(); +pub extern "C" fn SpliceInit_set_locktime(this_ptr: &mut SpliceInit, mut val: u32) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.locktime = val; } -/// Constructs a new FundingCreated given each field +/// The key of the sender (splice initiator) controlling the new funding transaction +#[no_mangle] +pub extern "C" fn SpliceInit_get_funding_pubkey(this_ptr: &SpliceInit) -> crate::c_types::PublicKey { + let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_pubkey; + crate::c_types::PublicKey::from_rust(&inner_val) +} +/// The key of the sender (splice initiator) controlling the new funding transaction +#[no_mangle] +pub extern "C" fn SpliceInit_set_funding_pubkey(this_ptr: &mut SpliceInit, mut val: crate::c_types::PublicKey) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_pubkey = val.into_rust(); +} +/// If set, only confirmed inputs added (by the splice acceptor) will be accepted +#[no_mangle] +pub extern "C" fn SpliceInit_get_require_confirmed_inputs(this_ptr: &SpliceInit) -> crate::c_types::derived::COption_NoneZ { + let mut inner_val = &mut this_ptr.get_native_mut_ref().require_confirmed_inputs; + let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_NoneZ::None } else { crate::c_types::derived::COption_NoneZ::Some /* { () /**/ } */ }; + local_inner_val +} +/// If set, only confirmed inputs added (by the splice acceptor) will be accepted +#[no_mangle] +pub extern "C" fn SpliceInit_set_require_confirmed_inputs(this_ptr: &mut SpliceInit, mut val: crate::c_types::derived::COption_NoneZ) { + let mut local_val = if val.is_some() { Some( { () /*val.take()*/ }) } else { None }; + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.require_confirmed_inputs = local_val; +} +/// Constructs a new SpliceInit given each field #[must_use] #[no_mangle] -pub extern "C" fn FundingCreated_new(mut temporary_channel_id_arg: crate::c_types::ThirtyTwoBytes, mut funding_txid_arg: crate::c_types::ThirtyTwoBytes, mut funding_output_index_arg: u16, mut signature_arg: crate::c_types::ECDSASignature) -> FundingCreated { - FundingCreated { inner: ObjOps::heap_alloc(nativeFundingCreated { - temporary_channel_id: ::lightning::ln::ChannelId(temporary_channel_id_arg.data), - funding_txid: ::bitcoin::hash_types::Txid::from_slice(&funding_txid_arg.data[..]).unwrap(), - funding_output_index: funding_output_index_arg, - signature: signature_arg.into_rust(), +pub extern "C" fn SpliceInit_new(mut channel_id_arg: crate::lightning::ln::types::ChannelId, mut funding_contribution_satoshis_arg: i64, mut funding_feerate_perkw_arg: u32, mut locktime_arg: u32, mut funding_pubkey_arg: crate::c_types::PublicKey, mut require_confirmed_inputs_arg: crate::c_types::derived::COption_NoneZ) -> SpliceInit { + let mut local_require_confirmed_inputs_arg = if require_confirmed_inputs_arg.is_some() { Some( { () /*require_confirmed_inputs_arg.take()*/ }) } else { None }; + SpliceInit { inner: ObjOps::heap_alloc(nativeSpliceInit { + channel_id: *unsafe { Box::from_raw(channel_id_arg.take_inner()) }, + funding_contribution_satoshis: funding_contribution_satoshis_arg, + funding_feerate_perkw: funding_feerate_perkw_arg, + locktime: locktime_arg, + funding_pubkey: funding_pubkey_arg.into_rust(), + require_confirmed_inputs: local_require_confirmed_inputs_arg, }), is_owned: true } } -impl Clone for FundingCreated { +impl Clone for SpliceInit { fn clone(&self) -> Self { Self { - inner: if <*mut nativeFundingCreated>::is_null(self.inner) { core::ptr::null_mut() } else { + inner: if <*mut nativeSpliceInit>::is_null(self.inner) { core::ptr::null_mut() } else { ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, is_owned: true, } @@ -2280,40 +3165,40 @@ impl Clone for FundingCreated { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn FundingCreated_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeFundingCreated)).clone() })) as *mut c_void +pub(crate) extern "C" fn SpliceInit_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeSpliceInit)).clone() })) as *mut c_void } #[no_mangle] -/// Creates a copy of the FundingCreated -pub extern "C" fn FundingCreated_clone(orig: &FundingCreated) -> FundingCreated { +/// Creates a copy of the SpliceInit +pub extern "C" fn SpliceInit_clone(orig: &SpliceInit) -> SpliceInit { orig.clone() } -/// Checks if two FundingCreateds contain equal inner contents. +/// Get a string which allows debug introspection of a SpliceInit object +pub extern "C" fn SpliceInit_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::SpliceInit }).into()} +/// Checks if two SpliceInits 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 FundingCreated_eq(a: &FundingCreated, b: &FundingCreated) -> bool { +pub extern "C" fn SpliceInit_eq(a: &SpliceInit, b: &SpliceInit) -> 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 } } -use lightning::ln::msgs::FundingSigned as nativeFundingSignedImport; -pub(crate) type nativeFundingSigned = nativeFundingSignedImport; +use lightning::ln::msgs::SpliceAck as nativeSpliceAckImport; +pub(crate) type nativeSpliceAck = nativeSpliceAckImport; -/// A [`funding_signed`] message to be sent to or received from a peer. -/// -/// Used in V1 channel establishment +/// A `splice_ack` message to be received by or sent to the splice initiator. /// -/// [`funding_signed`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#the-funding_signed-message #[must_use] #[repr(C)] -pub struct FundingSigned { +pub struct SpliceAck { /// 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 nativeFundingSigned, + pub inner: *mut nativeSpliceAck, /// 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 @@ -2321,72 +3206,110 @@ pub struct FundingSigned { pub is_owned: bool, } -impl Drop for FundingSigned { +impl core::ops::Deref for SpliceAck { + type Target = nativeSpliceAck; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for SpliceAck { } +unsafe impl core::marker::Sync for SpliceAck { } +impl Drop for SpliceAck { fn drop(&mut self) { - if self.is_owned && !<*mut nativeFundingSigned>::is_null(self.inner) { + if self.is_owned && !<*mut nativeSpliceAck>::is_null(self.inner) { let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; } } } -/// Frees any resources used by the FundingSigned, if is_owned is set and inner is non-NULL. +/// Frees any resources used by the SpliceAck, if is_owned is set and inner is non-NULL. #[no_mangle] -pub extern "C" fn FundingSigned_free(this_obj: FundingSigned) { } +pub extern "C" fn SpliceAck_free(this_obj: SpliceAck) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn FundingSigned_free_void(this_ptr: *mut c_void) { - let _ = unsafe { Box::from_raw(this_ptr as *mut nativeFundingSigned) }; +pub(crate) extern "C" fn SpliceAck_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeSpliceAck) }; } #[allow(unused)] -impl FundingSigned { - pub(crate) fn get_native_ref(&self) -> &'static nativeFundingSigned { +impl SpliceAck { + pub(crate) fn get_native_ref(&self) -> &'static nativeSpliceAck { unsafe { &*ObjOps::untweak_ptr(self.inner) } } - pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeFundingSigned { + pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeSpliceAck { 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 nativeFundingSigned { + pub(crate) fn take_inner(mut self) -> *mut nativeSpliceAck { assert!(self.is_owned); let ret = ObjOps::untweak_ptr(self.inner); self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } -/// The channel ID +/// The channel ID where splicing is intended #[no_mangle] -pub extern "C" fn FundingSigned_get_channel_id(this_ptr: &FundingSigned) -> *const [u8; 32] { +pub extern "C" fn SpliceAck_get_channel_id(this_ptr: &SpliceAck) -> crate::lightning::ln::types::ChannelId { let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_id; - &inner_val.0 + crate::lightning::ln::types::ChannelId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::types::ChannelId<>) as *mut _) }, is_owned: false } } -/// The channel ID +/// The channel ID where splicing is intended #[no_mangle] -pub extern "C" fn FundingSigned_set_channel_id(this_ptr: &mut FundingSigned, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = ::lightning::ln::ChannelId(val.data); +pub extern "C" fn SpliceAck_set_channel_id(this_ptr: &mut SpliceAck, mut val: crate::lightning::ln::types::ChannelId) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = *unsafe { Box::from_raw(val.take_inner()) }; } -/// The signature of the channel acceptor (fundee) on the initial commitment transaction +/// The amount the splice acceptor is intending to add to its channel balance (splice-in) +/// or remove from its channel balance (splice-out). #[no_mangle] -pub extern "C" fn FundingSigned_get_signature(this_ptr: &FundingSigned) -> crate::c_types::ECDSASignature { - let mut inner_val = &mut this_ptr.get_native_mut_ref().signature; - crate::c_types::ECDSASignature::from_rust(&inner_val) +pub extern "C" fn SpliceAck_get_funding_contribution_satoshis(this_ptr: &SpliceAck) -> i64 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_contribution_satoshis; + *inner_val } -/// The signature of the channel acceptor (fundee) on the initial commitment transaction +/// The amount the splice acceptor is intending to add to its channel balance (splice-in) +/// or remove from its channel balance (splice-out). #[no_mangle] -pub extern "C" fn FundingSigned_set_signature(this_ptr: &mut FundingSigned, mut val: crate::c_types::ECDSASignature) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.signature = val.into_rust(); +pub extern "C" fn SpliceAck_set_funding_contribution_satoshis(this_ptr: &mut SpliceAck, mut val: i64) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_contribution_satoshis = val; } -/// Constructs a new FundingSigned given each field +/// The key of the sender (splice acceptor) controlling the new funding transaction +#[no_mangle] +pub extern "C" fn SpliceAck_get_funding_pubkey(this_ptr: &SpliceAck) -> crate::c_types::PublicKey { + let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_pubkey; + crate::c_types::PublicKey::from_rust(&inner_val) +} +/// The key of the sender (splice acceptor) controlling the new funding transaction +#[no_mangle] +pub extern "C" fn SpliceAck_set_funding_pubkey(this_ptr: &mut SpliceAck, mut val: crate::c_types::PublicKey) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_pubkey = val.into_rust(); +} +/// If set, only confirmed inputs added (by the splice initiator) will be accepted +#[no_mangle] +pub extern "C" fn SpliceAck_get_require_confirmed_inputs(this_ptr: &SpliceAck) -> crate::c_types::derived::COption_NoneZ { + let mut inner_val = &mut this_ptr.get_native_mut_ref().require_confirmed_inputs; + let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_NoneZ::None } else { crate::c_types::derived::COption_NoneZ::Some /* { () /**/ } */ }; + local_inner_val +} +/// If set, only confirmed inputs added (by the splice initiator) will be accepted +#[no_mangle] +pub extern "C" fn SpliceAck_set_require_confirmed_inputs(this_ptr: &mut SpliceAck, mut val: crate::c_types::derived::COption_NoneZ) { + let mut local_val = if val.is_some() { Some( { () /*val.take()*/ }) } else { None }; + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.require_confirmed_inputs = local_val; +} +/// Constructs a new SpliceAck given each field #[must_use] #[no_mangle] -pub extern "C" fn FundingSigned_new(mut channel_id_arg: crate::c_types::ThirtyTwoBytes, mut signature_arg: crate::c_types::ECDSASignature) -> FundingSigned { - FundingSigned { inner: ObjOps::heap_alloc(nativeFundingSigned { - channel_id: ::lightning::ln::ChannelId(channel_id_arg.data), - signature: signature_arg.into_rust(), +pub extern "C" fn SpliceAck_new(mut channel_id_arg: crate::lightning::ln::types::ChannelId, mut funding_contribution_satoshis_arg: i64, mut funding_pubkey_arg: crate::c_types::PublicKey, mut require_confirmed_inputs_arg: crate::c_types::derived::COption_NoneZ) -> SpliceAck { + let mut local_require_confirmed_inputs_arg = if require_confirmed_inputs_arg.is_some() { Some( { () /*require_confirmed_inputs_arg.take()*/ }) } else { None }; + SpliceAck { inner: ObjOps::heap_alloc(nativeSpliceAck { + channel_id: *unsafe { Box::from_raw(channel_id_arg.take_inner()) }, + funding_contribution_satoshis: funding_contribution_satoshis_arg, + funding_pubkey: funding_pubkey_arg.into_rust(), + require_confirmed_inputs: local_require_confirmed_inputs_arg, }), is_owned: true } } -impl Clone for FundingSigned { +impl Clone for SpliceAck { fn clone(&self) -> Self { Self { - inner: if <*mut nativeFundingSigned>::is_null(self.inner) { core::ptr::null_mut() } else { + inner: if <*mut nativeSpliceAck>::is_null(self.inner) { core::ptr::null_mut() } else { ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, is_owned: true, } @@ -2394,38 +3317,40 @@ impl Clone for FundingSigned { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn FundingSigned_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeFundingSigned)).clone() })) as *mut c_void +pub(crate) extern "C" fn SpliceAck_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeSpliceAck)).clone() })) as *mut c_void } #[no_mangle] -/// Creates a copy of the FundingSigned -pub extern "C" fn FundingSigned_clone(orig: &FundingSigned) -> FundingSigned { +/// Creates a copy of the SpliceAck +pub extern "C" fn SpliceAck_clone(orig: &SpliceAck) -> SpliceAck { orig.clone() } -/// Checks if two FundingSigneds contain equal inner contents. +/// Get a string which allows debug introspection of a SpliceAck object +pub extern "C" fn SpliceAck_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::SpliceAck }).into()} +/// Checks if two SpliceAcks 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 FundingSigned_eq(a: &FundingSigned, b: &FundingSigned) -> bool { +pub extern "C" fn SpliceAck_eq(a: &SpliceAck, b: &SpliceAck) -> 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 } } -use lightning::ln::msgs::ChannelReady as nativeChannelReadyImport; -pub(crate) type nativeChannelReady = nativeChannelReadyImport; +use lightning::ln::msgs::SpliceLocked as nativeSpliceLockedImport; +pub(crate) type nativeSpliceLocked = nativeSpliceLockedImport; -/// A [`channel_ready`] message to be sent to or received from a peer. +/// A `splice_locked` message to be sent to or received from a peer. /// -/// [`channel_ready`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#the-channel_ready-message #[must_use] #[repr(C)] -pub struct ChannelReady { +pub struct SpliceLocked { /// 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 nativeChannelReady, + pub inner: *mut nativeSpliceLocked, /// 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 @@ -2433,93 +3358,81 @@ pub struct ChannelReady { pub is_owned: bool, } -impl Drop for ChannelReady { +impl core::ops::Deref for SpliceLocked { + type Target = nativeSpliceLocked; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for SpliceLocked { } +unsafe impl core::marker::Sync for SpliceLocked { } +impl Drop for SpliceLocked { fn drop(&mut self) { - if self.is_owned && !<*mut nativeChannelReady>::is_null(self.inner) { + if self.is_owned && !<*mut nativeSpliceLocked>::is_null(self.inner) { let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; } } } -/// Frees any resources used by the ChannelReady, if is_owned is set and inner is non-NULL. +/// Frees any resources used by the SpliceLocked, if is_owned is set and inner is non-NULL. #[no_mangle] -pub extern "C" fn ChannelReady_free(this_obj: ChannelReady) { } +pub extern "C" fn SpliceLocked_free(this_obj: SpliceLocked) { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn ChannelReady_free_void(this_ptr: *mut c_void) { - let _ = unsafe { Box::from_raw(this_ptr as *mut nativeChannelReady) }; +pub(crate) extern "C" fn SpliceLocked_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeSpliceLocked) }; } #[allow(unused)] -impl ChannelReady { - pub(crate) fn get_native_ref(&self) -> &'static nativeChannelReady { +impl SpliceLocked { + pub(crate) fn get_native_ref(&self) -> &'static nativeSpliceLocked { unsafe { &*ObjOps::untweak_ptr(self.inner) } } - pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChannelReady { + pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeSpliceLocked { 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 nativeChannelReady { + pub(crate) fn take_inner(mut self) -> *mut nativeSpliceLocked { assert!(self.is_owned); let ret = ObjOps::untweak_ptr(self.inner); self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// The channel ID #[no_mangle] -pub extern "C" fn ChannelReady_get_channel_id(this_ptr: &ChannelReady) -> *const [u8; 32] { +pub extern "C" fn SpliceLocked_get_channel_id(this_ptr: &SpliceLocked) -> crate::lightning::ln::types::ChannelId { let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_id; - &inner_val.0 + crate::lightning::ln::types::ChannelId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::types::ChannelId<>) as *mut _) }, is_owned: false } } /// The channel ID #[no_mangle] -pub extern "C" fn ChannelReady_set_channel_id(this_ptr: &mut ChannelReady, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = ::lightning::ln::ChannelId(val.data); -} -/// The per-commitment point of the second commitment transaction -#[no_mangle] -pub extern "C" fn ChannelReady_get_next_per_commitment_point(this_ptr: &ChannelReady) -> crate::c_types::PublicKey { - let mut inner_val = &mut this_ptr.get_native_mut_ref().next_per_commitment_point; - crate::c_types::PublicKey::from_rust(&inner_val) -} -/// The per-commitment point of the second commitment transaction -#[no_mangle] -pub extern "C" fn ChannelReady_set_next_per_commitment_point(this_ptr: &mut ChannelReady, mut val: crate::c_types::PublicKey) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.next_per_commitment_point = val.into_rust(); +pub extern "C" fn SpliceLocked_set_channel_id(this_ptr: &mut SpliceLocked, mut val: crate::lightning::ln::types::ChannelId) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = *unsafe { Box::from_raw(val.take_inner()) }; } -/// If set, provides a `short_channel_id` alias for this channel. -/// -/// The sender will accept payments to be forwarded over this SCID and forward them to this -/// messages' recipient. +/// The ID of the new funding transaction that has been locked #[no_mangle] -pub extern "C" fn ChannelReady_get_short_channel_id_alias(this_ptr: &ChannelReady) -> crate::c_types::derived::COption_u64Z { - let mut inner_val = &mut this_ptr.get_native_mut_ref().short_channel_id_alias; - let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { inner_val.unwrap() }) }; - local_inner_val +pub extern "C" fn SpliceLocked_get_splice_txid(this_ptr: &SpliceLocked) -> *const [u8; 32] { + let mut inner_val = &mut this_ptr.get_native_mut_ref().splice_txid; + inner_val.as_ref() } -/// If set, provides a `short_channel_id` alias for this channel. -/// -/// The sender will accept payments to be forwarded over this SCID and forward them to this -/// messages' recipient. +/// The ID of the new funding transaction that has been locked #[no_mangle] -pub extern "C" fn ChannelReady_set_short_channel_id_alias(this_ptr: &mut ChannelReady, mut val: crate::c_types::derived::COption_u64Z) { - let mut local_val = if val.is_some() { Some( { val.take() }) } else { None }; - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.short_channel_id_alias = local_val; +pub extern "C" fn SpliceLocked_set_splice_txid(this_ptr: &mut SpliceLocked, mut val: crate::c_types::ThirtyTwoBytes) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.splice_txid = ::bitcoin::hash_types::Txid::from_slice(&val.data[..]).unwrap(); } -/// Constructs a new ChannelReady given each field +/// Constructs a new SpliceLocked given each field #[must_use] #[no_mangle] -pub extern "C" fn ChannelReady_new(mut channel_id_arg: crate::c_types::ThirtyTwoBytes, mut next_per_commitment_point_arg: crate::c_types::PublicKey, mut short_channel_id_alias_arg: crate::c_types::derived::COption_u64Z) -> ChannelReady { - let mut local_short_channel_id_alias_arg = if short_channel_id_alias_arg.is_some() { Some( { short_channel_id_alias_arg.take() }) } else { None }; - ChannelReady { inner: ObjOps::heap_alloc(nativeChannelReady { - channel_id: ::lightning::ln::ChannelId(channel_id_arg.data), - next_per_commitment_point: next_per_commitment_point_arg.into_rust(), - short_channel_id_alias: local_short_channel_id_alias_arg, +pub extern "C" fn SpliceLocked_new(mut channel_id_arg: crate::lightning::ln::types::ChannelId, mut splice_txid_arg: crate::c_types::ThirtyTwoBytes) -> SpliceLocked { + SpliceLocked { inner: ObjOps::heap_alloc(nativeSpliceLocked { + channel_id: *unsafe { Box::from_raw(channel_id_arg.take_inner()) }, + splice_txid: ::bitcoin::hash_types::Txid::from_slice(&splice_txid_arg.data[..]).unwrap(), }), is_owned: true } } -impl Clone for ChannelReady { +impl Clone for SpliceLocked { fn clone(&self) -> Self { Self { - inner: if <*mut nativeChannelReady>::is_null(self.inner) { core::ptr::null_mut() } else { + inner: if <*mut nativeSpliceLocked>::is_null(self.inner) { core::ptr::null_mut() } else { ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, is_owned: true, } @@ -2527,19 +3440,22 @@ impl Clone for ChannelReady { } #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method -pub(crate) extern "C" fn ChannelReady_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelReady)).clone() })) as *mut c_void +pub(crate) extern "C" fn SpliceLocked_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeSpliceLocked)).clone() })) as *mut c_void } #[no_mangle] -/// Creates a copy of the ChannelReady -pub extern "C" fn ChannelReady_clone(orig: &ChannelReady) -> ChannelReady { +/// Creates a copy of the SpliceLocked +pub extern "C" fn SpliceLocked_clone(orig: &SpliceLocked) -> SpliceLocked { orig.clone() } -/// Checks if two ChannelReadys contain equal inner contents. +/// Get a string which allows debug introspection of a SpliceLocked object +pub extern "C" fn SpliceLocked_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::SpliceLocked }).into()} +/// Checks if two SpliceLockeds 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 ChannelReady_eq(a: &ChannelReady, b: &ChannelReady) -> bool { +pub extern "C" fn SpliceLocked_eq(a: &SpliceLocked, b: &SpliceLocked) -> 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 } @@ -2565,6 +3481,12 @@ pub struct TxAddInput { pub is_owned: bool, } +impl core::ops::Deref for TxAddInput { + type Target = nativeTxAddInput; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for TxAddInput { } +unsafe impl core::marker::Sync for TxAddInput { } impl Drop for TxAddInput { fn drop(&mut self) { if self.is_owned && !<*mut nativeTxAddInput>::is_null(self.inner) { @@ -2595,17 +3517,20 @@ impl TxAddInput { self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// The channel ID #[no_mangle] -pub extern "C" fn TxAddInput_get_channel_id(this_ptr: &TxAddInput) -> *const [u8; 32] { +pub extern "C" fn TxAddInput_get_channel_id(this_ptr: &TxAddInput) -> crate::lightning::ln::types::ChannelId { let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_id; - &inner_val.0 + crate::lightning::ln::types::ChannelId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::types::ChannelId<>) as *mut _) }, is_owned: false } } /// The channel ID #[no_mangle] -pub extern "C" fn TxAddInput_set_channel_id(this_ptr: &mut TxAddInput, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = ::lightning::ln::ChannelId(val.data); +pub extern "C" fn TxAddInput_set_channel_id(this_ptr: &mut TxAddInput, mut val: crate::lightning::ln::types::ChannelId) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = *unsafe { Box::from_raw(val.take_inner()) }; } /// A randomly chosen unique identifier for this input, which is even for initiators and odd for /// non-initiators. @@ -2655,16 +3580,31 @@ pub extern "C" fn TxAddInput_get_sequence(this_ptr: &TxAddInput) -> u32 { pub extern "C" fn TxAddInput_set_sequence(this_ptr: &mut TxAddInput, mut val: u32) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.sequence = val; } +/// The ID of the previous funding transaction, when it is being added as an input during splicing +#[no_mangle] +pub extern "C" fn TxAddInput_get_shared_input_txid(this_ptr: &TxAddInput) -> crate::c_types::derived::COption_ThirtyTwoBytesZ { + let mut inner_val = &mut this_ptr.get_native_mut_ref().shared_input_txid; + let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_ThirtyTwoBytesZ::None } else { crate::c_types::derived::COption_ThirtyTwoBytesZ::Some(/* WARNING: CLONING CONVERSION HERE! &Option is otherwise un-expressable. */ { crate::c_types::ThirtyTwoBytes { data: *(*inner_val.as_ref().unwrap()).clone().as_ref() } }) }; + local_inner_val +} +/// The ID of the previous funding transaction, when it is being added as an input during splicing +#[no_mangle] +pub extern "C" fn TxAddInput_set_shared_input_txid(this_ptr: &mut TxAddInput, mut val: crate::c_types::derived::COption_ThirtyTwoBytesZ) { + let mut local_val = { /*val*/ let val_opt = val; if val_opt.is_none() { None } else { Some({ { ::bitcoin::hash_types::Txid::from_slice(&{ val_opt.take() }.data[..]).unwrap() }})} }; + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.shared_input_txid = local_val; +} /// Constructs a new TxAddInput given each field #[must_use] #[no_mangle] -pub extern "C" fn TxAddInput_new(mut channel_id_arg: crate::c_types::ThirtyTwoBytes, mut serial_id_arg: u64, mut prevtx_arg: crate::lightning::util::ser::TransactionU16LenLimited, mut prevtx_out_arg: u32, mut sequence_arg: u32) -> TxAddInput { +pub extern "C" fn TxAddInput_new(mut channel_id_arg: crate::lightning::ln::types::ChannelId, mut serial_id_arg: u64, mut prevtx_arg: crate::lightning::util::ser::TransactionU16LenLimited, mut prevtx_out_arg: u32, mut sequence_arg: u32, mut shared_input_txid_arg: crate::c_types::derived::COption_ThirtyTwoBytesZ) -> TxAddInput { + let mut local_shared_input_txid_arg = { /*shared_input_txid_arg*/ let shared_input_txid_arg_opt = shared_input_txid_arg; if shared_input_txid_arg_opt.is_none() { None } else { Some({ { ::bitcoin::hash_types::Txid::from_slice(&{ shared_input_txid_arg_opt.take() }.data[..]).unwrap() }})} }; TxAddInput { inner: ObjOps::heap_alloc(nativeTxAddInput { - channel_id: ::lightning::ln::ChannelId(channel_id_arg.data), + channel_id: *unsafe { Box::from_raw(channel_id_arg.take_inner()) }, serial_id: serial_id_arg, prevtx: *unsafe { Box::from_raw(prevtx_arg.take_inner()) }, prevtx_out: prevtx_out_arg, sequence: sequence_arg, + shared_input_txid: local_shared_input_txid_arg, }), is_owned: true } } impl Clone for TxAddInput { @@ -2679,13 +3619,26 @@ impl Clone for TxAddInput { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn TxAddInput_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeTxAddInput)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeTxAddInput)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the TxAddInput pub extern "C" fn TxAddInput_clone(orig: &TxAddInput) -> TxAddInput { orig.clone() } +/// Get a string which allows debug introspection of a TxAddInput object +pub extern "C" fn TxAddInput_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::TxAddInput }).into()} +/// Generates a non-cryptographic 64-bit hash of the TxAddInput. +#[no_mangle] +pub extern "C" fn TxAddInput_hash(o: &TxAddInput) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two TxAddInputs 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. @@ -2716,6 +3669,12 @@ pub struct TxAddOutput { pub is_owned: bool, } +impl core::ops::Deref for TxAddOutput { + type Target = nativeTxAddOutput; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for TxAddOutput { } +unsafe impl core::marker::Sync for TxAddOutput { } impl Drop for TxAddOutput { fn drop(&mut self) { if self.is_owned && !<*mut nativeTxAddOutput>::is_null(self.inner) { @@ -2746,17 +3705,20 @@ impl TxAddOutput { self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// The channel ID #[no_mangle] -pub extern "C" fn TxAddOutput_get_channel_id(this_ptr: &TxAddOutput) -> *const [u8; 32] { +pub extern "C" fn TxAddOutput_get_channel_id(this_ptr: &TxAddOutput) -> crate::lightning::ln::types::ChannelId { let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_id; - &inner_val.0 + crate::lightning::ln::types::ChannelId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::types::ChannelId<>) as *mut _) }, is_owned: false } } /// The channel ID #[no_mangle] -pub extern "C" fn TxAddOutput_set_channel_id(this_ptr: &mut TxAddOutput, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = ::lightning::ln::ChannelId(val.data); +pub extern "C" fn TxAddOutput_set_channel_id(this_ptr: &mut TxAddOutput, mut val: crate::lightning::ln::types::ChannelId) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = *unsafe { Box::from_raw(val.take_inner()) }; } /// A randomly chosen unique identifier for this output, which is even for initiators and odd for /// non-initiators. @@ -2784,24 +3746,24 @@ pub extern "C" fn TxAddOutput_set_sats(this_ptr: &mut TxAddOutput, mut val: u64) } /// The scriptPubKey for the output #[no_mangle] -pub extern "C" fn TxAddOutput_get_script(this_ptr: &TxAddOutput) -> crate::c_types::u8slice { +pub extern "C" fn TxAddOutput_get_script(this_ptr: &TxAddOutput) -> crate::c_types::derived::CVec_u8Z { let mut inner_val = &mut this_ptr.get_native_mut_ref().script; - crate::c_types::u8slice::from_slice(&inner_val[..]) + inner_val.as_bytes().to_vec().into() } /// The scriptPubKey for the output #[no_mangle] pub extern "C" fn TxAddOutput_set_script(this_ptr: &mut TxAddOutput, mut val: crate::c_types::derived::CVec_u8Z) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.script = ::bitcoin::blockdata::script::Script::from(val.into_rust()); + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.script = ::bitcoin::script::ScriptBuf::from(val.into_rust()); } /// Constructs a new TxAddOutput given each field #[must_use] #[no_mangle] -pub extern "C" fn TxAddOutput_new(mut channel_id_arg: crate::c_types::ThirtyTwoBytes, mut serial_id_arg: u64, mut sats_arg: u64, mut script_arg: crate::c_types::derived::CVec_u8Z) -> TxAddOutput { +pub extern "C" fn TxAddOutput_new(mut channel_id_arg: crate::lightning::ln::types::ChannelId, mut serial_id_arg: u64, mut sats_arg: u64, mut script_arg: crate::c_types::derived::CVec_u8Z) -> TxAddOutput { TxAddOutput { inner: ObjOps::heap_alloc(nativeTxAddOutput { - channel_id: ::lightning::ln::ChannelId(channel_id_arg.data), + channel_id: *unsafe { Box::from_raw(channel_id_arg.take_inner()) }, serial_id: serial_id_arg, sats: sats_arg, - script: ::bitcoin::blockdata::script::Script::from(script_arg.into_rust()), + script: ::bitcoin::script::ScriptBuf::from(script_arg.into_rust()), }), is_owned: true } } impl Clone for TxAddOutput { @@ -2816,13 +3778,26 @@ impl Clone for TxAddOutput { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn TxAddOutput_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeTxAddOutput)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeTxAddOutput)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the TxAddOutput pub extern "C" fn TxAddOutput_clone(orig: &TxAddOutput) -> TxAddOutput { orig.clone() } +/// Get a string which allows debug introspection of a TxAddOutput object +pub extern "C" fn TxAddOutput_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::TxAddOutput }).into()} +/// Generates a non-cryptographic 64-bit hash of the TxAddOutput. +#[no_mangle] +pub extern "C" fn TxAddOutput_hash(o: &TxAddOutput) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two TxAddOutputs 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. @@ -2853,6 +3828,12 @@ pub struct TxRemoveInput { pub is_owned: bool, } +impl core::ops::Deref for TxRemoveInput { + type Target = nativeTxRemoveInput; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for TxRemoveInput { } +unsafe impl core::marker::Sync for TxRemoveInput { } impl Drop for TxRemoveInput { fn drop(&mut self) { if self.is_owned && !<*mut nativeTxRemoveInput>::is_null(self.inner) { @@ -2883,17 +3864,20 @@ impl TxRemoveInput { self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// The channel ID #[no_mangle] -pub extern "C" fn TxRemoveInput_get_channel_id(this_ptr: &TxRemoveInput) -> *const [u8; 32] { +pub extern "C" fn TxRemoveInput_get_channel_id(this_ptr: &TxRemoveInput) -> crate::lightning::ln::types::ChannelId { let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_id; - &inner_val.0 + crate::lightning::ln::types::ChannelId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::types::ChannelId<>) as *mut _) }, is_owned: false } } /// The channel ID #[no_mangle] -pub extern "C" fn TxRemoveInput_set_channel_id(this_ptr: &mut TxRemoveInput, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = ::lightning::ln::ChannelId(val.data); +pub extern "C" fn TxRemoveInput_set_channel_id(this_ptr: &mut TxRemoveInput, mut val: crate::lightning::ln::types::ChannelId) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = *unsafe { Box::from_raw(val.take_inner()) }; } /// The serial ID of the input to be removed #[no_mangle] @@ -2909,9 +3893,9 @@ pub extern "C" fn TxRemoveInput_set_serial_id(this_ptr: &mut TxRemoveInput, mut /// Constructs a new TxRemoveInput given each field #[must_use] #[no_mangle] -pub extern "C" fn TxRemoveInput_new(mut channel_id_arg: crate::c_types::ThirtyTwoBytes, mut serial_id_arg: u64) -> TxRemoveInput { +pub extern "C" fn TxRemoveInput_new(mut channel_id_arg: crate::lightning::ln::types::ChannelId, mut serial_id_arg: u64) -> TxRemoveInput { TxRemoveInput { inner: ObjOps::heap_alloc(nativeTxRemoveInput { - channel_id: ::lightning::ln::ChannelId(channel_id_arg.data), + channel_id: *unsafe { Box::from_raw(channel_id_arg.take_inner()) }, serial_id: serial_id_arg, }), is_owned: true } } @@ -2927,13 +3911,26 @@ impl Clone for TxRemoveInput { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn TxRemoveInput_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeTxRemoveInput)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeTxRemoveInput)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the TxRemoveInput pub extern "C" fn TxRemoveInput_clone(orig: &TxRemoveInput) -> TxRemoveInput { orig.clone() } +/// Get a string which allows debug introspection of a TxRemoveInput object +pub extern "C" fn TxRemoveInput_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::TxRemoveInput }).into()} +/// Generates a non-cryptographic 64-bit hash of the TxRemoveInput. +#[no_mangle] +pub extern "C" fn TxRemoveInput_hash(o: &TxRemoveInput) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two TxRemoveInputs 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. @@ -2964,6 +3961,12 @@ pub struct TxRemoveOutput { pub is_owned: bool, } +impl core::ops::Deref for TxRemoveOutput { + type Target = nativeTxRemoveOutput; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for TxRemoveOutput { } +unsafe impl core::marker::Sync for TxRemoveOutput { } impl Drop for TxRemoveOutput { fn drop(&mut self) { if self.is_owned && !<*mut nativeTxRemoveOutput>::is_null(self.inner) { @@ -2994,17 +3997,20 @@ impl TxRemoveOutput { self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// The channel ID #[no_mangle] -pub extern "C" fn TxRemoveOutput_get_channel_id(this_ptr: &TxRemoveOutput) -> *const [u8; 32] { +pub extern "C" fn TxRemoveOutput_get_channel_id(this_ptr: &TxRemoveOutput) -> crate::lightning::ln::types::ChannelId { let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_id; - &inner_val.0 + crate::lightning::ln::types::ChannelId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::types::ChannelId<>) as *mut _) }, is_owned: false } } /// The channel ID #[no_mangle] -pub extern "C" fn TxRemoveOutput_set_channel_id(this_ptr: &mut TxRemoveOutput, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = ::lightning::ln::ChannelId(val.data); +pub extern "C" fn TxRemoveOutput_set_channel_id(this_ptr: &mut TxRemoveOutput, mut val: crate::lightning::ln::types::ChannelId) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = *unsafe { Box::from_raw(val.take_inner()) }; } /// The serial ID of the output to be removed #[no_mangle] @@ -3020,9 +4026,9 @@ pub extern "C" fn TxRemoveOutput_set_serial_id(this_ptr: &mut TxRemoveOutput, mu /// Constructs a new TxRemoveOutput given each field #[must_use] #[no_mangle] -pub extern "C" fn TxRemoveOutput_new(mut channel_id_arg: crate::c_types::ThirtyTwoBytes, mut serial_id_arg: u64) -> TxRemoveOutput { +pub extern "C" fn TxRemoveOutput_new(mut channel_id_arg: crate::lightning::ln::types::ChannelId, mut serial_id_arg: u64) -> TxRemoveOutput { TxRemoveOutput { inner: ObjOps::heap_alloc(nativeTxRemoveOutput { - channel_id: ::lightning::ln::ChannelId(channel_id_arg.data), + channel_id: *unsafe { Box::from_raw(channel_id_arg.take_inner()) }, serial_id: serial_id_arg, }), is_owned: true } } @@ -3038,13 +4044,26 @@ impl Clone for TxRemoveOutput { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn TxRemoveOutput_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeTxRemoveOutput)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeTxRemoveOutput)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the TxRemoveOutput pub extern "C" fn TxRemoveOutput_clone(orig: &TxRemoveOutput) -> TxRemoveOutput { orig.clone() } +/// Get a string which allows debug introspection of a TxRemoveOutput object +pub extern "C" fn TxRemoveOutput_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::TxRemoveOutput }).into()} +/// Generates a non-cryptographic 64-bit hash of the TxRemoveOutput. +#[no_mangle] +pub extern "C" fn TxRemoveOutput_hash(o: &TxRemoveOutput) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two TxRemoveOutputs 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. @@ -3076,6 +4095,12 @@ pub struct TxComplete { pub is_owned: bool, } +impl core::ops::Deref for TxComplete { + type Target = nativeTxComplete; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for TxComplete { } +unsafe impl core::marker::Sync for TxComplete { } impl Drop for TxComplete { fn drop(&mut self) { if self.is_owned && !<*mut nativeTxComplete>::is_null(self.inner) { @@ -3106,24 +4131,27 @@ impl TxComplete { self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// The channel ID #[no_mangle] -pub extern "C" fn TxComplete_get_channel_id(this_ptr: &TxComplete) -> *const [u8; 32] { +pub extern "C" fn TxComplete_get_channel_id(this_ptr: &TxComplete) -> crate::lightning::ln::types::ChannelId { let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_id; - &inner_val.0 + crate::lightning::ln::types::ChannelId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::types::ChannelId<>) as *mut _) }, is_owned: false } } /// The channel ID #[no_mangle] -pub extern "C" fn TxComplete_set_channel_id(this_ptr: &mut TxComplete, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = ::lightning::ln::ChannelId(val.data); +pub extern "C" fn TxComplete_set_channel_id(this_ptr: &mut TxComplete, mut val: crate::lightning::ln::types::ChannelId) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = *unsafe { Box::from_raw(val.take_inner()) }; } /// Constructs a new TxComplete given each field #[must_use] #[no_mangle] -pub extern "C" fn TxComplete_new(mut channel_id_arg: crate::c_types::ThirtyTwoBytes) -> TxComplete { +pub extern "C" fn TxComplete_new(mut channel_id_arg: crate::lightning::ln::types::ChannelId) -> TxComplete { TxComplete { inner: ObjOps::heap_alloc(nativeTxComplete { - channel_id: ::lightning::ln::ChannelId(channel_id_arg.data), + channel_id: *unsafe { Box::from_raw(channel_id_arg.take_inner()) }, }), is_owned: true } } impl Clone for TxComplete { @@ -3138,13 +4166,26 @@ impl Clone for TxComplete { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn TxComplete_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeTxComplete)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeTxComplete)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the TxComplete pub extern "C" fn TxComplete_clone(orig: &TxComplete) -> TxComplete { orig.clone() } +/// Get a string which allows debug introspection of a TxComplete object +pub extern "C" fn TxComplete_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::TxComplete }).into()} +/// Generates a non-cryptographic 64-bit hash of the TxComplete. +#[no_mangle] +pub extern "C" fn TxComplete_hash(o: &TxComplete) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two TxCompletes 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. @@ -3176,6 +4217,12 @@ pub struct TxSignatures { pub is_owned: bool, } +impl core::ops::Deref for TxSignatures { + type Target = nativeTxSignatures; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for TxSignatures { } +unsafe impl core::marker::Sync for TxSignatures { } impl Drop for TxSignatures { fn drop(&mut self) { if self.is_owned && !<*mut nativeTxSignatures>::is_null(self.inner) { @@ -3206,23 +4253,26 @@ impl TxSignatures { self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// The channel ID #[no_mangle] -pub extern "C" fn TxSignatures_get_channel_id(this_ptr: &TxSignatures) -> *const [u8; 32] { +pub extern "C" fn TxSignatures_get_channel_id(this_ptr: &TxSignatures) -> crate::lightning::ln::types::ChannelId { let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_id; - &inner_val.0 + crate::lightning::ln::types::ChannelId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::types::ChannelId<>) as *mut _) }, is_owned: false } } /// The channel ID #[no_mangle] -pub extern "C" fn TxSignatures_set_channel_id(this_ptr: &mut TxSignatures, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = ::lightning::ln::ChannelId(val.data); +pub extern "C" fn TxSignatures_set_channel_id(this_ptr: &mut TxSignatures, mut val: crate::lightning::ln::types::ChannelId) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = *unsafe { Box::from_raw(val.take_inner()) }; } /// The TXID #[no_mangle] pub extern "C" fn TxSignatures_get_tx_hash(this_ptr: &TxSignatures) -> *const [u8; 32] { let mut inner_val = &mut this_ptr.get_native_mut_ref().tx_hash; - inner_val.as_inner() + inner_val.as_ref() } /// The TXID #[no_mangle] @@ -3244,15 +4294,30 @@ pub extern "C" fn TxSignatures_set_witnesses(this_ptr: &mut TxSignatures, mut va let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item.into_bitcoin() }); }; unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.witnesses = local_val; } +/// Optional signature for the shared input -- the previous funding outpoint -- signed by both peers +#[no_mangle] +pub extern "C" fn TxSignatures_get_shared_input_signature(this_ptr: &TxSignatures) -> crate::c_types::derived::COption_ECDSASignatureZ { + let mut inner_val = &mut this_ptr.get_native_mut_ref().shared_input_signature; + let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_ECDSASignatureZ::None } else { crate::c_types::derived::COption_ECDSASignatureZ::Some(/* WARNING: CLONING CONVERSION HERE! &Option is otherwise un-expressable. */ { crate::c_types::ECDSASignature::from_rust(&(*inner_val.as_ref().unwrap()).clone()) }) }; + local_inner_val +} +/// Optional signature for the shared input -- the previous funding outpoint -- signed by both peers +#[no_mangle] +pub extern "C" fn TxSignatures_set_shared_input_signature(this_ptr: &mut TxSignatures, mut val: crate::c_types::derived::COption_ECDSASignatureZ) { + let mut local_val = { /*val*/ let val_opt = val; if val_opt.is_none() { None } else { Some({ { { val_opt.take() }.into_rust() }})} }; + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.shared_input_signature = local_val; +} /// Constructs a new TxSignatures given each field #[must_use] #[no_mangle] -pub extern "C" fn TxSignatures_new(mut channel_id_arg: crate::c_types::ThirtyTwoBytes, mut tx_hash_arg: crate::c_types::ThirtyTwoBytes, mut witnesses_arg: crate::c_types::derived::CVec_WitnessZ) -> TxSignatures { +pub extern "C" fn TxSignatures_new(mut channel_id_arg: crate::lightning::ln::types::ChannelId, mut tx_hash_arg: crate::c_types::ThirtyTwoBytes, mut witnesses_arg: crate::c_types::derived::CVec_WitnessZ, mut shared_input_signature_arg: crate::c_types::derived::COption_ECDSASignatureZ) -> TxSignatures { let mut local_witnesses_arg = Vec::new(); for mut item in witnesses_arg.into_rust().drain(..) { local_witnesses_arg.push( { item.into_bitcoin() }); }; + let mut local_shared_input_signature_arg = { /*shared_input_signature_arg*/ let shared_input_signature_arg_opt = shared_input_signature_arg; if shared_input_signature_arg_opt.is_none() { None } else { Some({ { { shared_input_signature_arg_opt.take() }.into_rust() }})} }; TxSignatures { inner: ObjOps::heap_alloc(nativeTxSignatures { - channel_id: ::lightning::ln::ChannelId(channel_id_arg.data), + channel_id: *unsafe { Box::from_raw(channel_id_arg.take_inner()) }, tx_hash: ::bitcoin::hash_types::Txid::from_slice(&tx_hash_arg.data[..]).unwrap(), witnesses: local_witnesses_arg, + shared_input_signature: local_shared_input_signature_arg, }), is_owned: true } } impl Clone for TxSignatures { @@ -3267,13 +4332,26 @@ impl Clone for TxSignatures { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn TxSignatures_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeTxSignatures)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeTxSignatures)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the TxSignatures pub extern "C" fn TxSignatures_clone(orig: &TxSignatures) -> TxSignatures { orig.clone() } +/// Get a string which allows debug introspection of a TxSignatures object +pub extern "C" fn TxSignatures_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::TxSignatures }).into()} +/// Generates a non-cryptographic 64-bit hash of the TxSignatures. +#[no_mangle] +pub extern "C" fn TxSignatures_hash(o: &TxSignatures) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two TxSignaturess 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. @@ -3305,6 +4383,12 @@ pub struct TxInitRbf { pub is_owned: bool, } +impl core::ops::Deref for TxInitRbf { + type Target = nativeTxInitRbf; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for TxInitRbf { } +unsafe impl core::marker::Sync for TxInitRbf { } impl Drop for TxInitRbf { fn drop(&mut self) { if self.is_owned && !<*mut nativeTxInitRbf>::is_null(self.inner) { @@ -3335,17 +4419,20 @@ impl TxInitRbf { self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// The channel ID #[no_mangle] -pub extern "C" fn TxInitRbf_get_channel_id(this_ptr: &TxInitRbf) -> *const [u8; 32] { +pub extern "C" fn TxInitRbf_get_channel_id(this_ptr: &TxInitRbf) -> crate::lightning::ln::types::ChannelId { let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_id; - &inner_val.0 + crate::lightning::ln::types::ChannelId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::types::ChannelId<>) as *mut _) }, is_owned: false } } /// The channel ID #[no_mangle] -pub extern "C" fn TxInitRbf_set_channel_id(this_ptr: &mut TxInitRbf, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = ::lightning::ln::ChannelId(val.data); +pub extern "C" fn TxInitRbf_set_channel_id(this_ptr: &mut TxInitRbf, mut val: crate::lightning::ln::types::ChannelId) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = *unsafe { Box::from_raw(val.take_inner()) }; } /// The locktime of the transaction #[no_mangle] @@ -3387,10 +4474,10 @@ pub extern "C" fn TxInitRbf_set_funding_output_contribution(this_ptr: &mut TxIni /// Constructs a new TxInitRbf given each field #[must_use] #[no_mangle] -pub extern "C" fn TxInitRbf_new(mut channel_id_arg: crate::c_types::ThirtyTwoBytes, mut locktime_arg: u32, mut feerate_sat_per_1000_weight_arg: u32, mut funding_output_contribution_arg: crate::c_types::derived::COption_i64Z) -> TxInitRbf { +pub extern "C" fn TxInitRbf_new(mut channel_id_arg: crate::lightning::ln::types::ChannelId, mut locktime_arg: u32, mut feerate_sat_per_1000_weight_arg: u32, mut funding_output_contribution_arg: crate::c_types::derived::COption_i64Z) -> TxInitRbf { let mut local_funding_output_contribution_arg = if funding_output_contribution_arg.is_some() { Some( { funding_output_contribution_arg.take() }) } else { None }; TxInitRbf { inner: ObjOps::heap_alloc(nativeTxInitRbf { - channel_id: ::lightning::ln::ChannelId(channel_id_arg.data), + channel_id: *unsafe { Box::from_raw(channel_id_arg.take_inner()) }, locktime: locktime_arg, feerate_sat_per_1000_weight: feerate_sat_per_1000_weight_arg, funding_output_contribution: local_funding_output_contribution_arg, @@ -3408,13 +4495,26 @@ impl Clone for TxInitRbf { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn TxInitRbf_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeTxInitRbf)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeTxInitRbf)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the TxInitRbf pub extern "C" fn TxInitRbf_clone(orig: &TxInitRbf) -> TxInitRbf { orig.clone() } +/// Get a string which allows debug introspection of a TxInitRbf object +pub extern "C" fn TxInitRbf_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::TxInitRbf }).into()} +/// Generates a non-cryptographic 64-bit hash of the TxInitRbf. +#[no_mangle] +pub extern "C" fn TxInitRbf_hash(o: &TxInitRbf) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two TxInitRbfs 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. @@ -3446,6 +4546,12 @@ pub struct TxAckRbf { pub is_owned: bool, } +impl core::ops::Deref for TxAckRbf { + type Target = nativeTxAckRbf; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for TxAckRbf { } +unsafe impl core::marker::Sync for TxAckRbf { } impl Drop for TxAckRbf { fn drop(&mut self) { if self.is_owned && !<*mut nativeTxAckRbf>::is_null(self.inner) { @@ -3476,17 +4582,20 @@ impl TxAckRbf { self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// The channel ID #[no_mangle] -pub extern "C" fn TxAckRbf_get_channel_id(this_ptr: &TxAckRbf) -> *const [u8; 32] { +pub extern "C" fn TxAckRbf_get_channel_id(this_ptr: &TxAckRbf) -> crate::lightning::ln::types::ChannelId { let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_id; - &inner_val.0 + crate::lightning::ln::types::ChannelId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::types::ChannelId<>) as *mut _) }, is_owned: false } } /// The channel ID #[no_mangle] -pub extern "C" fn TxAckRbf_set_channel_id(this_ptr: &mut TxAckRbf, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = ::lightning::ln::ChannelId(val.data); +pub extern "C" fn TxAckRbf_set_channel_id(this_ptr: &mut TxAckRbf, mut val: crate::lightning::ln::types::ChannelId) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = *unsafe { Box::from_raw(val.take_inner()) }; } /// The number of satoshis the sender will contribute to or, if negative, remove from /// (e.g. splice-out) the funding output of the transaction @@ -3506,10 +4615,10 @@ pub extern "C" fn TxAckRbf_set_funding_output_contribution(this_ptr: &mut TxAckR /// Constructs a new TxAckRbf given each field #[must_use] #[no_mangle] -pub extern "C" fn TxAckRbf_new(mut channel_id_arg: crate::c_types::ThirtyTwoBytes, mut funding_output_contribution_arg: crate::c_types::derived::COption_i64Z) -> TxAckRbf { +pub extern "C" fn TxAckRbf_new(mut channel_id_arg: crate::lightning::ln::types::ChannelId, mut funding_output_contribution_arg: crate::c_types::derived::COption_i64Z) -> TxAckRbf { let mut local_funding_output_contribution_arg = if funding_output_contribution_arg.is_some() { Some( { funding_output_contribution_arg.take() }) } else { None }; TxAckRbf { inner: ObjOps::heap_alloc(nativeTxAckRbf { - channel_id: ::lightning::ln::ChannelId(channel_id_arg.data), + channel_id: *unsafe { Box::from_raw(channel_id_arg.take_inner()) }, funding_output_contribution: local_funding_output_contribution_arg, }), is_owned: true } } @@ -3525,13 +4634,26 @@ impl Clone for TxAckRbf { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn TxAckRbf_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeTxAckRbf)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeTxAckRbf)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the TxAckRbf pub extern "C" fn TxAckRbf_clone(orig: &TxAckRbf) -> TxAckRbf { orig.clone() } +/// Get a string which allows debug introspection of a TxAckRbf object +pub extern "C" fn TxAckRbf_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::TxAckRbf }).into()} +/// Generates a non-cryptographic 64-bit hash of the TxAckRbf. +#[no_mangle] +pub extern "C" fn TxAckRbf_hash(o: &TxAckRbf) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two TxAckRbfs 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. @@ -3562,6 +4684,12 @@ pub struct TxAbort { pub is_owned: bool, } +impl core::ops::Deref for TxAbort { + type Target = nativeTxAbort; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for TxAbort { } +unsafe impl core::marker::Sync for TxAbort { } impl Drop for TxAbort { fn drop(&mut self) { if self.is_owned && !<*mut nativeTxAbort>::is_null(self.inner) { @@ -3592,17 +4720,20 @@ impl TxAbort { self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// The channel ID #[no_mangle] -pub extern "C" fn TxAbort_get_channel_id(this_ptr: &TxAbort) -> *const [u8; 32] { +pub extern "C" fn TxAbort_get_channel_id(this_ptr: &TxAbort) -> crate::lightning::ln::types::ChannelId { let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_id; - &inner_val.0 + crate::lightning::ln::types::ChannelId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::types::ChannelId<>) as *mut _) }, is_owned: false } } /// The channel ID #[no_mangle] -pub extern "C" fn TxAbort_set_channel_id(this_ptr: &mut TxAbort, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = ::lightning::ln::ChannelId(val.data); +pub extern "C" fn TxAbort_set_channel_id(this_ptr: &mut TxAbort, mut val: crate::lightning::ln::types::ChannelId) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = *unsafe { Box::from_raw(val.take_inner()) }; } /// Message data /// @@ -3622,10 +4753,10 @@ pub extern "C" fn TxAbort_set_data(this_ptr: &mut TxAbort, mut val: crate::c_typ /// Constructs a new TxAbort given each field #[must_use] #[no_mangle] -pub extern "C" fn TxAbort_new(mut channel_id_arg: crate::c_types::ThirtyTwoBytes, mut data_arg: crate::c_types::derived::CVec_u8Z) -> TxAbort { +pub extern "C" fn TxAbort_new(mut channel_id_arg: crate::lightning::ln::types::ChannelId, mut data_arg: crate::c_types::derived::CVec_u8Z) -> TxAbort { let mut local_data_arg = Vec::new(); for mut item in data_arg.into_rust().drain(..) { local_data_arg.push( { item }); }; TxAbort { inner: ObjOps::heap_alloc(nativeTxAbort { - channel_id: ::lightning::ln::ChannelId(channel_id_arg.data), + channel_id: *unsafe { Box::from_raw(channel_id_arg.take_inner()) }, data: local_data_arg, }), is_owned: true } } @@ -3641,13 +4772,26 @@ impl Clone for TxAbort { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn TxAbort_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeTxAbort)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeTxAbort)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the TxAbort pub extern "C" fn TxAbort_clone(orig: &TxAbort) -> TxAbort { orig.clone() } +/// Get a string which allows debug introspection of a TxAbort object +pub extern "C" fn TxAbort_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::TxAbort }).into()} +/// Generates a non-cryptographic 64-bit hash of the TxAbort. +#[no_mangle] +pub extern "C" fn TxAbort_hash(o: &TxAbort) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two TxAborts 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. @@ -3679,6 +4823,12 @@ pub struct Shutdown { pub is_owned: bool, } +impl core::ops::Deref for Shutdown { + type Target = nativeShutdown; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for Shutdown { } +unsafe impl core::marker::Sync for Shutdown { } impl Drop for Shutdown { fn drop(&mut self) { if self.is_owned && !<*mut nativeShutdown>::is_null(self.inner) { @@ -3709,40 +4859,43 @@ impl Shutdown { self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// The channel ID #[no_mangle] -pub extern "C" fn Shutdown_get_channel_id(this_ptr: &Shutdown) -> *const [u8; 32] { +pub extern "C" fn Shutdown_get_channel_id(this_ptr: &Shutdown) -> crate::lightning::ln::types::ChannelId { let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_id; - &inner_val.0 + crate::lightning::ln::types::ChannelId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::types::ChannelId<>) as *mut _) }, is_owned: false } } /// The channel ID #[no_mangle] -pub extern "C" fn Shutdown_set_channel_id(this_ptr: &mut Shutdown, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = ::lightning::ln::ChannelId(val.data); +pub extern "C" fn Shutdown_set_channel_id(this_ptr: &mut Shutdown, mut val: crate::lightning::ln::types::ChannelId) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = *unsafe { Box::from_raw(val.take_inner()) }; } /// The destination of this peer's funds on closing. /// /// Must be in one of these forms: P2PKH, P2SH, P2WPKH, P2WSH, P2TR. #[no_mangle] -pub extern "C" fn Shutdown_get_scriptpubkey(this_ptr: &Shutdown) -> crate::c_types::u8slice { +pub extern "C" fn Shutdown_get_scriptpubkey(this_ptr: &Shutdown) -> crate::c_types::derived::CVec_u8Z { let mut inner_val = &mut this_ptr.get_native_mut_ref().scriptpubkey; - crate::c_types::u8slice::from_slice(&inner_val[..]) + inner_val.as_bytes().to_vec().into() } /// The destination of this peer's funds on closing. /// /// Must be in one of these forms: P2PKH, P2SH, P2WPKH, P2WSH, P2TR. #[no_mangle] pub extern "C" fn Shutdown_set_scriptpubkey(this_ptr: &mut Shutdown, mut val: crate::c_types::derived::CVec_u8Z) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.scriptpubkey = ::bitcoin::blockdata::script::Script::from(val.into_rust()); + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.scriptpubkey = ::bitcoin::script::ScriptBuf::from(val.into_rust()); } /// Constructs a new Shutdown given each field #[must_use] #[no_mangle] -pub extern "C" fn Shutdown_new(mut channel_id_arg: crate::c_types::ThirtyTwoBytes, mut scriptpubkey_arg: crate::c_types::derived::CVec_u8Z) -> Shutdown { +pub extern "C" fn Shutdown_new(mut channel_id_arg: crate::lightning::ln::types::ChannelId, mut scriptpubkey_arg: crate::c_types::derived::CVec_u8Z) -> Shutdown { Shutdown { inner: ObjOps::heap_alloc(nativeShutdown { - channel_id: ::lightning::ln::ChannelId(channel_id_arg.data), - scriptpubkey: ::bitcoin::blockdata::script::Script::from(scriptpubkey_arg.into_rust()), + channel_id: *unsafe { Box::from_raw(channel_id_arg.take_inner()) }, + scriptpubkey: ::bitcoin::script::ScriptBuf::from(scriptpubkey_arg.into_rust()), }), is_owned: true } } impl Clone for Shutdown { @@ -3757,13 +4910,26 @@ impl Clone for Shutdown { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn Shutdown_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeShutdown)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeShutdown)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the Shutdown pub extern "C" fn Shutdown_clone(orig: &Shutdown) -> Shutdown { orig.clone() } +/// Get a string which allows debug introspection of a Shutdown object +pub extern "C" fn Shutdown_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::Shutdown }).into()} +/// Generates a non-cryptographic 64-bit hash of the Shutdown. +#[no_mangle] +pub extern "C" fn Shutdown_hash(o: &Shutdown) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two Shutdowns 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. @@ -3796,6 +4962,12 @@ pub struct ClosingSignedFeeRange { pub is_owned: bool, } +impl core::ops::Deref for ClosingSignedFeeRange { + type Target = nativeClosingSignedFeeRange; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for ClosingSignedFeeRange { } +unsafe impl core::marker::Sync for ClosingSignedFeeRange { } impl Drop for ClosingSignedFeeRange { fn drop(&mut self) { if self.is_owned && !<*mut nativeClosingSignedFeeRange>::is_null(self.inner) { @@ -3826,6 +4998,9 @@ impl ClosingSignedFeeRange { self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// The minimum absolute fee, in satoshis, which the sender is willing to place on the closing /// transaction. @@ -3874,13 +5049,26 @@ impl Clone for ClosingSignedFeeRange { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ClosingSignedFeeRange_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeClosingSignedFeeRange)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeClosingSignedFeeRange)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ClosingSignedFeeRange pub extern "C" fn ClosingSignedFeeRange_clone(orig: &ClosingSignedFeeRange) -> ClosingSignedFeeRange { orig.clone() } +/// Get a string which allows debug introspection of a ClosingSignedFeeRange object +pub extern "C" fn ClosingSignedFeeRange_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::ClosingSignedFeeRange }).into()} +/// Generates a non-cryptographic 64-bit hash of the ClosingSignedFeeRange. +#[no_mangle] +pub extern "C" fn ClosingSignedFeeRange_hash(o: &ClosingSignedFeeRange) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two ClosingSignedFeeRanges 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. @@ -3912,6 +5100,12 @@ pub struct ClosingSigned { pub is_owned: bool, } +impl core::ops::Deref for ClosingSigned { + type Target = nativeClosingSigned; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for ClosingSigned { } +unsafe impl core::marker::Sync for ClosingSigned { } impl Drop for ClosingSigned { fn drop(&mut self) { if self.is_owned && !<*mut nativeClosingSigned>::is_null(self.inner) { @@ -3942,17 +5136,20 @@ impl ClosingSigned { self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// The channel ID #[no_mangle] -pub extern "C" fn ClosingSigned_get_channel_id(this_ptr: &ClosingSigned) -> *const [u8; 32] { +pub extern "C" fn ClosingSigned_get_channel_id(this_ptr: &ClosingSigned) -> crate::lightning::ln::types::ChannelId { let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_id; - &inner_val.0 + crate::lightning::ln::types::ChannelId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::types::ChannelId<>) as *mut _) }, is_owned: false } } /// The channel ID #[no_mangle] -pub extern "C" fn ClosingSigned_set_channel_id(this_ptr: &mut ClosingSigned, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = ::lightning::ln::ChannelId(val.data); +pub extern "C" fn ClosingSigned_set_channel_id(this_ptr: &mut ClosingSigned, mut val: crate::lightning::ln::types::ChannelId) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = *unsafe { Box::from_raw(val.take_inner()) }; } /// The proposed total fee for the closing transaction #[no_mangle] @@ -4000,10 +5197,10 @@ pub extern "C" fn ClosingSigned_set_fee_range(this_ptr: &mut ClosingSigned, mut /// Note that fee_range_arg (or a relevant inner pointer) may be NULL or all-0s to represent None #[must_use] #[no_mangle] -pub extern "C" fn ClosingSigned_new(mut channel_id_arg: crate::c_types::ThirtyTwoBytes, mut fee_satoshis_arg: u64, mut signature_arg: crate::c_types::ECDSASignature, mut fee_range_arg: crate::lightning::ln::msgs::ClosingSignedFeeRange) -> ClosingSigned { +pub extern "C" fn ClosingSigned_new(mut channel_id_arg: crate::lightning::ln::types::ChannelId, mut fee_satoshis_arg: u64, mut signature_arg: crate::c_types::ECDSASignature, mut fee_range_arg: crate::lightning::ln::msgs::ClosingSignedFeeRange) -> ClosingSigned { let mut local_fee_range_arg = if fee_range_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(fee_range_arg.take_inner()) } }) }; ClosingSigned { inner: ObjOps::heap_alloc(nativeClosingSigned { - channel_id: ::lightning::ln::ChannelId(channel_id_arg.data), + channel_id: *unsafe { Box::from_raw(channel_id_arg.take_inner()) }, fee_satoshis: fee_satoshis_arg, signature: signature_arg.into_rust(), fee_range: local_fee_range_arg, @@ -4021,13 +5218,26 @@ impl Clone for ClosingSigned { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ClosingSigned_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeClosingSigned)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeClosingSigned)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ClosingSigned pub extern "C" fn ClosingSigned_clone(orig: &ClosingSigned) -> ClosingSigned { orig.clone() } +/// Get a string which allows debug introspection of a ClosingSigned object +pub extern "C" fn ClosingSigned_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::ClosingSigned }).into()} +/// Generates a non-cryptographic 64-bit hash of the ClosingSigned. +#[no_mangle] +pub extern "C" fn ClosingSigned_hash(o: &ClosingSigned) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two ClosingSigneds 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. @@ -4059,6 +5269,12 @@ pub struct UpdateAddHTLC { pub is_owned: bool, } +impl core::ops::Deref for UpdateAddHTLC { + type Target = nativeUpdateAddHTLC; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for UpdateAddHTLC { } +unsafe impl core::marker::Sync for UpdateAddHTLC { } impl Drop for UpdateAddHTLC { fn drop(&mut self) { if self.is_owned && !<*mut nativeUpdateAddHTLC>::is_null(self.inner) { @@ -4089,17 +5305,20 @@ impl UpdateAddHTLC { self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// The channel ID #[no_mangle] -pub extern "C" fn UpdateAddHTLC_get_channel_id(this_ptr: &UpdateAddHTLC) -> *const [u8; 32] { +pub extern "C" fn UpdateAddHTLC_get_channel_id(this_ptr: &UpdateAddHTLC) -> crate::lightning::ln::types::ChannelId { let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_id; - &inner_val.0 + crate::lightning::ln::types::ChannelId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::types::ChannelId<>) as *mut _) }, is_owned: false } } /// The channel ID #[no_mangle] -pub extern "C" fn UpdateAddHTLC_set_channel_id(this_ptr: &mut UpdateAddHTLC, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = ::lightning::ln::ChannelId(val.data); +pub extern "C" fn UpdateAddHTLC_set_channel_id(this_ptr: &mut UpdateAddHTLC, mut val: crate::lightning::ln::types::ChannelId) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = *unsafe { Box::from_raw(val.take_inner()) }; } /// The HTLC ID #[no_mangle] @@ -4132,7 +5351,7 @@ pub extern "C" fn UpdateAddHTLC_get_payment_hash(this_ptr: &UpdateAddHTLC) -> *c /// The payment hash, the pre-image of which controls HTLC redemption #[no_mangle] pub extern "C" fn UpdateAddHTLC_set_payment_hash(this_ptr: &mut UpdateAddHTLC, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_hash = ::lightning::ln::PaymentHash(val.data); + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_hash = ::lightning::ln::types::PaymentHash(val.data); } /// The expiry height of the HTLC #[no_mangle] @@ -4164,6 +5383,55 @@ pub extern "C" fn UpdateAddHTLC_set_skimmed_fee_msat(this_ptr: &mut UpdateAddHTL let mut local_val = if val.is_some() { Some( { val.take() }) } else { None }; unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.skimmed_fee_msat = local_val; } +/// The onion routing packet with encrypted data for the next hop. +#[no_mangle] +pub extern "C" fn UpdateAddHTLC_get_onion_routing_packet(this_ptr: &UpdateAddHTLC) -> crate::lightning::ln::msgs::OnionPacket { + let mut inner_val = &mut this_ptr.get_native_mut_ref().onion_routing_packet; + crate::lightning::ln::msgs::OnionPacket { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::msgs::OnionPacket<>) as *mut _) }, is_owned: false } +} +/// The onion routing packet with encrypted data for the next hop. +#[no_mangle] +pub extern "C" fn UpdateAddHTLC_set_onion_routing_packet(this_ptr: &mut UpdateAddHTLC, mut val: crate::lightning::ln::msgs::OnionPacket) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.onion_routing_packet = *unsafe { Box::from_raw(val.take_inner()) }; +} +/// Provided if we are relaying or receiving a payment within a blinded path, to decrypt the onion +/// routing packet and the recipient-provided encrypted payload within. +/// +/// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None +#[no_mangle] +pub extern "C" fn UpdateAddHTLC_get_blinding_point(this_ptr: &UpdateAddHTLC) -> crate::c_types::PublicKey { + let mut inner_val = &mut this_ptr.get_native_mut_ref().blinding_point; + let mut local_inner_val = if inner_val.is_none() { crate::c_types::PublicKey::null() } else { { crate::c_types::PublicKey::from_rust(&(inner_val.unwrap())) } }; + local_inner_val +} +/// Provided if we are relaying or receiving a payment within a blinded path, to decrypt the onion +/// routing packet and the recipient-provided encrypted payload within. +/// +/// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None +#[no_mangle] +pub extern "C" fn UpdateAddHTLC_set_blinding_point(this_ptr: &mut UpdateAddHTLC, mut val: crate::c_types::PublicKey) { + let mut local_val = if val.is_null() { None } else { Some( { val.into_rust() }) }; + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.blinding_point = local_val; +} +/// Constructs a new UpdateAddHTLC given each field +/// +/// Note that blinding_point_arg (or a relevant inner pointer) may be NULL or all-0s to represent None +#[must_use] +#[no_mangle] +pub extern "C" fn UpdateAddHTLC_new(mut channel_id_arg: crate::lightning::ln::types::ChannelId, mut htlc_id_arg: u64, mut amount_msat_arg: u64, mut payment_hash_arg: crate::c_types::ThirtyTwoBytes, mut cltv_expiry_arg: u32, mut skimmed_fee_msat_arg: crate::c_types::derived::COption_u64Z, mut onion_routing_packet_arg: crate::lightning::ln::msgs::OnionPacket, mut blinding_point_arg: crate::c_types::PublicKey) -> UpdateAddHTLC { + let mut local_skimmed_fee_msat_arg = if skimmed_fee_msat_arg.is_some() { Some( { skimmed_fee_msat_arg.take() }) } else { None }; + let mut local_blinding_point_arg = if blinding_point_arg.is_null() { None } else { Some( { blinding_point_arg.into_rust() }) }; + UpdateAddHTLC { inner: ObjOps::heap_alloc(nativeUpdateAddHTLC { + channel_id: *unsafe { Box::from_raw(channel_id_arg.take_inner()) }, + htlc_id: htlc_id_arg, + amount_msat: amount_msat_arg, + payment_hash: ::lightning::ln::types::PaymentHash(payment_hash_arg.data), + cltv_expiry: cltv_expiry_arg, + skimmed_fee_msat: local_skimmed_fee_msat_arg, + onion_routing_packet: *unsafe { Box::from_raw(onion_routing_packet_arg.take_inner()) }, + blinding_point: local_blinding_point_arg, + }), is_owned: true } +} impl Clone for UpdateAddHTLC { fn clone(&self) -> Self { Self { @@ -4176,13 +5444,26 @@ impl Clone for UpdateAddHTLC { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn UpdateAddHTLC_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUpdateAddHTLC)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeUpdateAddHTLC)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the UpdateAddHTLC pub extern "C" fn UpdateAddHTLC_clone(orig: &UpdateAddHTLC) -> UpdateAddHTLC { orig.clone() } +/// Get a string which allows debug introspection of a UpdateAddHTLC object +pub extern "C" fn UpdateAddHTLC_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::UpdateAddHTLC }).into()} +/// Generates a non-cryptographic 64-bit hash of the UpdateAddHTLC. +#[no_mangle] +pub extern "C" fn UpdateAddHTLC_hash(o: &UpdateAddHTLC) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two UpdateAddHTLCs 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. @@ -4213,6 +5494,12 @@ pub struct OnionMessage { pub is_owned: bool, } +impl core::ops::Deref for OnionMessage { + type Target = nativeOnionMessage; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for OnionMessage { } +unsafe impl core::marker::Sync for OnionMessage { } impl Drop for OnionMessage { fn drop(&mut self) { if self.is_owned && !<*mut nativeOnionMessage>::is_null(self.inner) { @@ -4243,6 +5530,9 @@ impl OnionMessage { self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// Used in decrypting the onion packet's payload. #[no_mangle] @@ -4287,13 +5577,26 @@ impl Clone for OnionMessage { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn OnionMessage_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeOnionMessage)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeOnionMessage)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the OnionMessage pub extern "C" fn OnionMessage_clone(orig: &OnionMessage) -> OnionMessage { orig.clone() } +/// Get a string which allows debug introspection of a OnionMessage object +pub extern "C" fn OnionMessage_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::OnionMessage }).into()} +/// Generates a non-cryptographic 64-bit hash of the OnionMessage. +#[no_mangle] +pub extern "C" fn OnionMessage_hash(o: &OnionMessage) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two OnionMessages 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. @@ -4325,6 +5628,12 @@ pub struct UpdateFulfillHTLC { pub is_owned: bool, } +impl core::ops::Deref for UpdateFulfillHTLC { + type Target = nativeUpdateFulfillHTLC; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for UpdateFulfillHTLC { } +unsafe impl core::marker::Sync for UpdateFulfillHTLC { } impl Drop for UpdateFulfillHTLC { fn drop(&mut self) { if self.is_owned && !<*mut nativeUpdateFulfillHTLC>::is_null(self.inner) { @@ -4355,17 +5664,20 @@ impl UpdateFulfillHTLC { self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// The channel ID #[no_mangle] -pub extern "C" fn UpdateFulfillHTLC_get_channel_id(this_ptr: &UpdateFulfillHTLC) -> *const [u8; 32] { +pub extern "C" fn UpdateFulfillHTLC_get_channel_id(this_ptr: &UpdateFulfillHTLC) -> crate::lightning::ln::types::ChannelId { let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_id; - &inner_val.0 + crate::lightning::ln::types::ChannelId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::types::ChannelId<>) as *mut _) }, is_owned: false } } /// The channel ID #[no_mangle] -pub extern "C" fn UpdateFulfillHTLC_set_channel_id(this_ptr: &mut UpdateFulfillHTLC, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = ::lightning::ln::ChannelId(val.data); +pub extern "C" fn UpdateFulfillHTLC_set_channel_id(this_ptr: &mut UpdateFulfillHTLC, mut val: crate::lightning::ln::types::ChannelId) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = *unsafe { Box::from_raw(val.take_inner()) }; } /// The HTLC ID #[no_mangle] @@ -4387,16 +5699,16 @@ pub extern "C" fn UpdateFulfillHTLC_get_payment_preimage(this_ptr: &UpdateFulfil /// The pre-image of the payment hash, allowing HTLC redemption #[no_mangle] pub extern "C" fn UpdateFulfillHTLC_set_payment_preimage(this_ptr: &mut UpdateFulfillHTLC, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_preimage = ::lightning::ln::PaymentPreimage(val.data); + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_preimage = ::lightning::ln::types::PaymentPreimage(val.data); } /// Constructs a new UpdateFulfillHTLC given each field #[must_use] #[no_mangle] -pub extern "C" fn UpdateFulfillHTLC_new(mut channel_id_arg: crate::c_types::ThirtyTwoBytes, mut htlc_id_arg: u64, mut payment_preimage_arg: crate::c_types::ThirtyTwoBytes) -> UpdateFulfillHTLC { +pub extern "C" fn UpdateFulfillHTLC_new(mut channel_id_arg: crate::lightning::ln::types::ChannelId, mut htlc_id_arg: u64, mut payment_preimage_arg: crate::c_types::ThirtyTwoBytes) -> UpdateFulfillHTLC { UpdateFulfillHTLC { inner: ObjOps::heap_alloc(nativeUpdateFulfillHTLC { - channel_id: ::lightning::ln::ChannelId(channel_id_arg.data), + channel_id: *unsafe { Box::from_raw(channel_id_arg.take_inner()) }, htlc_id: htlc_id_arg, - payment_preimage: ::lightning::ln::PaymentPreimage(payment_preimage_arg.data), + payment_preimage: ::lightning::ln::types::PaymentPreimage(payment_preimage_arg.data), }), is_owned: true } } impl Clone for UpdateFulfillHTLC { @@ -4411,13 +5723,26 @@ impl Clone for UpdateFulfillHTLC { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn UpdateFulfillHTLC_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUpdateFulfillHTLC)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeUpdateFulfillHTLC)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the UpdateFulfillHTLC pub extern "C" fn UpdateFulfillHTLC_clone(orig: &UpdateFulfillHTLC) -> UpdateFulfillHTLC { orig.clone() } +/// Get a string which allows debug introspection of a UpdateFulfillHTLC object +pub extern "C" fn UpdateFulfillHTLC_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::UpdateFulfillHTLC }).into()} +/// Generates a non-cryptographic 64-bit hash of the UpdateFulfillHTLC. +#[no_mangle] +pub extern "C" fn UpdateFulfillHTLC_hash(o: &UpdateFulfillHTLC) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two UpdateFulfillHTLCs 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. @@ -4449,6 +5774,12 @@ pub struct UpdateFailHTLC { pub is_owned: bool, } +impl core::ops::Deref for UpdateFailHTLC { + type Target = nativeUpdateFailHTLC; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for UpdateFailHTLC { } +unsafe impl core::marker::Sync for UpdateFailHTLC { } impl Drop for UpdateFailHTLC { fn drop(&mut self) { if self.is_owned && !<*mut nativeUpdateFailHTLC>::is_null(self.inner) { @@ -4479,17 +5810,20 @@ impl UpdateFailHTLC { self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// The channel ID #[no_mangle] -pub extern "C" fn UpdateFailHTLC_get_channel_id(this_ptr: &UpdateFailHTLC) -> *const [u8; 32] { +pub extern "C" fn UpdateFailHTLC_get_channel_id(this_ptr: &UpdateFailHTLC) -> crate::lightning::ln::types::ChannelId { let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_id; - &inner_val.0 + crate::lightning::ln::types::ChannelId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::types::ChannelId<>) as *mut _) }, is_owned: false } } /// The channel ID #[no_mangle] -pub extern "C" fn UpdateFailHTLC_set_channel_id(this_ptr: &mut UpdateFailHTLC, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = ::lightning::ln::ChannelId(val.data); +pub extern "C" fn UpdateFailHTLC_set_channel_id(this_ptr: &mut UpdateFailHTLC, mut val: crate::lightning::ln::types::ChannelId) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = *unsafe { Box::from_raw(val.take_inner()) }; } /// The HTLC ID #[no_mangle] @@ -4514,13 +5848,26 @@ impl Clone for UpdateFailHTLC { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn UpdateFailHTLC_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUpdateFailHTLC)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeUpdateFailHTLC)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the UpdateFailHTLC pub extern "C" fn UpdateFailHTLC_clone(orig: &UpdateFailHTLC) -> UpdateFailHTLC { orig.clone() } +/// Get a string which allows debug introspection of a UpdateFailHTLC object +pub extern "C" fn UpdateFailHTLC_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::UpdateFailHTLC }).into()} +/// Generates a non-cryptographic 64-bit hash of the UpdateFailHTLC. +#[no_mangle] +pub extern "C" fn UpdateFailHTLC_hash(o: &UpdateFailHTLC) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two UpdateFailHTLCs 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. @@ -4552,6 +5899,12 @@ pub struct UpdateFailMalformedHTLC { pub is_owned: bool, } +impl core::ops::Deref for UpdateFailMalformedHTLC { + type Target = nativeUpdateFailMalformedHTLC; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for UpdateFailMalformedHTLC { } +unsafe impl core::marker::Sync for UpdateFailMalformedHTLC { } impl Drop for UpdateFailMalformedHTLC { fn drop(&mut self) { if self.is_owned && !<*mut nativeUpdateFailMalformedHTLC>::is_null(self.inner) { @@ -4582,17 +5935,20 @@ impl UpdateFailMalformedHTLC { self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// The channel ID #[no_mangle] -pub extern "C" fn UpdateFailMalformedHTLC_get_channel_id(this_ptr: &UpdateFailMalformedHTLC) -> *const [u8; 32] { +pub extern "C" fn UpdateFailMalformedHTLC_get_channel_id(this_ptr: &UpdateFailMalformedHTLC) -> crate::lightning::ln::types::ChannelId { let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_id; - &inner_val.0 + crate::lightning::ln::types::ChannelId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::types::ChannelId<>) as *mut _) }, is_owned: false } } /// The channel ID #[no_mangle] -pub extern "C" fn UpdateFailMalformedHTLC_set_channel_id(this_ptr: &mut UpdateFailMalformedHTLC, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = ::lightning::ln::ChannelId(val.data); +pub extern "C" fn UpdateFailMalformedHTLC_set_channel_id(this_ptr: &mut UpdateFailMalformedHTLC, mut val: crate::lightning::ln::types::ChannelId) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = *unsafe { Box::from_raw(val.take_inner()) }; } /// The HTLC ID #[no_mangle] @@ -4628,13 +5984,26 @@ impl Clone for UpdateFailMalformedHTLC { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn UpdateFailMalformedHTLC_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUpdateFailMalformedHTLC)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeUpdateFailMalformedHTLC)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the UpdateFailMalformedHTLC pub extern "C" fn UpdateFailMalformedHTLC_clone(orig: &UpdateFailMalformedHTLC) -> UpdateFailMalformedHTLC { orig.clone() } +/// Get a string which allows debug introspection of a UpdateFailMalformedHTLC object +pub extern "C" fn UpdateFailMalformedHTLC_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::UpdateFailMalformedHTLC }).into()} +/// Generates a non-cryptographic 64-bit hash of the UpdateFailMalformedHTLC. +#[no_mangle] +pub extern "C" fn UpdateFailMalformedHTLC_hash(o: &UpdateFailMalformedHTLC) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two UpdateFailMalformedHTLCs 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. @@ -4645,6 +6014,138 @@ pub extern "C" fn UpdateFailMalformedHTLC_eq(a: &UpdateFailMalformedHTLC, b: &Up if a.get_native_ref() == b.get_native_ref() { true } else { false } } +use lightning::ln::msgs::CommitmentSignedBatch as nativeCommitmentSignedBatchImport; +pub(crate) type nativeCommitmentSignedBatch = nativeCommitmentSignedBatchImport; + +/// Optional batch parameters for `commitment_signed` message. +#[must_use] +#[repr(C)] +pub struct CommitmentSignedBatch { + /// 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 nativeCommitmentSignedBatch, + /// 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 core::ops::Deref for CommitmentSignedBatch { + type Target = nativeCommitmentSignedBatch; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for CommitmentSignedBatch { } +unsafe impl core::marker::Sync for CommitmentSignedBatch { } +impl Drop for CommitmentSignedBatch { + fn drop(&mut self) { + if self.is_owned && !<*mut nativeCommitmentSignedBatch>::is_null(self.inner) { + let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; + } + } +} +/// Frees any resources used by the CommitmentSignedBatch, if is_owned is set and inner is non-NULL. +#[no_mangle] +pub extern "C" fn CommitmentSignedBatch_free(this_obj: CommitmentSignedBatch) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn CommitmentSignedBatch_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeCommitmentSignedBatch) }; +} +#[allow(unused)] +impl CommitmentSignedBatch { + pub(crate) fn get_native_ref(&self) -> &'static nativeCommitmentSignedBatch { + unsafe { &*ObjOps::untweak_ptr(self.inner) } + } + pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeCommitmentSignedBatch { + 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 nativeCommitmentSignedBatch { + assert!(self.is_owned); + let ret = ObjOps::untweak_ptr(self.inner); + self.inner = core::ptr::null_mut(); + ret + } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } +} +/// Batch size N: all N `commitment_signed` messages must be received before being processed +#[no_mangle] +pub extern "C" fn CommitmentSignedBatch_get_batch_size(this_ptr: &CommitmentSignedBatch) -> u16 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().batch_size; + *inner_val +} +/// Batch size N: all N `commitment_signed` messages must be received before being processed +#[no_mangle] +pub extern "C" fn CommitmentSignedBatch_set_batch_size(this_ptr: &mut CommitmentSignedBatch, mut val: u16) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.batch_size = val; +} +/// The funding transaction, to discriminate among multiple pending funding transactions (e.g. in case of splicing) +#[no_mangle] +pub extern "C" fn CommitmentSignedBatch_get_funding_txid(this_ptr: &CommitmentSignedBatch) -> *const [u8; 32] { + let mut inner_val = &mut this_ptr.get_native_mut_ref().funding_txid; + inner_val.as_ref() +} +/// The funding transaction, to discriminate among multiple pending funding transactions (e.g. in case of splicing) +#[no_mangle] +pub extern "C" fn CommitmentSignedBatch_set_funding_txid(this_ptr: &mut CommitmentSignedBatch, mut val: crate::c_types::ThirtyTwoBytes) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.funding_txid = ::bitcoin::hash_types::Txid::from_slice(&val.data[..]).unwrap(); +} +/// Constructs a new CommitmentSignedBatch given each field +#[must_use] +#[no_mangle] +pub extern "C" fn CommitmentSignedBatch_new(mut batch_size_arg: u16, mut funding_txid_arg: crate::c_types::ThirtyTwoBytes) -> CommitmentSignedBatch { + CommitmentSignedBatch { inner: ObjOps::heap_alloc(nativeCommitmentSignedBatch { + batch_size: batch_size_arg, + funding_txid: ::bitcoin::hash_types::Txid::from_slice(&funding_txid_arg.data[..]).unwrap(), + }), is_owned: true } +} +impl Clone for CommitmentSignedBatch { + fn clone(&self) -> Self { + Self { + inner: if <*mut nativeCommitmentSignedBatch>::is_null(self.inner) { core::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 CommitmentSignedBatch_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeCommitmentSignedBatch)).clone() })) as *mut c_void +} +#[no_mangle] +/// Creates a copy of the CommitmentSignedBatch +pub extern "C" fn CommitmentSignedBatch_clone(orig: &CommitmentSignedBatch) -> CommitmentSignedBatch { + orig.clone() +} +/// Get a string which allows debug introspection of a CommitmentSignedBatch object +pub extern "C" fn CommitmentSignedBatch_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::CommitmentSignedBatch }).into()} +/// Generates a non-cryptographic 64-bit hash of the CommitmentSignedBatch. +#[no_mangle] +pub extern "C" fn CommitmentSignedBatch_hash(o: &CommitmentSignedBatch) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} +/// Checks if two CommitmentSignedBatchs 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 CommitmentSignedBatch_eq(a: &CommitmentSignedBatch, b: &CommitmentSignedBatch) -> 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 } +} + use lightning::ln::msgs::CommitmentSigned as nativeCommitmentSignedImport; pub(crate) type nativeCommitmentSigned = nativeCommitmentSignedImport; @@ -4666,6 +6167,12 @@ pub struct CommitmentSigned { pub is_owned: bool, } +impl core::ops::Deref for CommitmentSigned { + type Target = nativeCommitmentSigned; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for CommitmentSigned { } +unsafe impl core::marker::Sync for CommitmentSigned { } impl Drop for CommitmentSigned { fn drop(&mut self) { if self.is_owned && !<*mut nativeCommitmentSigned>::is_null(self.inner) { @@ -4696,17 +6203,20 @@ impl CommitmentSigned { self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// The channel ID #[no_mangle] -pub extern "C" fn CommitmentSigned_get_channel_id(this_ptr: &CommitmentSigned) -> *const [u8; 32] { +pub extern "C" fn CommitmentSigned_get_channel_id(this_ptr: &CommitmentSigned) -> crate::lightning::ln::types::ChannelId { let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_id; - &inner_val.0 + crate::lightning::ln::types::ChannelId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::types::ChannelId<>) as *mut _) }, is_owned: false } } /// The channel ID #[no_mangle] -pub extern "C" fn CommitmentSigned_set_channel_id(this_ptr: &mut CommitmentSigned, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = ::lightning::ln::ChannelId(val.data); +pub extern "C" fn CommitmentSigned_set_channel_id(this_ptr: &mut CommitmentSigned, mut val: crate::lightning::ln::types::ChannelId) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = *unsafe { Box::from_raw(val.take_inner()) }; } /// A signature on the commitment transaction #[no_mangle] @@ -4734,15 +6244,36 @@ pub extern "C" fn CommitmentSigned_set_htlc_signatures(this_ptr: &mut Commitment let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item.into_rust() }); }; unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.htlc_signatures = local_val; } +/// Optional batch size and other parameters +/// +/// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None +#[no_mangle] +pub extern "C" fn CommitmentSigned_get_batch(this_ptr: &CommitmentSigned) -> crate::lightning::ln::msgs::CommitmentSignedBatch { + let mut inner_val = &mut this_ptr.get_native_mut_ref().batch; + let mut local_inner_val = crate::lightning::ln::msgs::CommitmentSignedBatch { inner: unsafe { (if inner_val.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (inner_val.as_ref().unwrap()) }) } as *const lightning::ln::msgs::CommitmentSignedBatch<>) as *mut _ }, is_owned: false }; + local_inner_val +} +/// Optional batch size and other parameters +/// +/// Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None +#[no_mangle] +pub extern "C" fn CommitmentSigned_set_batch(this_ptr: &mut CommitmentSigned, mut val: crate::lightning::ln::msgs::CommitmentSignedBatch) { + let mut local_val = if val.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(val.take_inner()) } }) }; + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.batch = local_val; +} /// Constructs a new CommitmentSigned given each field +/// +/// Note that batch_arg (or a relevant inner pointer) may be NULL or all-0s to represent None #[must_use] #[no_mangle] -pub extern "C" fn CommitmentSigned_new(mut channel_id_arg: crate::c_types::ThirtyTwoBytes, mut signature_arg: crate::c_types::ECDSASignature, mut htlc_signatures_arg: crate::c_types::derived::CVec_ECDSASignatureZ) -> CommitmentSigned { +pub extern "C" fn CommitmentSigned_new(mut channel_id_arg: crate::lightning::ln::types::ChannelId, mut signature_arg: crate::c_types::ECDSASignature, mut htlc_signatures_arg: crate::c_types::derived::CVec_ECDSASignatureZ, mut batch_arg: crate::lightning::ln::msgs::CommitmentSignedBatch) -> CommitmentSigned { let mut local_htlc_signatures_arg = Vec::new(); for mut item in htlc_signatures_arg.into_rust().drain(..) { local_htlc_signatures_arg.push( { item.into_rust() }); }; + let mut local_batch_arg = if batch_arg.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(batch_arg.take_inner()) } }) }; CommitmentSigned { inner: ObjOps::heap_alloc(nativeCommitmentSigned { - channel_id: ::lightning::ln::ChannelId(channel_id_arg.data), + channel_id: *unsafe { Box::from_raw(channel_id_arg.take_inner()) }, signature: signature_arg.into_rust(), htlc_signatures: local_htlc_signatures_arg, + batch: local_batch_arg, }), is_owned: true } } impl Clone for CommitmentSigned { @@ -4757,13 +6288,26 @@ impl Clone for CommitmentSigned { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn CommitmentSigned_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeCommitmentSigned)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeCommitmentSigned)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the CommitmentSigned pub extern "C" fn CommitmentSigned_clone(orig: &CommitmentSigned) -> CommitmentSigned { orig.clone() } +/// Get a string which allows debug introspection of a CommitmentSigned object +pub extern "C" fn CommitmentSigned_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::CommitmentSigned }).into()} +/// Generates a non-cryptographic 64-bit hash of the CommitmentSigned. +#[no_mangle] +pub extern "C" fn CommitmentSigned_hash(o: &CommitmentSigned) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two CommitmentSigneds 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. @@ -4795,6 +6339,12 @@ pub struct RevokeAndACK { pub is_owned: bool, } +impl core::ops::Deref for RevokeAndACK { + type Target = nativeRevokeAndACK; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for RevokeAndACK { } +unsafe impl core::marker::Sync for RevokeAndACK { } impl Drop for RevokeAndACK { fn drop(&mut self) { if self.is_owned && !<*mut nativeRevokeAndACK>::is_null(self.inner) { @@ -4825,17 +6375,20 @@ impl RevokeAndACK { self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// The channel ID #[no_mangle] -pub extern "C" fn RevokeAndACK_get_channel_id(this_ptr: &RevokeAndACK) -> *const [u8; 32] { +pub extern "C" fn RevokeAndACK_get_channel_id(this_ptr: &RevokeAndACK) -> crate::lightning::ln::types::ChannelId { let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_id; - &inner_val.0 + crate::lightning::ln::types::ChannelId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::types::ChannelId<>) as *mut _) }, is_owned: false } } /// The channel ID #[no_mangle] -pub extern "C" fn RevokeAndACK_set_channel_id(this_ptr: &mut RevokeAndACK, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = ::lightning::ln::ChannelId(val.data); +pub extern "C" fn RevokeAndACK_set_channel_id(this_ptr: &mut RevokeAndACK, mut val: crate::lightning::ln::types::ChannelId) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = *unsafe { Box::from_raw(val.take_inner()) }; } /// The secret corresponding to the per-commitment point #[no_mangle] @@ -4862,9 +6415,9 @@ pub extern "C" fn RevokeAndACK_set_next_per_commitment_point(this_ptr: &mut Revo /// Constructs a new RevokeAndACK given each field #[must_use] #[no_mangle] -pub extern "C" fn RevokeAndACK_new(mut channel_id_arg: crate::c_types::ThirtyTwoBytes, mut per_commitment_secret_arg: crate::c_types::ThirtyTwoBytes, mut next_per_commitment_point_arg: crate::c_types::PublicKey) -> RevokeAndACK { +pub extern "C" fn RevokeAndACK_new(mut channel_id_arg: crate::lightning::ln::types::ChannelId, mut per_commitment_secret_arg: crate::c_types::ThirtyTwoBytes, mut next_per_commitment_point_arg: crate::c_types::PublicKey) -> RevokeAndACK { RevokeAndACK { inner: ObjOps::heap_alloc(nativeRevokeAndACK { - channel_id: ::lightning::ln::ChannelId(channel_id_arg.data), + channel_id: *unsafe { Box::from_raw(channel_id_arg.take_inner()) }, per_commitment_secret: per_commitment_secret_arg.data, next_per_commitment_point: next_per_commitment_point_arg.into_rust(), }), is_owned: true } @@ -4881,13 +6434,26 @@ impl Clone for RevokeAndACK { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn RevokeAndACK_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeRevokeAndACK)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeRevokeAndACK)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the RevokeAndACK pub extern "C" fn RevokeAndACK_clone(orig: &RevokeAndACK) -> RevokeAndACK { orig.clone() } +/// Get a string which allows debug introspection of a RevokeAndACK object +pub extern "C" fn RevokeAndACK_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::RevokeAndACK }).into()} +/// Generates a non-cryptographic 64-bit hash of the RevokeAndACK. +#[no_mangle] +pub extern "C" fn RevokeAndACK_hash(o: &RevokeAndACK) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two RevokeAndACKs 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. @@ -4919,6 +6485,12 @@ pub struct UpdateFee { pub is_owned: bool, } +impl core::ops::Deref for UpdateFee { + type Target = nativeUpdateFee; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for UpdateFee { } +unsafe impl core::marker::Sync for UpdateFee { } impl Drop for UpdateFee { fn drop(&mut self) { if self.is_owned && !<*mut nativeUpdateFee>::is_null(self.inner) { @@ -4949,17 +6521,20 @@ impl UpdateFee { self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// The channel ID #[no_mangle] -pub extern "C" fn UpdateFee_get_channel_id(this_ptr: &UpdateFee) -> *const [u8; 32] { +pub extern "C" fn UpdateFee_get_channel_id(this_ptr: &UpdateFee) -> crate::lightning::ln::types::ChannelId { let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_id; - &inner_val.0 + crate::lightning::ln::types::ChannelId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::types::ChannelId<>) as *mut _) }, is_owned: false } } /// The channel ID #[no_mangle] -pub extern "C" fn UpdateFee_set_channel_id(this_ptr: &mut UpdateFee, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = ::lightning::ln::ChannelId(val.data); +pub extern "C" fn UpdateFee_set_channel_id(this_ptr: &mut UpdateFee, mut val: crate::lightning::ln::types::ChannelId) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = *unsafe { Box::from_raw(val.take_inner()) }; } /// Fee rate per 1000-weight of the transaction #[no_mangle] @@ -4975,9 +6550,9 @@ pub extern "C" fn UpdateFee_set_feerate_per_kw(this_ptr: &mut UpdateFee, mut val /// Constructs a new UpdateFee given each field #[must_use] #[no_mangle] -pub extern "C" fn UpdateFee_new(mut channel_id_arg: crate::c_types::ThirtyTwoBytes, mut feerate_per_kw_arg: u32) -> UpdateFee { +pub extern "C" fn UpdateFee_new(mut channel_id_arg: crate::lightning::ln::types::ChannelId, mut feerate_per_kw_arg: u32) -> UpdateFee { UpdateFee { inner: ObjOps::heap_alloc(nativeUpdateFee { - channel_id: ::lightning::ln::ChannelId(channel_id_arg.data), + channel_id: *unsafe { Box::from_raw(channel_id_arg.take_inner()) }, feerate_per_kw: feerate_per_kw_arg, }), is_owned: true } } @@ -4993,13 +6568,26 @@ impl Clone for UpdateFee { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn UpdateFee_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUpdateFee)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeUpdateFee)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the UpdateFee pub extern "C" fn UpdateFee_clone(orig: &UpdateFee) -> UpdateFee { orig.clone() } +/// Get a string which allows debug introspection of a UpdateFee object +pub extern "C" fn UpdateFee_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::UpdateFee }).into()} +/// Generates a non-cryptographic 64-bit hash of the UpdateFee. +#[no_mangle] +pub extern "C" fn UpdateFee_hash(o: &UpdateFee) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two UpdateFees 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. @@ -5031,6 +6619,12 @@ pub struct ChannelReestablish { pub is_owned: bool, } +impl core::ops::Deref for ChannelReestablish { + type Target = nativeChannelReestablish; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for ChannelReestablish { } +unsafe impl core::marker::Sync for ChannelReestablish { } impl Drop for ChannelReestablish { fn drop(&mut self) { if self.is_owned && !<*mut nativeChannelReestablish>::is_null(self.inner) { @@ -5061,17 +6655,20 @@ impl ChannelReestablish { self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// The channel ID #[no_mangle] -pub extern "C" fn ChannelReestablish_get_channel_id(this_ptr: &ChannelReestablish) -> *const [u8; 32] { +pub extern "C" fn ChannelReestablish_get_channel_id(this_ptr: &ChannelReestablish) -> crate::lightning::ln::types::ChannelId { let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_id; - &inner_val.0 + crate::lightning::ln::types::ChannelId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::types::ChannelId<>) as *mut _) }, is_owned: false } } /// The channel ID #[no_mangle] -pub extern "C" fn ChannelReestablish_set_channel_id(this_ptr: &mut ChannelReestablish, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = ::lightning::ln::ChannelId(val.data); +pub extern "C" fn ChannelReestablish_set_channel_id(this_ptr: &mut ChannelReestablish, mut val: crate::lightning::ln::types::ChannelId) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = *unsafe { Box::from_raw(val.take_inner()) }; } /// The next commitment number for the sender #[no_mangle] @@ -5123,7 +6720,7 @@ pub extern "C" fn ChannelReestablish_set_my_current_per_commitment_point(this_pt #[no_mangle] pub extern "C" fn ChannelReestablish_get_next_funding_txid(this_ptr: &ChannelReestablish) -> crate::c_types::derived::COption_ThirtyTwoBytesZ { let mut inner_val = &mut this_ptr.get_native_mut_ref().next_funding_txid; - let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_ThirtyTwoBytesZ::None } else { crate::c_types::derived::COption_ThirtyTwoBytesZ::Some(/* WARNING: CLONING CONVERSION HERE! &Option is otherwise un-expressable. */ { crate::c_types::ThirtyTwoBytes { data: (*inner_val.as_ref().unwrap()).clone().into_inner() } }) }; + let mut local_inner_val = if inner_val.is_none() { crate::c_types::derived::COption_ThirtyTwoBytesZ::None } else { crate::c_types::derived::COption_ThirtyTwoBytesZ::Some(/* WARNING: CLONING CONVERSION HERE! &Option is otherwise un-expressable. */ { crate::c_types::ThirtyTwoBytes { data: *(*inner_val.as_ref().unwrap()).clone().as_ref() } }) }; local_inner_val } /// The next funding transaction ID @@ -5135,10 +6732,10 @@ pub extern "C" fn ChannelReestablish_set_next_funding_txid(this_ptr: &mut Channe /// Constructs a new ChannelReestablish given each field #[must_use] #[no_mangle] -pub extern "C" fn ChannelReestablish_new(mut channel_id_arg: crate::c_types::ThirtyTwoBytes, mut next_local_commitment_number_arg: u64, mut next_remote_commitment_number_arg: u64, mut your_last_per_commitment_secret_arg: crate::c_types::ThirtyTwoBytes, mut my_current_per_commitment_point_arg: crate::c_types::PublicKey, mut next_funding_txid_arg: crate::c_types::derived::COption_ThirtyTwoBytesZ) -> ChannelReestablish { +pub extern "C" fn ChannelReestablish_new(mut channel_id_arg: crate::lightning::ln::types::ChannelId, mut next_local_commitment_number_arg: u64, mut next_remote_commitment_number_arg: u64, mut your_last_per_commitment_secret_arg: crate::c_types::ThirtyTwoBytes, mut my_current_per_commitment_point_arg: crate::c_types::PublicKey, mut next_funding_txid_arg: crate::c_types::derived::COption_ThirtyTwoBytesZ) -> ChannelReestablish { let mut local_next_funding_txid_arg = { /*next_funding_txid_arg*/ let next_funding_txid_arg_opt = next_funding_txid_arg; if next_funding_txid_arg_opt.is_none() { None } else { Some({ { ::bitcoin::hash_types::Txid::from_slice(&{ next_funding_txid_arg_opt.take() }.data[..]).unwrap() }})} }; ChannelReestablish { inner: ObjOps::heap_alloc(nativeChannelReestablish { - channel_id: ::lightning::ln::ChannelId(channel_id_arg.data), + channel_id: *unsafe { Box::from_raw(channel_id_arg.take_inner()) }, next_local_commitment_number: next_local_commitment_number_arg, next_remote_commitment_number: next_remote_commitment_number_arg, your_last_per_commitment_secret: your_last_per_commitment_secret_arg.data, @@ -5158,13 +6755,26 @@ impl Clone for ChannelReestablish { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ChannelReestablish_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelReestablish)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelReestablish)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ChannelReestablish pub extern "C" fn ChannelReestablish_clone(orig: &ChannelReestablish) -> ChannelReestablish { orig.clone() } +/// Get a string which allows debug introspection of a ChannelReestablish object +pub extern "C" fn ChannelReestablish_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::ChannelReestablish }).into()} +/// Generates a non-cryptographic 64-bit hash of the ChannelReestablish. +#[no_mangle] +pub extern "C" fn ChannelReestablish_hash(o: &ChannelReestablish) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two ChannelReestablishs 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. @@ -5196,6 +6806,12 @@ pub struct AnnouncementSignatures { pub is_owned: bool, } +impl core::ops::Deref for AnnouncementSignatures { + type Target = nativeAnnouncementSignatures; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for AnnouncementSignatures { } +unsafe impl core::marker::Sync for AnnouncementSignatures { } impl Drop for AnnouncementSignatures { fn drop(&mut self) { if self.is_owned && !<*mut nativeAnnouncementSignatures>::is_null(self.inner) { @@ -5226,17 +6842,20 @@ impl AnnouncementSignatures { self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// The channel ID #[no_mangle] -pub extern "C" fn AnnouncementSignatures_get_channel_id(this_ptr: &AnnouncementSignatures) -> *const [u8; 32] { +pub extern "C" fn AnnouncementSignatures_get_channel_id(this_ptr: &AnnouncementSignatures) -> crate::lightning::ln::types::ChannelId { let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_id; - &inner_val.0 + crate::lightning::ln::types::ChannelId { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::types::ChannelId<>) as *mut _) }, is_owned: false } } /// The channel ID #[no_mangle] -pub extern "C" fn AnnouncementSignatures_set_channel_id(this_ptr: &mut AnnouncementSignatures, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = ::lightning::ln::ChannelId(val.data); +pub extern "C" fn AnnouncementSignatures_set_channel_id(this_ptr: &mut AnnouncementSignatures, mut val: crate::lightning::ln::types::ChannelId) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_id = *unsafe { Box::from_raw(val.take_inner()) }; } /// The short channel ID #[no_mangle] @@ -5274,9 +6893,9 @@ pub extern "C" fn AnnouncementSignatures_set_bitcoin_signature(this_ptr: &mut An /// Constructs a new AnnouncementSignatures given each field #[must_use] #[no_mangle] -pub extern "C" fn AnnouncementSignatures_new(mut channel_id_arg: crate::c_types::ThirtyTwoBytes, mut short_channel_id_arg: u64, mut node_signature_arg: crate::c_types::ECDSASignature, mut bitcoin_signature_arg: crate::c_types::ECDSASignature) -> AnnouncementSignatures { +pub extern "C" fn AnnouncementSignatures_new(mut channel_id_arg: crate::lightning::ln::types::ChannelId, mut short_channel_id_arg: u64, mut node_signature_arg: crate::c_types::ECDSASignature, mut bitcoin_signature_arg: crate::c_types::ECDSASignature) -> AnnouncementSignatures { AnnouncementSignatures { inner: ObjOps::heap_alloc(nativeAnnouncementSignatures { - channel_id: ::lightning::ln::ChannelId(channel_id_arg.data), + channel_id: *unsafe { Box::from_raw(channel_id_arg.take_inner()) }, short_channel_id: short_channel_id_arg, node_signature: node_signature_arg.into_rust(), bitcoin_signature: bitcoin_signature_arg.into_rust(), @@ -5294,13 +6913,26 @@ impl Clone for AnnouncementSignatures { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn AnnouncementSignatures_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeAnnouncementSignatures)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeAnnouncementSignatures)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the AnnouncementSignatures pub extern "C" fn AnnouncementSignatures_clone(orig: &AnnouncementSignatures) -> AnnouncementSignatures { orig.clone() } +/// Get a string which allows debug introspection of a AnnouncementSignatures object +pub extern "C" fn AnnouncementSignatures_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::AnnouncementSignatures }).into()} +/// Generates a non-cryptographic 64-bit hash of the AnnouncementSignatures. +#[no_mangle] +pub extern "C" fn AnnouncementSignatures_hash(o: &AnnouncementSignatures) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two AnnouncementSignaturess 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. @@ -5445,7 +7077,8 @@ impl SocketAddress { } } #[allow(unused)] - pub(crate) fn from_native(native: &nativeSocketAddress) -> Self { + pub(crate) fn from_native(native: &SocketAddressImport) -> Self { + let native = unsafe { &*(native as *const _ as *const c_void as *const nativeSocketAddress) }; match native { nativeSocketAddress::TcpIpV4 {ref addr, ref port, } => { let mut addr_nonref = Clone::clone(addr); @@ -5536,6 +7169,16 @@ pub extern "C" fn SocketAddress_free(this_ptr: SocketAddress) { } pub extern "C" fn SocketAddress_clone(orig: &SocketAddress) -> SocketAddress { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn SocketAddress_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const SocketAddress)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn SocketAddress_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut SocketAddress) }; +} #[no_mangle] /// Utility method to constructs a new TcpIpV4-variant SocketAddress pub extern "C" fn SocketAddress_tcp_ip_v4(addr: crate::c_types::FourBytes, port: u16) -> SocketAddress { @@ -5575,6 +7218,18 @@ pub extern "C" fn SocketAddress_hostname(hostname: crate::lightning::util::ser:: port, } } +/// Get a string which allows debug introspection of a SocketAddress object +pub extern "C" fn SocketAddress_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::SocketAddress }).into()} +/// Generates a non-cryptographic 64-bit hash of the SocketAddress. +#[no_mangle] +pub extern "C" fn SocketAddress_hash(o: &SocketAddress) -> u64 { + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(&o.to_native(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two SocketAddresss contain equal inner contents. /// This ignores pointers and is_owned flags and looks at the values in fields. #[no_mangle] @@ -5586,6 +7241,10 @@ pub extern "C" fn SocketAddress_eq(a: &SocketAddress, b: &SocketAddress) -> bool pub extern "C" fn SocketAddress_write(obj: &crate::lightning::ln::msgs::SocketAddress) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(&unsafe { &*obj }.to_native()) } +#[allow(unused)] +pub(crate) extern "C" fn SocketAddress_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + SocketAddress_write(unsafe { &*(obj as *const SocketAddress) }) +} #[no_mangle] /// Read a SocketAddress from a byte array, created by SocketAddress_write pub extern "C" fn SocketAddress_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_SocketAddressDecodeErrorZ { @@ -5630,7 +7289,8 @@ impl SocketAddressParseError { } } #[allow(unused)] - pub(crate) fn from_native(native: &nativeSocketAddressParseError) -> Self { + pub(crate) fn from_native(native: &SocketAddressParseErrorImport) -> Self { + let native = unsafe { &*(native as *const _ as *const c_void as *const nativeSocketAddressParseError) }; match native { nativeSocketAddressParseError::SocketAddrParse => SocketAddressParseError::SocketAddrParse, nativeSocketAddressParseError::InvalidInput => SocketAddressParseError::InvalidInput, @@ -5653,6 +7313,16 @@ impl SocketAddressParseError { pub extern "C" fn SocketAddressParseError_clone(orig: &SocketAddressParseError) -> SocketAddressParseError { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn SocketAddressParseError_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const SocketAddressParseError)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn SocketAddressParseError_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut SocketAddressParseError) }; +} #[no_mangle] /// Utility method to constructs a new SocketAddrParse-variant SocketAddressParseError pub extern "C" fn SocketAddressParseError_socket_addr_parse() -> SocketAddressParseError { @@ -5669,12 +7339,29 @@ pub extern "C" fn SocketAddressParseError_invalid_port() -> SocketAddressParseEr /// Utility method to constructs a new InvalidOnionV3-variant SocketAddressParseError pub extern "C" fn SocketAddressParseError_invalid_onion_v3() -> SocketAddressParseError { SocketAddressParseError::InvalidOnionV3} +/// Get a string which allows debug introspection of a SocketAddressParseError object +pub extern "C" fn SocketAddressParseError_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::SocketAddressParseError }).into()} +/// Generates a non-cryptographic 64-bit hash of the SocketAddressParseError. +#[no_mangle] +pub extern "C" fn SocketAddressParseError_hash(o: &SocketAddressParseError) -> u64 { + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(&o.to_native(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two SocketAddressParseErrors contain equal inner contents. /// This ignores pointers and is_owned flags and looks at the values in fields. #[no_mangle] pub extern "C" fn SocketAddressParseError_eq(a: &SocketAddressParseError, b: &SocketAddressParseError) -> bool { if &a.to_native() == &b.to_native() { true } else { false } } +#[no_mangle] +/// Get the string representation of a SocketAddressParseError object +pub extern "C" fn SocketAddressParseError_to_str(o: &crate::lightning::ln::msgs::SocketAddressParseError) -> Str { + alloc::format!("{}", &o.to_native()).into() +} /// Parses an OnionV3 host and port into a [`SocketAddress::OnionV3`]. /// /// The host part must end with \".onion\". @@ -5685,6 +7372,11 @@ pub extern "C" fn parse_onion_address(mut host: crate::c_types::Str, mut port: u local_ret } +#[no_mangle] +/// Get the string representation of a SocketAddress object +pub extern "C" fn SocketAddress_to_str(o: &crate::lightning::ln::msgs::SocketAddress) -> Str { + alloc::format!("{}", &o.to_native()).into() +} #[no_mangle] /// Read a SocketAddress object from a string pub extern "C" fn SocketAddress_from_str(s: crate::c_types::Str) -> crate::c_types::derived::CResult_SocketAddressSocketAddressParseErrorZ { @@ -5764,7 +7456,8 @@ impl UnsignedGossipMessage { } } #[allow(unused)] - pub(crate) fn from_native(native: &nativeUnsignedGossipMessage) -> Self { + pub(crate) fn from_native(native: &UnsignedGossipMessageImport) -> Self { + let native = unsafe { &*(native as *const _ as *const c_void as *const nativeUnsignedGossipMessage) }; match native { nativeUnsignedGossipMessage::ChannelAnnouncement (ref a, ) => { let mut a_nonref = Clone::clone(a); @@ -5815,6 +7508,16 @@ pub extern "C" fn UnsignedGossipMessage_free(this_ptr: UnsignedGossipMessage) { pub extern "C" fn UnsignedGossipMessage_clone(orig: &UnsignedGossipMessage) -> UnsignedGossipMessage { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn UnsignedGossipMessage_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const UnsignedGossipMessage)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn UnsignedGossipMessage_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut UnsignedGossipMessage) }; +} #[no_mangle] /// Utility method to constructs a new ChannelAnnouncement-variant UnsignedGossipMessage pub extern "C" fn UnsignedGossipMessage_channel_announcement(a: crate::lightning::ln::msgs::UnsignedChannelAnnouncement) -> UnsignedGossipMessage { @@ -5835,6 +7538,10 @@ pub extern "C" fn UnsignedGossipMessage_node_announcement(a: crate::lightning::l pub extern "C" fn UnsignedGossipMessage_write(obj: &crate::lightning::ln::msgs::UnsignedGossipMessage) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(&unsafe { &*obj }.to_native()) } +#[allow(unused)] +pub(crate) extern "C" fn UnsignedGossipMessage_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + UnsignedGossipMessage_write(unsafe { &*(obj as *const UnsignedGossipMessage) }) +} use lightning::ln::msgs::UnsignedNodeAnnouncement as nativeUnsignedNodeAnnouncementImport; pub(crate) type nativeUnsignedNodeAnnouncement = nativeUnsignedNodeAnnouncementImport; @@ -5857,6 +7564,12 @@ pub struct UnsignedNodeAnnouncement { pub is_owned: bool, } +impl core::ops::Deref for UnsignedNodeAnnouncement { + type Target = nativeUnsignedNodeAnnouncement; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for UnsignedNodeAnnouncement { } +unsafe impl core::marker::Sync for UnsignedNodeAnnouncement { } impl Drop for UnsignedNodeAnnouncement { fn drop(&mut self) { if self.is_owned && !<*mut nativeUnsignedNodeAnnouncement>::is_null(self.inner) { @@ -5887,16 +7600,19 @@ impl UnsignedNodeAnnouncement { self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// The advertised features #[no_mangle] -pub extern "C" fn UnsignedNodeAnnouncement_get_features(this_ptr: &UnsignedNodeAnnouncement) -> crate::lightning::ln::features::NodeFeatures { +pub extern "C" fn UnsignedNodeAnnouncement_get_features(this_ptr: &UnsignedNodeAnnouncement) -> crate::lightning_types::features::NodeFeatures { let mut inner_val = &mut this_ptr.get_native_mut_ref().features; - crate::lightning::ln::features::NodeFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::features::NodeFeatures<>) as *mut _) }, is_owned: false } + crate::lightning_types::features::NodeFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning_types::features::NodeFeatures<>) as *mut _) }, is_owned: false } } /// The advertised features #[no_mangle] -pub extern "C" fn UnsignedNodeAnnouncement_set_features(this_ptr: &mut UnsignedNodeAnnouncement, mut val: crate::lightning::ln::features::NodeFeatures) { +pub extern "C" fn UnsignedNodeAnnouncement_set_features(this_ptr: &mut UnsignedNodeAnnouncement, mut val: crate::lightning_types::features::NodeFeatures) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) }; } /// A strictly monotonic announcement counter, with gaps allowed @@ -5964,6 +7680,66 @@ pub extern "C" fn UnsignedNodeAnnouncement_set_addresses(this_ptr: &mut Unsigned let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item.into_native() }); }; unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.addresses = local_val; } +/// Excess address data which was signed as a part of the message which we do not (yet) understand how +/// to decode. +/// +/// This is stored to ensure forward-compatibility as new address types are added to the lightning gossip protocol. +/// +/// Returns a copy of the field. +#[no_mangle] +pub extern "C" fn UnsignedNodeAnnouncement_get_excess_address_data(this_ptr: &UnsignedNodeAnnouncement) -> crate::c_types::derived::CVec_u8Z { + let mut inner_val = this_ptr.get_native_mut_ref().excess_address_data.clone(); + let mut local_inner_val = Vec::new(); for mut item in inner_val.drain(..) { local_inner_val.push( { item }); }; + local_inner_val.into() +} +/// Excess address data which was signed as a part of the message which we do not (yet) understand how +/// to decode. +/// +/// This is stored to ensure forward-compatibility as new address types are added to the lightning gossip protocol. +#[no_mangle] +pub extern "C" fn UnsignedNodeAnnouncement_set_excess_address_data(this_ptr: &mut UnsignedNodeAnnouncement, mut val: crate::c_types::derived::CVec_u8Z) { + let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); }; + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.excess_address_data = local_val; +} +/// Excess data which was signed as a part of the message which we do not (yet) understand how +/// to decode. +/// +/// This is stored to ensure forward-compatibility as new fields are added to the lightning gossip protocol. +/// +/// Returns a copy of the field. +#[no_mangle] +pub extern "C" fn UnsignedNodeAnnouncement_get_excess_data(this_ptr: &UnsignedNodeAnnouncement) -> crate::c_types::derived::CVec_u8Z { + let mut inner_val = this_ptr.get_native_mut_ref().excess_data.clone(); + let mut local_inner_val = Vec::new(); for mut item in inner_val.drain(..) { local_inner_val.push( { item }); }; + local_inner_val.into() +} +/// Excess data which was signed as a part of the message which we do not (yet) understand how +/// to decode. +/// +/// This is stored to ensure forward-compatibility as new fields are added to the lightning gossip protocol. +#[no_mangle] +pub extern "C" fn UnsignedNodeAnnouncement_set_excess_data(this_ptr: &mut UnsignedNodeAnnouncement, mut val: crate::c_types::derived::CVec_u8Z) { + let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); }; + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.excess_data = local_val; +} +/// Constructs a new UnsignedNodeAnnouncement given each field +#[must_use] +#[no_mangle] +pub extern "C" fn UnsignedNodeAnnouncement_new(mut features_arg: crate::lightning_types::features::NodeFeatures, mut timestamp_arg: u32, mut node_id_arg: crate::lightning::routing::gossip::NodeId, mut rgb_arg: crate::c_types::ThreeBytes, mut alias_arg: crate::lightning::routing::gossip::NodeAlias, mut addresses_arg: crate::c_types::derived::CVec_SocketAddressZ, mut excess_address_data_arg: crate::c_types::derived::CVec_u8Z, mut excess_data_arg: crate::c_types::derived::CVec_u8Z) -> UnsignedNodeAnnouncement { + let mut local_addresses_arg = Vec::new(); for mut item in addresses_arg.into_rust().drain(..) { local_addresses_arg.push( { item.into_native() }); }; + let mut local_excess_address_data_arg = Vec::new(); for mut item in excess_address_data_arg.into_rust().drain(..) { local_excess_address_data_arg.push( { item }); }; + let mut local_excess_data_arg = Vec::new(); for mut item in excess_data_arg.into_rust().drain(..) { local_excess_data_arg.push( { item }); }; + UnsignedNodeAnnouncement { inner: ObjOps::heap_alloc(nativeUnsignedNodeAnnouncement { + features: *unsafe { Box::from_raw(features_arg.take_inner()) }, + timestamp: timestamp_arg, + node_id: *unsafe { Box::from_raw(node_id_arg.take_inner()) }, + rgb: rgb_arg.data, + alias: *unsafe { Box::from_raw(alias_arg.take_inner()) }, + addresses: local_addresses_arg, + excess_address_data: local_excess_address_data_arg, + excess_data: local_excess_data_arg, + }), is_owned: true } +} impl Clone for UnsignedNodeAnnouncement { fn clone(&self) -> Self { Self { @@ -5976,13 +7752,26 @@ impl Clone for UnsignedNodeAnnouncement { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn UnsignedNodeAnnouncement_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUnsignedNodeAnnouncement)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeUnsignedNodeAnnouncement)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the UnsignedNodeAnnouncement pub extern "C" fn UnsignedNodeAnnouncement_clone(orig: &UnsignedNodeAnnouncement) -> UnsignedNodeAnnouncement { orig.clone() } +/// Get a string which allows debug introspection of a UnsignedNodeAnnouncement object +pub extern "C" fn UnsignedNodeAnnouncement_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::UnsignedNodeAnnouncement }).into()} +/// Generates a non-cryptographic 64-bit hash of the UnsignedNodeAnnouncement. +#[no_mangle] +pub extern "C" fn UnsignedNodeAnnouncement_hash(o: &UnsignedNodeAnnouncement) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two UnsignedNodeAnnouncements 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. @@ -6014,6 +7803,12 @@ pub struct NodeAnnouncement { pub is_owned: bool, } +impl core::ops::Deref for NodeAnnouncement { + type Target = nativeNodeAnnouncement; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for NodeAnnouncement { } +unsafe impl core::marker::Sync for NodeAnnouncement { } impl Drop for NodeAnnouncement { fn drop(&mut self) { if self.is_owned && !<*mut nativeNodeAnnouncement>::is_null(self.inner) { @@ -6044,6 +7839,9 @@ impl NodeAnnouncement { self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// The signature by the node key #[no_mangle] @@ -6088,13 +7886,26 @@ impl Clone for NodeAnnouncement { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn NodeAnnouncement_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeNodeAnnouncement)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeNodeAnnouncement)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the NodeAnnouncement pub extern "C" fn NodeAnnouncement_clone(orig: &NodeAnnouncement) -> NodeAnnouncement { orig.clone() } +/// Get a string which allows debug introspection of a NodeAnnouncement object +pub extern "C" fn NodeAnnouncement_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::NodeAnnouncement }).into()} +/// Generates a non-cryptographic 64-bit hash of the NodeAnnouncement. +#[no_mangle] +pub extern "C" fn NodeAnnouncement_hash(o: &NodeAnnouncement) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two NodeAnnouncements 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. @@ -6126,6 +7937,12 @@ pub struct UnsignedChannelAnnouncement { pub is_owned: bool, } +impl core::ops::Deref for UnsignedChannelAnnouncement { + type Target = nativeUnsignedChannelAnnouncement; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for UnsignedChannelAnnouncement { } +unsafe impl core::marker::Sync for UnsignedChannelAnnouncement { } impl Drop for UnsignedChannelAnnouncement { fn drop(&mut self) { if self.is_owned && !<*mut nativeUnsignedChannelAnnouncement>::is_null(self.inner) { @@ -6156,28 +7973,31 @@ impl UnsignedChannelAnnouncement { self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// The advertised channel features #[no_mangle] -pub extern "C" fn UnsignedChannelAnnouncement_get_features(this_ptr: &UnsignedChannelAnnouncement) -> crate::lightning::ln::features::ChannelFeatures { +pub extern "C" fn UnsignedChannelAnnouncement_get_features(this_ptr: &UnsignedChannelAnnouncement) -> crate::lightning_types::features::ChannelFeatures { let mut inner_val = &mut this_ptr.get_native_mut_ref().features; - crate::lightning::ln::features::ChannelFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning::ln::features::ChannelFeatures<>) as *mut _) }, is_owned: false } + crate::lightning_types::features::ChannelFeatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((inner_val as *const lightning_types::features::ChannelFeatures<>) as *mut _) }, is_owned: false } } /// The advertised channel features #[no_mangle] -pub extern "C" fn UnsignedChannelAnnouncement_set_features(this_ptr: &mut UnsignedChannelAnnouncement, mut val: crate::lightning::ln::features::ChannelFeatures) { +pub extern "C" fn UnsignedChannelAnnouncement_set_features(this_ptr: &mut UnsignedChannelAnnouncement, mut val: crate::lightning_types::features::ChannelFeatures) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.features = *unsafe { Box::from_raw(val.take_inner()) }; } /// The genesis hash of the blockchain where the channel is to be opened #[no_mangle] pub extern "C" fn UnsignedChannelAnnouncement_get_chain_hash(this_ptr: &UnsignedChannelAnnouncement) -> *const [u8; 32] { let mut inner_val = &mut this_ptr.get_native_mut_ref().chain_hash; - inner_val.as_inner() + inner_val.as_ref() } /// The genesis hash of the blockchain where the channel is to be opened #[no_mangle] pub extern "C" fn UnsignedChannelAnnouncement_set_chain_hash(this_ptr: &mut UnsignedChannelAnnouncement, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_hash = ::bitcoin::hash_types::BlockHash::from_slice(&val.data[..]).unwrap(); + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_hash = ::bitcoin::constants::ChainHash::from(&val.data); } /// The short channel ID #[no_mangle] @@ -6258,11 +8078,11 @@ pub extern "C" fn UnsignedChannelAnnouncement_set_excess_data(this_ptr: &mut Uns /// Constructs a new UnsignedChannelAnnouncement given each field #[must_use] #[no_mangle] -pub extern "C" fn UnsignedChannelAnnouncement_new(mut features_arg: crate::lightning::ln::features::ChannelFeatures, mut chain_hash_arg: crate::c_types::ThirtyTwoBytes, mut short_channel_id_arg: u64, mut node_id_1_arg: crate::lightning::routing::gossip::NodeId, mut node_id_2_arg: crate::lightning::routing::gossip::NodeId, mut bitcoin_key_1_arg: crate::lightning::routing::gossip::NodeId, mut bitcoin_key_2_arg: crate::lightning::routing::gossip::NodeId, mut excess_data_arg: crate::c_types::derived::CVec_u8Z) -> UnsignedChannelAnnouncement { +pub extern "C" fn UnsignedChannelAnnouncement_new(mut features_arg: crate::lightning_types::features::ChannelFeatures, mut chain_hash_arg: crate::c_types::ThirtyTwoBytes, mut short_channel_id_arg: u64, mut node_id_1_arg: crate::lightning::routing::gossip::NodeId, mut node_id_2_arg: crate::lightning::routing::gossip::NodeId, mut bitcoin_key_1_arg: crate::lightning::routing::gossip::NodeId, mut bitcoin_key_2_arg: crate::lightning::routing::gossip::NodeId, mut excess_data_arg: crate::c_types::derived::CVec_u8Z) -> UnsignedChannelAnnouncement { let mut local_excess_data_arg = Vec::new(); for mut item in excess_data_arg.into_rust().drain(..) { local_excess_data_arg.push( { item }); }; UnsignedChannelAnnouncement { inner: ObjOps::heap_alloc(nativeUnsignedChannelAnnouncement { features: *unsafe { Box::from_raw(features_arg.take_inner()) }, - chain_hash: ::bitcoin::hash_types::BlockHash::from_slice(&chain_hash_arg.data[..]).unwrap(), + chain_hash: ::bitcoin::constants::ChainHash::from(&chain_hash_arg.data), short_channel_id: short_channel_id_arg, node_id_1: *unsafe { Box::from_raw(node_id_1_arg.take_inner()) }, node_id_2: *unsafe { Box::from_raw(node_id_2_arg.take_inner()) }, @@ -6283,13 +8103,26 @@ impl Clone for UnsignedChannelAnnouncement { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn UnsignedChannelAnnouncement_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUnsignedChannelAnnouncement)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeUnsignedChannelAnnouncement)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the UnsignedChannelAnnouncement pub extern "C" fn UnsignedChannelAnnouncement_clone(orig: &UnsignedChannelAnnouncement) -> UnsignedChannelAnnouncement { orig.clone() } +/// Get a string which allows debug introspection of a UnsignedChannelAnnouncement object +pub extern "C" fn UnsignedChannelAnnouncement_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::UnsignedChannelAnnouncement }).into()} +/// Generates a non-cryptographic 64-bit hash of the UnsignedChannelAnnouncement. +#[no_mangle] +pub extern "C" fn UnsignedChannelAnnouncement_hash(o: &UnsignedChannelAnnouncement) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two UnsignedChannelAnnouncements 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. @@ -6321,6 +8154,12 @@ pub struct ChannelAnnouncement { pub is_owned: bool, } +impl core::ops::Deref for ChannelAnnouncement { + type Target = nativeChannelAnnouncement; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for ChannelAnnouncement { } +unsafe impl core::marker::Sync for ChannelAnnouncement { } impl Drop for ChannelAnnouncement { fn drop(&mut self) { if self.is_owned && !<*mut nativeChannelAnnouncement>::is_null(self.inner) { @@ -6351,6 +8190,9 @@ impl ChannelAnnouncement { self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// Authentication of the announcement by the first public node #[no_mangle] @@ -6431,13 +8273,26 @@ impl Clone for ChannelAnnouncement { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ChannelAnnouncement_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelAnnouncement)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelAnnouncement)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ChannelAnnouncement pub extern "C" fn ChannelAnnouncement_clone(orig: &ChannelAnnouncement) -> ChannelAnnouncement { orig.clone() } +/// Get a string which allows debug introspection of a ChannelAnnouncement object +pub extern "C" fn ChannelAnnouncement_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::ChannelAnnouncement }).into()} +/// Generates a non-cryptographic 64-bit hash of the ChannelAnnouncement. +#[no_mangle] +pub extern "C" fn ChannelAnnouncement_hash(o: &ChannelAnnouncement) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two ChannelAnnouncements 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. @@ -6469,6 +8324,12 @@ pub struct UnsignedChannelUpdate { pub is_owned: bool, } +impl core::ops::Deref for UnsignedChannelUpdate { + type Target = nativeUnsignedChannelUpdate; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for UnsignedChannelUpdate { } +unsafe impl core::marker::Sync for UnsignedChannelUpdate { } impl Drop for UnsignedChannelUpdate { fn drop(&mut self) { if self.is_owned && !<*mut nativeUnsignedChannelUpdate>::is_null(self.inner) { @@ -6499,17 +8360,20 @@ impl UnsignedChannelUpdate { self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// The genesis hash of the blockchain where the channel is to be opened #[no_mangle] pub extern "C" fn UnsignedChannelUpdate_get_chain_hash(this_ptr: &UnsignedChannelUpdate) -> *const [u8; 32] { let mut inner_val = &mut this_ptr.get_native_mut_ref().chain_hash; - inner_val.as_inner() + inner_val.as_ref() } /// The genesis hash of the blockchain where the channel is to be opened #[no_mangle] pub extern "C" fn UnsignedChannelUpdate_set_chain_hash(this_ptr: &mut UnsignedChannelUpdate, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_hash = ::bitcoin::hash_types::BlockHash::from_slice(&val.data[..]).unwrap(); + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_hash = ::bitcoin::constants::ChainHash::from(&val.data); } /// The short channel ID #[no_mangle] @@ -6533,16 +8397,29 @@ pub extern "C" fn UnsignedChannelUpdate_get_timestamp(this_ptr: &UnsignedChannel pub extern "C" fn UnsignedChannelUpdate_set_timestamp(this_ptr: &mut UnsignedChannelUpdate, mut val: u32) { unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.timestamp = val; } -/// Channel flags +/// Flags pertaining to this message. +#[no_mangle] +pub extern "C" fn UnsignedChannelUpdate_get_message_flags(this_ptr: &UnsignedChannelUpdate) -> u8 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().message_flags; + *inner_val +} +/// Flags pertaining to this message. +#[no_mangle] +pub extern "C" fn UnsignedChannelUpdate_set_message_flags(this_ptr: &mut UnsignedChannelUpdate, mut val: u8) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.message_flags = val; +} +/// Flags pertaining to the channel, including to which direction in the channel this update +/// applies and whether the direction is currently able to forward HTLCs. #[no_mangle] -pub extern "C" fn UnsignedChannelUpdate_get_flags(this_ptr: &UnsignedChannelUpdate) -> u8 { - let mut inner_val = &mut this_ptr.get_native_mut_ref().flags; +pub extern "C" fn UnsignedChannelUpdate_get_channel_flags(this_ptr: &UnsignedChannelUpdate) -> u8 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().channel_flags; *inner_val } -/// Channel flags +/// Flags pertaining to the channel, including to which direction in the channel this update +/// applies and whether the direction is currently able to forward HTLCs. #[no_mangle] -pub extern "C" fn UnsignedChannelUpdate_set_flags(this_ptr: &mut UnsignedChannelUpdate, mut val: u8) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.flags = val; +pub extern "C" fn UnsignedChannelUpdate_set_channel_flags(this_ptr: &mut UnsignedChannelUpdate, mut val: u8) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.channel_flags = val; } /// The number of blocks such that if: /// `incoming_htlc.cltv_expiry < outgoing_htlc.cltv_expiry + cltv_expiry_delta` @@ -6641,13 +8518,14 @@ pub extern "C" fn UnsignedChannelUpdate_set_excess_data(this_ptr: &mut UnsignedC /// Constructs a new UnsignedChannelUpdate given each field #[must_use] #[no_mangle] -pub extern "C" fn UnsignedChannelUpdate_new(mut chain_hash_arg: crate::c_types::ThirtyTwoBytes, mut short_channel_id_arg: u64, mut timestamp_arg: u32, mut flags_arg: u8, mut cltv_expiry_delta_arg: u16, mut htlc_minimum_msat_arg: u64, mut htlc_maximum_msat_arg: u64, mut fee_base_msat_arg: u32, mut fee_proportional_millionths_arg: u32, mut excess_data_arg: crate::c_types::derived::CVec_u8Z) -> UnsignedChannelUpdate { +pub extern "C" fn UnsignedChannelUpdate_new(mut chain_hash_arg: crate::c_types::ThirtyTwoBytes, mut short_channel_id_arg: u64, mut timestamp_arg: u32, mut message_flags_arg: u8, mut channel_flags_arg: u8, mut cltv_expiry_delta_arg: u16, mut htlc_minimum_msat_arg: u64, mut htlc_maximum_msat_arg: u64, mut fee_base_msat_arg: u32, mut fee_proportional_millionths_arg: u32, mut excess_data_arg: crate::c_types::derived::CVec_u8Z) -> UnsignedChannelUpdate { let mut local_excess_data_arg = Vec::new(); for mut item in excess_data_arg.into_rust().drain(..) { local_excess_data_arg.push( { item }); }; UnsignedChannelUpdate { inner: ObjOps::heap_alloc(nativeUnsignedChannelUpdate { - chain_hash: ::bitcoin::hash_types::BlockHash::from_slice(&chain_hash_arg.data[..]).unwrap(), + chain_hash: ::bitcoin::constants::ChainHash::from(&chain_hash_arg.data), short_channel_id: short_channel_id_arg, timestamp: timestamp_arg, - flags: flags_arg, + message_flags: message_flags_arg, + channel_flags: channel_flags_arg, cltv_expiry_delta: cltv_expiry_delta_arg, htlc_minimum_msat: htlc_minimum_msat_arg, htlc_maximum_msat: htlc_maximum_msat_arg, @@ -6668,13 +8546,26 @@ impl Clone for UnsignedChannelUpdate { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn UnsignedChannelUpdate_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeUnsignedChannelUpdate)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeUnsignedChannelUpdate)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the UnsignedChannelUpdate pub extern "C" fn UnsignedChannelUpdate_clone(orig: &UnsignedChannelUpdate) -> UnsignedChannelUpdate { orig.clone() } +/// Get a string which allows debug introspection of a UnsignedChannelUpdate object +pub extern "C" fn UnsignedChannelUpdate_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::UnsignedChannelUpdate }).into()} +/// Generates a non-cryptographic 64-bit hash of the UnsignedChannelUpdate. +#[no_mangle] +pub extern "C" fn UnsignedChannelUpdate_hash(o: &UnsignedChannelUpdate) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two UnsignedChannelUpdates 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. @@ -6706,6 +8597,12 @@ pub struct ChannelUpdate { pub is_owned: bool, } +impl core::ops::Deref for ChannelUpdate { + type Target = nativeChannelUpdate; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for ChannelUpdate { } +unsafe impl core::marker::Sync for ChannelUpdate { } impl Drop for ChannelUpdate { fn drop(&mut self) { if self.is_owned && !<*mut nativeChannelUpdate>::is_null(self.inner) { @@ -6736,6 +8633,9 @@ impl ChannelUpdate { self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// A signature of the channel update #[no_mangle] @@ -6780,13 +8680,26 @@ impl Clone for ChannelUpdate { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ChannelUpdate_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeChannelUpdate)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeChannelUpdate)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ChannelUpdate pub extern "C" fn ChannelUpdate_clone(orig: &ChannelUpdate) -> ChannelUpdate { orig.clone() } +/// Get a string which allows debug introspection of a ChannelUpdate object +pub extern "C" fn ChannelUpdate_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::ChannelUpdate }).into()} +/// Generates a non-cryptographic 64-bit hash of the ChannelUpdate. +#[no_mangle] +pub extern "C" fn ChannelUpdate_hash(o: &ChannelUpdate) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two ChannelUpdates 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. @@ -6821,6 +8734,12 @@ pub struct QueryChannelRange { pub is_owned: bool, } +impl core::ops::Deref for QueryChannelRange { + type Target = nativeQueryChannelRange; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for QueryChannelRange { } +unsafe impl core::marker::Sync for QueryChannelRange { } impl Drop for QueryChannelRange { fn drop(&mut self) { if self.is_owned && !<*mut nativeQueryChannelRange>::is_null(self.inner) { @@ -6851,17 +8770,20 @@ impl QueryChannelRange { self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// The genesis hash of the blockchain being queried #[no_mangle] pub extern "C" fn QueryChannelRange_get_chain_hash(this_ptr: &QueryChannelRange) -> *const [u8; 32] { let mut inner_val = &mut this_ptr.get_native_mut_ref().chain_hash; - inner_val.as_inner() + inner_val.as_ref() } /// The genesis hash of the blockchain being queried #[no_mangle] pub extern "C" fn QueryChannelRange_set_chain_hash(this_ptr: &mut QueryChannelRange, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_hash = ::bitcoin::hash_types::BlockHash::from_slice(&val.data[..]).unwrap(); + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_hash = ::bitcoin::constants::ChainHash::from(&val.data); } /// The height of the first block for the channel UTXOs being queried #[no_mangle] @@ -6890,7 +8812,7 @@ pub extern "C" fn QueryChannelRange_set_number_of_blocks(this_ptr: &mut QueryCha #[no_mangle] pub extern "C" fn QueryChannelRange_new(mut chain_hash_arg: crate::c_types::ThirtyTwoBytes, mut first_blocknum_arg: u32, mut number_of_blocks_arg: u32) -> QueryChannelRange { QueryChannelRange { inner: ObjOps::heap_alloc(nativeQueryChannelRange { - chain_hash: ::bitcoin::hash_types::BlockHash::from_slice(&chain_hash_arg.data[..]).unwrap(), + chain_hash: ::bitcoin::constants::ChainHash::from(&chain_hash_arg.data), first_blocknum: first_blocknum_arg, number_of_blocks: number_of_blocks_arg, }), is_owned: true } @@ -6907,13 +8829,26 @@ impl Clone for QueryChannelRange { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn QueryChannelRange_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeQueryChannelRange)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeQueryChannelRange)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the QueryChannelRange pub extern "C" fn QueryChannelRange_clone(orig: &QueryChannelRange) -> QueryChannelRange { orig.clone() } +/// Get a string which allows debug introspection of a QueryChannelRange object +pub extern "C" fn QueryChannelRange_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::QueryChannelRange }).into()} +/// Generates a non-cryptographic 64-bit hash of the QueryChannelRange. +#[no_mangle] +pub extern "C" fn QueryChannelRange_hash(o: &QueryChannelRange) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two QueryChannelRanges 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. @@ -6953,6 +8888,12 @@ pub struct ReplyChannelRange { pub is_owned: bool, } +impl core::ops::Deref for ReplyChannelRange { + type Target = nativeReplyChannelRange; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for ReplyChannelRange { } +unsafe impl core::marker::Sync for ReplyChannelRange { } impl Drop for ReplyChannelRange { fn drop(&mut self) { if self.is_owned && !<*mut nativeReplyChannelRange>::is_null(self.inner) { @@ -6983,17 +8924,20 @@ impl ReplyChannelRange { self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// The genesis hash of the blockchain being queried #[no_mangle] pub extern "C" fn ReplyChannelRange_get_chain_hash(this_ptr: &ReplyChannelRange) -> *const [u8; 32] { let mut inner_val = &mut this_ptr.get_native_mut_ref().chain_hash; - inner_val.as_inner() + inner_val.as_ref() } /// The genesis hash of the blockchain being queried #[no_mangle] pub extern "C" fn ReplyChannelRange_set_chain_hash(this_ptr: &mut ReplyChannelRange, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_hash = ::bitcoin::hash_types::BlockHash::from_slice(&val.data[..]).unwrap(); + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_hash = ::bitcoin::constants::ChainHash::from(&val.data); } /// The height of the first block in the range of the reply #[no_mangle] @@ -7049,7 +8993,7 @@ pub extern "C" fn ReplyChannelRange_set_short_channel_ids(this_ptr: &mut ReplyCh pub extern "C" fn ReplyChannelRange_new(mut chain_hash_arg: crate::c_types::ThirtyTwoBytes, mut first_blocknum_arg: u32, mut number_of_blocks_arg: u32, mut sync_complete_arg: bool, mut short_channel_ids_arg: crate::c_types::derived::CVec_u64Z) -> ReplyChannelRange { let mut local_short_channel_ids_arg = Vec::new(); for mut item in short_channel_ids_arg.into_rust().drain(..) { local_short_channel_ids_arg.push( { item }); }; ReplyChannelRange { inner: ObjOps::heap_alloc(nativeReplyChannelRange { - chain_hash: ::bitcoin::hash_types::BlockHash::from_slice(&chain_hash_arg.data[..]).unwrap(), + chain_hash: ::bitcoin::constants::ChainHash::from(&chain_hash_arg.data), first_blocknum: first_blocknum_arg, number_of_blocks: number_of_blocks_arg, sync_complete: sync_complete_arg, @@ -7068,13 +9012,26 @@ impl Clone for ReplyChannelRange { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ReplyChannelRange_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeReplyChannelRange)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeReplyChannelRange)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ReplyChannelRange pub extern "C" fn ReplyChannelRange_clone(orig: &ReplyChannelRange) -> ReplyChannelRange { orig.clone() } +/// Get a string which allows debug introspection of a ReplyChannelRange object +pub extern "C" fn ReplyChannelRange_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::ReplyChannelRange }).into()} +/// Generates a non-cryptographic 64-bit hash of the ReplyChannelRange. +#[no_mangle] +pub extern "C" fn ReplyChannelRange_hash(o: &ReplyChannelRange) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two ReplyChannelRanges 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. @@ -7114,6 +9071,12 @@ pub struct QueryShortChannelIds { pub is_owned: bool, } +impl core::ops::Deref for QueryShortChannelIds { + type Target = nativeQueryShortChannelIds; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for QueryShortChannelIds { } +unsafe impl core::marker::Sync for QueryShortChannelIds { } impl Drop for QueryShortChannelIds { fn drop(&mut self) { if self.is_owned && !<*mut nativeQueryShortChannelIds>::is_null(self.inner) { @@ -7144,17 +9107,20 @@ impl QueryShortChannelIds { self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// The genesis hash of the blockchain being queried #[no_mangle] pub extern "C" fn QueryShortChannelIds_get_chain_hash(this_ptr: &QueryShortChannelIds) -> *const [u8; 32] { let mut inner_val = &mut this_ptr.get_native_mut_ref().chain_hash; - inner_val.as_inner() + inner_val.as_ref() } /// The genesis hash of the blockchain being queried #[no_mangle] pub extern "C" fn QueryShortChannelIds_set_chain_hash(this_ptr: &mut QueryShortChannelIds, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_hash = ::bitcoin::hash_types::BlockHash::from_slice(&val.data[..]).unwrap(); + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_hash = ::bitcoin::constants::ChainHash::from(&val.data); } /// The short_channel_ids that are being queried /// @@ -7177,7 +9143,7 @@ pub extern "C" fn QueryShortChannelIds_set_short_channel_ids(this_ptr: &mut Quer pub extern "C" fn QueryShortChannelIds_new(mut chain_hash_arg: crate::c_types::ThirtyTwoBytes, mut short_channel_ids_arg: crate::c_types::derived::CVec_u64Z) -> QueryShortChannelIds { let mut local_short_channel_ids_arg = Vec::new(); for mut item in short_channel_ids_arg.into_rust().drain(..) { local_short_channel_ids_arg.push( { item }); }; QueryShortChannelIds { inner: ObjOps::heap_alloc(nativeQueryShortChannelIds { - chain_hash: ::bitcoin::hash_types::BlockHash::from_slice(&chain_hash_arg.data[..]).unwrap(), + chain_hash: ::bitcoin::constants::ChainHash::from(&chain_hash_arg.data), short_channel_ids: local_short_channel_ids_arg, }), is_owned: true } } @@ -7193,13 +9159,26 @@ impl Clone for QueryShortChannelIds { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn QueryShortChannelIds_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeQueryShortChannelIds)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeQueryShortChannelIds)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the QueryShortChannelIds pub extern "C" fn QueryShortChannelIds_clone(orig: &QueryShortChannelIds) -> QueryShortChannelIds { orig.clone() } +/// Get a string which allows debug introspection of a QueryShortChannelIds object +pub extern "C" fn QueryShortChannelIds_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::QueryShortChannelIds }).into()} +/// Generates a non-cryptographic 64-bit hash of the QueryShortChannelIds. +#[no_mangle] +pub extern "C" fn QueryShortChannelIds_hash(o: &QueryShortChannelIds) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two QueryShortChannelIdss 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. @@ -7234,6 +9213,12 @@ pub struct ReplyShortChannelIdsEnd { pub is_owned: bool, } +impl core::ops::Deref for ReplyShortChannelIdsEnd { + type Target = nativeReplyShortChannelIdsEnd; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for ReplyShortChannelIdsEnd { } +unsafe impl core::marker::Sync for ReplyShortChannelIdsEnd { } impl Drop for ReplyShortChannelIdsEnd { fn drop(&mut self) { if self.is_owned && !<*mut nativeReplyShortChannelIdsEnd>::is_null(self.inner) { @@ -7264,17 +9249,20 @@ impl ReplyShortChannelIdsEnd { self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// The genesis hash of the blockchain that was queried #[no_mangle] pub extern "C" fn ReplyShortChannelIdsEnd_get_chain_hash(this_ptr: &ReplyShortChannelIdsEnd) -> *const [u8; 32] { let mut inner_val = &mut this_ptr.get_native_mut_ref().chain_hash; - inner_val.as_inner() + inner_val.as_ref() } /// The genesis hash of the blockchain that was queried #[no_mangle] pub extern "C" fn ReplyShortChannelIdsEnd_set_chain_hash(this_ptr: &mut ReplyShortChannelIdsEnd, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_hash = ::bitcoin::hash_types::BlockHash::from_slice(&val.data[..]).unwrap(); + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_hash = ::bitcoin::constants::ChainHash::from(&val.data); } /// Indicates if the query recipient maintains up-to-date channel /// information for the `chain_hash` @@ -7294,7 +9282,7 @@ pub extern "C" fn ReplyShortChannelIdsEnd_set_full_information(this_ptr: &mut Re #[no_mangle] pub extern "C" fn ReplyShortChannelIdsEnd_new(mut chain_hash_arg: crate::c_types::ThirtyTwoBytes, mut full_information_arg: bool) -> ReplyShortChannelIdsEnd { ReplyShortChannelIdsEnd { inner: ObjOps::heap_alloc(nativeReplyShortChannelIdsEnd { - chain_hash: ::bitcoin::hash_types::BlockHash::from_slice(&chain_hash_arg.data[..]).unwrap(), + chain_hash: ::bitcoin::constants::ChainHash::from(&chain_hash_arg.data), full_information: full_information_arg, }), is_owned: true } } @@ -7310,13 +9298,26 @@ impl Clone for ReplyShortChannelIdsEnd { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn ReplyShortChannelIdsEnd_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeReplyShortChannelIdsEnd)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeReplyShortChannelIdsEnd)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the ReplyShortChannelIdsEnd pub extern "C" fn ReplyShortChannelIdsEnd_clone(orig: &ReplyShortChannelIdsEnd) -> ReplyShortChannelIdsEnd { orig.clone() } +/// Get a string which allows debug introspection of a ReplyShortChannelIdsEnd object +pub extern "C" fn ReplyShortChannelIdsEnd_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::ReplyShortChannelIdsEnd }).into()} +/// Generates a non-cryptographic 64-bit hash of the ReplyShortChannelIdsEnd. +#[no_mangle] +pub extern "C" fn ReplyShortChannelIdsEnd_hash(o: &ReplyShortChannelIdsEnd) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two ReplyShortChannelIdsEnds 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. @@ -7350,6 +9351,12 @@ pub struct GossipTimestampFilter { pub is_owned: bool, } +impl core::ops::Deref for GossipTimestampFilter { + type Target = nativeGossipTimestampFilter; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for GossipTimestampFilter { } +unsafe impl core::marker::Sync for GossipTimestampFilter { } impl Drop for GossipTimestampFilter { fn drop(&mut self) { if self.is_owned && !<*mut nativeGossipTimestampFilter>::is_null(self.inner) { @@ -7380,17 +9387,20 @@ impl GossipTimestampFilter { self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// The genesis hash of the blockchain for channel and node information #[no_mangle] pub extern "C" fn GossipTimestampFilter_get_chain_hash(this_ptr: &GossipTimestampFilter) -> *const [u8; 32] { let mut inner_val = &mut this_ptr.get_native_mut_ref().chain_hash; - inner_val.as_inner() + inner_val.as_ref() } /// The genesis hash of the blockchain for channel and node information #[no_mangle] pub extern "C" fn GossipTimestampFilter_set_chain_hash(this_ptr: &mut GossipTimestampFilter, mut val: crate::c_types::ThirtyTwoBytes) { - unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_hash = ::bitcoin::hash_types::BlockHash::from_slice(&val.data[..]).unwrap(); + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.chain_hash = ::bitcoin::constants::ChainHash::from(&val.data); } /// The starting unix timestamp #[no_mangle] @@ -7419,7 +9429,7 @@ pub extern "C" fn GossipTimestampFilter_set_timestamp_range(this_ptr: &mut Gossi #[no_mangle] pub extern "C" fn GossipTimestampFilter_new(mut chain_hash_arg: crate::c_types::ThirtyTwoBytes, mut first_timestamp_arg: u32, mut timestamp_range_arg: u32) -> GossipTimestampFilter { GossipTimestampFilter { inner: ObjOps::heap_alloc(nativeGossipTimestampFilter { - chain_hash: ::bitcoin::hash_types::BlockHash::from_slice(&chain_hash_arg.data[..]).unwrap(), + chain_hash: ::bitcoin::constants::ChainHash::from(&chain_hash_arg.data), first_timestamp: first_timestamp_arg, timestamp_range: timestamp_range_arg, }), is_owned: true } @@ -7436,13 +9446,26 @@ impl Clone for GossipTimestampFilter { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn GossipTimestampFilter_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeGossipTimestampFilter)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeGossipTimestampFilter)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the GossipTimestampFilter pub extern "C" fn GossipTimestampFilter_clone(orig: &GossipTimestampFilter) -> GossipTimestampFilter { orig.clone() } +/// Get a string which allows debug introspection of a GossipTimestampFilter object +pub extern "C" fn GossipTimestampFilter_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::GossipTimestampFilter }).into()} +/// Generates a non-cryptographic 64-bit hash of the GossipTimestampFilter. +#[no_mangle] +pub extern "C" fn GossipTimestampFilter_hash(o: &GossipTimestampFilter) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two GossipTimestampFilters 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. @@ -7573,7 +9596,8 @@ impl ErrorAction { } } #[allow(unused)] - pub(crate) fn from_native(native: &nativeErrorAction) -> Self { + pub(crate) fn from_native(native: &ErrorActionImport) -> Self { + let native = unsafe { &*(native as *const _ as *const c_void as *const nativeErrorAction) }; match native { nativeErrorAction::DisconnectPeer {ref msg, } => { let mut msg_nonref = Clone::clone(msg); @@ -7655,6 +9679,16 @@ pub extern "C" fn ErrorAction_free(this_ptr: ErrorAction) { } pub extern "C" fn ErrorAction_clone(orig: &ErrorAction) -> ErrorAction { orig.clone() } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn ErrorAction_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const ErrorAction)).clone() })) as *mut c_void +} +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn ErrorAction_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut ErrorAction) }; +} #[no_mangle] /// Utility method to constructs a new DisconnectPeer-variant ErrorAction pub extern "C" fn ErrorAction_disconnect_peer(msg: crate::lightning::ln::msgs::ErrorMessage) -> ErrorAction { @@ -7697,6 +9731,18 @@ pub extern "C" fn ErrorAction_send_warning_message(msg: crate::lightning::ln::ms log_level, } } +/// Get a string which allows debug introspection of a ErrorAction object +pub extern "C" fn ErrorAction_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::ErrorAction }).into()} +/// Generates a non-cryptographic 64-bit hash of the ErrorAction. +#[no_mangle] +pub extern "C" fn ErrorAction_hash(o: &ErrorAction) -> u64 { + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(&o.to_native(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} use lightning::ln::msgs::LightningError as nativeLightningErrorImport; pub(crate) type nativeLightningError = nativeLightningErrorImport; @@ -7717,6 +9763,12 @@ pub struct LightningError { pub is_owned: bool, } +impl core::ops::Deref for LightningError { + type Target = nativeLightningError; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for LightningError { } +unsafe impl core::marker::Sync for LightningError { } impl Drop for LightningError { fn drop(&mut self) { if self.is_owned && !<*mut nativeLightningError>::is_null(self.inner) { @@ -7747,6 +9799,9 @@ impl LightningError { self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// A human-readable message describing the error #[no_mangle] @@ -7791,13 +9846,16 @@ impl Clone for LightningError { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn LightningError_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeLightningError)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeLightningError)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the LightningError pub extern "C" fn LightningError_clone(orig: &LightningError) -> LightningError { orig.clone() } +/// Get a string which allows debug introspection of a LightningError object +pub extern "C" fn LightningError_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::LightningError }).into()} use lightning::ln::msgs::CommitmentUpdate as nativeCommitmentUpdateImport; pub(crate) type nativeCommitmentUpdate = nativeCommitmentUpdateImport; @@ -7819,6 +9877,12 @@ pub struct CommitmentUpdate { pub is_owned: bool, } +impl core::ops::Deref for CommitmentUpdate { + type Target = nativeCommitmentUpdate; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for CommitmentUpdate { } +unsafe impl core::marker::Sync for CommitmentUpdate { } impl Drop for CommitmentUpdate { fn drop(&mut self) { if self.is_owned && !<*mut nativeCommitmentUpdate>::is_null(self.inner) { @@ -7849,6 +9913,9 @@ impl CommitmentUpdate { self.inner = core::ptr::null_mut(); ret } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } } /// `update_add_htlc` messages which should be sent #[no_mangle] @@ -7962,13 +10029,26 @@ impl Clone for CommitmentUpdate { #[allow(unused)] /// Used only if an object of this type is returned as a trait impl by a method pub(crate) extern "C" fn CommitmentUpdate_clone_void(this_ptr: *const c_void) -> *mut c_void { - Box::into_raw(Box::new(unsafe { (*(this_ptr as *mut nativeCommitmentUpdate)).clone() })) as *mut c_void + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeCommitmentUpdate)).clone() })) as *mut c_void } #[no_mangle] /// Creates a copy of the CommitmentUpdate pub extern "C" fn CommitmentUpdate_clone(orig: &CommitmentUpdate) -> CommitmentUpdate { orig.clone() } +/// Get a string which allows debug introspection of a CommitmentUpdate object +pub extern "C" fn CommitmentUpdate_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::CommitmentUpdate }).into()} +/// Generates a non-cryptographic 64-bit hash of the CommitmentUpdate. +#[no_mangle] +pub extern "C" fn CommitmentUpdate_hash(o: &CommitmentUpdate) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} /// Checks if two CommitmentUpdates 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. @@ -8005,6 +10085,8 @@ pub struct ChannelMessageHandler { pub handle_shutdown: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::Shutdown), /// Handle an incoming `closing_signed` message from the given peer. pub handle_closing_signed: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::ClosingSigned), + /// Handle an incoming `stfu` message from the given peer. + pub handle_stfu: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::Stfu), /// Handle an incoming `tx_add_input message` from the given peer. pub handle_tx_add_input: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::TxAddInput), /// Handle an incoming `tx_add_output` message from the given peer. @@ -8056,18 +10138,18 @@ pub struct ChannelMessageHandler { /// Gets the node feature flags which this handler itself supports. All available handlers are /// queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`] /// which are broadcasted in our [`NodeAnnouncement`] message. - pub provided_node_features: extern "C" fn (this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures, + pub provided_node_features: extern "C" fn (this_arg: *const c_void) -> crate::lightning_types::features::NodeFeatures, /// Gets the init feature flags which should be sent to the given peer. All available handlers /// are queried similarly and their feature flags are OR'd together to form the [`InitFeatures`] /// which are sent in our [`Init`] message. /// /// Note that this method is called before [`Self::peer_connected`]. - pub provided_init_features: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey) -> crate::lightning::ln::features::InitFeatures, - /// Gets the genesis hashes for this `ChannelMessageHandler` indicating which chains it supports. + pub provided_init_features: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey) -> crate::lightning_types::features::InitFeatures, + /// Gets the chain hashes for this `ChannelMessageHandler` indicating which chains it supports. /// /// If it's `None`, then no particular network chain hash compatibility will be enforced when /// connecting to peers. - pub get_genesis_hashes: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ, + pub get_chain_hashes: extern "C" fn (this_arg: *const c_void) -> crate::c_types::derived::COption_CVec_ThirtyTwoBytesZZ, /// Implementation of MessageSendEventsProvider for this object. pub MessageSendEventsProvider: crate::lightning::events::MessageSendEventsProvider, /// Frees any resources associated with this object given its this_arg pointer. @@ -8076,6 +10158,7 @@ pub struct ChannelMessageHandler { } unsafe impl Send for ChannelMessageHandler {} unsafe impl Sync for ChannelMessageHandler {} +#[allow(unused)] pub(crate) fn ChannelMessageHandler_clone_fields(orig: &ChannelMessageHandler) -> ChannelMessageHandler { ChannelMessageHandler { this_arg: orig.this_arg, @@ -8088,6 +10171,7 @@ pub(crate) fn ChannelMessageHandler_clone_fields(orig: &ChannelMessageHandler) - handle_channel_ready: Clone::clone(&orig.handle_channel_ready), handle_shutdown: Clone::clone(&orig.handle_shutdown), handle_closing_signed: Clone::clone(&orig.handle_closing_signed), + handle_stfu: Clone::clone(&orig.handle_stfu), handle_tx_add_input: Clone::clone(&orig.handle_tx_add_input), handle_tx_add_output: Clone::clone(&orig.handle_tx_add_output), handle_tx_remove_input: Clone::clone(&orig.handle_tx_remove_input), @@ -8112,7 +10196,7 @@ pub(crate) fn ChannelMessageHandler_clone_fields(orig: &ChannelMessageHandler) - handle_error: Clone::clone(&orig.handle_error), provided_node_features: Clone::clone(&orig.provided_node_features), provided_init_features: Clone::clone(&orig.provided_init_features), - get_genesis_hashes: Clone::clone(&orig.get_genesis_hashes), + get_chain_hashes: Clone::clone(&orig.get_chain_hashes), MessageSendEventsProvider: crate::lightning::events::MessageSendEventsProvider_clone_fields(&orig.MessageSendEventsProvider), free: Clone::clone(&orig.free), } @@ -8124,6 +10208,13 @@ impl lightning::events::MessageSendEventsProvider for ChannelMessageHandler { local_ret } } +impl lightning::events::MessageSendEventsProvider for ChannelMessageHandlerRef { + fn get_and_clear_pending_msg_events(&self) -> Vec { + let mut ret = (self.0.MessageSendEventsProvider.get_and_clear_pending_msg_events)(self.0.MessageSendEventsProvider.this_arg); + let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { item.into_native() }); }; + local_ret + } +} use lightning::ln::msgs::ChannelMessageHandler as rustChannelMessageHandler; impl rustChannelMessageHandler for ChannelMessageHandler { @@ -8154,6 +10245,9 @@ impl rustChannelMessageHandler for ChannelMessageHandler { fn handle_closing_signed(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::ClosingSigned) { (self.handle_closing_signed)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::ClosingSigned { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::ClosingSigned<>) as *mut _) }, is_owned: false }) } + fn handle_stfu(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::Stfu) { + (self.handle_stfu)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::Stfu { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::Stfu<>) as *mut _) }, is_owned: false }) + } fn handle_tx_add_input(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::TxAddInput) { (self.handle_tx_add_input)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::TxAddInput { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::TxAddInput<>) as *mut _) }, is_owned: false }) } @@ -8222,17 +10316,132 @@ impl rustChannelMessageHandler for ChannelMessageHandler { fn handle_error(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::ErrorMessage) { (self.handle_error)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::ErrorMessage { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::ErrorMessage<>) as *mut _) }, is_owned: false }) } - fn provided_node_features(&self) -> lightning::ln::features::NodeFeatures { + fn provided_node_features(&self) -> lightning_types::features::NodeFeatures { let mut ret = (self.provided_node_features)(self.this_arg); *unsafe { Box::from_raw(ret.take_inner()) } } - fn provided_init_features(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey) -> lightning::ln::features::InitFeatures { + fn provided_init_features(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey) -> lightning_types::features::InitFeatures { let mut ret = (self.provided_init_features)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id)); *unsafe { Box::from_raw(ret.take_inner()) } } - fn get_genesis_hashes(&self) -> Option> { - let mut ret = (self.get_genesis_hashes)(self.this_arg); - let mut local_ret = { /*ret*/ let ret_opt = ret; if ret_opt.is_none() { None } else { Some({ { let mut local_ret_0 = Vec::new(); for mut item in { ret_opt.take() }.into_rust().drain(..) { local_ret_0.push( { ::bitcoin::blockdata::constants::ChainHash::from(&item.data[..]) }); }; local_ret_0 }})} }; + fn get_chain_hashes(&self) -> Option> { + let mut ret = (self.get_chain_hashes)(self.this_arg); + let mut local_ret = { /*ret*/ let ret_opt = ret; if ret_opt.is_none() { None } else { Some({ { let mut local_ret_0 = Vec::new(); for mut item in { ret_opt.take() }.into_rust().drain(..) { local_ret_0.push( { ::bitcoin::constants::ChainHash::from(&item.data) }); }; local_ret_0 }})} }; + local_ret + } +} + +pub struct ChannelMessageHandlerRef(ChannelMessageHandler); +impl rustChannelMessageHandler for ChannelMessageHandlerRef { + fn handle_open_channel(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::OpenChannel) { + (self.0.handle_open_channel)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::OpenChannel { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::OpenChannel<>) as *mut _) }, is_owned: false }) + } + fn handle_open_channel_v2(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::OpenChannelV2) { + (self.0.handle_open_channel_v2)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::OpenChannelV2 { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::OpenChannelV2<>) as *mut _) }, is_owned: false }) + } + fn handle_accept_channel(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::AcceptChannel) { + (self.0.handle_accept_channel)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::AcceptChannel { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::AcceptChannel<>) as *mut _) }, is_owned: false }) + } + fn handle_accept_channel_v2(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::AcceptChannelV2) { + (self.0.handle_accept_channel_v2)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::AcceptChannelV2 { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::AcceptChannelV2<>) as *mut _) }, is_owned: false }) + } + fn handle_funding_created(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::FundingCreated) { + (self.0.handle_funding_created)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::FundingCreated { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::FundingCreated<>) as *mut _) }, is_owned: false }) + } + fn handle_funding_signed(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::FundingSigned) { + (self.0.handle_funding_signed)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::FundingSigned { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::FundingSigned<>) as *mut _) }, is_owned: false }) + } + fn handle_channel_ready(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::ChannelReady) { + (self.0.handle_channel_ready)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::ChannelReady { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::ChannelReady<>) as *mut _) }, is_owned: false }) + } + fn handle_shutdown(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::Shutdown) { + (self.0.handle_shutdown)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::Shutdown { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::Shutdown<>) as *mut _) }, is_owned: false }) + } + fn handle_closing_signed(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::ClosingSigned) { + (self.0.handle_closing_signed)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::ClosingSigned { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::ClosingSigned<>) as *mut _) }, is_owned: false }) + } + fn handle_stfu(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::Stfu) { + (self.0.handle_stfu)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::Stfu { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::Stfu<>) as *mut _) }, is_owned: false }) + } + fn handle_tx_add_input(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::TxAddInput) { + (self.0.handle_tx_add_input)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::TxAddInput { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::TxAddInput<>) as *mut _) }, is_owned: false }) + } + fn handle_tx_add_output(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::TxAddOutput) { + (self.0.handle_tx_add_output)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::TxAddOutput { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::TxAddOutput<>) as *mut _) }, is_owned: false }) + } + fn handle_tx_remove_input(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::TxRemoveInput) { + (self.0.handle_tx_remove_input)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::TxRemoveInput { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::TxRemoveInput<>) as *mut _) }, is_owned: false }) + } + fn handle_tx_remove_output(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::TxRemoveOutput) { + (self.0.handle_tx_remove_output)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::TxRemoveOutput { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::TxRemoveOutput<>) as *mut _) }, is_owned: false }) + } + fn handle_tx_complete(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::TxComplete) { + (self.0.handle_tx_complete)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::TxComplete { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::TxComplete<>) as *mut _) }, is_owned: false }) + } + fn handle_tx_signatures(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::TxSignatures) { + (self.0.handle_tx_signatures)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::TxSignatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::TxSignatures<>) as *mut _) }, is_owned: false }) + } + fn handle_tx_init_rbf(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::TxInitRbf) { + (self.0.handle_tx_init_rbf)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::TxInitRbf { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::TxInitRbf<>) as *mut _) }, is_owned: false }) + } + fn handle_tx_ack_rbf(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::TxAckRbf) { + (self.0.handle_tx_ack_rbf)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::TxAckRbf { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::TxAckRbf<>) as *mut _) }, is_owned: false }) + } + fn handle_tx_abort(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::TxAbort) { + (self.0.handle_tx_abort)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::TxAbort { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::TxAbort<>) as *mut _) }, is_owned: false }) + } + fn handle_update_add_htlc(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::UpdateAddHTLC) { + (self.0.handle_update_add_htlc)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::UpdateAddHTLC { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::UpdateAddHTLC<>) as *mut _) }, is_owned: false }) + } + fn handle_update_fulfill_htlc(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::UpdateFulfillHTLC) { + (self.0.handle_update_fulfill_htlc)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::UpdateFulfillHTLC { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::UpdateFulfillHTLC<>) as *mut _) }, is_owned: false }) + } + fn handle_update_fail_htlc(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::UpdateFailHTLC) { + (self.0.handle_update_fail_htlc)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::UpdateFailHTLC { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::UpdateFailHTLC<>) as *mut _) }, is_owned: false }) + } + fn handle_update_fail_malformed_htlc(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::UpdateFailMalformedHTLC) { + (self.0.handle_update_fail_malformed_htlc)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::UpdateFailMalformedHTLC { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::UpdateFailMalformedHTLC<>) as *mut _) }, is_owned: false }) + } + fn handle_commitment_signed(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::CommitmentSigned) { + (self.0.handle_commitment_signed)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::CommitmentSigned { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::CommitmentSigned<>) as *mut _) }, is_owned: false }) + } + fn handle_revoke_and_ack(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::RevokeAndACK) { + (self.0.handle_revoke_and_ack)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::RevokeAndACK { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::RevokeAndACK<>) as *mut _) }, is_owned: false }) + } + fn handle_update_fee(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::UpdateFee) { + (self.0.handle_update_fee)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::UpdateFee { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::UpdateFee<>) as *mut _) }, is_owned: false }) + } + fn handle_announcement_signatures(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::AnnouncementSignatures) { + (self.0.handle_announcement_signatures)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::AnnouncementSignatures { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::AnnouncementSignatures<>) as *mut _) }, is_owned: false }) + } + fn peer_disconnected(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey) { + (self.0.peer_disconnected)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id)) + } + fn peer_connected(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::Init, mut inbound: bool) -> Result<(), ()> { + let mut ret = (self.0.peer_connected)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::Init { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::Init<>) as *mut _) }, is_owned: false }, inbound); + let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })}; + local_ret + } + fn handle_channel_reestablish(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::ChannelReestablish) { + (self.0.handle_channel_reestablish)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::ChannelReestablish { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::ChannelReestablish<>) as *mut _) }, is_owned: false }) + } + fn handle_channel_update(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::ChannelUpdate) { + (self.0.handle_channel_update)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::ChannelUpdate { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::ChannelUpdate<>) as *mut _) }, is_owned: false }) + } + fn handle_error(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::ErrorMessage) { + (self.0.handle_error)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::ErrorMessage { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::ErrorMessage<>) as *mut _) }, is_owned: false }) + } + fn provided_node_features(&self) -> lightning_types::features::NodeFeatures { + let mut ret = (self.0.provided_node_features)(self.0.this_arg); + *unsafe { Box::from_raw(ret.take_inner()) } + } + fn provided_init_features(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey) -> lightning_types::features::InitFeatures { + let mut ret = (self.0.provided_init_features)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id)); + *unsafe { Box::from_raw(ret.take_inner()) } + } + fn get_chain_hashes(&self) -> Option> { + let mut ret = (self.0.get_chain_hashes)(self.0.this_arg); + let mut local_ret = { /*ret*/ let ret_opt = ret; if ret_opt.is_none() { None } else { Some({ { let mut local_ret_0 = Vec::new(); for mut item in { ret_opt.take() }.into_rust().drain(..) { local_ret_0.push( { ::bitcoin::constants::ChainHash::from(&item.data) }); }; local_ret_0 }})} }; local_ret } } @@ -8240,14 +10449,14 @@ impl rustChannelMessageHandler for ChannelMessageHandler { // We're essentially a pointer already, or at least a set of pointers, so allow us to be used // directly as a Deref trait in higher-level structs: impl core::ops::Deref for ChannelMessageHandler { - type Target = Self; - fn deref(&self) -> &Self { - self + type Target = ChannelMessageHandlerRef; + fn deref(&self) -> &Self::Target { + unsafe { &*(self as *const _ as *const ChannelMessageHandlerRef) } } } impl core::ops::DerefMut for ChannelMessageHandler { - fn deref_mut(&mut self) -> &mut Self { - self + fn deref_mut(&mut self) -> &mut ChannelMessageHandlerRef { + unsafe { &mut *(self as *mut _ as *mut ChannelMessageHandlerRef) } } } /// Calls the free function if one is set @@ -8324,13 +10533,13 @@ pub struct RoutingMessageHandler { /// Gets the node feature flags which this handler itself supports. All available handlers are /// queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`] /// which are broadcasted in our [`NodeAnnouncement`] message. - pub provided_node_features: extern "C" fn (this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures, + pub provided_node_features: extern "C" fn (this_arg: *const c_void) -> crate::lightning_types::features::NodeFeatures, /// Gets the init feature flags which should be sent to the given peer. All available handlers /// are queried similarly and their feature flags are OR'd together to form the [`InitFeatures`] /// which are sent in our [`Init`] message. /// /// Note that this method is called before [`Self::peer_connected`]. - pub provided_init_features: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey) -> crate::lightning::ln::features::InitFeatures, + pub provided_init_features: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey) -> crate::lightning_types::features::InitFeatures, /// Implementation of MessageSendEventsProvider for this object. pub MessageSendEventsProvider: crate::lightning::events::MessageSendEventsProvider, /// Frees any resources associated with this object given its this_arg pointer. @@ -8339,6 +10548,7 @@ pub struct RoutingMessageHandler { } unsafe impl Send for RoutingMessageHandler {} unsafe impl Sync for RoutingMessageHandler {} +#[allow(unused)] pub(crate) fn RoutingMessageHandler_clone_fields(orig: &RoutingMessageHandler) -> RoutingMessageHandler { RoutingMessageHandler { this_arg: orig.this_arg, @@ -8366,70 +10576,144 @@ impl lightning::events::MessageSendEventsProvider for RoutingMessageHandler { local_ret } } +impl lightning::events::MessageSendEventsProvider for RoutingMessageHandlerRef { + fn get_and_clear_pending_msg_events(&self) -> Vec { + let mut ret = (self.0.MessageSendEventsProvider.get_and_clear_pending_msg_events)(self.0.MessageSendEventsProvider.this_arg); + let mut local_ret = Vec::new(); for mut item in ret.into_rust().drain(..) { local_ret.push( { item.into_native() }); }; + local_ret + } +} + +use lightning::ln::msgs::RoutingMessageHandler as rustRoutingMessageHandler; +impl rustRoutingMessageHandler for RoutingMessageHandler { + fn handle_node_announcement(&self, mut msg: &lightning::ln::msgs::NodeAnnouncement) -> Result { + let mut ret = (self.handle_node_announcement)(self.this_arg, &crate::lightning::ln::msgs::NodeAnnouncement { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::NodeAnnouncement<>) as *mut _) }, is_owned: false }); + let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }) }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).take_inner()) } })}; + local_ret + } + fn handle_channel_announcement(&self, mut msg: &lightning::ln::msgs::ChannelAnnouncement) -> Result { + let mut ret = (self.handle_channel_announcement)(self.this_arg, &crate::lightning::ln::msgs::ChannelAnnouncement { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::ChannelAnnouncement<>) as *mut _) }, is_owned: false }); + let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }) }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).take_inner()) } })}; + local_ret + } + fn handle_channel_update(&self, mut msg: &lightning::ln::msgs::ChannelUpdate) -> Result { + let mut ret = (self.handle_channel_update)(self.this_arg, &crate::lightning::ln::msgs::ChannelUpdate { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::ChannelUpdate<>) as *mut _) }, is_owned: false }); + let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }) }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).take_inner()) } })}; + local_ret + } + fn get_next_channel_announcement(&self, mut starting_point: u64) -> Option<(lightning::ln::msgs::ChannelAnnouncement, Option, Option)> { + let mut ret = (self.get_next_channel_announcement)(self.this_arg, starting_point); + let mut local_ret = if ret.is_some() { Some( { let (mut orig_ret_0_0, mut orig_ret_0_1, mut orig_ret_0_2) = ret.take().to_rust(); let mut local_orig_ret_0_1 = if orig_ret_0_1.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(orig_ret_0_1.take_inner()) } }) }; let mut local_orig_ret_0_2 = if orig_ret_0_2.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(orig_ret_0_2.take_inner()) } }) }; let mut local_ret_0 = (*unsafe { Box::from_raw(orig_ret_0_0.take_inner()) }, local_orig_ret_0_1, local_orig_ret_0_2); local_ret_0 }) } else { None }; + local_ret + } + fn get_next_node_announcement(&self, mut starting_point: Option<&lightning::routing::gossip::NodeId>) -> Option { + let mut local_starting_point = crate::lightning::routing::gossip::NodeId { inner: unsafe { (if starting_point.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (starting_point.unwrap()) }) } as *const lightning::routing::gossip::NodeId<>) as *mut _ }, is_owned: false }; + let mut ret = (self.get_next_node_announcement)(self.this_arg, local_starting_point); + let mut local_ret = if ret.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(ret.take_inner()) } }) }; + local_ret + } + fn peer_connected(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut init: &lightning::ln::msgs::Init, mut inbound: bool) -> Result<(), ()> { + let mut ret = (self.peer_connected)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::Init { inner: unsafe { ObjOps::nonnull_ptr_to_inner((init as *const lightning::ln::msgs::Init<>) as *mut _) }, is_owned: false }, inbound); + let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })}; + local_ret + } + fn handle_reply_channel_range(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: lightning::ln::msgs::ReplyChannelRange) -> Result<(), lightning::ln::msgs::LightningError> { + let mut ret = (self.handle_reply_channel_range)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), crate::lightning::ln::msgs::ReplyChannelRange { inner: ObjOps::heap_alloc(msg), is_owned: true }); + let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).take_inner()) } })}; + local_ret + } + fn handle_reply_short_channel_ids_end(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: lightning::ln::msgs::ReplyShortChannelIdsEnd) -> Result<(), lightning::ln::msgs::LightningError> { + let mut ret = (self.handle_reply_short_channel_ids_end)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), crate::lightning::ln::msgs::ReplyShortChannelIdsEnd { inner: ObjOps::heap_alloc(msg), is_owned: true }); + let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).take_inner()) } })}; + local_ret + } + fn handle_query_channel_range(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: lightning::ln::msgs::QueryChannelRange) -> Result<(), lightning::ln::msgs::LightningError> { + let mut ret = (self.handle_query_channel_range)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), crate::lightning::ln::msgs::QueryChannelRange { inner: ObjOps::heap_alloc(msg), is_owned: true }); + let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).take_inner()) } })}; + local_ret + } + fn handle_query_short_channel_ids(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: lightning::ln::msgs::QueryShortChannelIds) -> Result<(), lightning::ln::msgs::LightningError> { + let mut ret = (self.handle_query_short_channel_ids)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), crate::lightning::ln::msgs::QueryShortChannelIds { inner: ObjOps::heap_alloc(msg), is_owned: true }); + let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).take_inner()) } })}; + local_ret + } + fn processing_queue_high(&self) -> bool { + let mut ret = (self.processing_queue_high)(self.this_arg); + ret + } + fn provided_node_features(&self) -> lightning_types::features::NodeFeatures { + let mut ret = (self.provided_node_features)(self.this_arg); + *unsafe { Box::from_raw(ret.take_inner()) } + } + fn provided_init_features(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey) -> lightning_types::features::InitFeatures { + let mut ret = (self.provided_init_features)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id)); + *unsafe { Box::from_raw(ret.take_inner()) } + } +} -use lightning::ln::msgs::RoutingMessageHandler as rustRoutingMessageHandler; -impl rustRoutingMessageHandler for RoutingMessageHandler { +pub struct RoutingMessageHandlerRef(RoutingMessageHandler); +impl rustRoutingMessageHandler for RoutingMessageHandlerRef { fn handle_node_announcement(&self, mut msg: &lightning::ln::msgs::NodeAnnouncement) -> Result { - let mut ret = (self.handle_node_announcement)(self.this_arg, &crate::lightning::ln::msgs::NodeAnnouncement { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::NodeAnnouncement<>) as *mut _) }, is_owned: false }); + let mut ret = (self.0.handle_node_announcement)(self.0.this_arg, &crate::lightning::ln::msgs::NodeAnnouncement { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::NodeAnnouncement<>) as *mut _) }, is_owned: false }); let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }) }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).take_inner()) } })}; local_ret } fn handle_channel_announcement(&self, mut msg: &lightning::ln::msgs::ChannelAnnouncement) -> Result { - let mut ret = (self.handle_channel_announcement)(self.this_arg, &crate::lightning::ln::msgs::ChannelAnnouncement { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::ChannelAnnouncement<>) as *mut _) }, is_owned: false }); + let mut ret = (self.0.handle_channel_announcement)(self.0.this_arg, &crate::lightning::ln::msgs::ChannelAnnouncement { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::ChannelAnnouncement<>) as *mut _) }, is_owned: false }); let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }) }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).take_inner()) } })}; local_ret } fn handle_channel_update(&self, mut msg: &lightning::ln::msgs::ChannelUpdate) -> Result { - let mut ret = (self.handle_channel_update)(self.this_arg, &crate::lightning::ln::msgs::ChannelUpdate { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::ChannelUpdate<>) as *mut _) }, is_owned: false }); + let mut ret = (self.0.handle_channel_update)(self.0.this_arg, &crate::lightning::ln::msgs::ChannelUpdate { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::ChannelUpdate<>) as *mut _) }, is_owned: false }); let mut local_ret = match ret.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) }) }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).take_inner()) } })}; local_ret } fn get_next_channel_announcement(&self, mut starting_point: u64) -> Option<(lightning::ln::msgs::ChannelAnnouncement, Option, Option)> { - let mut ret = (self.get_next_channel_announcement)(self.this_arg, starting_point); + let mut ret = (self.0.get_next_channel_announcement)(self.0.this_arg, starting_point); let mut local_ret = if ret.is_some() { Some( { let (mut orig_ret_0_0, mut orig_ret_0_1, mut orig_ret_0_2) = ret.take().to_rust(); let mut local_orig_ret_0_1 = if orig_ret_0_1.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(orig_ret_0_1.take_inner()) } }) }; let mut local_orig_ret_0_2 = if orig_ret_0_2.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(orig_ret_0_2.take_inner()) } }) }; let mut local_ret_0 = (*unsafe { Box::from_raw(orig_ret_0_0.take_inner()) }, local_orig_ret_0_1, local_orig_ret_0_2); local_ret_0 }) } else { None }; local_ret } fn get_next_node_announcement(&self, mut starting_point: Option<&lightning::routing::gossip::NodeId>) -> Option { let mut local_starting_point = crate::lightning::routing::gossip::NodeId { inner: unsafe { (if starting_point.is_none() { core::ptr::null() } else { ObjOps::nonnull_ptr_to_inner( { (starting_point.unwrap()) }) } as *const lightning::routing::gossip::NodeId<>) as *mut _ }, is_owned: false }; - let mut ret = (self.get_next_node_announcement)(self.this_arg, local_starting_point); + let mut ret = (self.0.get_next_node_announcement)(self.0.this_arg, local_starting_point); let mut local_ret = if ret.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(ret.take_inner()) } }) }; local_ret } fn peer_connected(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut init: &lightning::ln::msgs::Init, mut inbound: bool) -> Result<(), ()> { - let mut ret = (self.peer_connected)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::Init { inner: unsafe { ObjOps::nonnull_ptr_to_inner((init as *const lightning::ln::msgs::Init<>) as *mut _) }, is_owned: false }, inbound); + let mut ret = (self.0.peer_connected)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::Init { inner: unsafe { ObjOps::nonnull_ptr_to_inner((init as *const lightning::ln::msgs::Init<>) as *mut _) }, is_owned: false }, inbound); let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })}; local_ret } fn handle_reply_channel_range(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: lightning::ln::msgs::ReplyChannelRange) -> Result<(), lightning::ln::msgs::LightningError> { - let mut ret = (self.handle_reply_channel_range)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), crate::lightning::ln::msgs::ReplyChannelRange { inner: ObjOps::heap_alloc(msg), is_owned: true }); + let mut ret = (self.0.handle_reply_channel_range)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), crate::lightning::ln::msgs::ReplyChannelRange { inner: ObjOps::heap_alloc(msg), is_owned: true }); let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).take_inner()) } })}; local_ret } fn handle_reply_short_channel_ids_end(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: lightning::ln::msgs::ReplyShortChannelIdsEnd) -> Result<(), lightning::ln::msgs::LightningError> { - let mut ret = (self.handle_reply_short_channel_ids_end)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), crate::lightning::ln::msgs::ReplyShortChannelIdsEnd { inner: ObjOps::heap_alloc(msg), is_owned: true }); + let mut ret = (self.0.handle_reply_short_channel_ids_end)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), crate::lightning::ln::msgs::ReplyShortChannelIdsEnd { inner: ObjOps::heap_alloc(msg), is_owned: true }); let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).take_inner()) } })}; local_ret } fn handle_query_channel_range(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: lightning::ln::msgs::QueryChannelRange) -> Result<(), lightning::ln::msgs::LightningError> { - let mut ret = (self.handle_query_channel_range)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), crate::lightning::ln::msgs::QueryChannelRange { inner: ObjOps::heap_alloc(msg), is_owned: true }); + let mut ret = (self.0.handle_query_channel_range)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), crate::lightning::ln::msgs::QueryChannelRange { inner: ObjOps::heap_alloc(msg), is_owned: true }); let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).take_inner()) } })}; local_ret } fn handle_query_short_channel_ids(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut msg: lightning::ln::msgs::QueryShortChannelIds) -> Result<(), lightning::ln::msgs::LightningError> { - let mut ret = (self.handle_query_short_channel_ids)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), crate::lightning::ln::msgs::QueryShortChannelIds { inner: ObjOps::heap_alloc(msg), is_owned: true }); + let mut ret = (self.0.handle_query_short_channel_ids)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), crate::lightning::ln::msgs::QueryShortChannelIds { inner: ObjOps::heap_alloc(msg), is_owned: true }); let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { *unsafe { Box::from_raw((*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) }).take_inner()) } })}; local_ret } fn processing_queue_high(&self) -> bool { - let mut ret = (self.processing_queue_high)(self.this_arg); + let mut ret = (self.0.processing_queue_high)(self.0.this_arg); ret } - fn provided_node_features(&self) -> lightning::ln::features::NodeFeatures { - let mut ret = (self.provided_node_features)(self.this_arg); + fn provided_node_features(&self) -> lightning_types::features::NodeFeatures { + let mut ret = (self.0.provided_node_features)(self.0.this_arg); *unsafe { Box::from_raw(ret.take_inner()) } } - fn provided_init_features(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey) -> lightning::ln::features::InitFeatures { - let mut ret = (self.provided_init_features)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id)); + fn provided_init_features(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey) -> lightning_types::features::InitFeatures { + let mut ret = (self.0.provided_init_features)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id)); *unsafe { Box::from_raw(ret.take_inner()) } } } @@ -8437,14 +10721,14 @@ impl rustRoutingMessageHandler for RoutingMessageHandler { // We're essentially a pointer already, or at least a set of pointers, so allow us to be used // directly as a Deref trait in higher-level structs: impl core::ops::Deref for RoutingMessageHandler { - type Target = Self; - fn deref(&self) -> &Self { - self + type Target = RoutingMessageHandlerRef; + fn deref(&self) -> &Self::Target { + unsafe { &*(self as *const _ as *const RoutingMessageHandlerRef) } } } impl core::ops::DerefMut for RoutingMessageHandler { - fn deref_mut(&mut self) -> &mut Self { - self + fn deref_mut(&mut self) -> &mut RoutingMessageHandlerRef { + unsafe { &mut *(self as *mut _ as *mut RoutingMessageHandlerRef) } } } /// Calls the free function if one is set @@ -8457,7 +10741,7 @@ impl Drop for RoutingMessageHandler { } } } -/// A trait to describe an object that can receive onion messages. +/// A handler for received [`OnionMessage`]s and for providing generated ones to send. #[repr(C)] pub struct OnionMessageHandler { /// An opaque pointer which is passed to your function implementations as an argument. @@ -8465,6 +10749,10 @@ pub struct OnionMessageHandler { pub this_arg: *mut c_void, /// Handle an incoming `onion_message` message from the given peer. pub handle_onion_message: extern "C" fn (this_arg: *const c_void, peer_node_id: crate::c_types::PublicKey, msg: &crate::lightning::ln::msgs::OnionMessage), + /// Returns the next pending onion message for the peer with the given node id. + /// + /// Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None + pub next_onion_message_for_peer: extern "C" fn (this_arg: *const c_void, peer_node_id: crate::c_types::PublicKey) -> crate::lightning::ln::msgs::OnionMessage, /// Called when a connection is established with a peer. Can be used to track which peers /// advertise onion message support and are online. /// @@ -8475,110 +10763,585 @@ pub struct OnionMessageHandler { /// Indicates a connection to the peer failed/an existing connection was lost. Allows handlers to /// drop and refuse to forward onion messages to this peer. pub peer_disconnected: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey), + /// Performs actions that should happen roughly every ten seconds after startup. Allows handlers + /// to drop any buffered onion messages intended for prospective peers. + pub timer_tick_occurred: extern "C" fn (this_arg: *const c_void), /// Gets the node feature flags which this handler itself supports. All available handlers are /// queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`] /// which are broadcasted in our [`NodeAnnouncement`] message. - pub provided_node_features: extern "C" fn (this_arg: *const c_void) -> crate::lightning::ln::features::NodeFeatures, + pub provided_node_features: extern "C" fn (this_arg: *const c_void) -> crate::lightning_types::features::NodeFeatures, /// Gets the init feature flags which should be sent to the given peer. All available handlers /// are queried similarly and their feature flags are OR'd together to form the [`InitFeatures`] /// which are sent in our [`Init`] message. /// /// Note that this method is called before [`Self::peer_connected`]. - pub provided_init_features: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey) -> crate::lightning::ln::features::InitFeatures, - /// Implementation of OnionMessageProvider for this object. - pub OnionMessageProvider: crate::lightning::events::OnionMessageProvider, + pub provided_init_features: extern "C" fn (this_arg: *const c_void, their_node_id: crate::c_types::PublicKey) -> crate::lightning_types::features::InitFeatures, /// Frees any resources associated with this object given its this_arg pointer. /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed. pub free: Option, } unsafe impl Send for OnionMessageHandler {} unsafe impl Sync for OnionMessageHandler {} +#[allow(unused)] pub(crate) fn OnionMessageHandler_clone_fields(orig: &OnionMessageHandler) -> OnionMessageHandler { OnionMessageHandler { this_arg: orig.this_arg, handle_onion_message: Clone::clone(&orig.handle_onion_message), + next_onion_message_for_peer: Clone::clone(&orig.next_onion_message_for_peer), peer_connected: Clone::clone(&orig.peer_connected), peer_disconnected: Clone::clone(&orig.peer_disconnected), + timer_tick_occurred: Clone::clone(&orig.timer_tick_occurred), provided_node_features: Clone::clone(&orig.provided_node_features), provided_init_features: Clone::clone(&orig.provided_init_features), - OnionMessageProvider: crate::lightning::events::OnionMessageProvider_clone_fields(&orig.OnionMessageProvider), free: Clone::clone(&orig.free), } } -impl lightning::events::OnionMessageProvider for OnionMessageHandler { + +use lightning::ln::msgs::OnionMessageHandler as rustOnionMessageHandler; +impl rustOnionMessageHandler for OnionMessageHandler { + fn handle_onion_message(&self, mut peer_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::OnionMessage) { + (self.handle_onion_message)(self.this_arg, crate::c_types::PublicKey::from_rust(&peer_node_id), &crate::lightning::ln::msgs::OnionMessage { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::OnionMessage<>) as *mut _) }, is_owned: false }) + } + fn next_onion_message_for_peer(&self, mut peer_node_id: bitcoin::secp256k1::PublicKey) -> Option { + let mut ret = (self.next_onion_message_for_peer)(self.this_arg, crate::c_types::PublicKey::from_rust(&peer_node_id)); + let mut local_ret = if ret.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(ret.take_inner()) } }) }; + local_ret + } + fn peer_connected(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut init: &lightning::ln::msgs::Init, mut inbound: bool) -> Result<(), ()> { + let mut ret = (self.peer_connected)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::Init { inner: unsafe { ObjOps::nonnull_ptr_to_inner((init as *const lightning::ln::msgs::Init<>) as *mut _) }, is_owned: false }, inbound); + let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })}; + local_ret + } + fn peer_disconnected(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey) { + (self.peer_disconnected)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id)) + } + fn timer_tick_occurred(&self) { + (self.timer_tick_occurred)(self.this_arg) + } + fn provided_node_features(&self) -> lightning_types::features::NodeFeatures { + let mut ret = (self.provided_node_features)(self.this_arg); + *unsafe { Box::from_raw(ret.take_inner()) } + } + fn provided_init_features(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey) -> lightning_types::features::InitFeatures { + let mut ret = (self.provided_init_features)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id)); + *unsafe { Box::from_raw(ret.take_inner()) } + } +} + +pub struct OnionMessageHandlerRef(OnionMessageHandler); +impl rustOnionMessageHandler for OnionMessageHandlerRef { + fn handle_onion_message(&self, mut peer_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::OnionMessage) { + (self.0.handle_onion_message)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&peer_node_id), &crate::lightning::ln::msgs::OnionMessage { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::OnionMessage<>) as *mut _) }, is_owned: false }) + } fn next_onion_message_for_peer(&self, mut peer_node_id: bitcoin::secp256k1::PublicKey) -> Option { - let mut ret = (self.OnionMessageProvider.next_onion_message_for_peer)(self.OnionMessageProvider.this_arg, crate::c_types::PublicKey::from_rust(&peer_node_id)); + let mut ret = (self.0.next_onion_message_for_peer)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&peer_node_id)); let mut local_ret = if ret.inner.is_null() { None } else { Some( { *unsafe { Box::from_raw(ret.take_inner()) } }) }; local_ret } + fn peer_connected(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut init: &lightning::ln::msgs::Init, mut inbound: bool) -> Result<(), ()> { + let mut ret = (self.0.peer_connected)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::Init { inner: unsafe { ObjOps::nonnull_ptr_to_inner((init as *const lightning::ln::msgs::Init<>) as *mut _) }, is_owned: false }, inbound); + let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })}; + local_ret + } + fn peer_disconnected(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey) { + (self.0.peer_disconnected)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id)) + } + fn timer_tick_occurred(&self) { + (self.0.timer_tick_occurred)(self.0.this_arg) + } + fn provided_node_features(&self) -> lightning_types::features::NodeFeatures { + let mut ret = (self.0.provided_node_features)(self.0.this_arg); + *unsafe { Box::from_raw(ret.take_inner()) } + } + fn provided_init_features(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey) -> lightning_types::features::InitFeatures { + let mut ret = (self.0.provided_init_features)(self.0.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id)); + *unsafe { Box::from_raw(ret.take_inner()) } + } +} + +// We're essentially a pointer already, or at least a set of pointers, so allow us to be used +// directly as a Deref trait in higher-level structs: +impl core::ops::Deref for OnionMessageHandler { + type Target = OnionMessageHandlerRef; + fn deref(&self) -> &Self::Target { + unsafe { &*(self as *const _ as *const OnionMessageHandlerRef) } + } +} +impl core::ops::DerefMut for OnionMessageHandler { + fn deref_mut(&mut self) -> &mut OnionMessageHandlerRef { + unsafe { &mut *(self as *mut _ as *mut OnionMessageHandlerRef) } + } +} +/// Calls the free function if one is set +#[no_mangle] +pub extern "C" fn OnionMessageHandler_free(this_ptr: OnionMessageHandler) { } +impl Drop for OnionMessageHandler { + fn drop(&mut self) { + if let Some(f) = self.free { + f(self.this_arg); + } + } +} + +use lightning::ln::msgs::FinalOnionHopData as nativeFinalOnionHopDataImport; +pub(crate) type nativeFinalOnionHopData = nativeFinalOnionHopDataImport; + +/// Information communicated in the onion to the recipient for multi-part tracking and proof that +/// the payment is associated with an invoice. +#[must_use] +#[repr(C)] +pub struct FinalOnionHopData { + /// 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 nativeFinalOnionHopData, + /// 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 core::ops::Deref for FinalOnionHopData { + type Target = nativeFinalOnionHopData; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for FinalOnionHopData { } +unsafe impl core::marker::Sync for FinalOnionHopData { } +impl Drop for FinalOnionHopData { + fn drop(&mut self) { + if self.is_owned && !<*mut nativeFinalOnionHopData>::is_null(self.inner) { + let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; + } + } +} +/// Frees any resources used by the FinalOnionHopData, if is_owned is set and inner is non-NULL. +#[no_mangle] +pub extern "C" fn FinalOnionHopData_free(this_obj: FinalOnionHopData) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn FinalOnionHopData_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeFinalOnionHopData) }; +} +#[allow(unused)] +impl FinalOnionHopData { + pub(crate) fn get_native_ref(&self) -> &'static nativeFinalOnionHopData { + unsafe { &*ObjOps::untweak_ptr(self.inner) } + } + pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeFinalOnionHopData { + 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 nativeFinalOnionHopData { + assert!(self.is_owned); + let ret = ObjOps::untweak_ptr(self.inner); + self.inner = core::ptr::null_mut(); + ret + } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } +} +/// When sending a multi-part payment, this secret is used to identify a payment across HTLCs. +/// Because it is generated by the recipient and included in the invoice, it also provides +/// proof to the recipient that the payment was sent by someone with the generated invoice. +#[no_mangle] +pub extern "C" fn FinalOnionHopData_get_payment_secret(this_ptr: &FinalOnionHopData) -> *const [u8; 32] { + let mut inner_val = &mut this_ptr.get_native_mut_ref().payment_secret; + &inner_val.0 +} +/// When sending a multi-part payment, this secret is used to identify a payment across HTLCs. +/// Because it is generated by the recipient and included in the invoice, it also provides +/// proof to the recipient that the payment was sent by someone with the generated invoice. +#[no_mangle] +pub extern "C" fn FinalOnionHopData_set_payment_secret(this_ptr: &mut FinalOnionHopData, mut val: crate::c_types::ThirtyTwoBytes) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.payment_secret = ::lightning::ln::types::PaymentSecret(val.data); +} +/// The intended total amount that this payment is for. +/// +/// Message serialization may panic if this value is more than 21 million Bitcoin. +#[no_mangle] +pub extern "C" fn FinalOnionHopData_get_total_msat(this_ptr: &FinalOnionHopData) -> u64 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().total_msat; + *inner_val +} +/// The intended total amount that this payment is for. +/// +/// Message serialization may panic if this value is more than 21 million Bitcoin. +#[no_mangle] +pub extern "C" fn FinalOnionHopData_set_total_msat(this_ptr: &mut FinalOnionHopData, mut val: u64) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.total_msat = val; +} +/// Constructs a new FinalOnionHopData given each field +#[must_use] +#[no_mangle] +pub extern "C" fn FinalOnionHopData_new(mut payment_secret_arg: crate::c_types::ThirtyTwoBytes, mut total_msat_arg: u64) -> FinalOnionHopData { + FinalOnionHopData { inner: ObjOps::heap_alloc(nativeFinalOnionHopData { + payment_secret: ::lightning::ln::types::PaymentSecret(payment_secret_arg.data), + total_msat: total_msat_arg, + }), is_owned: true } +} +impl Clone for FinalOnionHopData { + fn clone(&self) -> Self { + Self { + inner: if <*mut nativeFinalOnionHopData>::is_null(self.inner) { core::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 FinalOnionHopData_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeFinalOnionHopData)).clone() })) as *mut c_void +} +#[no_mangle] +/// Creates a copy of the FinalOnionHopData +pub extern "C" fn FinalOnionHopData_clone(orig: &FinalOnionHopData) -> FinalOnionHopData { + orig.clone() +} +mod fuzzy_internal_msgs { + +use alloc::str::FromStr; +use alloc::string::String; +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}; + +} + +use lightning::ln::msgs::OnionPacket as nativeOnionPacketImport; +pub(crate) type nativeOnionPacket = nativeOnionPacketImport; + +/// BOLT 4 onion packet including hop data for the next peer. +#[must_use] +#[repr(C)] +pub struct OnionPacket { + /// 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 nativeOnionPacket, + /// 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 core::ops::Deref for OnionPacket { + type Target = nativeOnionPacket; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for OnionPacket { } +unsafe impl core::marker::Sync for OnionPacket { } +impl Drop for OnionPacket { + fn drop(&mut self) { + if self.is_owned && !<*mut nativeOnionPacket>::is_null(self.inner) { + let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; + } + } +} +/// Frees any resources used by the OnionPacket, if is_owned is set and inner is non-NULL. +#[no_mangle] +pub extern "C" fn OnionPacket_free(this_obj: OnionPacket) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn OnionPacket_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeOnionPacket) }; +} +#[allow(unused)] +impl OnionPacket { + pub(crate) fn get_native_ref(&self) -> &'static nativeOnionPacket { + unsafe { &*ObjOps::untweak_ptr(self.inner) } + } + pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeOnionPacket { + 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 nativeOnionPacket { + assert!(self.is_owned); + let ret = ObjOps::untweak_ptr(self.inner); + self.inner = core::ptr::null_mut(); + ret + } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } + } +} +/// BOLT 4 version number. +#[no_mangle] +pub extern "C" fn OnionPacket_get_version(this_ptr: &OnionPacket) -> u8 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().version; + *inner_val +} +/// BOLT 4 version number. +#[no_mangle] +pub extern "C" fn OnionPacket_set_version(this_ptr: &mut OnionPacket, mut val: u8) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.version = val; +} +/// In order to ensure we always return an error on onion decode in compliance with [BOLT +/// #4](https://github.com/lightning/bolts/blob/master/04-onion-routing.md), we have to +/// deserialize `OnionPacket`s contained in [`UpdateAddHTLC`] messages even if the ephemeral +/// public key (here) is bogus, so we hold a [`Result`] instead of a [`PublicKey`] as we'd +/// like. +/// +/// Returns a copy of the field. +#[no_mangle] +pub extern "C" fn OnionPacket_get_public_key(this_ptr: &OnionPacket) -> crate::c_types::derived::CResult_PublicKeySecp256k1ErrorZ { + let mut inner_val = this_ptr.get_native_mut_ref().public_key.clone(); + let mut local_inner_val = match inner_val { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::PublicKey::from_rust(&o) }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::c_types::Secp256k1Error::from_rust(e) }).into() }; + local_inner_val +} +/// In order to ensure we always return an error on onion decode in compliance with [BOLT +/// #4](https://github.com/lightning/bolts/blob/master/04-onion-routing.md), we have to +/// deserialize `OnionPacket`s contained in [`UpdateAddHTLC`] messages even if the ephemeral +/// public key (here) is bogus, so we hold a [`Result`] instead of a [`PublicKey`] as we'd +/// like. +#[no_mangle] +pub extern "C" fn OnionPacket_set_public_key(this_ptr: &mut OnionPacket, mut val: crate::c_types::derived::CResult_PublicKeySecp256k1ErrorZ) { + let mut local_val = match val.result_ok { true => Ok( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut val.contents.result)) }).into_rust() }), false => Err( { (*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut val.contents.err)) }).into_rust() })}; + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.public_key = local_val; +} +/// HMAC to verify the integrity of hop_data. +#[no_mangle] +pub extern "C" fn OnionPacket_get_hmac(this_ptr: &OnionPacket) -> *const [u8; 32] { + let mut inner_val = &mut this_ptr.get_native_mut_ref().hmac; + inner_val +} +/// HMAC to verify the integrity of hop_data. +#[no_mangle] +pub extern "C" fn OnionPacket_set_hmac(this_ptr: &mut OnionPacket, mut val: crate::c_types::ThirtyTwoBytes) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.hmac = val.data; +} +impl Clone for OnionPacket { + fn clone(&self) -> Self { + Self { + inner: if <*mut nativeOnionPacket>::is_null(self.inner) { core::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 OnionPacket_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeOnionPacket)).clone() })) as *mut c_void +} +#[no_mangle] +/// Creates a copy of the OnionPacket +pub extern "C" fn OnionPacket_clone(orig: &OnionPacket) -> OnionPacket { + orig.clone() +} +/// Generates a non-cryptographic 64-bit hash of the OnionPacket. +#[no_mangle] +pub extern "C" fn OnionPacket_hash(o: &OnionPacket) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} +/// Checks if two OnionPackets 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 OnionPacket_eq(a: &OnionPacket, b: &OnionPacket) -> 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 } +} +/// Get a string which allows debug introspection of a OnionPacket object +pub extern "C" fn OnionPacket_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::OnionPacket }).into()} + +use lightning::ln::msgs::TrampolineOnionPacket as nativeTrampolineOnionPacketImport; +pub(crate) type nativeTrampolineOnionPacket = nativeTrampolineOnionPacketImport; + +/// BOLT 4 onion packet including hop data for the next peer. +#[must_use] +#[repr(C)] +pub struct TrampolineOnionPacket { + /// 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 nativeTrampolineOnionPacket, + /// 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, } -use lightning::ln::msgs::OnionMessageHandler as rustOnionMessageHandler; -impl rustOnionMessageHandler for OnionMessageHandler { - fn handle_onion_message(&self, mut peer_node_id: &bitcoin::secp256k1::PublicKey, mut msg: &lightning::ln::msgs::OnionMessage) { - (self.handle_onion_message)(self.this_arg, crate::c_types::PublicKey::from_rust(&peer_node_id), &crate::lightning::ln::msgs::OnionMessage { inner: unsafe { ObjOps::nonnull_ptr_to_inner((msg as *const lightning::ln::msgs::OnionMessage<>) as *mut _) }, is_owned: false }) +impl core::ops::Deref for TrampolineOnionPacket { + type Target = nativeTrampolineOnionPacket; + fn deref(&self) -> &Self::Target { unsafe { &*ObjOps::untweak_ptr(self.inner) } } +} +unsafe impl core::marker::Send for TrampolineOnionPacket { } +unsafe impl core::marker::Sync for TrampolineOnionPacket { } +impl Drop for TrampolineOnionPacket { + fn drop(&mut self) { + if self.is_owned && !<*mut nativeTrampolineOnionPacket>::is_null(self.inner) { + let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) }; + } } - fn peer_connected(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey, mut init: &lightning::ln::msgs::Init, mut inbound: bool) -> Result<(), ()> { - let mut ret = (self.peer_connected)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id), &crate::lightning::ln::msgs::Init { inner: unsafe { ObjOps::nonnull_ptr_to_inner((init as *const lightning::ln::msgs::Init<>) as *mut _) }, is_owned: false }, inbound); - let mut local_ret = match ret.result_ok { true => Ok( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.result)) })*/ }), false => Err( { () /*(*unsafe { Box::from_raw(<*mut _>::take_ptr(&mut ret.contents.err)) })*/ })}; - local_ret +} +/// Frees any resources used by the TrampolineOnionPacket, if is_owned is set and inner is non-NULL. +#[no_mangle] +pub extern "C" fn TrampolineOnionPacket_free(this_obj: TrampolineOnionPacket) { } +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn TrampolineOnionPacket_free_void(this_ptr: *mut c_void) { + let _ = unsafe { Box::from_raw(this_ptr as *mut nativeTrampolineOnionPacket) }; +} +#[allow(unused)] +impl TrampolineOnionPacket { + pub(crate) fn get_native_ref(&self) -> &'static nativeTrampolineOnionPacket { + unsafe { &*ObjOps::untweak_ptr(self.inner) } } - fn peer_disconnected(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey) { - (self.peer_disconnected)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id)) + pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeTrampolineOnionPacket { + unsafe { &mut *ObjOps::untweak_ptr(self.inner) } } - fn provided_node_features(&self) -> lightning::ln::features::NodeFeatures { - let mut ret = (self.provided_node_features)(self.this_arg); - *unsafe { Box::from_raw(ret.take_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 nativeTrampolineOnionPacket { + assert!(self.is_owned); + let ret = ObjOps::untweak_ptr(self.inner); + self.inner = core::ptr::null_mut(); + ret } - fn provided_init_features(&self, mut their_node_id: &bitcoin::secp256k1::PublicKey) -> lightning::ln::features::InitFeatures { - let mut ret = (self.provided_init_features)(self.this_arg, crate::c_types::PublicKey::from_rust(&their_node_id)); - *unsafe { Box::from_raw(ret.take_inner()) } + pub(crate) fn as_ref_to(&self) -> Self { + Self { inner: self.inner, is_owned: false } } } - -// We're essentially a pointer already, or at least a set of pointers, so allow us to be used -// directly as a Deref trait in higher-level structs: -impl core::ops::Deref for OnionMessageHandler { - type Target = Self; - fn deref(&self) -> &Self { - self - } +/// Bolt 04 version number +#[no_mangle] +pub extern "C" fn TrampolineOnionPacket_get_version(this_ptr: &TrampolineOnionPacket) -> u8 { + let mut inner_val = &mut this_ptr.get_native_mut_ref().version; + *inner_val } -impl core::ops::DerefMut for OnionMessageHandler { - fn deref_mut(&mut self) -> &mut Self { - self - } +/// Bolt 04 version number +#[no_mangle] +pub extern "C" fn TrampolineOnionPacket_set_version(this_ptr: &mut TrampolineOnionPacket, mut val: u8) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.version = val; } -/// Calls the free function if one is set +/// A random sepc256k1 point, used to build the ECDH shared secret to decrypt hop_data #[no_mangle] -pub extern "C" fn OnionMessageHandler_free(this_ptr: OnionMessageHandler) { } -impl Drop for OnionMessageHandler { - fn drop(&mut self) { - if let Some(f) = self.free { - f(self.this_arg); +pub extern "C" fn TrampolineOnionPacket_get_public_key(this_ptr: &TrampolineOnionPacket) -> crate::c_types::PublicKey { + let mut inner_val = &mut this_ptr.get_native_mut_ref().public_key; + crate::c_types::PublicKey::from_rust(&inner_val) +} +/// A random sepc256k1 point, used to build the ECDH shared secret to decrypt hop_data +#[no_mangle] +pub extern "C" fn TrampolineOnionPacket_set_public_key(this_ptr: &mut TrampolineOnionPacket, mut val: crate::c_types::PublicKey) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.public_key = val.into_rust(); +} +/// Encrypted payload for the next hop +/// +/// Returns a copy of the field. +#[no_mangle] +pub extern "C" fn TrampolineOnionPacket_get_hop_data(this_ptr: &TrampolineOnionPacket) -> crate::c_types::derived::CVec_u8Z { + let mut inner_val = this_ptr.get_native_mut_ref().hop_data.clone(); + let mut local_inner_val = Vec::new(); for mut item in inner_val.drain(..) { local_inner_val.push( { item }); }; + local_inner_val.into() +} +/// Encrypted payload for the next hop +#[no_mangle] +pub extern "C" fn TrampolineOnionPacket_set_hop_data(this_ptr: &mut TrampolineOnionPacket, mut val: crate::c_types::derived::CVec_u8Z) { + let mut local_val = Vec::new(); for mut item in val.into_rust().drain(..) { local_val.push( { item }); }; + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.hop_data = local_val; +} +/// HMAC to verify the integrity of hop_data +#[no_mangle] +pub extern "C" fn TrampolineOnionPacket_get_hmac(this_ptr: &TrampolineOnionPacket) -> *const [u8; 32] { + let mut inner_val = &mut this_ptr.get_native_mut_ref().hmac; + inner_val +} +/// HMAC to verify the integrity of hop_data +#[no_mangle] +pub extern "C" fn TrampolineOnionPacket_set_hmac(this_ptr: &mut TrampolineOnionPacket, mut val: crate::c_types::ThirtyTwoBytes) { + unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.hmac = val.data; +} +/// Constructs a new TrampolineOnionPacket given each field +#[must_use] +#[no_mangle] +pub extern "C" fn TrampolineOnionPacket_new(mut version_arg: u8, mut public_key_arg: crate::c_types::PublicKey, mut hop_data_arg: crate::c_types::derived::CVec_u8Z, mut hmac_arg: crate::c_types::ThirtyTwoBytes) -> TrampolineOnionPacket { + let mut local_hop_data_arg = Vec::new(); for mut item in hop_data_arg.into_rust().drain(..) { local_hop_data_arg.push( { item }); }; + TrampolineOnionPacket { inner: ObjOps::heap_alloc(nativeTrampolineOnionPacket { + version: version_arg, + public_key: public_key_arg.into_rust(), + hop_data: local_hop_data_arg, + hmac: hmac_arg.data, + }), is_owned: true } +} +impl Clone for TrampolineOnionPacket { + fn clone(&self) -> Self { + Self { + inner: if <*mut nativeTrampolineOnionPacket>::is_null(self.inner) { core::ptr::null_mut() } else { + ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) }, + is_owned: true, } } } -mod fuzzy_internal_msgs { - -use alloc::str::FromStr; -use alloc::string::String; -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}; - +#[allow(unused)] +/// Used only if an object of this type is returned as a trait impl by a method +pub(crate) extern "C" fn TrampolineOnionPacket_clone_void(this_ptr: *const c_void) -> *mut c_void { + Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeTrampolineOnionPacket)).clone() })) as *mut c_void +} +#[no_mangle] +/// Creates a copy of the TrampolineOnionPacket +pub extern "C" fn TrampolineOnionPacket_clone(orig: &TrampolineOnionPacket) -> TrampolineOnionPacket { + orig.clone() +} +/// Generates a non-cryptographic 64-bit hash of the TrampolineOnionPacket. +#[no_mangle] +pub extern "C" fn TrampolineOnionPacket_hash(o: &TrampolineOnionPacket) -> u64 { + if o.inner.is_null() { return 0; } + // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core + #[allow(deprecated)] + let mut hasher = core::hash::SipHasher::new(); + core::hash::Hash::hash(o.get_native_ref(), &mut hasher); + core::hash::Hasher::finish(&hasher) +} +/// Checks if two TrampolineOnionPackets 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 TrampolineOnionPacket_eq(a: &TrampolineOnionPacket, b: &TrampolineOnionPacket) -> 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 } +} +#[no_mangle] +/// Serialize the TrampolineOnionPacket object into a byte array which can be read by TrampolineOnionPacket_read +pub extern "C" fn TrampolineOnionPacket_write(obj: &crate::lightning::ln::msgs::TrampolineOnionPacket) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) +} +#[allow(unused)] +pub(crate) extern "C" fn TrampolineOnionPacket_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeTrampolineOnionPacket) }) +} +/// Get a string which allows debug introspection of a TrampolineOnionPacket object +pub extern "C" fn TrampolineOnionPacket_debug_str_void(o: *const c_void) -> Str { + alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::msgs::TrampolineOnionPacket }).into()} +#[no_mangle] +/// Get the string representation of a DecodeError object +pub extern "C" fn DecodeError_to_str(o: &crate::lightning::ln::msgs::DecodeError) -> Str { + alloc::format!("{}", &o.to_native()).into() } #[no_mangle] /// Serialize the AcceptChannel object into a byte array which can be read by AcceptChannel_read pub extern "C" fn AcceptChannel_write(obj: &crate::lightning::ln::msgs::AcceptChannel) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn AcceptChannel_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeAcceptChannel) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeAcceptChannel) }) } #[no_mangle] /// Read a AcceptChannel from a byte array, created by AcceptChannel_write @@ -8592,9 +11355,9 @@ pub extern "C" fn AcceptChannel_read(ser: crate::c_types::u8slice) -> crate::c_t pub extern "C" fn AcceptChannelV2_write(obj: &crate::lightning::ln::msgs::AcceptChannelV2) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn AcceptChannelV2_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeAcceptChannelV2) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeAcceptChannelV2) }) } #[no_mangle] /// Read a AcceptChannelV2 from a byte array, created by AcceptChannelV2_write @@ -8604,13 +11367,77 @@ pub extern "C" fn AcceptChannelV2_read(ser: crate::c_types::u8slice) -> crate::c local_res } #[no_mangle] +/// Serialize the Stfu object into a byte array which can be read by Stfu_read +pub extern "C" fn Stfu_write(obj: &crate::lightning::ln::msgs::Stfu) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) +} +#[allow(unused)] +pub(crate) extern "C" fn Stfu_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeStfu) }) +} +#[no_mangle] +/// Read a Stfu from a byte array, created by Stfu_write +pub extern "C" fn Stfu_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_StfuDecodeErrorZ { + 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::msgs::Stfu { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; + local_res +} +#[no_mangle] +/// Serialize the SpliceInit object into a byte array which can be read by SpliceInit_read +pub extern "C" fn SpliceInit_write(obj: &crate::lightning::ln::msgs::SpliceInit) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) +} +#[allow(unused)] +pub(crate) extern "C" fn SpliceInit_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeSpliceInit) }) +} +#[no_mangle] +/// Read a SpliceInit from a byte array, created by SpliceInit_write +pub extern "C" fn SpliceInit_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_SpliceInitDecodeErrorZ { + 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::msgs::SpliceInit { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; + local_res +} +#[no_mangle] +/// Serialize the SpliceAck object into a byte array which can be read by SpliceAck_read +pub extern "C" fn SpliceAck_write(obj: &crate::lightning::ln::msgs::SpliceAck) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) +} +#[allow(unused)] +pub(crate) extern "C" fn SpliceAck_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeSpliceAck) }) +} +#[no_mangle] +/// Read a SpliceAck from a byte array, created by SpliceAck_write +pub extern "C" fn SpliceAck_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_SpliceAckDecodeErrorZ { + 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::msgs::SpliceAck { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; + local_res +} +#[no_mangle] +/// Serialize the SpliceLocked object into a byte array which can be read by SpliceLocked_read +pub extern "C" fn SpliceLocked_write(obj: &crate::lightning::ln::msgs::SpliceLocked) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) +} +#[allow(unused)] +pub(crate) extern "C" fn SpliceLocked_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeSpliceLocked) }) +} +#[no_mangle] +/// Read a SpliceLocked from a byte array, created by SpliceLocked_write +pub extern "C" fn SpliceLocked_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_SpliceLockedDecodeErrorZ { + 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::msgs::SpliceLocked { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; + local_res +} +#[no_mangle] /// Serialize the TxAddInput object into a byte array which can be read by TxAddInput_read pub extern "C" fn TxAddInput_write(obj: &crate::lightning::ln::msgs::TxAddInput) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn TxAddInput_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeTxAddInput) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeTxAddInput) }) } #[no_mangle] /// Read a TxAddInput from a byte array, created by TxAddInput_write @@ -8624,9 +11451,9 @@ pub extern "C" fn TxAddInput_read(ser: crate::c_types::u8slice) -> crate::c_type pub extern "C" fn TxAddOutput_write(obj: &crate::lightning::ln::msgs::TxAddOutput) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn TxAddOutput_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeTxAddOutput) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeTxAddOutput) }) } #[no_mangle] /// Read a TxAddOutput from a byte array, created by TxAddOutput_write @@ -8640,9 +11467,9 @@ pub extern "C" fn TxAddOutput_read(ser: crate::c_types::u8slice) -> crate::c_typ pub extern "C" fn TxRemoveInput_write(obj: &crate::lightning::ln::msgs::TxRemoveInput) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn TxRemoveInput_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeTxRemoveInput) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeTxRemoveInput) }) } #[no_mangle] /// Read a TxRemoveInput from a byte array, created by TxRemoveInput_write @@ -8656,9 +11483,9 @@ pub extern "C" fn TxRemoveInput_read(ser: crate::c_types::u8slice) -> crate::c_t pub extern "C" fn TxRemoveOutput_write(obj: &crate::lightning::ln::msgs::TxRemoveOutput) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn TxRemoveOutput_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeTxRemoveOutput) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeTxRemoveOutput) }) } #[no_mangle] /// Read a TxRemoveOutput from a byte array, created by TxRemoveOutput_write @@ -8672,9 +11499,9 @@ pub extern "C" fn TxRemoveOutput_read(ser: crate::c_types::u8slice) -> crate::c_ pub extern "C" fn TxComplete_write(obj: &crate::lightning::ln::msgs::TxComplete) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn TxComplete_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeTxComplete) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeTxComplete) }) } #[no_mangle] /// Read a TxComplete from a byte array, created by TxComplete_write @@ -8688,9 +11515,9 @@ pub extern "C" fn TxComplete_read(ser: crate::c_types::u8slice) -> crate::c_type pub extern "C" fn TxSignatures_write(obj: &crate::lightning::ln::msgs::TxSignatures) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn TxSignatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeTxSignatures) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeTxSignatures) }) } #[no_mangle] /// Read a TxSignatures from a byte array, created by TxSignatures_write @@ -8704,9 +11531,9 @@ pub extern "C" fn TxSignatures_read(ser: crate::c_types::u8slice) -> crate::c_ty pub extern "C" fn TxInitRbf_write(obj: &crate::lightning::ln::msgs::TxInitRbf) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn TxInitRbf_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeTxInitRbf) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeTxInitRbf) }) } #[no_mangle] /// Read a TxInitRbf from a byte array, created by TxInitRbf_write @@ -8720,9 +11547,9 @@ pub extern "C" fn TxInitRbf_read(ser: crate::c_types::u8slice) -> crate::c_types pub extern "C" fn TxAckRbf_write(obj: &crate::lightning::ln::msgs::TxAckRbf) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn TxAckRbf_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeTxAckRbf) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeTxAckRbf) }) } #[no_mangle] /// Read a TxAckRbf from a byte array, created by TxAckRbf_write @@ -8736,9 +11563,9 @@ pub extern "C" fn TxAckRbf_read(ser: crate::c_types::u8slice) -> crate::c_types: pub extern "C" fn TxAbort_write(obj: &crate::lightning::ln::msgs::TxAbort) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn TxAbort_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeTxAbort) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeTxAbort) }) } #[no_mangle] /// Read a TxAbort from a byte array, created by TxAbort_write @@ -8752,9 +11579,9 @@ pub extern "C" fn TxAbort_read(ser: crate::c_types::u8slice) -> crate::c_types:: pub extern "C" fn AnnouncementSignatures_write(obj: &crate::lightning::ln::msgs::AnnouncementSignatures) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn AnnouncementSignatures_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeAnnouncementSignatures) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeAnnouncementSignatures) }) } #[no_mangle] /// Read a AnnouncementSignatures from a byte array, created by AnnouncementSignatures_write @@ -8768,9 +11595,9 @@ pub extern "C" fn AnnouncementSignatures_read(ser: crate::c_types::u8slice) -> c pub extern "C" fn ChannelReestablish_write(obj: &crate::lightning::ln::msgs::ChannelReestablish) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn ChannelReestablish_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelReestablish) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeChannelReestablish) }) } #[no_mangle] /// Read a ChannelReestablish from a byte array, created by ChannelReestablish_write @@ -8784,9 +11611,9 @@ pub extern "C" fn ChannelReestablish_read(ser: crate::c_types::u8slice) -> crate pub extern "C" fn ClosingSigned_write(obj: &crate::lightning::ln::msgs::ClosingSigned) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn ClosingSigned_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeClosingSigned) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeClosingSigned) }) } #[no_mangle] /// Read a ClosingSigned from a byte array, created by ClosingSigned_write @@ -8800,9 +11627,9 @@ pub extern "C" fn ClosingSigned_read(ser: crate::c_types::u8slice) -> crate::c_t pub extern "C" fn ClosingSignedFeeRange_write(obj: &crate::lightning::ln::msgs::ClosingSignedFeeRange) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn ClosingSignedFeeRange_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeClosingSignedFeeRange) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeClosingSignedFeeRange) }) } #[no_mangle] /// Read a ClosingSignedFeeRange from a byte array, created by ClosingSignedFeeRange_write @@ -8812,13 +11639,29 @@ pub extern "C" fn ClosingSignedFeeRange_read(ser: crate::c_types::u8slice) -> cr local_res } #[no_mangle] +/// Serialize the CommitmentSignedBatch object into a byte array which can be read by CommitmentSignedBatch_read +pub extern "C" fn CommitmentSignedBatch_write(obj: &crate::lightning::ln::msgs::CommitmentSignedBatch) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) +} +#[allow(unused)] +pub(crate) extern "C" fn CommitmentSignedBatch_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeCommitmentSignedBatch) }) +} +#[no_mangle] +/// Read a CommitmentSignedBatch from a byte array, created by CommitmentSignedBatch_write +pub extern "C" fn CommitmentSignedBatch_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_CommitmentSignedBatchDecodeErrorZ { + 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::msgs::CommitmentSignedBatch { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; + local_res +} +#[no_mangle] /// Serialize the CommitmentSigned object into a byte array which can be read by CommitmentSigned_read pub extern "C" fn CommitmentSigned_write(obj: &crate::lightning::ln::msgs::CommitmentSigned) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn CommitmentSigned_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeCommitmentSigned) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeCommitmentSigned) }) } #[no_mangle] /// Read a CommitmentSigned from a byte array, created by CommitmentSigned_write @@ -8832,9 +11675,9 @@ pub extern "C" fn CommitmentSigned_read(ser: crate::c_types::u8slice) -> crate:: pub extern "C" fn FundingCreated_write(obj: &crate::lightning::ln::msgs::FundingCreated) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn FundingCreated_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeFundingCreated) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeFundingCreated) }) } #[no_mangle] /// Read a FundingCreated from a byte array, created by FundingCreated_write @@ -8848,9 +11691,9 @@ pub extern "C" fn FundingCreated_read(ser: crate::c_types::u8slice) -> crate::c_ pub extern "C" fn FundingSigned_write(obj: &crate::lightning::ln::msgs::FundingSigned) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn FundingSigned_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeFundingSigned) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeFundingSigned) }) } #[no_mangle] /// Read a FundingSigned from a byte array, created by FundingSigned_write @@ -8864,9 +11707,9 @@ pub extern "C" fn FundingSigned_read(ser: crate::c_types::u8slice) -> crate::c_t pub extern "C" fn ChannelReady_write(obj: &crate::lightning::ln::msgs::ChannelReady) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn ChannelReady_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelReady) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeChannelReady) }) } #[no_mangle] /// Read a ChannelReady from a byte array, created by ChannelReady_write @@ -8880,9 +11723,9 @@ pub extern "C" fn ChannelReady_read(ser: crate::c_types::u8slice) -> crate::c_ty pub extern "C" fn Init_write(obj: &crate::lightning::ln::msgs::Init) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn Init_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeInit) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeInit) }) } #[no_mangle] /// Read a Init from a byte array, created by Init_write @@ -8896,9 +11739,9 @@ pub extern "C" fn Init_read(ser: crate::c_types::u8slice) -> crate::c_types::der pub extern "C" fn OpenChannel_write(obj: &crate::lightning::ln::msgs::OpenChannel) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn OpenChannel_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeOpenChannel) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeOpenChannel) }) } #[no_mangle] /// Read a OpenChannel from a byte array, created by OpenChannel_write @@ -8912,9 +11755,9 @@ pub extern "C" fn OpenChannel_read(ser: crate::c_types::u8slice) -> crate::c_typ pub extern "C" fn OpenChannelV2_write(obj: &crate::lightning::ln::msgs::OpenChannelV2) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn OpenChannelV2_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeOpenChannelV2) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeOpenChannelV2) }) } #[no_mangle] /// Read a OpenChannelV2 from a byte array, created by OpenChannelV2_write @@ -8928,9 +11771,9 @@ pub extern "C" fn OpenChannelV2_read(ser: crate::c_types::u8slice) -> crate::c_t pub extern "C" fn RevokeAndACK_write(obj: &crate::lightning::ln::msgs::RevokeAndACK) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn RevokeAndACK_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRevokeAndACK) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeRevokeAndACK) }) } #[no_mangle] /// Read a RevokeAndACK from a byte array, created by RevokeAndACK_write @@ -8944,9 +11787,9 @@ pub extern "C" fn RevokeAndACK_read(ser: crate::c_types::u8slice) -> crate::c_ty pub extern "C" fn Shutdown_write(obj: &crate::lightning::ln::msgs::Shutdown) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn Shutdown_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeShutdown) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeShutdown) }) } #[no_mangle] /// Read a Shutdown from a byte array, created by Shutdown_write @@ -8960,9 +11803,9 @@ pub extern "C" fn Shutdown_read(ser: crate::c_types::u8slice) -> crate::c_types: pub extern "C" fn UpdateFailHTLC_write(obj: &crate::lightning::ln::msgs::UpdateFailHTLC) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn UpdateFailHTLC_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUpdateFailHTLC) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeUpdateFailHTLC) }) } #[no_mangle] /// Read a UpdateFailHTLC from a byte array, created by UpdateFailHTLC_write @@ -8976,9 +11819,9 @@ pub extern "C" fn UpdateFailHTLC_read(ser: crate::c_types::u8slice) -> crate::c_ pub extern "C" fn UpdateFailMalformedHTLC_write(obj: &crate::lightning::ln::msgs::UpdateFailMalformedHTLC) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn UpdateFailMalformedHTLC_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUpdateFailMalformedHTLC) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeUpdateFailMalformedHTLC) }) } #[no_mangle] /// Read a UpdateFailMalformedHTLC from a byte array, created by UpdateFailMalformedHTLC_write @@ -8992,9 +11835,9 @@ pub extern "C" fn UpdateFailMalformedHTLC_read(ser: crate::c_types::u8slice) -> pub extern "C" fn UpdateFee_write(obj: &crate::lightning::ln::msgs::UpdateFee) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn UpdateFee_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUpdateFee) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeUpdateFee) }) } #[no_mangle] /// Read a UpdateFee from a byte array, created by UpdateFee_write @@ -9008,9 +11851,9 @@ pub extern "C" fn UpdateFee_read(ser: crate::c_types::u8slice) -> crate::c_types pub extern "C" fn UpdateFulfillHTLC_write(obj: &crate::lightning::ln::msgs::UpdateFulfillHTLC) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn UpdateFulfillHTLC_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUpdateFulfillHTLC) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeUpdateFulfillHTLC) }) } #[no_mangle] /// Read a UpdateFulfillHTLC from a byte array, created by UpdateFulfillHTLC_write @@ -9020,13 +11863,29 @@ pub extern "C" fn UpdateFulfillHTLC_read(ser: crate::c_types::u8slice) -> crate: local_res } #[no_mangle] +/// Serialize the OnionPacket object into a byte array which can be read by OnionPacket_read +pub extern "C" fn OnionPacket_write(obj: &crate::lightning::ln::msgs::OnionPacket) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) +} +#[allow(unused)] +pub(crate) extern "C" fn OnionPacket_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeOnionPacket) }) +} +#[no_mangle] +/// Read a OnionPacket from a byte array, created by OnionPacket_write +pub extern "C" fn OnionPacket_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_OnionPacketDecodeErrorZ { + 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::msgs::OnionPacket { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; + local_res +} +#[no_mangle] /// Serialize the UpdateAddHTLC object into a byte array which can be read by UpdateAddHTLC_read pub extern "C" fn UpdateAddHTLC_write(obj: &crate::lightning::ln::msgs::UpdateAddHTLC) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn UpdateAddHTLC_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUpdateAddHTLC) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeUpdateAddHTLC) }) } #[no_mangle] /// Read a UpdateAddHTLC from a byte array, created by UpdateAddHTLC_write @@ -9047,18 +11906,34 @@ pub extern "C" fn OnionMessage_read(ser: crate::c_types::u8slice) -> crate::c_ty pub extern "C" fn OnionMessage_write(obj: &crate::lightning::ln::msgs::OnionMessage) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn OnionMessage_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeOnionMessage) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeOnionMessage) }) +} +#[no_mangle] +/// Serialize the FinalOnionHopData object into a byte array which can be read by FinalOnionHopData_read +pub extern "C" fn FinalOnionHopData_write(obj: &crate::lightning::ln::msgs::FinalOnionHopData) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) +} +#[allow(unused)] +pub(crate) extern "C" fn FinalOnionHopData_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeFinalOnionHopData) }) +} +#[no_mangle] +/// Read a FinalOnionHopData from a byte array, created by FinalOnionHopData_write +pub extern "C" fn FinalOnionHopData_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_FinalOnionHopDataDecodeErrorZ { + 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::msgs::FinalOnionHopData { inner: ObjOps::heap_alloc(o), is_owned: true } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::ln::msgs::DecodeError::native_into(e) }).into() }; + local_res } #[no_mangle] /// Serialize the Ping object into a byte array which can be read by Ping_read pub extern "C" fn Ping_write(obj: &crate::lightning::ln::msgs::Ping) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn Ping_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativePing) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativePing) }) } #[no_mangle] /// Read a Ping from a byte array, created by Ping_write @@ -9072,9 +11947,9 @@ pub extern "C" fn Ping_read(ser: crate::c_types::u8slice) -> crate::c_types::der pub extern "C" fn Pong_write(obj: &crate::lightning::ln::msgs::Pong) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn Pong_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativePong) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativePong) }) } #[no_mangle] /// Read a Pong from a byte array, created by Pong_write @@ -9088,9 +11963,9 @@ pub extern "C" fn Pong_read(ser: crate::c_types::u8slice) -> crate::c_types::der pub extern "C" fn UnsignedChannelAnnouncement_write(obj: &crate::lightning::ln::msgs::UnsignedChannelAnnouncement) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn UnsignedChannelAnnouncement_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUnsignedChannelAnnouncement) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeUnsignedChannelAnnouncement) }) } #[no_mangle] /// Read a UnsignedChannelAnnouncement from a byte array, created by UnsignedChannelAnnouncement_write @@ -9104,9 +11979,9 @@ pub extern "C" fn UnsignedChannelAnnouncement_read(ser: crate::c_types::u8slice) pub extern "C" fn ChannelAnnouncement_write(obj: &crate::lightning::ln::msgs::ChannelAnnouncement) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn ChannelAnnouncement_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelAnnouncement) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeChannelAnnouncement) }) } #[no_mangle] /// Read a ChannelAnnouncement from a byte array, created by ChannelAnnouncement_write @@ -9120,9 +11995,9 @@ pub extern "C" fn ChannelAnnouncement_read(ser: crate::c_types::u8slice) -> crat pub extern "C" fn UnsignedChannelUpdate_write(obj: &crate::lightning::ln::msgs::UnsignedChannelUpdate) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn UnsignedChannelUpdate_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUnsignedChannelUpdate) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeUnsignedChannelUpdate) }) } #[no_mangle] /// Read a UnsignedChannelUpdate from a byte array, created by UnsignedChannelUpdate_write @@ -9136,9 +12011,9 @@ pub extern "C" fn UnsignedChannelUpdate_read(ser: crate::c_types::u8slice) -> cr pub extern "C" fn ChannelUpdate_write(obj: &crate::lightning::ln::msgs::ChannelUpdate) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn ChannelUpdate_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeChannelUpdate) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeChannelUpdate) }) } #[no_mangle] /// Read a ChannelUpdate from a byte array, created by ChannelUpdate_write @@ -9152,9 +12027,9 @@ pub extern "C" fn ChannelUpdate_read(ser: crate::c_types::u8slice) -> crate::c_t pub extern "C" fn ErrorMessage_write(obj: &crate::lightning::ln::msgs::ErrorMessage) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn ErrorMessage_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeErrorMessage) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeErrorMessage) }) } #[no_mangle] /// Read a ErrorMessage from a byte array, created by ErrorMessage_write @@ -9168,9 +12043,9 @@ pub extern "C" fn ErrorMessage_read(ser: crate::c_types::u8slice) -> crate::c_ty pub extern "C" fn WarningMessage_write(obj: &crate::lightning::ln::msgs::WarningMessage) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn WarningMessage_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeWarningMessage) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeWarningMessage) }) } #[no_mangle] /// Read a WarningMessage from a byte array, created by WarningMessage_write @@ -9184,9 +12059,9 @@ pub extern "C" fn WarningMessage_read(ser: crate::c_types::u8slice) -> crate::c_ pub extern "C" fn UnsignedNodeAnnouncement_write(obj: &crate::lightning::ln::msgs::UnsignedNodeAnnouncement) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn UnsignedNodeAnnouncement_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeUnsignedNodeAnnouncement) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeUnsignedNodeAnnouncement) }) } #[no_mangle] /// Read a UnsignedNodeAnnouncement from a byte array, created by UnsignedNodeAnnouncement_write @@ -9200,9 +12075,9 @@ pub extern "C" fn UnsignedNodeAnnouncement_read(ser: crate::c_types::u8slice) -> pub extern "C" fn NodeAnnouncement_write(obj: &crate::lightning::ln::msgs::NodeAnnouncement) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn NodeAnnouncement_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeNodeAnnouncement) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeNodeAnnouncement) }) } #[no_mangle] /// Read a NodeAnnouncement from a byte array, created by NodeAnnouncement_write @@ -9223,18 +12098,18 @@ pub extern "C" fn QueryShortChannelIds_read(ser: crate::c_types::u8slice) -> cra pub extern "C" fn QueryShortChannelIds_write(obj: &crate::lightning::ln::msgs::QueryShortChannelIds) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn QueryShortChannelIds_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeQueryShortChannelIds) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeQueryShortChannelIds) }) } #[no_mangle] /// Serialize the ReplyShortChannelIdsEnd object into a byte array which can be read by ReplyShortChannelIdsEnd_read pub extern "C" fn ReplyShortChannelIdsEnd_write(obj: &crate::lightning::ln::msgs::ReplyShortChannelIdsEnd) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn ReplyShortChannelIdsEnd_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeReplyShortChannelIdsEnd) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeReplyShortChannelIdsEnd) }) } #[no_mangle] /// Read a ReplyShortChannelIdsEnd from a byte array, created by ReplyShortChannelIdsEnd_write @@ -9258,9 +12133,9 @@ pub extern "C" fn QueryChannelRange_end_blocknum(this_arg: &crate::lightning::ln pub extern "C" fn QueryChannelRange_write(obj: &crate::lightning::ln::msgs::QueryChannelRange) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn QueryChannelRange_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeQueryChannelRange) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeQueryChannelRange) }) } #[no_mangle] /// Read a QueryChannelRange from a byte array, created by QueryChannelRange_write @@ -9281,18 +12156,18 @@ pub extern "C" fn ReplyChannelRange_read(ser: crate::c_types::u8slice) -> crate: pub extern "C" fn ReplyChannelRange_write(obj: &crate::lightning::ln::msgs::ReplyChannelRange) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn ReplyChannelRange_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeReplyChannelRange) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeReplyChannelRange) }) } #[no_mangle] /// Serialize the GossipTimestampFilter object into a byte array which can be read by GossipTimestampFilter_read pub extern "C" fn GossipTimestampFilter_write(obj: &crate::lightning::ln::msgs::GossipTimestampFilter) -> crate::c_types::derived::CVec_u8Z { crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref()) } -#[no_mangle] +#[allow(unused)] pub(crate) extern "C" fn GossipTimestampFilter_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z { - crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeGossipTimestampFilter) }) + crate::c_types::serialize_obj(unsafe { &*(obj as *const crate::lightning::ln::msgs::nativeGossipTimestampFilter) }) } #[no_mangle] /// Read a GossipTimestampFilter from a byte array, created by GossipTimestampFilter_write