Update auto-generated bindings
[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 unsafe impl Send for BroadcasterInterface {}
33 unsafe impl Sync for BroadcasterInterface {}
34 #[no_mangle]
35 pub(crate) extern "C" fn BroadcasterInterface_clone_fields(orig: &BroadcasterInterface) -> BroadcasterInterface {
36         BroadcasterInterface {
37                 this_arg: orig.this_arg,
38                 broadcast_transaction: Clone::clone(&orig.broadcast_transaction),
39                 free: Clone::clone(&orig.free),
40         }
41 }
42
43 use lightning::chain::chaininterface::BroadcasterInterface as rustBroadcasterInterface;
44 impl rustBroadcasterInterface for BroadcasterInterface {
45         fn broadcast_transaction(&self, mut tx: &bitcoin::blockdata::transaction::Transaction) {
46                 (self.broadcast_transaction)(self.this_arg, crate::c_types::Transaction::from_bitcoin(tx))
47         }
48 }
49
50 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
51 // directly as a Deref trait in higher-level structs:
52 impl std::ops::Deref for BroadcasterInterface {
53         type Target = Self;
54         fn deref(&self) -> &Self {
55                 self
56         }
57 }
58 /// Calls the free function if one is set
59 #[no_mangle]
60 pub extern "C" fn BroadcasterInterface_free(this_ptr: BroadcasterInterface) { }
61 impl Drop for BroadcasterInterface {
62         fn drop(&mut self) {
63                 if let Some(f) = self.free {
64                         f(self.this_arg);
65                 }
66         }
67 }
68 /// An enum that represents the speed at which we want a transaction to confirm used for feerate
69 /// estimation.
70 #[must_use]
71 #[derive(Clone)]
72 #[repr(C)]
73 pub enum ConfirmationTarget {
74         /// We are happy with this transaction confirming slowly when feerate drops some.
75         Background,
76         /// We'd like this transaction to confirm without major delay, but 12-18 blocks is fine.
77         Normal,
78         /// We'd like this transaction to confirm in the next few blocks.
79         HighPriority,
80 }
81 use lightning::chain::chaininterface::ConfirmationTarget as nativeConfirmationTarget;
82 impl ConfirmationTarget {
83         #[allow(unused)]
84         pub(crate) fn to_native(&self) -> nativeConfirmationTarget {
85                 match self {
86                         ConfirmationTarget::Background => nativeConfirmationTarget::Background,
87                         ConfirmationTarget::Normal => nativeConfirmationTarget::Normal,
88                         ConfirmationTarget::HighPriority => nativeConfirmationTarget::HighPriority,
89                 }
90         }
91         #[allow(unused)]
92         pub(crate) fn into_native(self) -> nativeConfirmationTarget {
93                 match self {
94                         ConfirmationTarget::Background => nativeConfirmationTarget::Background,
95                         ConfirmationTarget::Normal => nativeConfirmationTarget::Normal,
96                         ConfirmationTarget::HighPriority => nativeConfirmationTarget::HighPriority,
97                 }
98         }
99         #[allow(unused)]
100         pub(crate) fn from_native(native: &nativeConfirmationTarget) -> Self {
101                 match native {
102                         nativeConfirmationTarget::Background => ConfirmationTarget::Background,
103                         nativeConfirmationTarget::Normal => ConfirmationTarget::Normal,
104                         nativeConfirmationTarget::HighPriority => ConfirmationTarget::HighPriority,
105                 }
106         }
107         #[allow(unused)]
108         pub(crate) fn native_into(native: nativeConfirmationTarget) -> Self {
109                 match native {
110                         nativeConfirmationTarget::Background => ConfirmationTarget::Background,
111                         nativeConfirmationTarget::Normal => ConfirmationTarget::Normal,
112                         nativeConfirmationTarget::HighPriority => ConfirmationTarget::HighPriority,
113                 }
114         }
115 }
116 /// Creates a copy of the ConfirmationTarget
117 #[no_mangle]
118 pub extern "C" fn ConfirmationTarget_clone(orig: &ConfirmationTarget) -> ConfirmationTarget {
119         orig.clone()
120 }
121 #[no_mangle]
122 /// Utility method to constructs a new Background-variant ConfirmationTarget
123 pub extern "C" fn ConfirmationTarget_background() -> ConfirmationTarget {
124         ConfirmationTarget::Background}
125 #[no_mangle]
126 /// Utility method to constructs a new Normal-variant ConfirmationTarget
127 pub extern "C" fn ConfirmationTarget_normal() -> ConfirmationTarget {
128         ConfirmationTarget::Normal}
129 #[no_mangle]
130 /// Utility method to constructs a new HighPriority-variant ConfirmationTarget
131 pub extern "C" fn ConfirmationTarget_high_priority() -> ConfirmationTarget {
132         ConfirmationTarget::HighPriority}
133 /// A trait which should be implemented to provide feerate information on a number of time
134 /// horizons.
135 ///
136 /// Note that all of the functions implemented here *must* be reentrant-safe (obviously - they're
137 /// called from inside the library in response to chain events, P2P events, or timer events).
138 #[repr(C)]
139 pub struct FeeEstimator {
140         /// An opaque pointer which is passed to your function implementations as an argument.
141         /// This has no meaning in the LDK, and can be NULL or any other value.
142         pub this_arg: *mut c_void,
143         /// Gets estimated satoshis of fee required per 1000 Weight-Units.
144         ///
145         /// Must be no smaller than 253 (ie 1 satoshi-per-byte rounded up to ensure later round-downs
146         /// don't put us below 1 satoshi-per-byte).
147         ///
148         /// This translates to:
149         ///  * satoshis-per-byte * 250
150         ///  * ceil(satoshis-per-kbyte / 4)
151         #[must_use]
152         pub get_est_sat_per_1000_weight: extern "C" fn (this_arg: *const c_void, confirmation_target: crate::lightning::chain::chaininterface::ConfirmationTarget) -> u32,
153         /// Frees any resources associated with this object given its this_arg pointer.
154         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
155         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
156 }
157 unsafe impl Send for FeeEstimator {}
158 unsafe impl Sync for FeeEstimator {}
159 #[no_mangle]
160 pub(crate) extern "C" fn FeeEstimator_clone_fields(orig: &FeeEstimator) -> FeeEstimator {
161         FeeEstimator {
162                 this_arg: orig.this_arg,
163                 get_est_sat_per_1000_weight: Clone::clone(&orig.get_est_sat_per_1000_weight),
164                 free: Clone::clone(&orig.free),
165         }
166 }
167
168 use lightning::chain::chaininterface::FeeEstimator as rustFeeEstimator;
169 impl rustFeeEstimator for FeeEstimator {
170         fn get_est_sat_per_1000_weight(&self, mut confirmation_target: lightning::chain::chaininterface::ConfirmationTarget) -> u32 {
171                 let mut ret = (self.get_est_sat_per_1000_weight)(self.this_arg, crate::lightning::chain::chaininterface::ConfirmationTarget::native_into(confirmation_target));
172                 ret
173         }
174 }
175
176 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
177 // directly as a Deref trait in higher-level structs:
178 impl std::ops::Deref for FeeEstimator {
179         type Target = Self;
180         fn deref(&self) -> &Self {
181                 self
182         }
183 }
184 /// Calls the free function if one is set
185 #[no_mangle]
186 pub extern "C" fn FeeEstimator_free(this_ptr: FeeEstimator) { }
187 impl Drop for FeeEstimator {
188         fn drop(&mut self) {
189                 if let Some(f) = self.free {
190                         f(self.this_arg);
191                 }
192         }
193 }
194 /// Minimum relay fee as required by bitcoin network mempool policy.
195
196 #[no_mangle]
197 pub static MIN_RELAY_FEE_SAT_PER_1000_WEIGHT: u64 = lightning::chain::chaininterface::MIN_RELAY_FEE_SAT_PER_1000_WEIGHT;