Update auto-generated bindings
[ldk-c-bindings] / lightning-c-bindings / src / lightning / chain / chaininterface.rs
index 9b8e84b105e22e160ebe75a1bb5bec63aa82bbbc..7d8291d64fd2fa88dd4d5e671b04a856ab6c8630 100644 (file)
 //! Includes traits for monitoring and receiving notifications of new blocks and block
 //! disconnections, transaction broadcasting, and feerate information requests.
 
-use std::ffi::c_void;
+use alloc::str::FromStr;
+use core::ffi::c_void;
+use core::convert::Infallible;
 use bitcoin::hashes::Hash;
 use crate::c_types::*;
+#[cfg(feature="no-std")]
+use alloc::{vec::Vec, boxed::Box};
 
 /// An interface to send a transaction to the Bitcoin network.
 #[repr(C)]
@@ -28,20 +32,27 @@ pub struct BroadcasterInterface {
        /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
        pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
 }
-unsafe impl Sync for BroadcasterInterface {}
 unsafe impl Send for BroadcasterInterface {}
+unsafe impl Sync for BroadcasterInterface {}
+#[no_mangle]
+pub(crate) extern "C" fn BroadcasterInterface_clone_fields(orig: &BroadcasterInterface) -> BroadcasterInterface {
+       BroadcasterInterface {
+               this_arg: orig.this_arg,
+               broadcast_transaction: Clone::clone(&orig.broadcast_transaction),
+               free: Clone::clone(&orig.free),
+       }
+}
 
 use lightning::chain::chaininterface::BroadcasterInterface as rustBroadcasterInterface;
 impl rustBroadcasterInterface for BroadcasterInterface {
-       fn broadcast_transaction(&self, tx: &bitcoin::blockdata::transaction::Transaction) {
-               let mut local_tx = ::bitcoin::consensus::encode::serialize(tx);
-               (self.broadcast_transaction)(self.this_arg, crate::c_types::Transaction::from_vec(local_tx))
+       fn broadcast_transaction(&self, mut tx: &bitcoin::blockdata::transaction::Transaction) {
+               (self.broadcast_transaction)(self.this_arg, crate::c_types::Transaction::from_bitcoin(tx))
        }
 }
 
 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
 // directly as a Deref trait in higher-level structs:
-impl std::ops::Deref for BroadcasterInterface {
+impl core::ops::Deref for BroadcasterInterface {
        type Target = Self;
        fn deref(&self) -> &Self {
                self
@@ -110,6 +121,24 @@ impl ConfirmationTarget {
 pub extern "C" fn ConfirmationTarget_clone(orig: &ConfirmationTarget) -> ConfirmationTarget {
        orig.clone()
 }
+#[no_mangle]
+/// Utility method to constructs a new Background-variant ConfirmationTarget
+pub extern "C" fn ConfirmationTarget_background() -> ConfirmationTarget {
+       ConfirmationTarget::Background}
+#[no_mangle]
+/// Utility method to constructs a new Normal-variant ConfirmationTarget
+pub extern "C" fn ConfirmationTarget_normal() -> ConfirmationTarget {
+       ConfirmationTarget::Normal}
+#[no_mangle]
+/// Utility method to constructs a new HighPriority-variant ConfirmationTarget
+pub extern "C" fn ConfirmationTarget_high_priority() -> ConfirmationTarget {
+       ConfirmationTarget::HighPriority}
+/// Checks if two ConfirmationTargets contain equal inner contents.
+/// This ignores pointers and is_owned flags and looks at the values in fields.
+#[no_mangle]
+pub extern "C" fn ConfirmationTarget_eq(a: &ConfirmationTarget, b: &ConfirmationTarget) -> bool {
+       if &a.to_native() == &b.to_native() { true } else { false }
+}
 /// A trait which should be implemented to provide feerate information on a number of time
 /// horizons.
 ///
@@ -122,24 +151,32 @@ pub struct FeeEstimator {
        pub this_arg: *mut c_void,
        /// Gets estimated satoshis of fee required per 1000 Weight-Units.
        ///
-       /// Must be no smaller than 253 (ie 1 satoshi-per-byte rounded up to ensure later round-downs
-       /// don't put us below 1 satoshi-per-byte).
+       /// Must return a value no smaller than 253 (ie 1 satoshi-per-byte rounded up to ensure later
+       /// round-downs don't put us below 1 satoshi-per-byte).
        ///
-       /// This translates to:
-       ///  * satoshis-per-byte * 250
-       ///  * ceil(satoshis-per-kbyte / 4)
+       /// This method can be implemented with the following unit conversions:
+       ///  * max(satoshis-per-byte * 250, 253)
+       ///  * max(satoshis-per-kbyte / 4, 253)
        #[must_use]
        pub get_est_sat_per_1000_weight: extern "C" fn (this_arg: *const c_void, confirmation_target: crate::lightning::chain::chaininterface::ConfirmationTarget) -> u32,
        /// Frees any resources associated with this object given its this_arg pointer.
        /// Does not need to free the outer struct containing function pointers and may be NULL is no resources need to be freed.
        pub free: Option<extern "C" fn(this_arg: *mut c_void)>,
 }
-unsafe impl Sync for FeeEstimator {}
 unsafe impl Send for FeeEstimator {}
+unsafe impl Sync for FeeEstimator {}
+#[no_mangle]
+pub(crate) extern "C" fn FeeEstimator_clone_fields(orig: &FeeEstimator) -> FeeEstimator {
+       FeeEstimator {
+               this_arg: orig.this_arg,
+               get_est_sat_per_1000_weight: Clone::clone(&orig.get_est_sat_per_1000_weight),
+               free: Clone::clone(&orig.free),
+       }
+}
 
 use lightning::chain::chaininterface::FeeEstimator as rustFeeEstimator;
 impl rustFeeEstimator for FeeEstimator {
-       fn get_est_sat_per_1000_weight(&self, confirmation_target: lightning::chain::chaininterface::ConfirmationTarget) -> u32 {
+       fn get_est_sat_per_1000_weight(&self, mut confirmation_target: lightning::chain::chaininterface::ConfirmationTarget) -> u32 {
                let mut ret = (self.get_est_sat_per_1000_weight)(self.this_arg, crate::lightning::chain::chaininterface::ConfirmationTarget::native_into(confirmation_target));
                ret
        }
@@ -147,7 +184,7 @@ impl rustFeeEstimator for FeeEstimator {
 
 // We're essentially a pointer already, or at least a set of pointers, so allow us to be used
 // directly as a Deref trait in higher-level structs:
-impl std::ops::Deref for FeeEstimator {
+impl core::ops::Deref for FeeEstimator {
        type Target = Self;
        fn deref(&self) -> &Self {
                self