Update auto-generated bindings
[ldk-c-bindings] / lightning-c-bindings / src / lightning / chain / chainmonitor.rs
index 3e237dfc2b50b1827012b66eddb41c0af7a8d29f..311c2f397cd432025d14db3dfd2c0e2dea71f470 100644 (file)
@@ -22,6 +22,7 @@
 //! events. The remote server would make use of [`ChainMonitor`] for block processing and for
 //! servicing [`ChannelMonitor`] updates from the client.
 
+use std::str::FromStr;
 use std::ffi::c_void;
 use bitcoin::hashes::Hash;
 use crate::c_types::*;
@@ -79,105 +80,93 @@ impl ChainMonitor {
                ret
        }
 }
-/// Dispatches to per-channel monitors, which are responsible for updating their on-chain view
-/// of a channel and reacting accordingly based on transactions in the connected block. See
-/// [`ChannelMonitor::block_connected`] for details. Any HTLCs that were resolved on chain will
-/// be returned by [`chain::Watch::release_pending_monitor_events`].
-///
-/// Calls back to [`chain::Filter`] if any monitor indicated new outputs to watch. Subsequent
-/// calls must not exclude any transactions matching the new outputs nor any in-block
-/// descendants of such transactions. It is not necessary to re-fetch the block to obtain
-/// updated `txdata`.
-#[no_mangle]
-pub extern "C" fn ChainMonitor_block_connected(this_arg: &ChainMonitor, header: *const [u8; 80], mut txdata: crate::c_types::derived::CVec_C2Tuple_usizeTransactionZZ, mut height: u32) {
-       let mut local_txdata = Vec::new(); for mut item in txdata.into_rust().drain(..) { local_txdata.push( { let (mut orig_txdata_0_0, mut orig_txdata_0_1) = item.to_rust(); let mut local_txdata_0 = (orig_txdata_0_0, orig_txdata_0_1.into_bitcoin()); local_txdata_0 }); };
-       unsafe { &*this_arg.inner }.block_connected(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), &local_txdata.iter().map(|(a, b)| (*a, b)).collect::<Vec<_>>()[..], height)
-}
-
-/// Dispatches to per-channel monitors, which are responsible for updating their on-chain view
-/// of a channel and reacting accordingly to newly confirmed transactions. For details, see
-/// [`ChannelMonitor::transactions_confirmed`].
+/// Creates a new `ChainMonitor` used to watch on-chain activity pertaining to channels.
 ///
-/// Used instead of [`block_connected`] by clients that are notified of transactions rather than
-/// blocks. May be called before or after [`update_best_block`] for transactions in the
-/// corresponding block. See [`update_best_block`] for further calling expectations.
+/// When an optional chain source implementing [`chain::Filter`] is provided, the chain monitor
+/// will call back to it indicating transactions and outputs of interest. This allows clients to
+/// pre-filter blocks or only fetch blocks matching a compact filter. Otherwise, clients may
+/// always need to fetch full blocks absent another means for determining which blocks contain
+/// transactions relevant to the watched channels.
 ///
-/// [`block_connected`]: Self::block_connected
-/// [`update_best_block`]: Self::update_best_block
+/// Note that chain_source (or a relevant inner pointer) may be NULL or all-0s to represent None
+#[must_use]
 #[no_mangle]
-pub extern "C" fn ChainMonitor_transactions_confirmed(this_arg: &ChainMonitor, header: *const [u8; 80], mut txdata: crate::c_types::derived::CVec_C2Tuple_usizeTransactionZZ, mut height: u32) {
-       let mut local_txdata = Vec::new(); for mut item in txdata.into_rust().drain(..) { local_txdata.push( { let (mut orig_txdata_0_0, mut orig_txdata_0_1) = item.to_rust(); let mut local_txdata_0 = (orig_txdata_0_0, orig_txdata_0_1.into_bitcoin()); local_txdata_0 }); };
-       unsafe { &*this_arg.inner }.transactions_confirmed(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), &local_txdata.iter().map(|(a, b)| (*a, b)).collect::<Vec<_>>()[..], height)
+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) } }) };
+       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 }
 }
 
