Struct LiquidityManager

Source
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>

Source

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.

Source

pub fn lsps0_client_handler(&self) -> &LSPS0ClientHandler<ES>

Returns a reference to the LSPS0 client-side handler.

Source

pub fn lsps0_service_handler(&self) -> Option<&LSPS0ServiceHandler>

Returns a reference to the LSPS0 server-side handler.

Source

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.

Source

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.

Source

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.

Source

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);
Source

pub fn wait_next_event(&self) -> Event

Available on crate feature 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.

Source

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.

Source

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.

Source

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>

Source§

fn transactions_confirmed( &self, _header: &Header, _txdata: &TransactionData<'_>, _height: u32, )

Notifies LDK of transactions confirmed in a block with a given header and height. Read more
Source§

fn transaction_unconfirmed(&self, _txid: &Txid)

Notifies LDK of a transaction that is no longer confirmed as result of a chain reorganization. Read more
Source§

fn best_block_updated(&self, header: &Header, height: u32)

Notifies LDK of an update to the best header connected at the given height. Read more
Source§

fn get_relevant_txids(&self) -> Vec<(Txid, u32, Option<BlockHash>)>

Returns transactions that must be monitored for reorganization out of the chain along with the height and the hash of the block as part of which it had been previously confirmed. Read more
Source§

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>

Handles the given message sent from 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)>

Returns the list of pending messages that were generated by the handler, clearing the list in the process. Each message is paired with the node id of the intended recipient. If no connection to the node exists, then the message is simply not sent.
Source§

fn provided_node_features(&self) -> NodeFeatures

Gets the node feature flags which this handler itself supports. All available handlers are queried similarly and their feature flags are OR’d together to form the NodeFeatures which are broadcasted in our NodeAnnouncement message.
Source§

fn provided_init_features(&self, _their_node_id: PublicKey) -> InitFeatures

Gets the init feature flags which should be sent to the given peer. All available handlers are queried similarly and their feature flags are OR’d together to form the InitFeatures which are sent in our Init message.
Source§

fn peer_disconnected(&self, counterparty_node_id: PublicKey)

Indicates a peer disconnected.
Source§

fn peer_connected(&self, _: PublicKey, _: &Init, _: bool) -> Result<(), ()>

Handle a peer connecting. Read more
Source§

impl<ES: Deref + Clone, CM: Deref + Clone, C: Deref + Clone> CustomMessageReader for LiquidityManager<ES, CM, C>

Source§

type CustomMessage = RawLSPSMessage

The type of the message decoded by the implementation.
Source§

fn read<RD: Read>( &self, message_type: u16, buffer: &mut RD, ) -> Result<Option<Self::CustomMessage>, DecodeError>

Decodes a custom message to 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.
Source§

impl<ES: Deref + Clone, CM: Deref + Clone, C: Deref + Clone> Listen for LiquidityManager<ES, CM, C>

Source§

fn filtered_block_connected( &self, header: &Header, txdata: &TransactionData<'_>, height: u32, )

Notifies the listener that a block was added at the given height, with the transaction data possibly filtered.
Source§

fn block_disconnected(&self, header: &Header, height: u32)

Notifies the listener that a block was removed at the given height.
Source§

fn block_connected(&self, block: &Block, height: u32)

Notifies the listener that a block was added at the given height.

Auto Trait Implementations§

§

impl<ES, CM, C> !Freeze for LiquidityManager<ES, CM, C>

§

impl<ES, CM, C> RefUnwindSafe for LiquidityManager<ES, CM, C>

§

impl<ES, CM, C> Send for LiquidityManager<ES, CM, C>
where ES: Send, C: Send, CM: Send,

§

impl<ES, CM, C> Sync for LiquidityManager<ES, CM, C>
where ES: Sync, C: Sync, CM: Sync,

§

impl<ES, CM, C> Unpin for LiquidityManager<ES, CM, C>
where ES: Unpin, C: Unpin, CM: Unpin,

§

impl<ES, CM, C> UnwindSafe for LiquidityManager<ES, CM, C>
where ES: UnwindSafe, C: UnwindSafe, CM: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.