Update auto-generated bindings to 0.0.113
[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 alloc::str::FromStr;
16 use core::ffi::c_void;
17 use core::convert::Infallible;
18 use bitcoin::hashes::Hash;
19 use crate::c_types::*;
20 #[cfg(feature="no-std")]
21 use alloc::{vec::Vec, boxed::Box};
22
23 /// An interface to send a transaction to the Bitcoin network.
24 #[repr(C)]
25 pub struct BroadcasterInterface {
26         /// An opaque pointer which is passed to your function implementations as an argument.
27         /// This has no meaning in the LDK, and can be NULL or any other value.
28         pub this_arg: *mut c_void,
29         /// Sends a transaction out to (hopefully) be mined.
30         pub broadcast_transaction: extern "C" fn (this_arg: *const c_void, tx: crate::c_types::Transaction),
31         /// Frees any resources associated with this object given its this_arg pointer.
32         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
33         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
34 }
35 unsafe impl Send for BroadcasterInterface {}
36 unsafe impl Sync for BroadcasterInterface {}
37 #[no_mangle]
38 pub(crate) extern "C" fn BroadcasterInterface_clone_fields(orig: &BroadcasterInterface) -> BroadcasterInterface {
39         BroadcasterInterface {
40                 this_arg: orig.this_arg,
41                 broadcast_transaction: Clone::clone(&orig.broadcast_transaction),
42                 free: Clone::clone(&orig.free),
43         }
44 }
45
46 use lightning::chain::chaininterface::BroadcasterInterface as rustBroadcasterInterface;
47 impl rustBroadcasterInterface for BroadcasterInterface {
48         fn broadcast_transaction(&self, mut tx: &bitcoin::blockdata::transaction::Transaction) {
49                 (self.broadcast_transaction)(self.this_arg, crate::c_types::Transaction::from_bitcoin(tx))
50         }
51 }
52
53 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
54 // directly as a Deref trait in higher-level structs:
55 impl core::ops::Deref for BroadcasterInterface {
56         type Target = Self;
57         fn deref(&self) -> &Self {
58                 self
59         }
60 }
61 /// Calls the free function if one is set
62 #[no_mangle]
63 pub extern "C" fn BroadcasterInterface_free(this_ptr: BroadcasterInterface) { }
64 impl Drop for BroadcasterInterface {
65         fn drop(&mut self) {
66                 if let Some(f) = self.free {
67                         f(self.this_arg);
68                 }
69         }
70 }
71 /// An enum that represents the speed at which we want a transaction to confirm used for feerate
72 /// estimation.
73 #[derive(Clone)]
74 #[must_use]
75 #[repr(C)]
76 pub enum ConfirmationTarget {
77         /// We are happy with this transaction confirming slowly when feerate drops some.
78         Background,
79         /// We'd like this transaction to confirm without major delay, but 12-18 blocks is fine.
80         Normal,
81         /// We'd like this transaction to confirm in the next few blocks.
82         HighPriority,
83 }
84 use lightning::chain::chaininterface::ConfirmationTarget as ConfirmationTargetImport;
85 pub(crate) type nativeConfirmationTarget = ConfirmationTargetImport;
86
87 impl ConfirmationTarget {
88         #[allow(unused)]
89         pub(crate) fn to_native(&self) -> nativeConfirmationTarget {
90                 match self {
91                         ConfirmationTarget::Background => nativeConfirmationTarget::Background,
92                         ConfirmationTarget::Normal => nativeConfirmationTarget::Normal,
93                         ConfirmationTarget::HighPriority => nativeConfirmationTarget::HighPriority,
94                 }
95         }
96         #[allow(unused)]
97         pub(crate) fn into_native(self) -> nativeConfirmationTarget {
98                 match self {
99                         ConfirmationTarget::Background => nativeConfirmationTarget::Background,
100                         ConfirmationTarget::Normal => nativeConfirmationTarget::Normal,
101                         ConfirmationTarget::HighPriority => nativeConfirmationTarget::HighPriority,
102                 }
103         }
104         #[allow(unused)]
105         pub(crate) fn from_native(native: &nativeConfirmationTarget) -> Self {
106                 match native {
107                         nativeConfirmationTarget::Background => ConfirmationTarget::Background,
108                         nativeConfirmationTarget::Normal => ConfirmationTarget::Normal,
109                         nativeConfirmationTarget::HighPriority => ConfirmationTarget::HighPriority,
110                 }
111         }
112         #[allow(unused)]
113         pub(crate) fn native_into(native: nativeConfirmationTarget) -> Self {
114                 match native {
115                         nativeConfirmationTarget::Background => ConfirmationTarget::Background,
116                         nativeConfirmationTarget::Normal => ConfirmationTarget::Normal,
117                         nativeConfirmationTarget::HighPriority => ConfirmationTarget::HighPriority,
118                 }
119         }
120 }
121 /// Creates a copy of the ConfirmationTarget
122 #[no_mangle]
123 pub extern "C" fn ConfirmationTarget_clone(orig: &ConfirmationTarget) -> ConfirmationTarget {
124         orig.clone()
125 }
126 #[no_mangle]
127 /// Utility method to constructs a new Background-variant ConfirmationTarget
128 pub extern "C" fn ConfirmationTarget_background() -> ConfirmationTarget {
129         ConfirmationTarget::Background}
130 #[no_mangle]
131 /// Utility method to constructs a new Normal-variant ConfirmationTarget
132 pub extern "C" fn ConfirmationTarget_normal() -> ConfirmationTarget {
133         ConfirmationTarget::Normal}
134 #[no_mangle]
135 /// Utility method to constructs a new HighPriority-variant ConfirmationTarget
136 pub extern "C" fn ConfirmationTarget_high_priority() -> ConfirmationTarget {
137         ConfirmationTarget::HighPriority}
138 /// Checks if two ConfirmationTargets contain equal inner contents.
139 #[no_mangle]
140 pub extern "C" fn ConfirmationTarget_hash(o: &ConfirmationTarget) -> u64 {
141         // Note that we'd love to use alloc::collections::hash_map::DefaultHasher but it's not in core
142         #[allow(deprecated)]
143         let mut hasher = core::hash::SipHasher::new();
144         core::hash::Hash::hash(&o.to_native(), &mut hasher);
145         core::hash::Hasher::finish(&hasher)
146 }
147 /// Checks if two ConfirmationTargets contain equal inner contents.
148 /// This ignores pointers and is_owned flags and looks at the values in fields.
149 #[no_mangle]
150 pub extern "C" fn ConfirmationTarget_eq(a: &ConfirmationTarget, b: &ConfirmationTarget) -> bool {
151         if &a.to_native() == &b.to_native() { true } else { false }
152 }
153 /// A trait which should be implemented to provide feerate information on a number of time
154 /// horizons.
155 ///
156 /// Note that all of the functions implemented here *must* be reentrant-safe (obviously - they're
157 /// called from inside the library in response to chain events, P2P events, or timer events).
158 #[repr(C)]
159 pub struct FeeEstimator {
160         /// An opaque pointer which is passed to your function implementations as an argument.
161         /// This has no meaning in the LDK, and can be NULL or any other value.
162         pub this_arg: *mut c_void,
163         /// Gets estimated satoshis of fee required per 1000 Weight-Units.
164         ///
165         /// LDK will wrap this method and ensure that the value returned is no smaller than 253
166         /// (ie 1 satoshi-per-byte rounded up to ensure later round-downs don't put us below 1 satoshi-per-byte).
167         ///
168         /// The following unit conversions can be used to convert to sats/KW:
169         ///  * satoshis-per-byte * 250
170         ///  * satoshis-per-kbyte / 4
171         #[must_use]
172         pub get_est_sat_per_1000_weight: extern "C" fn (this_arg: *const c_void, confirmation_target: crate::lightning::chain::chaininterface::ConfirmationTarget) -> u32,
173         /// Frees any resources associated with this object given its this_arg pointer.
174         /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
175         pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
176 }
177 unsafe impl Send for FeeEstimator {}
178 unsafe impl Sync for FeeEstimator {}
179 #[no_mangle]
180 pub(crate) extern "C" fn FeeEstimator_clone_fields(orig: &FeeEstimator) -> FeeEstimator {
181         FeeEstimator {
182                 this_arg: orig.this_arg,
183                 get_est_sat_per_1000_weight: Clone::clone(&orig.get_est_sat_per_1000_weight),
184                 free: Clone::clone(&orig.free),
185         }
186 }
187
188 use lightning::chain::chaininterface::FeeEstimator as rustFeeEstimator;
189 impl rustFeeEstimator for FeeEstimator {
190         fn get_est_sat_per_1000_weight(&self, mut confirmation_target: lightning::chain::chaininterface::ConfirmationTarget) -> u32 {
191                 let mut ret = (self.get_est_sat_per_1000_weight)(self.this_arg, crate::lightning::chain::chaininterface::ConfirmationTarget::native_into(confirmation_target));
192                 ret
193         }
194 }
195
196 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
197 // directly as a Deref trait in higher-level structs:
198 impl core::ops::Deref for FeeEstimator {
199         type Target = Self;
200         fn deref(&self) -> &Self {
201                 self
202         }
203 }
204 /// Calls the free function if one is set
205 #[no_mangle]
206 pub extern "C" fn FeeEstimator_free(this_ptr: FeeEstimator) { }
207 impl Drop for FeeEstimator {
208         fn drop(&mut self) {
209                 if let Some(f) = self.free {
210                         f(self.this_arg);
211                 }
212         }
213 }
214 /// Minimum relay fee as required by bitcoin network mempool policy.
215
216 #[no_mangle]
217 pub static MIN_RELAY_FEE_SAT_PER_1000_WEIGHT: u64 = lightning::chain::chaininterface::MIN_RELAY_FEE_SAT_PER_1000_WEIGHT;
218 /// Minimum feerate that takes a sane approach to bitcoind weight-to-vbytes rounding.
219 /// See the following Core Lightning commit for an explanation:
220 /// <https://github.com/ElementsProject/lightning/commit/2e687b9b352c9092b5e8bd4a688916ac50b44af0>
221
222 #[no_mangle]
223 pub static FEERATE_FLOOR_SATS_PER_KW: u32 = lightning::chain::chaininterface::FEERATE_FLOOR_SATS_PER_KW;