-/// Dispatches to per-channel monitors, which are responsible for updating their on-chain view
-/// of a channel and reacting accordingly based on the new chain tip. For details, see
-/// [`ChannelMonitor::update_best_block`].
-///
-/// Used instead of [`block_connected`] by clients that are notified of transactions rather than
-/// blocks. May be called before or after [`transactions_confirmed`] for the corresponding
-/// block.
-///
-/// Must be called after new blocks become available for the most recent block. Intermediary
-/// blocks, however, may be safely skipped. In the event of a chain re-organization, this only
-/// needs to be called for the most recent block assuming `transaction_unconfirmed` is called
-/// for any affected transactions.
-///
-/// [`block_connected`]: Self::block_connected
-/// [`transactions_confirmed`]: Self::transactions_confirmed
-/// [`transaction_unconfirmed`]: Self::transaction_unconfirmed
+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 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();
+               ret.free = Some(ChainMonitor_free_void);
+               ret
+       }
+}
+/// Constructs a new Listen which calls the relevant methods on this_arg.
+/// This copies the `inner` pointer in this_arg and thus the returned Listen must be freed before this_arg is
 #[no_mangle]
-pub extern "C" fn ChainMonitor_update_best_block(this_arg: &ChainMonitor, header: *const [u8; 80], mut height: u32) {
-       unsafe { &*this_arg.inner }.update_best_block(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height)
+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 },
+               free: None,
+               block_connected: ChainMonitor_Listen_block_connected,
+               block_disconnected: ChainMonitor_Listen_block_disconnected,
+       }
 }
 
-/// Dispatches to per-channel monitors, which are responsible for updating their on-chain view
-/// of a channel based on the disconnected block. See [`ChannelMonitor::block_disconnected`] for
-/// details.
-#[no_mangle]
-pub extern "C" fn ChainMonitor_block_disconnected(this_arg: &ChainMonitor, header: *const [u8; 80], mut disconnected_height: u32) {
-       unsafe { &*this_arg.inner }.block_disconnected(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), disconnected_height)
+extern "C" fn ChainMonitor_Listen_block_connected(this_arg: *const c_void, mut block: crate::c_types::u8slice, mut height: u32) {
+       <nativeChainMonitor as lightning::chain::Listen<>>::block_connected(unsafe { &mut *(this_arg as *mut nativeChainMonitor) }, &::bitcoin::consensus::encode::deserialize(block.to_slice()).unwrap(), height)
+}
+extern "C" fn ChainMonitor_Listen_block_disconnected(this_arg: *const c_void, header: *const [u8; 80], mut height: u32) {
+       <nativeChainMonitor as lightning::chain::Listen<>>::block_disconnected(unsafe { &mut *(this_arg as *mut nativeChainMonitor) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height)
 }
 
-/// Dispatches to per-channel monitors, which are responsible for updating their on-chain view
-/// of a channel based on transactions unconfirmed as a result of a chain reorganization. See
-/// [`ChannelMonitor::transaction_unconfirmed`] for details.
-///
-/// Used instead of [`block_disconnected`] by clients that are notified of transactions rather
-/// than blocks. May be called before or after [`update_best_block`] for transactions in the
-/// corresponding block. See [`update_best_block`] for further calling expectations. 
-///
-/// [`block_disconnected`]: Self::block_disconnected
-/// [`update_best_block`]: Self::update_best_block
+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 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();
+               ret.free = Some(ChainMonitor_free_void);
+               ret
+       }
+}
+/// Constructs a new Confirm which calls the relevant methods on this_arg.
+/// This copies the `inner` pointer in this_arg and thus the returned Confirm must be freed before this_arg is
 #[no_mangle]
-pub extern "C" fn ChainMonitor_transaction_unconfirmed(this_arg: &ChainMonitor, txid: *const [u8; 32]) {
-       unsafe { &*this_arg.inner }.transaction_unconfirmed(&::bitcoin::hash_types::Txid::from_slice(&unsafe { &*txid }[..]).unwrap())
+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 },
+               free: None,
+               transactions_confirmed: ChainMonitor_Confirm_transactions_confirmed,
+               transaction_unconfirmed: ChainMonitor_Confirm_transaction_unconfirmed,
+               best_block_updated: ChainMonitor_Confirm_best_block_updated,
+               get_relevant_txids: ChainMonitor_Confirm_get_relevant_txids,
+       }
 }
 
