//! future, as well as generate and broadcast funding transactions handle payment preimages and a
//! few other things.
-use std::str::FromStr;
-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};
/// Some information provided on receipt of payment depends on whether the payment received is a
/// spontaneous payment or a \"conventional\" lightning payment that's paying an invoice.
/// Note that this does *not* indicate that all paths for an MPP payment have failed, see
/// [`Event::PaymentFailed`] and [`all_paths_failed`].
///
- /// [`all_paths_failed`]: Self::all_paths_failed
+ /// [`all_paths_failed`]: Self::PaymentPathFailed::all_paths_failed
PaymentPathFailed {
/// The id returned by [`ChannelManager::send_payment`] and used with
/// [`ChannelManager::retry_payment`] and [`ChannelManager::abandon_payment`].
/// May contain a closed channel if the HTLC sent along the path was fulfilled on chain.
path: crate::c_types::derived::CVec_RouteHopZ,
},
+ /// Indicates a request to open a new channel by a peer.
+ ///
+ /// To accept the request, call [`ChannelManager::accept_inbound_channel`]. To reject the
+ /// request, call [`ChannelManager::force_close_channel`].
+ ///
+ /// The event is only triggered when a new open channel request is received and the
+ /// [`UserConfig::manually_accept_inbound_channels`] config flag is set to true.
+ ///
+ /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
+ /// [`ChannelManager::force_close_channel`]: crate::ln::channelmanager::ChannelManager::force_close_channel
+ /// [`UserConfig::manually_accept_inbound_channels`]: crate::util::config::UserConfig::manually_accept_inbound_channels
+ OpenChannelRequest {
+ /// The temporary channel ID of the channel requested to be opened.
+ ///
+ /// When responding to the request, the `temporary_channel_id` should be passed
+ /// back to the ChannelManager with [`ChannelManager::accept_inbound_channel`] to accept,
+ /// or to [`ChannelManager::force_close_channel`] to reject.
+ ///
+ /// [`ChannelManager::accept_inbound_channel`]: crate::ln::channelmanager::ChannelManager::accept_inbound_channel
+ /// [`ChannelManager::force_close_channel`]: crate::ln::channelmanager::ChannelManager::force_close_channel
+ temporary_channel_id: crate::c_types::ThirtyTwoBytes,
+ /// The node_id of the counterparty requesting to open the channel.
+ counterparty_node_id: crate::c_types::PublicKey,
+ /// The channel value of the requested channel.
+ funding_satoshis: u64,
+ /// Our starting balance in the channel if the request is accepted, in milli-satoshi.
+ push_msat: u64,
+ },
}
use lightning::util::events::Event as nativeEvent;
impl Event {
Event::PendingHTLCsForwardable {ref time_forwardable, } => {
let mut time_forwardable_nonref = (*time_forwardable).clone();
nativeEvent::PendingHTLCsForwardable {
- time_forwardable: std::time::Duration::from_secs(time_forwardable_nonref),
+ time_forwardable: core::time::Duration::from_secs(time_forwardable_nonref),
}
},
Event::SpendableOutputs {ref outputs, } => {
path: local_path_nonref,
}
},
+ Event::OpenChannelRequest {ref temporary_channel_id, ref counterparty_node_id, ref funding_satoshis, ref push_msat, } => {
+ let mut temporary_channel_id_nonref = (*temporary_channel_id).clone();
+ let mut counterparty_node_id_nonref = (*counterparty_node_id).clone();
+ let mut funding_satoshis_nonref = (*funding_satoshis).clone();
+ let mut push_msat_nonref = (*push_msat).clone();
+ nativeEvent::OpenChannelRequest {
+ temporary_channel_id: temporary_channel_id_nonref.data,
+ counterparty_node_id: counterparty_node_id_nonref.into_rust(),
+ funding_satoshis: funding_satoshis_nonref,
+ push_msat: push_msat_nonref,
+ }
+ },
}
}
#[allow(unused)]
},
Event::PendingHTLCsForwardable {mut time_forwardable, } => {
nativeEvent::PendingHTLCsForwardable {
- time_forwardable: std::time::Duration::from_secs(time_forwardable),
+ time_forwardable: core::time::Duration::from_secs(time_forwardable),
}
},
Event::SpendableOutputs {mut outputs, } => {
path: local_path,
}
},
+ Event::OpenChannelRequest {mut temporary_channel_id, mut counterparty_node_id, mut funding_satoshis, mut push_msat, } => {
+ nativeEvent::OpenChannelRequest {
+ temporary_channel_id: temporary_channel_id.data,
+ counterparty_node_id: counterparty_node_id.into_rust(),
+ funding_satoshis: funding_satoshis,
+ push_msat: push_msat,
+ }
+ },
}
}
#[allow(unused)]
let mut short_channel_id_nonref = (*short_channel_id).clone();
let mut local_short_channel_id_nonref = if short_channel_id_nonref.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { short_channel_id_nonref.unwrap() }) };
let mut retry_nonref = (*retry).clone();
- let mut local_retry_nonref = crate::lightning::routing::router::RouteParameters { inner: if retry_nonref.is_none() { std::ptr::null_mut() } else { { ObjOps::heap_alloc((retry_nonref.unwrap())) } }, is_owned: true };
+ let mut local_retry_nonref = crate::lightning::routing::router::RouteParameters { inner: if retry_nonref.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((retry_nonref.unwrap())) } }, is_owned: true };
Event::PaymentPathFailed {
payment_id: local_payment_id_nonref,
payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash_nonref.0 },
path: local_path_nonref.into(),
}
},
+ nativeEvent::OpenChannelRequest {ref temporary_channel_id, ref counterparty_node_id, ref funding_satoshis, ref push_msat, } => {
+ let mut temporary_channel_id_nonref = (*temporary_channel_id).clone();
+ let mut counterparty_node_id_nonref = (*counterparty_node_id).clone();
+ let mut funding_satoshis_nonref = (*funding_satoshis).clone();
+ let mut push_msat_nonref = (*push_msat).clone();
+ Event::OpenChannelRequest {
+ temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id_nonref },
+ counterparty_node_id: crate::c_types::PublicKey::from_rust(&counterparty_node_id_nonref),
+ funding_satoshis: funding_satoshis_nonref,
+ push_msat: push_msat_nonref,
+ }
+ },
}
}
#[allow(unused)]
let mut local_network_update = if network_update.is_none() { crate::c_types::derived::COption_NetworkUpdateZ::None } else { crate::c_types::derived::COption_NetworkUpdateZ::Some( { crate::lightning::routing::network_graph::NetworkUpdate::native_into(network_update.unwrap()) }) };
let mut local_path = Vec::new(); for mut item in path.drain(..) { local_path.push( { crate::lightning::routing::router::RouteHop { inner: ObjOps::heap_alloc(item), is_owned: true } }); };
let mut local_short_channel_id = if short_channel_id.is_none() { crate::c_types::derived::COption_u64Z::None } else { crate::c_types::derived::COption_u64Z::Some( { short_channel_id.unwrap() }) };
- let mut local_retry = crate::lightning::routing::router::RouteParameters { inner: if retry.is_none() { std::ptr::null_mut() } else { { ObjOps::heap_alloc((retry.unwrap())) } }, is_owned: true };
+ let mut local_retry = crate::lightning::routing::router::RouteParameters { inner: if retry.is_none() { core::ptr::null_mut() } else { { ObjOps::heap_alloc((retry.unwrap())) } }, is_owned: true };
Event::PaymentPathFailed {
payment_id: local_payment_id,
payment_hash: crate::c_types::ThirtyTwoBytes { data: payment_hash.0 },
path: local_path.into(),
}
},
+ nativeEvent::OpenChannelRequest {mut temporary_channel_id, mut counterparty_node_id, mut funding_satoshis, mut push_msat, } => {
+ Event::OpenChannelRequest {
+ temporary_channel_id: crate::c_types::ThirtyTwoBytes { data: temporary_channel_id },
+ counterparty_node_id: crate::c_types::PublicKey::from_rust(&counterparty_node_id),
+ funding_satoshis: funding_satoshis,
+ push_msat: push_msat,
+ }
+ },
}
}
}
}
}
#[no_mangle]
+/// Utility method to constructs a new OpenChannelRequest-variant Event
+pub extern "C" fn Event_open_channel_request(temporary_channel_id: crate::c_types::ThirtyTwoBytes, counterparty_node_id: crate::c_types::PublicKey, funding_satoshis: u64, push_msat: u64) -> Event {
+ Event::OpenChannelRequest {
+ temporary_channel_id,
+ counterparty_node_id,
+ funding_satoshis,
+ push_msat,
+ }
+}
+#[no_mangle]
/// Serialize the Event object into a byte array which can be read by Event_read
pub extern "C" fn Event_write(obj: &Event) -> crate::c_types::derived::CVec_u8Z {
crate::c_types::serialize_obj(&unsafe { &*obj }.to_native())
// 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 MessageSendEventsProvider {
+impl core::ops::Deref for MessageSendEventsProvider {
type Target = Self;
fn deref(&self) -> &Self {
self
// 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 EventHandler {
+impl core::ops::Deref for EventHandler {
type Target = Self;
fn deref(&self) -> &Self {
self