Update auto-generated bindings
[ldk-c-bindings] / lightning-c-bindings / src / lightning / chain / chainmonitor.rs
index 3005c4be71bc78e5130caa418dff6c9e9b24e6c4..08997943b07b91c45ba5e7d6c7457fd7633955ed 100644 (file)
@@ -24,6 +24,7 @@
 
 use std::str::FromStr;
 use std::ffi::c_void;
+use core::convert::Infallible;
 use bitcoin::hashes::Hash;
 use crate::c_types::*;
 
@@ -58,7 +59,7 @@ pub struct ChainMonitor {
 impl Drop for ChainMonitor {
        fn drop(&mut self) {
                if self.is_owned && !<*mut nativeChainMonitor>::is_null(self.inner) {
-                       let _ = unsafe { Box::from_raw(self.inner) };
+                       let _ = unsafe { Box::from_raw(ObjOps::untweak_ptr(self.inner)) };
                }
        }
 }
@@ -71,11 +72,17 @@ extern "C" fn ChainMonitor_free_void(this_ptr: *mut c_void) {
        unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChainMonitor); }
 }
 #[allow(unused)]
-/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
 impl ChainMonitor {
+       pub(crate) fn get_native_ref(&self) -> &'static nativeChainMonitor {
+               unsafe { &*ObjOps::untweak_ptr(self.inner) }
+       }
+       pub(crate) fn get_native_mut_ref(&self) -> &'static mut nativeChainMonitor {
+               unsafe { &mut *ObjOps::untweak_ptr(self.inner) }
+       }
+       /// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
        pub(crate) fn take_inner(mut self) -> *mut nativeChainMonitor {
                assert!(self.is_owned);
-               let ret = self.inner;
+               let ret = ObjOps::untweak_ptr(self.inner);
                self.inner = std::ptr::null_mut();
                ret
        }
