pub struct LiquidityManager<ES: Deref + Clone, CM: Deref + Clone, C: Deref + Clone>{ /* private fields */ }
Expand description
The main interface into LSP functionality.
Should be used as a CustomMessageHandler
for your PeerManager
’s MessageHandler
.
Users should provide a callback to process queued messages via
LiquidityManager::set_process_msgs_callback
post construction. This allows the
LiquidityManager
to wake the PeerManager
when there are pending messages to be sent.
Users need to continually poll LiquidityManager::get_and_clear_pending_events
in order to surface
Event
’s that likely need to be handled.
If the LSPS2 service is configured, users must forward the following parameters from LDK events:
Implementations§
Source§impl<ES: Deref + Clone, CM: Deref + Clone, C: Deref + Clone> LiquidityManager<ES, CM, C>
impl<ES: Deref + Clone, CM: Deref + Clone, C: Deref + Clone> LiquidityManager<ES, CM, C>
Sourcepub fn new(
entropy_source: ES,
channel_manager: CM,
chain_source: Option<C>,
chain_params: Option<ChainParameters>,
service_config: Option<LiquidityServiceConfig>,
client_config: Option<LiquidityClientConfig>,
) -> Self
pub fn new( entropy_source: ES, channel_manager: CM, chain_source: Option<C>, chain_params: Option<ChainParameters>, service_config: Option<LiquidityServiceConfig>, client_config: Option<LiquidityClientConfig>, ) -> Self
Constructor for the LiquidityManager
.
Sets up the required protocol message handlers based on the given
LiquidityClientConfig
and LiquidityServiceConfig
.
Sourcepub fn lsps0_client_handler(&self) -> &LSPS0ClientHandler<ES>
pub fn lsps0_client_handler(&self) -> &LSPS0ClientHandler<ES>
Returns a reference to the LSPS0 client-side handler.
Sourcepub fn lsps0_service_handler(&self) -> Option<&LSPS0ServiceHandler>
pub fn lsps0_service_handler(&self) -> Option<&LSPS0ServiceHandler>
Returns a reference to the LSPS0 server-side handler.
Sourcepub fn lsps1_client_handler(&self) -> Option<&LSPS1ClientHandler<ES>>
pub fn lsps1_client_handler(&self) -> Option<&LSPS1ClientHandler<ES>>
Returns a reference to the LSPS1 client-side handler.
The returned hendler allows to initiate the LSPS1 client-side flow, i.e., allows to request channels from the configured LSP.
Sourcepub fn lsps2_client_handler(&self) -> Option<&LSPS2ClientHandler<ES>>
pub fn lsps2_client_handler(&self) -> Option<&LSPS2ClientHandler<ES>>
Returns a reference to the LSPS2 client-side handler.
The returned hendler allows to initiate the LSPS2 client-side flow. That is, it allows to retrieve all necessary data to create ‘just-in-time’ invoices that, when paid, will have the configured LSP open a ‘just-in-time’ channel.
Sourcepub fn lsps2_service_handler(&self) -> Option<&LSPS2ServiceHandler<CM>>
pub fn lsps2_service_handler(&self) -> Option<&LSPS2ServiceHandler<CM>>
Returns a reference to the LSPS2 server-side handler.
The returned hendler allows to initiate the LSPS2 service-side flow.
Sourcepub fn set_process_msgs_callback<F: 'static + ProcessMessagesCallback>(
&self,
callback: F,
)
pub fn set_process_msgs_callback<F: 'static + ProcessMessagesCallback>( &self, callback: F, )
Allows to set a callback that will be called after new messages are pushed to the message queue.
Usually, you’ll want to use this to call PeerManager::process_events
to clear the
message queue. For example:
let process_msgs_pm = Arc::clone(&my_peer_manager);
let process_msgs_callback = move || process_msgs_pm.process_events();
my_liquidity_manager.set_process_msgs_callback(process_msgs_callback);
Sourcepub fn wait_next_event(&self) -> Event
Available on crate feature std
only.
pub fn wait_next_event(&self) -> Event
std
only.Blocks the current thread until next event is ready and returns it.
Typically you would spawn a thread or task that calls this in a loop.
Note: Users must handle events as soon as possible to avoid an increased event queue
memory footprint. We will start dropping any generated events after
MAX_EVENT_QUEUE_SIZE
has been reached.
Sourcepub fn next_event(&self) -> Option<Event>
pub fn next_event(&self) -> Option<Event>
Returns Some
if an event is ready.
Typically you would spawn a thread or task that calls this in a loop.
Note: Users must handle events as soon as possible to avoid an increased event queue
memory footprint. We will start dropping any generated events after
MAX_EVENT_QUEUE_SIZE
has been reached.
Sourcepub async fn next_event_async(&self) -> Event
pub async fn next_event_async(&self) -> Event
Asynchronously polls the event queue and returns once the next event is ready.
Typically you would spawn a thread or task that calls this in a loop.
Note: Users must handle events as soon as possible to avoid an increased event queue
memory footprint. We will start dropping any generated events after
MAX_EVENT_QUEUE_SIZE
has been reached.
Sourcepub fn get_and_clear_pending_events(&self) -> Vec<Event>
pub fn get_and_clear_pending_events(&self) -> Vec<Event>
Returns and clears all events without blocking.
Typically you would spawn a thread or task that calls this in a loop.
Note: Users must handle events as soon as possible to avoid an increased event queue
memory footprint. We will start dropping any generated events after
MAX_EVENT_QUEUE_SIZE
has been reached.
Trait Implementations§
Source§impl<ES: Deref + Clone, CM: Deref + Clone, C: Deref + Clone> Confirm for LiquidityManager<ES, CM, C>
impl<ES: Deref + Clone, CM: Deref + Clone, C: Deref + Clone> Confirm for LiquidityManager<ES, CM, C>
Source§fn transactions_confirmed(
&self,
_header: &Header,
_txdata: &TransactionData<'_>,
_height: u32,
)
fn transactions_confirmed( &self, _header: &Header, _txdata: &TransactionData<'_>, _height: u32, )
Source§fn transaction_unconfirmed(&self, _txid: &Txid)
fn transaction_unconfirmed(&self, _txid: &Txid)
Source§impl<ES: Deref + Clone, CM: Deref + Clone, C: Deref + Clone> CustomMessageHandler for LiquidityManager<ES, CM, C>
impl<ES: Deref + Clone, CM: Deref + Clone, C: Deref + Clone> CustomMessageHandler for LiquidityManager<ES, CM, C>
Source§fn handle_custom_message(
&self,
msg: Self::CustomMessage,
sender_node_id: PublicKey,
) -> Result<(), LightningError>
fn handle_custom_message( &self, msg: Self::CustomMessage, sender_node_id: PublicKey, ) -> Result<(), LightningError>
sender_node_id
, possibly producing messages for
CustomMessageHandler::get_and_clear_pending_msg
to return and thus for PeerManager
to send.Source§fn get_and_clear_pending_msg(&self) -> Vec<(PublicKey, Self::CustomMessage)>
fn get_and_clear_pending_msg(&self) -> Vec<(PublicKey, Self::CustomMessage)>
Source§fn provided_node_features(&self) -> NodeFeatures
fn provided_node_features(&self) -> NodeFeatures
NodeFeatures
which are broadcasted in our NodeAnnouncement
message.Source§fn provided_init_features(&self, _their_node_id: PublicKey) -> InitFeatures
fn provided_init_features(&self, _their_node_id: PublicKey) -> InitFeatures
InitFeatures
which are sent in our Init
message.Source§fn peer_disconnected(&self, counterparty_node_id: PublicKey)
fn peer_disconnected(&self, counterparty_node_id: PublicKey)
Source§impl<ES: Deref + Clone, CM: Deref + Clone, C: Deref + Clone> CustomMessageReader for LiquidityManager<ES, CM, C>
impl<ES: Deref + Clone, CM: Deref + Clone, C: Deref + Clone> CustomMessageReader for LiquidityManager<ES, CM, C>
Source§type CustomMessage = RawLSPSMessage
type CustomMessage = RawLSPSMessage
Source§fn read<RD: Read>(
&self,
message_type: u16,
buffer: &mut RD,
) -> Result<Option<Self::CustomMessage>, DecodeError>
fn read<RD: Read>( &self, message_type: u16, buffer: &mut RD, ) -> Result<Option<Self::CustomMessage>, DecodeError>
CustomMessageType
. If the given message type is known to the
implementation and the message could be decoded, must return Ok(Some(message))
. If the
message type is unknown to the implementation, must return Ok(None)
. If a decoding error
occur, must return Err(DecodeError::X)
where X
details the encountered error.