Update auto-generated bindings
[ldk-c-bindings] / lightning-c-bindings / src / lightning / ln / inbound_payment.rs
1 // This file is Copyright its original authors, visible in version control
2 // history and in the source files from which this was generated.
3 //
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.
8
9 //! Utilities to generate inbound payment information in service of invoice creation.
10
11 use alloc::str::FromStr;
12 use alloc::string::String;
13 use core::ffi::c_void;
14 use core::convert::Infallible;
15 use bitcoin::hashes::Hash;
16 use crate::c_types::*;
17 #[cfg(feature="no-std")]
18 use alloc::{vec::Vec, boxed::Box};
19
20
21 use lightning::ln::inbound_payment::ExpandedKey as nativeExpandedKeyImport;
22 pub(crate) type nativeExpandedKey = nativeExpandedKeyImport;
23
24 /// A set of keys that were HKDF-expanded from an initial call to
25 /// [`NodeSigner::get_inbound_payment_key_material`].
26 ///
27 /// [`NodeSigner::get_inbound_payment_key_material`]: crate::sign::NodeSigner::get_inbound_payment_key_material
28 #[must_use]
29 #[repr(C)]
30 pub struct ExpandedKey {
31         /// A pointer to the opaque Rust object.
32
33         /// Nearly everywhere, inner must be non-null, however in places where
34         /// the Rust equivalent takes an Option, it may be set to null to indicate None.
35         pub inner: *mut nativeExpandedKey,
36         /// Indicates that this is the only struct which contains the same pointer.
37
38         /// Rust functions which take ownership of an object provided via an argument require
39         /// this to be true and invalidate the object pointed to by inner.
40         pub is_owned: bool,
41 }
42
43 impl Drop for ExpandedKey {
44         fn drop(&mut self) {
45                 if self.is_owned && !<*mut nativeExpandedKey>::is_null(self.inner) {
46                         let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
47                 }
48         }
49 }
50 /// Frees any resources used by the ExpandedKey, if is_owned is set and inner is non-NULL.
51 #[no_mangle]
52 pub extern "C" fn ExpandedKey_free(this_obj: ExpandedKey) { }
53 #[allow(unused)]
54 /// Used only if an object of this type is returned as a trait impl by a method
55 pub(crate) extern "C" fn ExpandedKey_free_void(this_ptr: *mut c_void) {
56         let _ = unsafe { Box::from_raw(this_ptr as *mut nativeExpandedKey) };
57 }
58 #[allow(unused)]
59 impl ExpandedKey {
60         pub(crate) fn get_native_ref(&self) -> &'static nativeExpandedKey {
61                 unsafe { &*ObjOps::untweak_ptr(self.inner) }
62         }
63         pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeExpandedKey {
64                 unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
65         }
66         /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
67         pub(crate) fn take_inner(mut self) -> *mut nativeExpandedKey {
68                 assert!(self.is_owned);
69                 let ret = ObjOps::untweak_ptr(self.inner);
70                 self.inner = core::ptr::null_mut();
71                 ret
72         }
73 }
74 /// Create a  new [`ExpandedKey`] for generating an inbound payment hash and secret.
75 ///
76 /// It is recommended to cache this value and not regenerate it for each new inbound payment.
77 #[must_use]
78 #[no_mangle]
79 pub extern "C" fn ExpandedKey_new(key_material: *const [u8; 32]) -> crate::lightning::ln::inbound_payment::ExpandedKey {
80         let mut ret = lightning::ln::inbound_payment::ExpandedKey::new(&::lightning::sign::KeyMaterial( unsafe { *key_material }));
81         crate::lightning::ln::inbound_payment::ExpandedKey { inner: ObjOps::heap_alloc(ret), is_owned: true }
82 }
83
84 /// Equivalent to [`crate::ln::channelmanager::ChannelManager::create_inbound_payment`], but no
85 /// `ChannelManager` is required. Useful for generating invoices for [phantom node payments] without
86 /// a `ChannelManager`.
87 ///
88 /// `keys` is generated by calling [`NodeSigner::get_inbound_payment_key_material`] and then
89 /// calling [`ExpandedKey::new`] with its result. It is recommended to cache this value and not
90 /// regenerate it for each new inbound payment.
91 ///
92 /// `current_time` is a Unix timestamp representing the current time.
93 ///
94 /// Note that if `min_final_cltv_expiry_delta` is set to some value, then the payment will not be receivable
95 /// on versions of LDK prior to 0.0.114.
96 ///
97 /// [phantom node payments]: crate::sign::PhantomKeysManager
98 /// [`NodeSigner::get_inbound_payment_key_material`]: crate::sign::NodeSigner::get_inbound_payment_key_material
99 #[no_mangle]
100 pub extern "C" fn create(keys: &crate::lightning::ln::inbound_payment::ExpandedKey, mut min_value_msat: crate::c_types::derived::COption_u64Z, mut invoice_expiry_delta_secs: u32, entropy_source: &crate::lightning::sign::EntropySource, mut current_time: u64, mut min_final_cltv_expiry_delta: crate::c_types::derived::COption_u16Z) -> crate::c_types::derived::CResult_C2Tuple_ThirtyTwoBytesThirtyTwoBytesZNoneZ {
101         let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None };
102         let mut local_min_final_cltv_expiry_delta = if min_final_cltv_expiry_delta.is_some() { Some( { min_final_cltv_expiry_delta.take() }) } else { None };
103         let mut ret = lightning::ln::inbound_payment::create::<crate::lightning::sign::EntropySource>(keys.get_native_ref(), local_min_value_msat, invoice_expiry_delta_secs, entropy_source, current_time, local_min_final_cltv_expiry_delta);
104         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let (mut orig_ret_0_0, mut orig_ret_0_1) = o; let mut local_ret_0 = (crate::c_types::ThirtyTwoBytes { data: orig_ret_0_0.0 }, crate::c_types::ThirtyTwoBytes { data: orig_ret_0_1.0 }).into(); local_ret_0 }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
105         local_ret
106 }
107
108 /// Equivalent to [`crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash`],
109 /// but no `ChannelManager` is required. Useful for generating invoices for [phantom node payments]
110 /// without a `ChannelManager`.
111 ///
112 /// See [`create`] for information on the `keys` and `current_time` parameters.
113 ///
114 /// Note that if `min_final_cltv_expiry_delta` is set to some value, then the payment will not be receivable
115 /// on versions of LDK prior to 0.0.114.
116 ///
117 /// [phantom node payments]: crate::sign::PhantomKeysManager
118 #[no_mangle]
119 pub extern "C" fn create_from_hash(keys: &crate::lightning::ln::inbound_payment::ExpandedKey, mut min_value_msat: crate::c_types::derived::COption_u64Z, mut payment_hash: crate::c_types::ThirtyTwoBytes, mut invoice_expiry_delta_secs: u32, mut current_time: u64, mut min_final_cltv_expiry_delta: crate::c_types::derived::COption_u16Z) -> crate::c_types::derived::CResult_ThirtyTwoBytesNoneZ {
120         let mut local_min_value_msat = if min_value_msat.is_some() { Some( { min_value_msat.take() }) } else { None };
121         let mut local_min_final_cltv_expiry_delta = if min_final_cltv_expiry_delta.is_some() { Some( { min_final_cltv_expiry_delta.take() }) } else { None };
122         let mut ret = lightning::ln::inbound_payment::create_from_hash(keys.get_native_ref(), local_min_value_msat, ::lightning::ln::PaymentHash(payment_hash.data), invoice_expiry_delta_secs, current_time, local_min_final_cltv_expiry_delta);
123         let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { crate::c_types::ThirtyTwoBytes { data: o.0 } }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { () /*e*/ }).into() };
124         local_ret
125 }
126