@@ -89,15 +96,33 @@ impl ChainMonitor {
 /// transactions relevant to the watched channels.
 #[must_use]
 #[no_mangle]
-pub extern "C" fn ChainMonitor_new(chain_source: *mut crate::lightning::chain::Filter, mut broadcaster: crate::lightning::chain::chaininterface::BroadcasterInterface, mut logger: crate::lightning::util::logger::Logger, mut feeest: crate::lightning::chain::chaininterface::FeeEstimator, mut persister: crate::lightning::chain::channelmonitor::Persist) -> ChainMonitor {
-       let mut local_chain_source = if chain_source == std::ptr::null_mut() { None } else { Some( { unsafe { *Box::from_raw(chain_source) } }) };
+pub extern "C" fn ChainMonitor_new(mut chain_source: crate::c_types::derived::COption_FilterZ, mut broadcaster: crate::lightning::chain::chaininterface::BroadcasterInterface, mut logger: crate::lightning::util::logger::Logger, mut feeest: crate::lightning::chain::chaininterface::FeeEstimator, mut persister: crate::lightning::chain::channelmonitor::Persist) -> ChainMonitor {
+       let mut local_chain_source = { /* chain_source*/ let chain_source_opt = chain_source; { } if chain_source_opt.is_none() { None } else { Some({ chain_source_opt.take() }) } };
        let mut ret = lightning::chain::chainmonitor::ChainMonitor::new(local_chain_source, broadcaster, logger, feeest, persister);
-       ChainMonitor { inner: Box::into_raw(Box::new(ret)), is_owned: true }
+       ChainMonitor { inner: ObjOps::heap_alloc(ret), is_owned: true }
+}
+
+/// Gets the balances in the contained [`ChannelMonitor`]s which are claimable on-chain or
+/// claims which are awaiting confirmation.
+///
+/// Includes the balances from each [`ChannelMonitor`] *except* those included in
+/// `ignored_channels`, allowing you to filter out balances from channels which are still open
+/// (and whose balance should likely be pulled from the [`ChannelDetails`]).
+///
+/// See [`ChannelMonitor::get_claimable_balances`] for more details on the exact criteria for
+/// inclusion in the return value.
+#[must_use]
+#[no_mangle]
+pub extern "C" fn ChainMonitor_get_claimable_balances(this_arg: &ChainMonitor, mut ignored_channels: crate::c_types::derived::CVec_ChannelDetailsZ) -> crate::c_types::derived::CVec_BalanceZ {
+       let mut local_ignored_channels = Vec::new(); for mut item in ignored_channels.as_slice().iter() { local_ignored_channels.push( { item.get_native_ref() }); };
+       let mut ret = unsafe { &*ObjOps::untweak_ptr(this_arg.inner) }.get_claimable_balances(&local_ignored_channels[..]);
+       let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::chain::channelmonitor::Balance::native_into(item) }); };
+       local_ret.into()
 }
 
 impl From<nativeChainMonitor> for crate::lightning::chain::Listen {
        fn from(obj: nativeChainMonitor) -> Self {
-               let mut rust_obj = ChainMonitor { inner: Box::into_raw(Box::new(obj)), is_owned: true };
+               let mut rust_obj = ChainMonitor { inner: ObjOps::heap_alloc(obj), is_owned: true };
                let mut ret = ChainMonitor_as_Listen(&rust_obj);
                // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
                rust_obj.inner = std::ptr::null_mut();
@@ -110,7 +135,7 @@ impl From<nativeChainMonitor> for crate::lightning::chain::Listen {
 #[no_mangle]
 pub extern "C" fn ChainMonitor_as_Listen(this_arg: &ChainMonitor) -> crate::lightning::chain::Listen {
        crate::lightning::chain::Listen {
-               this_arg: unsafe { (*this_arg).inner as *mut c_void },
+               this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
                free: None,
                block_connected: ChainMonitor_Listen_block_connected,
                block_disconnected: ChainMonitor_Listen_block_disconnected,
@@ -126,7 +151,7 @@ extern "C" fn ChainMonitor_Listen_block_disconnected(this_arg: *const c_void, he
 
 impl From<nativeChainMonitor> for crate::lightning::chain::Confirm {
        fn from(obj: nativeChainMonitor) -> Self {
-               let mut rust_obj = ChainMonitor { inner: Box::into_raw(Box::new(obj)), is_owned: true };
+               let mut rust_obj = ChainMonitor { inner: ObjOps::heap_alloc(obj), is_owned: true };
                let mut ret = ChainMonitor_as_Confirm(&rust_obj);
                // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
                rust_obj.inner = std::ptr::null_mut();
@@ -139,7 +164,7 @@ impl From<nativeChainMonitor> for crate::lightning::chain::Confirm {
 #[no_mangle]
 pub extern "C" fn ChainMonitor_as_Confirm(this_arg: &ChainMonitor) -> crate::lightning::chain::Confirm {
        crate::lightning::chain::Confirm {
-               this_arg: unsafe { (*this_arg).inner as *mut c_void },
+               this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
                free: None,
                transactions_confirmed: ChainMonitor_Confirm_transactions_confirmed,
                transaction_unconfirmed: ChainMonitor_Confirm_transaction_unconfirmed,
@@ -167,7 +192,7 @@ extern "C" fn ChainMonitor_Confirm_get_relevant_txids(this_arg: *const c_void) -
 
 impl From<nativeChainMonitor> for crate::lightning::chain::Watch {
        fn from(obj: nativeChainMonitor) -> Self {
-               let mut rust_obj = ChainMonitor { inner: Box::into_raw(Box::new(obj)), is_owned: true };
+               let mut rust_obj = ChainMonitor { inner: ObjOps::heap_alloc(obj), is_owned: true };
                let mut ret = ChainMonitor_as_Watch(&rust_obj);
                // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
                rust_obj.inner = std::ptr::null_mut();
@@ -180,7 +205,7 @@ impl From<nativeChainMonitor> for crate::lightning::chain::Watch {
 #[no_mangle]
 pub extern "C" fn ChainMonitor_as_Watch(this_arg: &ChainMonitor) -> crate::lightning::chain::Watch {
        crate::lightning::chain::Watch {
-               this_arg: unsafe { (*this_arg).inner as *mut c_void },
+               this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
                free: None,
                watch_channel: ChainMonitor_Watch_watch_channel,
                update_channel: ChainMonitor_Watch_update_channel,
@@ -209,7 +234,7 @@ extern "C" fn ChainMonitor_Watch_release_pending_monitor_events(this_arg: *const
 
 impl From<nativeChainMonitor> for crate::lightning::util::events::EventsProvider {
        fn from(obj: nativeChainMonitor) -> Self {
-               let mut rust_obj = ChainMonitor { inner: Box::into_raw(Box::new(obj)), is_owned: true };
+               let mut rust_obj = ChainMonitor { inner: ObjOps::heap_alloc(obj), is_owned: true };
                let mut ret = ChainMonitor_as_EventsProvider(&rust_obj);
                // We want to free rust_obj when ret gets drop()'d, not rust_obj, so wipe rust_obj's pointer and set ret's free() fn
                rust_obj.inner = std::ptr::null_mut();
@@ -222,16 +247,13 @@ impl From<nativeChainMonitor> for crate::lightning::util::events::EventsProvider
 #[no_mangle]
 pub extern "C" fn ChainMonitor_as_EventsProvider(this_arg: &ChainMonitor) -> crate::lightning::util::events::EventsProvider {
        crate::lightning::util::events::EventsProvider {
-               this_arg: unsafe { (*this_arg).inner as *mut c_void },
+               this_arg: unsafe { ObjOps::untweak_ptr((*this_arg).inner) as *mut c_void },
                free: None,
-               get_and_clear_pending_events: ChainMonitor_EventsProvider_get_and_clear_pending_events,
+               process_pending_events: ChainMonitor_EventsProvider_process_pending_events,
        }
 }
 
-#[must_use]
-extern "C" fn ChainMonitor_EventsProvider_get_and_clear_pending_events(this_arg: *const c_void) -> crate::c_types::derived::CVec_EventZ {
-       let mut ret = <nativeChainMonitor as lightning::util::events::EventsProvider<>>::get_and_clear_pending_events(unsafe { &mut *(this_arg as *mut nativeChainMonitor) }, );
-       let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::lightning::util::events::Event::native_into(item) }); };
-       local_ret.into()
+extern "C" fn ChainMonitor_EventsProvider_process_pending_events(this_arg: *const c_void, mut handler: crate::lightning::util::events::EventHandler) {
+       <nativeChainMonitor as lightning::util::events::EventsProvider<>>::process_pending_events(unsafe { &mut *(this_arg as *mut nativeChainMonitor) }, handler)
 }