-/// Returns the set of txids that should be monitored for re-organization out of the chain.
+extern "C" fn ChainMonitor_Confirm_transactions_confirmed(this_arg: *const c_void, header: *const [u8; 80], mut txdata: crate::c_types::derived::CVec_C2Tuple_usizeTransactionZZ, mut height: u32) {
+       let mut local_txdata = Vec::new(); for mut item in txdata.into_rust().drain(..) { local_txdata.push( { let (mut orig_txdata_0_0, mut orig_txdata_0_1) = item.to_rust(); let mut local_txdata_0 = (orig_txdata_0_0, orig_txdata_0_1.into_bitcoin()); local_txdata_0 }); };
+       <nativeChainMonitor as lightning::chain::Confirm<>>::transactions_confirmed(unsafe { &mut *(this_arg as *mut nativeChainMonitor) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), &local_txdata.iter().map(|(a, b)| (*a, b)).collect::<Vec<_>>()[..], height)
+}
+extern "C" fn ChainMonitor_Confirm_transaction_unconfirmed(this_arg: *const c_void, txid: *const [u8; 32]) {
+       <nativeChainMonitor as lightning::chain::Confirm<>>::transaction_unconfirmed(unsafe { &mut *(this_arg as *mut nativeChainMonitor) }, &::bitcoin::hash_types::Txid::from_slice(&unsafe { &*txid }[..]).unwrap())
+}
+extern "C" fn ChainMonitor_Confirm_best_block_updated(this_arg: *const c_void, header: *const [u8; 80], mut height: u32) {
+       <nativeChainMonitor as lightning::chain::Confirm<>>::best_block_updated(unsafe { &mut *(this_arg as *mut nativeChainMonitor) }, &::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height)
+}
 #[must_use]
-#[no_mangle]
-pub extern "C" fn ChainMonitor_get_relevant_txids(this_arg: &ChainMonitor) -> crate::c_types::derived::CVec_TxidZ {
-       let mut ret = unsafe { &*this_arg.inner }.get_relevant_txids();
+extern "C" fn ChainMonitor_Confirm_get_relevant_txids(this_arg: *const c_void) -> crate::c_types::derived::CVec_TxidZ {
+       let mut ret = <nativeChainMonitor as lightning::chain::Confirm<>>::get_relevant_txids(unsafe { &mut *(this_arg as *mut nativeChainMonitor) }, );
        let mut local_ret = Vec::new(); for mut item in ret.drain(..) { local_ret.push( { crate::c_types::ThirtyTwoBytes { data: item.into_inner() } }); };
        local_ret.into()
 }
 
-/// Creates a new `ChainMonitor` used to watch on-chain activity pertaining to channels.
-///
-/// When an optional chain source implementing [`chain::Filter`] is provided, the chain monitor
-/// will call back to it indicating transactions and outputs of interest. This allows clients to
-/// pre-filter blocks or only fetch blocks matching a compact filter. Otherwise, clients may
-/// always need to fetch full blocks absent another means for determining which blocks contain
-/// 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) } }) };
-       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 }
-}
-
 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 };
@@ -204,13 +193,13 @@ pub extern "C" fn ChainMonitor_as_Watch(this_arg: &ChainMonitor) -> crate::light
 #[must_use]
 extern "C" fn ChainMonitor_Watch_watch_channel(this_arg: *const c_void, mut funding_outpoint: crate::lightning::chain::transaction::OutPoint, mut monitor: crate::lightning::chain::channelmonitor::ChannelMonitor) -> crate::c_types::derived::CResult_NoneChannelMonitorUpdateErrZ {
        let mut ret = <nativeChainMonitor as lightning::chain::Watch<_>>::watch_channel(unsafe { &mut *(this_arg as *mut nativeChainMonitor) }, *unsafe { Box::from_raw(funding_outpoint.take_inner()) }, *unsafe { Box::from_raw(monitor.take_inner()) });
-       let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::chain::channelmonitor::ChannelMonitorUpdateErr::native_into(e) }).into() };
+       let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::chain::channelmonitor::ChannelMonitorUpdateErr::native_into(e) }).into() };
        local_ret
 }
 #[must_use]
 extern "C" fn ChainMonitor_Watch_update_channel(this_arg: *const c_void, mut funding_txo: crate::lightning::chain::transaction::OutPoint, mut update: crate::lightning::chain::channelmonitor::ChannelMonitorUpdate) -> crate::c_types::derived::CResult_NoneChannelMonitorUpdateErrZ {
        let mut ret = <nativeChainMonitor as lightning::chain::Watch<_>>::update_channel(unsafe { &mut *(this_arg as *mut nativeChainMonitor) }, *unsafe { Box::from_raw(funding_txo.take_inner()) }, *unsafe { Box::from_raw(update.take_inner()) });
-       let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { 0u8 /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::chain::channelmonitor::ChannelMonitorUpdateErr::native_into(e) }).into() };
+       let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { () /*o*/ }).into(), Err(mut e) => crate::c_types::CResultTempl::err( { crate::lightning::chain::channelmonitor::ChannelMonitorUpdateErr::native_into(e) }).into() };
        local_ret
 }
 #[must_use]
@@ -237,14 +226,11 @@ pub extern "C" fn ChainMonitor_as_EventsProvider(this_arg: &ChainMonitor) -> cra
        crate::lightning::util::events::EventsProvider {
                this_arg: unsafe { (*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)
 }