Update auto-generated bindings with new upstream invoice creation
[ldk-c-bindings] / lightning-c-bindings / src / lightning / chain / chaininterface.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 //! Traits and utility impls which allow other parts of rust-lightning to interact with the
10 //! blockchain.
11 //!
12 //! Includes traits for monitoring and receiving notifications of new blocks and block
13 //! disconnections, transaction broadcasting, and feerate information requests.
14
15 use std::str::FromStr;
16 use std::ffi::c_void;
17 use bitcoin::hashes::Hash;
18 use crate::c_types::*;
19
20 /// An interface to send a transaction to the Bitcoin network.
21 #[repr(C)]
22 pub struct BroadcasterInterface {
23         /// An opaque pointer which is passed to your function implementations as an argument.
24         /// This has no meaning in the LDK, and can be NULL or any other value.
25         pub this_arg: *mut c_void,
26         /// Sends a transaction out to (hopefully) be mined.
27         pub broadcast_transaction: extern "C" fn (this_arg: *const c_void, tx: crate::c_types::Transaction),
28         /// Frees any resources associated with this object given its this_arg pointer.
29         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
30         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
31 }
32
33 use lightning::chain::chaininterface::BroadcasterInterface as rustBroadcasterInterface;
34 impl rustBroadcasterInterface for BroadcasterInterface {
35         fn broadcast_transaction(&self, mut tx: &bitcoin::blockdata::transaction::Transaction) {
36                 (self.broadcast_transaction)(self.this_arg, crate::c_types::Transaction::from_bitcoin(tx))
37         }
38 }
39
40 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
41 // directly as a Deref trait in higher-level structs:
42 impl std::ops::Deref for BroadcasterInterface {
43         type Target = Self;
44         fn deref(&self) -> &Self {
45                 self
46         }
47 }
48 /// Calls the free function if one is set
49 #[no_mangle]
50 pub extern "C" fn BroadcasterInterface_free(this_ptr: BroadcasterInterface) { }
51 impl Drop for BroadcasterInterface {
52         fn drop(&mut self) {
53                 if let Some(f) = self.free {
54                         f(self.this_arg);
55                 }
56         }
57 }
58 /// An enum that represents the speed at which we want a transaction to confirm used for feerate
59 /// estimation.
60 #[must_use]
61 #[derive(Clone)]
62 #[repr(C)]
63 pub enum ConfirmationTarget {
64         /// We are happy with this transaction confirming slowly when feerate drops some.
65         Background,
66         /// We'd like this transaction to confirm without major delay, but 12-18 blocks is fine.
67         Normal,
68         /// We'd like this transaction to confirm in the next few blocks.
69         HighPriority,
70 }
71 use lightning::chain::chaininterface::ConfirmationTarget as nativeConfirmationTarget;
72 impl ConfirmationTarget {
73         #[allow(unused)]
74         pub(crate) fn to_native(&self) -> nativeConfirmationTarget {
75                 match self {
76                         ConfirmationTarget::Background => nativeConfirmationTarget::Background,
77                         ConfirmationTarget::Normal => nativeConfirmationTarget::Normal,
78                         ConfirmationTarget::HighPriority => nativeConfirmationTarget::HighPriority,
79                 }
80         }
81         #[allow(unused)]
82         pub(crate) fn into_native(self) -> nativeConfirmationTarget {
83                 match self {
84                         ConfirmationTarget::Background => nativeConfirmationTarget::Background,
85                         ConfirmationTarget::Normal => nativeConfirmationTarget::Normal,
86                         ConfirmationTarget::HighPriority => nativeConfirmationTarget::HighPriority,
87                 }
88         }
89         #[allow(unused)]
90         pub(crate) fn from_native(native: &nativeConfirmationTarget) -> Self {
91                 match native {
92                         nativeConfirmationTarget::Background => ConfirmationTarget::Background,
93                         nativeConfirmationTarget::Normal => ConfirmationTarget::Normal,
94                         nativeConfirmationTarget::HighPriority => ConfirmationTarget::HighPriority,
95                 }
96         }
97         #[allow(unused)]
98         pub(crate) fn native_into(native: nativeConfirmationTarget) -> Self {
99                 match native {
100                         nativeConfirmationTarget::Background => ConfirmationTarget::Background,
101                         nativeConfirmationTarget::Normal => ConfirmationTarget::Normal,
102                         nativeConfirmationTarget::HighPriority => ConfirmationTarget::HighPriority,
103                 }
104         }
105 }
106 /// Creates a copy of the ConfirmationTarget
107 #[no_mangle]
108 pub extern "C" fn ConfirmationTarget_clone(orig: &ConfirmationTarget) -> ConfirmationTarget {
109         orig.clone()
110 }
111 /// A trait which should be implemented to provide feerate information on a number of time
112 /// horizons.
113 ///
114 /// Note that all of the functions implemented here *must* be reentrant-safe (obviously - they're
115 /// called from inside the library in response to chain events, P2P events, or timer events).
116 #[repr(C)]
117 pub struct FeeEstimator {
118         /// An opaque pointer which is passed to your function implementations as an argument.
119         /// This has no meaning in the LDK, and can be NULL or any other value.
120         pub this_arg: *mut c_void,
121         /// Gets estimated satoshis of fee required per 1000 Weight-Units.
122         ///
123         /// Must be no smaller than 253 (ie 1 satoshi-per-byte rounded up to ensure later round-downs
124         /// don't put us below 1 satoshi-per-byte).
125         ///
126         /// This translates to:
127         ///  * satoshis-per-byte * 250
128         ///  * ceil(satoshis-per-kbyte / 4)
129         #[must_use]
130         pub get_est_sat_per_1000_weight: extern "C" fn (this_arg: *const c_void, confirmation_target: crate::lightning::chain::chaininterface::ConfirmationTarget) -> u32,
131         /// Frees any resources associated with this object given its this_arg pointer.
132         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
133         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
134 }
135
136 use lightning::chain::chaininterface::FeeEstimator as rustFeeEstimator;
137 impl rustFeeEstimator for FeeEstimator {
138         fn get_est_sat_per_1000_weight(&self, mut confirmation_target: lightning::chain::chaininterface::ConfirmationTarget) -> u32 {
139                 let mut ret = (self.get_est_sat_per_1000_weight)(self.this_arg, crate::lightning::chain::chaininterface::ConfirmationTarget::native_into(confirmation_target));
140                 ret
141         }
142 }
143
144 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
145 // directly as a Deref trait in higher-level structs:
146 impl std::ops::Deref for FeeEstimator {
147         type Target = Self;
148         fn deref(&self) -> &Self {
149                 self
150         }
151 }
152 /// Calls the free function if one is set
153 #[no_mangle]
154 pub extern "C" fn FeeEstimator_free(this_ptr: FeeEstimator) { }
155 impl Drop for FeeEstimator {
156         fn drop(&mut self) {
157                 if let Some(f) = self.free {
158                         f(self.this_arg);
159                 }
160         }
161 }
162 /// Minimum relay fee as required by bitcoin network mempool policy.
163
164 #[no_mangle]
165 pub static MIN_RELAY_FEE_SAT_PER_1000_WEIGHT: u64 = lightning::chain::chaininterface::MIN_RELAY_FEE_SAT_PER_1000_WEIGHT;