-
-use lightning::chain::chaininterface::ChainWatchedUtil as nativeChainWatchedUtilImport;
-type nativeChainWatchedUtil = nativeChainWatchedUtilImport;
-
-/// Utility for tracking registered txn/outpoints and checking for matches
-#[must_use]
-#[repr(C)]
-pub struct ChainWatchedUtil {
- /// Nearly everyhwere, inner must be non-null, however in places where
- /// the Rust equivalent takes an Option, it may be set to null to indicate None.
- pub inner: *mut nativeChainWatchedUtil,
- pub is_owned: bool,
-}
-
-impl Drop for ChainWatchedUtil {
- fn drop(&mut self) {
- if self.is_owned && !self.inner.is_null() {
- let _ = unsafe { Box::from_raw(self.inner) };
- }
- }
-}
-#[no_mangle]
-pub extern "C" fn ChainWatchedUtil_free(this_ptr: ChainWatchedUtil) { }
-#[allow(unused)]
-/// Used only if an object of this type is returned as a trait impl by a method
-extern "C" fn ChainWatchedUtil_free_void(this_ptr: *mut c_void) {
- unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChainWatchedUtil); }
-}
-#[allow(unused)]
-/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
-impl ChainWatchedUtil {
- pub(crate) fn take_ptr(mut self) -> *mut nativeChainWatchedUtil {
- assert!(self.is_owned);
- let ret = self.inner;
- self.inner = std::ptr::null_mut();
- ret
- }
-}
-/// Constructs an empty (watches nothing) ChainWatchedUtil
-#[must_use]
-#[no_mangle]
-pub extern "C" fn ChainWatchedUtil_new() -> ChainWatchedUtil {
- let mut ret = lightning::chain::chaininterface::ChainWatchedUtil::new();
- ChainWatchedUtil { inner: Box::into_raw(Box::new(ret)), is_owned: true }
-}
-
-/// Registers a tx for monitoring, returning true if it was a new tx and false if we'd already
-/// been watching for it.
-#[must_use]
-#[no_mangle]
-pub extern "C" fn ChainWatchedUtil_register_tx(this_arg: &mut ChainWatchedUtil, txid: *const [u8; 32], script_pub_key: crate::c_types::u8slice) -> bool {
- let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeChainWatchedUtil)) }.register_tx(&::bitcoin::hash_types::Txid::from_slice(&unsafe { &*txid }[..]).unwrap(), &::bitcoin::blockdata::script::Script::from(Vec::from(script_pub_key.to_slice())));
- ret
-}
-
-/// Registers an outpoint for monitoring, returning true if it was a new outpoint and false if
-/// we'd already been watching for it
-#[must_use]
-#[no_mangle]
-pub extern "C" fn ChainWatchedUtil_register_outpoint(this_arg: &mut ChainWatchedUtil, mut outpoint: crate::c_types::derived::C2Tuple_Txidu32Z, _script_pub_key: crate::c_types::u8slice) -> bool {
- let (mut orig_outpoint_0, mut orig_outpoint_1) = outpoint.to_rust(); let mut local_outpoint = (::bitcoin::hash_types::Txid::from_slice(&orig_outpoint_0.data[..]).unwrap(), orig_outpoint_1);
- let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeChainWatchedUtil)) }.register_outpoint(local_outpoint, &::bitcoin::blockdata::script::Script::from(Vec::from(_script_pub_key.to_slice())));
- ret
-}
-
-/// Sets us to match all transactions, returning true if this is a new setting and false if
-/// we'd already been set to match everything.
-#[must_use]
-#[no_mangle]
-pub extern "C" fn ChainWatchedUtil_watch_all(this_arg: &mut ChainWatchedUtil) -> bool {
- let mut ret = unsafe { &mut (*(this_arg.inner as *mut nativeChainWatchedUtil)) }.watch_all();
- ret
-}
-
-/// Checks if a given transaction matches the current filter.
-#[must_use]
-#[no_mangle]
-pub extern "C" fn ChainWatchedUtil_does_match_tx(this_arg: &ChainWatchedUtil, tx: crate::c_types::Transaction) -> bool {
- let mut ret = unsafe { &*this_arg.inner }.does_match_tx(&tx.into_bitcoin());
- ret
-}
-
-
-use lightning::chain::chaininterface::BlockNotifier as nativeBlockNotifierImport;
-type nativeBlockNotifier = nativeBlockNotifierImport<'static, crate::chain::chaininterface::ChainListener, crate::chain::chaininterface::ChainWatchInterface>;
-
-/// Utility for notifying listeners about new blocks, and handling block rescans if new watch
-/// data is registered.
-///
-/// Rather than using a plain BlockNotifier, it is preferable to use either a BlockNotifierArc
-/// or a BlockNotifierRef for conciseness. See their documentation for more details, but essentially
-/// you should default to using a BlockNotifierRef, and use a BlockNotifierArc instead when you
-/// require ChainListeners with static lifetimes, such as when you're using lightning-net-tokio.
-#[must_use]
-#[repr(C)]
-pub struct BlockNotifier {
- /// Nearly everyhwere, inner must be non-null, however in places where
- /// the Rust equivalent takes an Option, it may be set to null to indicate None.
- pub inner: *mut nativeBlockNotifier,
- pub is_owned: bool,
-}
-
-impl Drop for BlockNotifier {
- fn drop(&mut self) {
- if self.is_owned && !self.inner.is_null() {
- let _ = unsafe { Box::from_raw(self.inner) };
- }
- }
-}
-#[no_mangle]
-pub extern "C" fn BlockNotifier_free(this_ptr: BlockNotifier) { }
-#[allow(unused)]
-/// Used only if an object of this type is returned as a trait impl by a method
-extern "C" fn BlockNotifier_free_void(this_ptr: *mut c_void) {
- unsafe { let _ = Box::from_raw(this_ptr as *mut nativeBlockNotifier); }
-}
-#[allow(unused)]
-/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
-impl BlockNotifier {
- pub(crate) fn take_ptr(mut self) -> *mut nativeBlockNotifier {
- assert!(self.is_owned);
- let ret = self.inner;
- self.inner = std::ptr::null_mut();
- ret
- }
-}
-/// Constructs a new BlockNotifier without any listeners.
-#[must_use]
-#[no_mangle]
-pub extern "C" fn BlockNotifier_new(mut chain_monitor: crate::chain::chaininterface::ChainWatchInterface) -> crate::chain::chaininterface::BlockNotifier {
- let mut ret = lightning::chain::chaininterface::BlockNotifier::new(chain_monitor);
- crate::chain::chaininterface::BlockNotifier { inner: Box::into_raw(Box::new(ret)), is_owned: true }
-}
-
-/// Register the given listener to receive events.
-#[no_mangle]
-pub extern "C" fn BlockNotifier_register_listener(this_arg: &BlockNotifier, mut listener: crate::chain::chaininterface::ChainListener) {
- unsafe { &*this_arg.inner }.register_listener(listener)
-}
-
-/// Notify listeners that a block was connected given a full, unfiltered block.
-///
-/// Handles re-scanning the block and calling block_connected again if listeners register new
-/// watch data during the callbacks for you (see ChainListener::block_connected for more info).
-#[no_mangle]
-pub extern "C" fn BlockNotifier_block_connected(this_arg: &BlockNotifier, block: crate::c_types::u8slice, mut height: u32) {
- unsafe { &*this_arg.inner }.block_connected(&::bitcoin::consensus::encode::deserialize(block.to_slice()).unwrap(), height)
-}
-
-/// Notify listeners that a block was connected, given pre-filtered list of transactions in the
-/// block which matched the filter (probably using does_match_tx).
-///
-/// Returns true if notified listeners registered additional watch data (implying that the
-/// block must be re-scanned and this function called again prior to further block_connected
-/// calls, see ChainListener::block_connected for more info).
-#[must_use]
-#[no_mangle]
-pub extern "C" fn BlockNotifier_block_connected_checked(this_arg: &BlockNotifier, header: *const [u8; 80], mut height: u32, mut txn_matched: crate::c_types::derived::CVec_TransactionZ, mut indexes_of_txn_matched: crate::c_types::usizeslice) -> bool {
- let mut local_txn_matched = Vec::new(); for mut item in txn_matched.into_rust().drain(..) { local_txn_matched.push( { ::bitcoin::consensus::encode::deserialize(&item.into_rust()[..]).unwrap() }); };
- let mut ret = unsafe { &*this_arg.inner }.block_connected_checked(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), height, &local_txn_matched.iter().collect::<Vec<_>>()[..], indexes_of_txn_matched.to_slice());
- ret
-}
-
-/// Notify listeners that a block was disconnected.
-#[no_mangle]
-pub extern "C" fn BlockNotifier_block_disconnected(this_arg: &BlockNotifier, header: *const [u8; 80], mut disconnected_height: u32) {
- unsafe { &*this_arg.inner }.block_disconnected(&::bitcoin::consensus::encode::deserialize(unsafe { &*header }).unwrap(), disconnected_height)
-}
-
-
-use lightning::chain::chaininterface::ChainWatchInterfaceUtil as nativeChainWatchInterfaceUtilImport;
-type nativeChainWatchInterfaceUtil = nativeChainWatchInterfaceUtilImport;
-
-/// Utility to capture some common parts of ChainWatchInterface implementors.
-///
-/// Keeping a local copy of this in a ChainWatchInterface implementor is likely useful.
-#[must_use]
-#[repr(C)]
-pub struct ChainWatchInterfaceUtil {
- /// Nearly everyhwere, inner must be non-null, however in places where
- /// the Rust equivalent takes an Option, it may be set to null to indicate None.
- pub inner: *mut nativeChainWatchInterfaceUtil,
- pub is_owned: bool,
-}
-
-impl Drop for ChainWatchInterfaceUtil {
- fn drop(&mut self) {
- if self.is_owned && !self.inner.is_null() {
- let _ = unsafe { Box::from_raw(self.inner) };
- }
- }
-}
-#[no_mangle]
-pub extern "C" fn ChainWatchInterfaceUtil_free(this_ptr: ChainWatchInterfaceUtil) { }
-#[allow(unused)]
-/// Used only if an object of this type is returned as a trait impl by a method
-extern "C" fn ChainWatchInterfaceUtil_free_void(this_ptr: *mut c_void) {
- unsafe { let _ = Box::from_raw(this_ptr as *mut nativeChainWatchInterfaceUtil); }
-}
-#[allow(unused)]
-/// When moving out of the pointer, we have to ensure we aren't a reference, this makes that easy
-impl ChainWatchInterfaceUtil {
- pub(crate) fn take_ptr(mut self) -> *mut nativeChainWatchInterfaceUtil {
- assert!(self.is_owned);
- let ret = self.inner;
- self.inner = std::ptr::null_mut();
- ret
- }
-}
-#[no_mangle]
-pub extern "C" fn ChainWatchInterfaceUtil_as_ChainWatchInterface(this_arg: *const ChainWatchInterfaceUtil) -> crate::chain::chaininterface::ChainWatchInterface {
- crate::chain::chaininterface::ChainWatchInterface {
- this_arg: unsafe { (*this_arg).inner as *mut c_void },
- free: None,
- install_watch_tx: ChainWatchInterfaceUtil_ChainWatchInterface_install_watch_tx,
- install_watch_outpoint: ChainWatchInterfaceUtil_ChainWatchInterface_install_watch_outpoint,
- watch_all_txn: ChainWatchInterfaceUtil_ChainWatchInterface_watch_all_txn,
- get_chain_utxo: ChainWatchInterfaceUtil_ChainWatchInterface_get_chain_utxo,
- filter_block: ChainWatchInterfaceUtil_ChainWatchInterface_filter_block,
- reentered: ChainWatchInterfaceUtil_ChainWatchInterface_reentered,
- }
-}
-use lightning::chain::chaininterface::ChainWatchInterface as ChainWatchInterfaceTraitImport;
-extern "C" fn ChainWatchInterfaceUtil_ChainWatchInterface_install_watch_tx(this_arg: *const c_void, txid: *const [u8; 32], script_pub_key: crate::c_types::u8slice) {
- unsafe { &mut *(this_arg as *mut nativeChainWatchInterfaceUtil) }.install_watch_tx(&::bitcoin::hash_types::Txid::from_slice(&unsafe { &*txid }[..]).unwrap(), &::bitcoin::blockdata::script::Script::from(Vec::from(script_pub_key.to_slice())))
-}
-extern "C" fn ChainWatchInterfaceUtil_ChainWatchInterface_install_watch_outpoint(this_arg: *const c_void, mut outpoint: crate::c_types::derived::C2Tuple_Txidu32Z, out_script: crate::c_types::u8slice) {
- let (mut orig_outpoint_0, mut orig_outpoint_1) = outpoint.to_rust(); let mut local_outpoint = (::bitcoin::hash_types::Txid::from_slice(&orig_outpoint_0.data[..]).unwrap(), orig_outpoint_1);
- unsafe { &mut *(this_arg as *mut nativeChainWatchInterfaceUtil) }.install_watch_outpoint(local_outpoint, &::bitcoin::blockdata::script::Script::from(Vec::from(out_script.to_slice())))
-}
-extern "C" fn ChainWatchInterfaceUtil_ChainWatchInterface_watch_all_txn(this_arg: *const c_void) {
- unsafe { &mut *(this_arg as *mut nativeChainWatchInterfaceUtil) }.watch_all_txn()
-}
-#[must_use]
-extern "C" fn ChainWatchInterfaceUtil_ChainWatchInterface_get_chain_utxo(this_arg: *const c_void, mut genesis_hash: crate::c_types::ThirtyTwoBytes, mut _unspent_tx_output_identifier: u64) -> crate::c_types::derived::CResult_C2Tuple_Scriptu64ZChainErrorZ {
- let mut ret = unsafe { &mut *(this_arg as *mut nativeChainWatchInterfaceUtil) }.get_chain_utxo(::bitcoin::hash_types::BlockHash::from_slice(&genesis_hash.data[..]).unwrap(), _unspent_tx_output_identifier);
- let mut local_ret = match ret { Ok(mut o) => crate::c_types::CResultTempl::ok( { let (mut orig_ret_0_0, mut orig_ret_0_1) = o; let mut local_ret_0 = (orig_ret_0_0.into_bytes().into(), orig_ret_0_1).into(); local_ret_0 }), Err(mut e) => crate::c_types::CResultTempl::err( { crate::chain::chaininterface::ChainError::native_into(e) }) };
- local_ret
-}
-#[must_use]
-extern "C" fn ChainWatchInterfaceUtil_ChainWatchInterface_filter_block(this_arg: *const c_void, block: crate::c_types::u8slice) -> crate::c_types::derived::CVec_usizeZ {
- let mut ret = unsafe { &mut *(this_arg as *mut nativeChainWatchInterfaceUtil) }.filter_block(&::bitcoin::consensus::encode::deserialize(block.to_slice()).unwrap());
- let mut local_ret = Vec::new(); for item in ret.drain(..) { local_ret.push( { item }); };
- local_ret.into()
-}
-#[must_use]
-extern "C" fn ChainWatchInterfaceUtil_ChainWatchInterface_reentered(this_arg: *const c_void) -> usize {
- let mut ret = unsafe { &mut *(this_arg as *mut nativeChainWatchInterfaceUtil) }.reentered();
- ret
-}
-
-/// Creates a new ChainWatchInterfaceUtil for the given network
-#[must_use]
-#[no_mangle]
-pub extern "C" fn ChainWatchInterfaceUtil_new(mut network: crate::bitcoin::network::Network) -> crate::chain::chaininterface::ChainWatchInterfaceUtil {
- let mut ret = lightning::chain::chaininterface::ChainWatchInterfaceUtil::new(network.into_bitcoin());
- crate::chain::chaininterface::ChainWatchInterfaceUtil { inner: Box::into_raw(Box::new(ret)), is_owned: true }
-}
-
-/// Checks if a given transaction matches the current filter.
-#[must_use]
-#[no_mangle]
-pub extern "C" fn ChainWatchInterfaceUtil_does_match_tx(this_arg: &ChainWatchInterfaceUtil, tx: crate::c_types::Transaction) -> bool {
- let mut ret = unsafe { &*this_arg.inner }.does_match_tx(&tx.into_bitcoin());
- ret
-}
-