1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
4 // This file is licensed under the license available in the LICENSE or LICENSE.md
5 // file in the root of this repository or, if no such file exists, the same
6 // license as that which applies to the original source files from which this
7 // source was automatically generated.
9 //! Keys used to generate commitment transactions.
10 //! See: <https://github.com/lightning/bolts/blob/master/03-transactions.md#keys>
12 use alloc::str::FromStr;
13 use alloc::string::String;
14 use core::ffi::c_void;
15 use core::convert::Infallible;
16 use bitcoin::hashes::Hash;
17 use crate::c_types::*;
18 #[cfg(feature="no-std")]
19 use alloc::{vec::Vec, boxed::Box};
22 use lightning::ln::channel_keys::DelayedPaymentBasepoint as nativeDelayedPaymentBasepointImport;
23 pub(crate) type nativeDelayedPaymentBasepoint = nativeDelayedPaymentBasepointImport;
25 /// Base key used in conjunction with a `per_commitment_point` to generate a [`DelayedPaymentKey`].
27 /// The delayed payment key is used to pay the commitment state broadcaster their
28 /// non-HTLC-encumbered funds after a delay to give their counterparty a chance to punish if the
29 /// state broadcasted was previously revoked.
32 pub struct DelayedPaymentBasepoint {
33 /// A pointer to the opaque Rust object.
35 /// Nearly everywhere, inner must be non-null, however in places where
36 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
37 pub inner: *mut nativeDelayedPaymentBasepoint,
38 /// Indicates that this is the only struct which contains the same pointer.
40 /// Rust functions which take ownership of an object provided via an argument require
41 /// this to be true and invalidate the object pointed to by inner.
45 impl Drop for DelayedPaymentBasepoint {
47 if self.is_owned && !<*mut nativeDelayedPaymentBasepoint>::is_null(self.inner) {
48 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
52 /// Frees any resources used by the DelayedPaymentBasepoint, if is_owned is set and inner is non-NULL.
54 pub extern "C" fn DelayedPaymentBasepoint_free(this_obj: DelayedPaymentBasepoint) { }
56 /// Used only if an object of this type is returned as a trait impl by a method
57 pub(crate) extern "C" fn DelayedPaymentBasepoint_free_void(this_ptr: *mut c_void) {
58 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeDelayedPaymentBasepoint) };
61 impl DelayedPaymentBasepoint {
62 pub(crate) fn get_native_ref(&self) -> &'static nativeDelayedPaymentBasepoint {
63 unsafe { &*ObjOps::untweak_ptr(self.inner) }
65 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDelayedPaymentBasepoint {
66 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
68 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
69 pub(crate) fn take_inner(mut self) -> *mut nativeDelayedPaymentBasepoint {
70 assert!(self.is_owned);
71 let ret = ObjOps::untweak_ptr(self.inner);
72 self.inner = core::ptr::null_mut();
77 pub extern "C" fn DelayedPaymentBasepoint_get_a(this_ptr: &DelayedPaymentBasepoint) -> crate::c_types::PublicKey {
78 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
79 crate::c_types::PublicKey::from_rust(&inner_val)
82 pub extern "C" fn DelayedPaymentBasepoint_set_a(this_ptr: &mut DelayedPaymentBasepoint, mut val: crate::c_types::PublicKey) {
83 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val.into_rust();
85 /// Constructs a new DelayedPaymentBasepoint given each field
88 pub extern "C" fn DelayedPaymentBasepoint_new(mut a_arg: crate::c_types::PublicKey) -> DelayedPaymentBasepoint {
89 DelayedPaymentBasepoint { inner: ObjOps::heap_alloc(lightning::ln::channel_keys::DelayedPaymentBasepoint (
93 /// Checks if two DelayedPaymentBasepoints contain equal inner contents.
94 /// This ignores pointers and is_owned flags and looks at the values in fields.
95 /// Two objects with NULL inner values will be considered "equal" here.
97 pub extern "C" fn DelayedPaymentBasepoint_eq(a: &DelayedPaymentBasepoint, b: &DelayedPaymentBasepoint) -> bool {
98 if a.inner == b.inner { return true; }
99 if a.inner.is_null() || b.inner.is_null() { return false; }
100 if a.get_native_ref() == b.get_native_ref() { true } else { false }
102 impl Clone for DelayedPaymentBasepoint {
103 fn clone(&self) -> Self {
105 inner: if <*mut nativeDelayedPaymentBasepoint>::is_null(self.inner) { core::ptr::null_mut() } else {
106 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
112 /// Used only if an object of this type is returned as a trait impl by a method
113 pub(crate) extern "C" fn DelayedPaymentBasepoint_clone_void(this_ptr: *const c_void) -> *mut c_void {
114 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeDelayedPaymentBasepoint)).clone() })) as *mut c_void
117 /// Creates a copy of the DelayedPaymentBasepoint
118 pub extern "C" fn DelayedPaymentBasepoint_clone(orig: &DelayedPaymentBasepoint) -> DelayedPaymentBasepoint {
121 /// Get a string which allows debug introspection of a DelayedPaymentBasepoint object
122 pub extern "C" fn DelayedPaymentBasepoint_debug_str_void(o: *const c_void) -> Str {
123 alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::channel_keys::DelayedPaymentBasepoint }).into()}
124 /// Generates a non-cryptographic 64-bit hash of the DelayedPaymentBasepoint.
126 pub extern "C" fn DelayedPaymentBasepoint_hash(o: &DelayedPaymentBasepoint) -> u64 {
127 if o.inner.is_null() { return 0; }
128 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
130 let mut hasher = core::hash::SipHasher::new();
131 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
132 core::hash::Hasher::finish(&hasher)
134 /// Get inner Public Key
137 pub extern "C" fn DelayedPaymentBasepoint_to_public_key(this_arg: &crate::lightning::ln::channel_keys::DelayedPaymentBasepoint) -> crate::c_types::PublicKey {
138 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.to_public_key();
139 crate::c_types::PublicKey::from_rust(&ret)
142 ///Derives the \"tweak\" used in calculate [`DelayedPaymentKey::from_basepoint`].\n\n[`DelayedPaymentKey::from_basepoint`] calculates a private key as:\n`privkey = basepoint_secret + SHA256(per_commitment_point || basepoint)`\n\nThis calculates the hash part in the tweak derivation process, which is used to\nensure that each key is unique and cannot be guessed by an external party.
145 pub extern "C" fn DelayedPaymentBasepoint_derive_add_tweak(this_arg: &crate::lightning::ln::channel_keys::DelayedPaymentBasepoint, mut per_commitment_point: crate::c_types::PublicKey) -> crate::c_types::ThirtyTwoBytes {
146 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.derive_add_tweak(&per_commitment_point.into_rust());
147 crate::c_types::ThirtyTwoBytes { data: *ret.as_ref() }
151 /// Serialize the DelayedPaymentBasepoint object into a byte array which can be read by DelayedPaymentBasepoint_read
152 pub extern "C" fn DelayedPaymentBasepoint_write(obj: &crate::lightning::ln::channel_keys::DelayedPaymentBasepoint) -> crate::c_types::derived::CVec_u8Z {
153 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
156 pub(crate) extern "C" fn DelayedPaymentBasepoint_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
157 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeDelayedPaymentBasepoint) })
160 /// Read a DelayedPaymentBasepoint from a byte array, created by DelayedPaymentBasepoint_write
161 pub extern "C" fn DelayedPaymentBasepoint_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_DelayedPaymentBasepointDecodeErrorZ {
162 let res: Result<lightning::ln::channel_keys::DelayedPaymentBasepoint, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
163 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::channel_keys::DelayedPaymentBasepoint { 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() };
167 use lightning::ln::channel_keys::DelayedPaymentKey as nativeDelayedPaymentKeyImport;
168 pub(crate) type nativeDelayedPaymentKey = nativeDelayedPaymentKeyImport;
170 /// A derived key built from a [`DelayedPaymentBasepoint`] and `per_commitment_point`.
172 /// The delayed payment key is used to pay the commitment state broadcaster their
173 /// non-HTLC-encumbered funds after a delay. This delay gives their counterparty a chance to
174 /// punish and claim all the channel funds if the state broadcasted was previously revoked.
176 /// [See the BOLT specs]
177 /// (https://github.com/lightning/bolts/blob/master/03-transactions.md#localpubkey-local_htlcpubkey-remote_htlcpubkey-local_delayedpubkey-and-remote_delayedpubkey-derivation)
178 /// for more information on key derivation details.
181 pub struct DelayedPaymentKey {
182 /// A pointer to the opaque Rust object.
184 /// Nearly everywhere, inner must be non-null, however in places where
185 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
186 pub inner: *mut nativeDelayedPaymentKey,
187 /// Indicates that this is the only struct which contains the same pointer.
189 /// Rust functions which take ownership of an object provided via an argument require
190 /// this to be true and invalidate the object pointed to by inner.
194 impl Drop for DelayedPaymentKey {
196 if self.is_owned && !<*mut nativeDelayedPaymentKey>::is_null(self.inner) {
197 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
201 /// Frees any resources used by the DelayedPaymentKey, if is_owned is set and inner is non-NULL.
203 pub extern "C" fn DelayedPaymentKey_free(this_obj: DelayedPaymentKey) { }
205 /// Used only if an object of this type is returned as a trait impl by a method
206 pub(crate) extern "C" fn DelayedPaymentKey_free_void(this_ptr: *mut c_void) {
207 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeDelayedPaymentKey) };
210 impl DelayedPaymentKey {
211 pub(crate) fn get_native_ref(&self) -> &'static nativeDelayedPaymentKey {
212 unsafe { &*ObjOps::untweak_ptr(self.inner) }
214 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeDelayedPaymentKey {
215 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
217 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
218 pub(crate) fn take_inner(mut self) -> *mut nativeDelayedPaymentKey {
219 assert!(self.is_owned);
220 let ret = ObjOps::untweak_ptr(self.inner);
221 self.inner = core::ptr::null_mut();
226 pub extern "C" fn DelayedPaymentKey_get_a(this_ptr: &DelayedPaymentKey) -> crate::c_types::PublicKey {
227 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
228 crate::c_types::PublicKey::from_rust(&inner_val)
231 pub extern "C" fn DelayedPaymentKey_set_a(this_ptr: &mut DelayedPaymentKey, mut val: crate::c_types::PublicKey) {
232 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val.into_rust();
234 /// Constructs a new DelayedPaymentKey given each field
237 pub extern "C" fn DelayedPaymentKey_new(mut a_arg: crate::c_types::PublicKey) -> DelayedPaymentKey {
238 DelayedPaymentKey { inner: ObjOps::heap_alloc(lightning::ln::channel_keys::DelayedPaymentKey (
242 /// Checks if two DelayedPaymentKeys contain equal inner contents.
243 /// This ignores pointers and is_owned flags and looks at the values in fields.
244 /// Two objects with NULL inner values will be considered "equal" here.
246 pub extern "C" fn DelayedPaymentKey_eq(a: &DelayedPaymentKey, b: &DelayedPaymentKey) -> bool {
247 if a.inner == b.inner { return true; }
248 if a.inner.is_null() || b.inner.is_null() { return false; }
249 if a.get_native_ref() == b.get_native_ref() { true } else { false }
251 impl Clone for DelayedPaymentKey {
252 fn clone(&self) -> Self {
254 inner: if <*mut nativeDelayedPaymentKey>::is_null(self.inner) { core::ptr::null_mut() } else {
255 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
261 /// Used only if an object of this type is returned as a trait impl by a method
262 pub(crate) extern "C" fn DelayedPaymentKey_clone_void(this_ptr: *const c_void) -> *mut c_void {
263 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeDelayedPaymentKey)).clone() })) as *mut c_void
266 /// Creates a copy of the DelayedPaymentKey
267 pub extern "C" fn DelayedPaymentKey_clone(orig: &DelayedPaymentKey) -> DelayedPaymentKey {
270 /// Get a string which allows debug introspection of a DelayedPaymentKey object
271 pub extern "C" fn DelayedPaymentKey_debug_str_void(o: *const c_void) -> Str {
272 alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::channel_keys::DelayedPaymentKey }).into()}
273 ///Derive a public delayedpubkey using one node\'s `per_commitment_point` and its countersignatory\'s `basepoint`
276 pub extern "C" fn DelayedPaymentKey_from_basepoint(countersignatory_basepoint: &crate::lightning::ln::channel_keys::DelayedPaymentBasepoint, mut per_commitment_point: crate::c_types::PublicKey) -> crate::lightning::ln::channel_keys::DelayedPaymentKey {
277 let mut ret = lightning::ln::channel_keys::DelayedPaymentKey::from_basepoint(secp256k1::global::SECP256K1, countersignatory_basepoint.get_native_ref(), &per_commitment_point.into_rust());
278 crate::lightning::ln::channel_keys::DelayedPaymentKey { inner: ObjOps::heap_alloc(ret), is_owned: true }
281 ///Build a delayedpubkey directly from an already-derived private key
284 pub extern "C" fn DelayedPaymentKey_from_secret_key(sk: *const [u8; 32]) -> crate::lightning::ln::channel_keys::DelayedPaymentKey {
285 let mut ret = lightning::ln::channel_keys::DelayedPaymentKey::from_secret_key(secp256k1::global::SECP256K1, &::bitcoin::secp256k1::SecretKey::from_slice(&unsafe { *sk}[..]).unwrap());
286 crate::lightning::ln::channel_keys::DelayedPaymentKey { inner: ObjOps::heap_alloc(ret), is_owned: true }
289 /// Get inner Public Key
292 pub extern "C" fn DelayedPaymentKey_to_public_key(this_arg: &crate::lightning::ln::channel_keys::DelayedPaymentKey) -> crate::c_types::PublicKey {
293 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.to_public_key();
294 crate::c_types::PublicKey::from_rust(&ret)
298 /// Serialize the DelayedPaymentKey object into a byte array which can be read by DelayedPaymentKey_read
299 pub extern "C" fn DelayedPaymentKey_write(obj: &crate::lightning::ln::channel_keys::DelayedPaymentKey) -> crate::c_types::derived::CVec_u8Z {
300 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
303 pub(crate) extern "C" fn DelayedPaymentKey_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
304 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeDelayedPaymentKey) })
307 /// Read a DelayedPaymentKey from a byte array, created by DelayedPaymentKey_write
308 pub extern "C" fn DelayedPaymentKey_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_DelayedPaymentKeyDecodeErrorZ {
309 let res: Result<lightning::ln::channel_keys::DelayedPaymentKey, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
310 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::channel_keys::DelayedPaymentKey { 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() };
314 use lightning::ln::channel_keys::HtlcBasepoint as nativeHtlcBasepointImport;
315 pub(crate) type nativeHtlcBasepoint = nativeHtlcBasepointImport;
317 /// Base key used in conjunction with a `per_commitment_point` to generate an [`HtlcKey`].
319 /// HTLC keys are used to ensure only the recipient of an HTLC can claim it on-chain with the HTLC
320 /// preimage and that only the sender of an HTLC can claim it on-chain after it has timed out.
321 /// Thus, both channel counterparties' HTLC keys will appears in each HTLC output's script.
324 pub struct HtlcBasepoint {
325 /// A pointer to the opaque Rust object.
327 /// Nearly everywhere, inner must be non-null, however in places where
328 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
329 pub inner: *mut nativeHtlcBasepoint,
330 /// Indicates that this is the only struct which contains the same pointer.
332 /// Rust functions which take ownership of an object provided via an argument require
333 /// this to be true and invalidate the object pointed to by inner.
337 impl Drop for HtlcBasepoint {
339 if self.is_owned && !<*mut nativeHtlcBasepoint>::is_null(self.inner) {
340 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
344 /// Frees any resources used by the HtlcBasepoint, if is_owned is set and inner is non-NULL.
346 pub extern "C" fn HtlcBasepoint_free(this_obj: HtlcBasepoint) { }
348 /// Used only if an object of this type is returned as a trait impl by a method
349 pub(crate) extern "C" fn HtlcBasepoint_free_void(this_ptr: *mut c_void) {
350 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeHtlcBasepoint) };
354 pub(crate) fn get_native_ref(&self) -> &'static nativeHtlcBasepoint {
355 unsafe { &*ObjOps::untweak_ptr(self.inner) }
357 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeHtlcBasepoint {
358 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
360 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
361 pub(crate) fn take_inner(mut self) -> *mut nativeHtlcBasepoint {
362 assert!(self.is_owned);
363 let ret = ObjOps::untweak_ptr(self.inner);
364 self.inner = core::ptr::null_mut();
369 pub extern "C" fn HtlcBasepoint_get_a(this_ptr: &HtlcBasepoint) -> crate::c_types::PublicKey {
370 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
371 crate::c_types::PublicKey::from_rust(&inner_val)
374 pub extern "C" fn HtlcBasepoint_set_a(this_ptr: &mut HtlcBasepoint, mut val: crate::c_types::PublicKey) {
375 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val.into_rust();
377 /// Constructs a new HtlcBasepoint given each field
380 pub extern "C" fn HtlcBasepoint_new(mut a_arg: crate::c_types::PublicKey) -> HtlcBasepoint {
381 HtlcBasepoint { inner: ObjOps::heap_alloc(lightning::ln::channel_keys::HtlcBasepoint (
385 /// Checks if two HtlcBasepoints contain equal inner contents.
386 /// This ignores pointers and is_owned flags and looks at the values in fields.
387 /// Two objects with NULL inner values will be considered "equal" here.
389 pub extern "C" fn HtlcBasepoint_eq(a: &HtlcBasepoint, b: &HtlcBasepoint) -> bool {
390 if a.inner == b.inner { return true; }
391 if a.inner.is_null() || b.inner.is_null() { return false; }
392 if a.get_native_ref() == b.get_native_ref() { true } else { false }
394 impl Clone for HtlcBasepoint {
395 fn clone(&self) -> Self {
397 inner: if <*mut nativeHtlcBasepoint>::is_null(self.inner) { core::ptr::null_mut() } else {
398 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
404 /// Used only if an object of this type is returned as a trait impl by a method
405 pub(crate) extern "C" fn HtlcBasepoint_clone_void(this_ptr: *const c_void) -> *mut c_void {
406 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeHtlcBasepoint)).clone() })) as *mut c_void
409 /// Creates a copy of the HtlcBasepoint
410 pub extern "C" fn HtlcBasepoint_clone(orig: &HtlcBasepoint) -> HtlcBasepoint {
413 /// Get a string which allows debug introspection of a HtlcBasepoint object
414 pub extern "C" fn HtlcBasepoint_debug_str_void(o: *const c_void) -> Str {
415 alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::channel_keys::HtlcBasepoint }).into()}
416 /// Generates a non-cryptographic 64-bit hash of the HtlcBasepoint.
418 pub extern "C" fn HtlcBasepoint_hash(o: &HtlcBasepoint) -> u64 {
419 if o.inner.is_null() { return 0; }
420 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
422 let mut hasher = core::hash::SipHasher::new();
423 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
424 core::hash::Hasher::finish(&hasher)
426 /// Get inner Public Key
429 pub extern "C" fn HtlcBasepoint_to_public_key(this_arg: &crate::lightning::ln::channel_keys::HtlcBasepoint) -> crate::c_types::PublicKey {
430 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.to_public_key();
431 crate::c_types::PublicKey::from_rust(&ret)
434 ///Derives the \"tweak\" used in calculate [`HtlcKey::from_basepoint`].\n\n[`HtlcKey::from_basepoint`] calculates a private key as:\n`privkey = basepoint_secret + SHA256(per_commitment_point || basepoint)`\n\nThis calculates the hash part in the tweak derivation process, which is used to\nensure that each key is unique and cannot be guessed by an external party.
437 pub extern "C" fn HtlcBasepoint_derive_add_tweak(this_arg: &crate::lightning::ln::channel_keys::HtlcBasepoint, mut per_commitment_point: crate::c_types::PublicKey) -> crate::c_types::ThirtyTwoBytes {
438 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.derive_add_tweak(&per_commitment_point.into_rust());
439 crate::c_types::ThirtyTwoBytes { data: *ret.as_ref() }
443 /// Serialize the HtlcBasepoint object into a byte array which can be read by HtlcBasepoint_read
444 pub extern "C" fn HtlcBasepoint_write(obj: &crate::lightning::ln::channel_keys::HtlcBasepoint) -> crate::c_types::derived::CVec_u8Z {
445 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
448 pub(crate) extern "C" fn HtlcBasepoint_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
449 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHtlcBasepoint) })
452 /// Read a HtlcBasepoint from a byte array, created by HtlcBasepoint_write
453 pub extern "C" fn HtlcBasepoint_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_HtlcBasepointDecodeErrorZ {
454 let res: Result<lightning::ln::channel_keys::HtlcBasepoint, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
455 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::channel_keys::HtlcBasepoint { 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() };
459 use lightning::ln::channel_keys::HtlcKey as nativeHtlcKeyImport;
460 pub(crate) type nativeHtlcKey = nativeHtlcKeyImport;
462 /// A derived key built from a [`HtlcBasepoint`] and `per_commitment_point`.
464 /// HTLC keys are used to ensure only the recipient of an HTLC can claim it on-chain with the HTLC
465 /// preimage and that only the sender of an HTLC can claim it on-chain after it has timed out.
466 /// Thus, both channel counterparties' HTLC keys will appears in each HTLC output's script.
468 /// [See the BOLT specs]
469 /// (https://github.com/lightning/bolts/blob/master/03-transactions.md#localpubkey-local_htlcpubkey-remote_htlcpubkey-local_delayedpubkey-and-remote_delayedpubkey-derivation)
470 /// for more information on key derivation details.
474 /// A pointer to the opaque Rust object.
476 /// Nearly everywhere, inner must be non-null, however in places where
477 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
478 pub inner: *mut nativeHtlcKey,
479 /// Indicates that this is the only struct which contains the same pointer.
481 /// Rust functions which take ownership of an object provided via an argument require
482 /// this to be true and invalidate the object pointed to by inner.
486 impl Drop for HtlcKey {
488 if self.is_owned && !<*mut nativeHtlcKey>::is_null(self.inner) {
489 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
493 /// Frees any resources used by the HtlcKey, if is_owned is set and inner is non-NULL.
495 pub extern "C" fn HtlcKey_free(this_obj: HtlcKey) { }
497 /// Used only if an object of this type is returned as a trait impl by a method
498 pub(crate) extern "C" fn HtlcKey_free_void(this_ptr: *mut c_void) {
499 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeHtlcKey) };
503 pub(crate) fn get_native_ref(&self) -> &'static nativeHtlcKey {
504 unsafe { &*ObjOps::untweak_ptr(self.inner) }
506 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeHtlcKey {
507 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
509 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
510 pub(crate) fn take_inner(mut self) -> *mut nativeHtlcKey {
511 assert!(self.is_owned);
512 let ret = ObjOps::untweak_ptr(self.inner);
513 self.inner = core::ptr::null_mut();
518 pub extern "C" fn HtlcKey_get_a(this_ptr: &HtlcKey) -> crate::c_types::PublicKey {
519 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
520 crate::c_types::PublicKey::from_rust(&inner_val)
523 pub extern "C" fn HtlcKey_set_a(this_ptr: &mut HtlcKey, mut val: crate::c_types::PublicKey) {
524 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val.into_rust();
526 /// Constructs a new HtlcKey given each field
529 pub extern "C" fn HtlcKey_new(mut a_arg: crate::c_types::PublicKey) -> HtlcKey {
530 HtlcKey { inner: ObjOps::heap_alloc(lightning::ln::channel_keys::HtlcKey (
534 /// Checks if two HtlcKeys contain equal inner contents.
535 /// This ignores pointers and is_owned flags and looks at the values in fields.
536 /// Two objects with NULL inner values will be considered "equal" here.
538 pub extern "C" fn HtlcKey_eq(a: &HtlcKey, b: &HtlcKey) -> bool {
539 if a.inner == b.inner { return true; }
540 if a.inner.is_null() || b.inner.is_null() { return false; }
541 if a.get_native_ref() == b.get_native_ref() { true } else { false }
543 impl Clone for HtlcKey {
544 fn clone(&self) -> Self {
546 inner: if <*mut nativeHtlcKey>::is_null(self.inner) { core::ptr::null_mut() } else {
547 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
553 /// Used only if an object of this type is returned as a trait impl by a method
554 pub(crate) extern "C" fn HtlcKey_clone_void(this_ptr: *const c_void) -> *mut c_void {
555 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeHtlcKey)).clone() })) as *mut c_void
558 /// Creates a copy of the HtlcKey
559 pub extern "C" fn HtlcKey_clone(orig: &HtlcKey) -> HtlcKey {
562 /// Get a string which allows debug introspection of a HtlcKey object
563 pub extern "C" fn HtlcKey_debug_str_void(o: *const c_void) -> Str {
564 alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::channel_keys::HtlcKey }).into()}
565 ///Derive a public htlcpubkey using one node\'s `per_commitment_point` and its countersignatory\'s `basepoint`
568 pub extern "C" fn HtlcKey_from_basepoint(countersignatory_basepoint: &crate::lightning::ln::channel_keys::HtlcBasepoint, mut per_commitment_point: crate::c_types::PublicKey) -> crate::lightning::ln::channel_keys::HtlcKey {
569 let mut ret = lightning::ln::channel_keys::HtlcKey::from_basepoint(secp256k1::global::SECP256K1, countersignatory_basepoint.get_native_ref(), &per_commitment_point.into_rust());
570 crate::lightning::ln::channel_keys::HtlcKey { inner: ObjOps::heap_alloc(ret), is_owned: true }
573 ///Build a htlcpubkey directly from an already-derived private key
576 pub extern "C" fn HtlcKey_from_secret_key(sk: *const [u8; 32]) -> crate::lightning::ln::channel_keys::HtlcKey {
577 let mut ret = lightning::ln::channel_keys::HtlcKey::from_secret_key(secp256k1::global::SECP256K1, &::bitcoin::secp256k1::SecretKey::from_slice(&unsafe { *sk}[..]).unwrap());
578 crate::lightning::ln::channel_keys::HtlcKey { inner: ObjOps::heap_alloc(ret), is_owned: true }
581 /// Get inner Public Key
584 pub extern "C" fn HtlcKey_to_public_key(this_arg: &crate::lightning::ln::channel_keys::HtlcKey) -> crate::c_types::PublicKey {
585 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.to_public_key();
586 crate::c_types::PublicKey::from_rust(&ret)
590 /// Serialize the HtlcKey object into a byte array which can be read by HtlcKey_read
591 pub extern "C" fn HtlcKey_write(obj: &crate::lightning::ln::channel_keys::HtlcKey) -> crate::c_types::derived::CVec_u8Z {
592 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
595 pub(crate) extern "C" fn HtlcKey_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
596 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeHtlcKey) })
599 /// Read a HtlcKey from a byte array, created by HtlcKey_write
600 pub extern "C" fn HtlcKey_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_HtlcKeyDecodeErrorZ {
601 let res: Result<lightning::ln::channel_keys::HtlcKey, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
602 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::channel_keys::HtlcKey { 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() };
605 /// Adds a tweak to a public key to derive a new public key.
607 /// May panic if `tweak` is not the output of a SHA-256 hash.
609 pub extern "C" fn add_public_key_tweak(mut base_point: crate::c_types::PublicKey, tweak: *const [u8; 32]) -> crate::c_types::PublicKey {
610 let mut ret = lightning::ln::channel_keys::add_public_key_tweak(secp256k1::global::SECP256K1, &base_point.into_rust(), &::bitcoin::hashes::sha256::Hash::from_slice(&unsafe { &*tweak }[..]).unwrap());
611 crate::c_types::PublicKey::from_rust(&ret)
615 use lightning::ln::channel_keys::RevocationBasepoint as nativeRevocationBasepointImport;
616 pub(crate) type nativeRevocationBasepoint = nativeRevocationBasepointImport;
618 /// Master key used in conjunction with per_commitment_point to generate [htlcpubkey](https://github.com/lightning/bolts/blob/master/03-transactions.md#key-derivation) for the latest state of a channel.
619 /// A watcher can be given a [RevocationBasepoint] to generate per commitment [RevocationKey] to create justice transactions.
622 pub struct RevocationBasepoint {
623 /// A pointer to the opaque Rust object.
625 /// Nearly everywhere, inner must be non-null, however in places where
626 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
627 pub inner: *mut nativeRevocationBasepoint,
628 /// Indicates that this is the only struct which contains the same pointer.
630 /// Rust functions which take ownership of an object provided via an argument require
631 /// this to be true and invalidate the object pointed to by inner.
635 impl Drop for RevocationBasepoint {
637 if self.is_owned && !<*mut nativeRevocationBasepoint>::is_null(self.inner) {
638 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
642 /// Frees any resources used by the RevocationBasepoint, if is_owned is set and inner is non-NULL.
644 pub extern "C" fn RevocationBasepoint_free(this_obj: RevocationBasepoint) { }
646 /// Used only if an object of this type is returned as a trait impl by a method
647 pub(crate) extern "C" fn RevocationBasepoint_free_void(this_ptr: *mut c_void) {
648 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRevocationBasepoint) };
651 impl RevocationBasepoint {
652 pub(crate) fn get_native_ref(&self) -> &'static nativeRevocationBasepoint {
653 unsafe { &*ObjOps::untweak_ptr(self.inner) }
655 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRevocationBasepoint {
656 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
658 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
659 pub(crate) fn take_inner(mut self) -> *mut nativeRevocationBasepoint {
660 assert!(self.is_owned);
661 let ret = ObjOps::untweak_ptr(self.inner);
662 self.inner = core::ptr::null_mut();
667 pub extern "C" fn RevocationBasepoint_get_a(this_ptr: &RevocationBasepoint) -> crate::c_types::PublicKey {
668 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
669 crate::c_types::PublicKey::from_rust(&inner_val)
672 pub extern "C" fn RevocationBasepoint_set_a(this_ptr: &mut RevocationBasepoint, mut val: crate::c_types::PublicKey) {
673 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val.into_rust();
675 /// Constructs a new RevocationBasepoint given each field
678 pub extern "C" fn RevocationBasepoint_new(mut a_arg: crate::c_types::PublicKey) -> RevocationBasepoint {
679 RevocationBasepoint { inner: ObjOps::heap_alloc(lightning::ln::channel_keys::RevocationBasepoint (
683 /// Checks if two RevocationBasepoints contain equal inner contents.
684 /// This ignores pointers and is_owned flags and looks at the values in fields.
685 /// Two objects with NULL inner values will be considered "equal" here.
687 pub extern "C" fn RevocationBasepoint_eq(a: &RevocationBasepoint, b: &RevocationBasepoint) -> bool {
688 if a.inner == b.inner { return true; }
689 if a.inner.is_null() || b.inner.is_null() { return false; }
690 if a.get_native_ref() == b.get_native_ref() { true } else { false }
692 impl Clone for RevocationBasepoint {
693 fn clone(&self) -> Self {
695 inner: if <*mut nativeRevocationBasepoint>::is_null(self.inner) { core::ptr::null_mut() } else {
696 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
702 /// Used only if an object of this type is returned as a trait impl by a method
703 pub(crate) extern "C" fn RevocationBasepoint_clone_void(this_ptr: *const c_void) -> *mut c_void {
704 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeRevocationBasepoint)).clone() })) as *mut c_void
707 /// Creates a copy of the RevocationBasepoint
708 pub extern "C" fn RevocationBasepoint_clone(orig: &RevocationBasepoint) -> RevocationBasepoint {
711 /// Get a string which allows debug introspection of a RevocationBasepoint object
712 pub extern "C" fn RevocationBasepoint_debug_str_void(o: *const c_void) -> Str {
713 alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::channel_keys::RevocationBasepoint }).into()}
714 /// Generates a non-cryptographic 64-bit hash of the RevocationBasepoint.
716 pub extern "C" fn RevocationBasepoint_hash(o: &RevocationBasepoint) -> u64 {
717 if o.inner.is_null() { return 0; }
718 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
720 let mut hasher = core::hash::SipHasher::new();
721 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
722 core::hash::Hasher::finish(&hasher)
724 /// Get inner Public Key
727 pub extern "C" fn RevocationBasepoint_to_public_key(this_arg: &crate::lightning::ln::channel_keys::RevocationBasepoint) -> crate::c_types::PublicKey {
728 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.to_public_key();
729 crate::c_types::PublicKey::from_rust(&ret)
733 /// Serialize the RevocationBasepoint object into a byte array which can be read by RevocationBasepoint_read
734 pub extern "C" fn RevocationBasepoint_write(obj: &crate::lightning::ln::channel_keys::RevocationBasepoint) -> crate::c_types::derived::CVec_u8Z {
735 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
738 pub(crate) extern "C" fn RevocationBasepoint_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
739 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRevocationBasepoint) })
742 /// Read a RevocationBasepoint from a byte array, created by RevocationBasepoint_write
743 pub extern "C" fn RevocationBasepoint_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RevocationBasepointDecodeErrorZ {
744 let res: Result<lightning::ln::channel_keys::RevocationBasepoint, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
745 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::channel_keys::RevocationBasepoint { 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() };
749 use lightning::ln::channel_keys::RevocationKey as nativeRevocationKeyImport;
750 pub(crate) type nativeRevocationKey = nativeRevocationKeyImport;
752 /// The revocation key is used to allow a channel party to revoke their state - giving their
753 /// counterparty the required material to claim all of their funds if they broadcast that state.
755 /// Each commitment transaction has a revocation key based on the basepoint and
756 /// per_commitment_point which is used in both commitment and HTLC transactions.
758 /// See [the BOLT spec for derivation details]
759 /// (https://github.com/lightning/bolts/blob/master/03-transactions.md#revocationpubkey-derivation)
762 pub struct RevocationKey {
763 /// A pointer to the opaque Rust object.
765 /// Nearly everywhere, inner must be non-null, however in places where
766 /// the Rust equivalent takes an Option, it may be set to null to indicate None.
767 pub inner: *mut nativeRevocationKey,
768 /// Indicates that this is the only struct which contains the same pointer.
770 /// Rust functions which take ownership of an object provided via an argument require
771 /// this to be true and invalidate the object pointed to by inner.
775 impl Drop for RevocationKey {
777 if self.is_owned && !<*mut nativeRevocationKey>::is_null(self.inner) {
778 let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
782 /// Frees any resources used by the RevocationKey, if is_owned is set and inner is non-NULL.
784 pub extern "C" fn RevocationKey_free(this_obj: RevocationKey) { }
786 /// Used only if an object of this type is returned as a trait impl by a method
787 pub(crate) extern "C" fn RevocationKey_free_void(this_ptr: *mut c_void) {
788 let _ = unsafe { Box::from_raw(this_ptr as *mut nativeRevocationKey) };
792 pub(crate) fn get_native_ref(&self) -> &'static nativeRevocationKey {
793 unsafe { &*ObjOps::untweak_ptr(self.inner) }
795 pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeRevocationKey {
796 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
798 /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
799 pub(crate) fn take_inner(mut self) -> *mut nativeRevocationKey {
800 assert!(self.is_owned);
801 let ret = ObjOps::untweak_ptr(self.inner);
802 self.inner = core::ptr::null_mut();
807 pub extern "C" fn RevocationKey_get_a(this_ptr: &RevocationKey) -> crate::c_types::PublicKey {
808 let mut inner_val = &mut this_ptr.get_native_mut_ref().0;
809 crate::c_types::PublicKey::from_rust(&inner_val)
812 pub extern "C" fn RevocationKey_set_a(this_ptr: &mut RevocationKey, mut val: crate::c_types::PublicKey) {
813 unsafe { &mut *ObjOps::untweak_ptr(this_ptr.inner) }.0 = val.into_rust();
815 /// Constructs a new RevocationKey given each field
818 pub extern "C" fn RevocationKey_new(mut a_arg: crate::c_types::PublicKey) -> RevocationKey {
819 RevocationKey { inner: ObjOps::heap_alloc(lightning::ln::channel_keys::RevocationKey (
823 /// Checks if two RevocationKeys contain equal inner contents.
824 /// This ignores pointers and is_owned flags and looks at the values in fields.
825 /// Two objects with NULL inner values will be considered "equal" here.
827 pub extern "C" fn RevocationKey_eq(a: &RevocationKey, b: &RevocationKey) -> bool {
828 if a.inner == b.inner { return true; }
829 if a.inner.is_null() || b.inner.is_null() { return false; }
830 if a.get_native_ref() == b.get_native_ref() { true } else { false }
832 impl Clone for RevocationKey {
833 fn clone(&self) -> Self {
835 inner: if <*mut nativeRevocationKey>::is_null(self.inner) { core::ptr::null_mut() } else {
836 ObjOps::heap_alloc(unsafe { &*ObjOps::untweak_ptr(self.inner) }.clone()) },
842 /// Used only if an object of this type is returned as a trait impl by a method
843 pub(crate) extern "C" fn RevocationKey_clone_void(this_ptr: *const c_void) -> *mut c_void {
844 Box::into_raw(Box::new(unsafe { (*(this_ptr as *const nativeRevocationKey)).clone() })) as *mut c_void
847 /// Creates a copy of the RevocationKey
848 pub extern "C" fn RevocationKey_clone(orig: &RevocationKey) -> RevocationKey {
851 /// Get a string which allows debug introspection of a RevocationKey object
852 pub extern "C" fn RevocationKey_debug_str_void(o: *const c_void) -> Str {
853 alloc::format!("{:?}", unsafe { o as *const crate::lightning::ln::channel_keys::RevocationKey }).into()}
854 /// Generates a non-cryptographic 64-bit hash of the RevocationKey.
856 pub extern "C" fn RevocationKey_hash(o: &RevocationKey) -> u64 {
857 if o.inner.is_null() { return 0; }
858 // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
860 let mut hasher = core::hash::SipHasher::new();
861 core::hash::Hash::hash(o.get_native_ref(), &mut hasher);
862 core::hash::Hasher::finish(&hasher)
864 /// Derives a per-commitment-transaction revocation public key from one party's per-commitment
865 /// point and the other party's [`RevocationBasepoint`]. This is the public equivalent of
866 /// [`chan_utils::derive_private_revocation_key`] - using only public keys to derive a public
867 /// key instead of private keys.
869 /// Note that this is infallible iff we trust that at least one of the two input keys are randomly
870 /// generated (ie our own).
872 /// [`chan_utils::derive_private_revocation_key`]: crate::ln::chan_utils::derive_private_revocation_key
875 pub extern "C" fn RevocationKey_from_basepoint(countersignatory_basepoint: &crate::lightning::ln::channel_keys::RevocationBasepoint, mut per_commitment_point: crate::c_types::PublicKey) -> crate::lightning::ln::channel_keys::RevocationKey {
876 let mut ret = lightning::ln::channel_keys::RevocationKey::from_basepoint(secp256k1::global::SECP256K1, countersignatory_basepoint.get_native_ref(), &per_commitment_point.into_rust());
877 crate::lightning::ln::channel_keys::RevocationKey { inner: ObjOps::heap_alloc(ret), is_owned: true }
880 /// Get inner Public Key
883 pub extern "C" fn RevocationKey_to_public_key(this_arg: &crate::lightning::ln::channel_keys::RevocationKey) -> crate::c_types::PublicKey {
884 let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.to_public_key();
885 crate::c_types::PublicKey::from_rust(&ret)
889 /// Serialize the RevocationKey object into a byte array which can be read by RevocationKey_read
890 pub extern "C" fn RevocationKey_write(obj: &crate::lightning::ln::channel_keys::RevocationKey) -> crate::c_types::derived::CVec_u8Z {
891 crate::c_types::serialize_obj(unsafe { &*obj }.get_native_ref())
894 pub(crate) extern "C" fn RevocationKey_write_void(obj: *const c_void) -> crate::c_types::derived::CVec_u8Z {
895 crate::c_types::serialize_obj(unsafe { &*(obj as *const nativeRevocationKey) })
898 /// Read a RevocationKey from a byte array, created by RevocationKey_write
899 pub extern "C" fn RevocationKey_read(ser: crate::c_types::u8slice) -> crate::c_types::derived::CResult_RevocationKeyDecodeErrorZ {
900 let res: Result<lightning::ln::channel_keys::RevocationKey, lightning::ln::msgs::DecodeError> = crate::c_types::deserialize_obj(ser);
901 let mut local_res = match res { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::lightning::ln::channel_keys::RevocationKey { 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() };