LiquidityManager

Struct LiquidityManager 

Source
pub struct LiquidityManager<ES: Deref + Clone, NS: Deref + Clone, CM: Deref + Clone, C: Deref + Clone, K: Deref + Clone, TP: Deref + Clone, T: Deref + Clone>{ /* private fields */ }
Expand description

The main interface into LSP functionality.

Should be used as a CustomMessageHandler for your PeerManager’s MessageHandler.

Users need to continually poll LiquidityManager::get_and_clear_pending_events in order to surface LiquidityEvent’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, NS: Deref + Clone, CM: Deref + Clone, C: Deref + Clone, K: Deref + Clone, T: Deref + Clone> LiquidityManager<ES, NS, CM, C, K, DefaultTimeProvider, T>

Source

pub async fn new( entropy_source: ES, node_signer: NS, channel_manager: CM, chain_source: Option<C>, chain_params: Option<ChainParameters>, kv_store: K, transaction_broadcaster: T, service_config: Option<LiquidityServiceConfig>, client_config: Option<LiquidityClientConfig>, ) -> Result<Self, Error>

Available on crate feature time only.

Constructor for the LiquidityManager using the default system clock

Will read persisted service states from the given KVStore.

Source§

impl<ES: Deref + Clone, NS: Deref + Clone, CM: Deref + Clone, C: Deref + Clone, K: Deref + Clone, TP: Deref + Clone, T: Deref + Clone> LiquidityManager<ES, NS, CM, C, K, TP, T>

Source

pub async fn new_with_custom_time_provider( entropy_source: ES, node_signer: NS, channel_manager: CM, transaction_broadcaster: T, chain_source: Option<C>, chain_params: Option<ChainParameters>, kv_store: K, service_config: Option<LiquidityServiceConfig>, client_config: Option<LiquidityClientConfig>, time_provider: TP, ) -> Result<Self, Error>

Constructor for the LiquidityManager with a custom time provider.

Will read persisted service states from the given KVStore.

This should be used on non-std platforms where access to the system time is not available. Sets up the required protocol message handlers based on the given LiquidityClientConfig and LiquidityServiceConfig.

Source

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

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, K>>

Returns a reference to the LSPS1 client-side handler.

The returned handler 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, K>>

Returns a reference to the LSPS2 client-side handler.

The returned handler 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, K, T>>

Returns a reference to the LSPS2 server-side handler.

The returned hendler allows to initiate the LSPS2 service-side flow.

Source

pub fn lsps5_client_handler(&self) -> Option<&LSPS5ClientHandler<ES, K>>

Returns a reference to the LSPS5 client-side handler.

The returned handler allows to initiate the LSPS5 client-side flow. That is, it allows to

Source

pub fn lsps5_service_handler( &self, ) -> Option<&LSPS5ServiceHandler<CM, NS, K, TP>>

Returns a reference to the LSPS5 server-side handler.

The returned handler allows to initiate the LSPS5 service-side flow.

Source

pub fn get_pending_msgs_or_needs_persist_future(&self) -> Future

Returns a Future that will complete when the next batch of pending messages is ready to be processed or we need to be repersisted.

Note that callbacks registered on the Future MUST NOT call back into this LiquidityManager and should instead register actions to be taken later.

Source

pub fn next_event(&self) -> Option<LiquidityEvent>

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) -> LiquidityEvent

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

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.

Source

pub async fn persist(&self) -> Result<(), Error>

Persists the state of the service handlers towards the given KVStore implementation.

This will be regularly called by LDK’s background processor if necessary and only needs to be called manually if it’s not utilized.

Trait Implementations§

Source§

impl<ES: Deref + Clone, NS: Deref + Clone, CM: Deref + Clone, C: Deref + Clone, K: Deref + Clone, TP: Deref + Clone, T: Deref + Clone> ALiquidityManager for LiquidityManager<ES, NS, CM, C, K, TP, T>

Source§

type EntropySource = <ES as Deref>::Target

A type implementing EntropySource
Source§

type ES = ES

A type that may be dereferenced to Self::EntropySource.
Source§

type NodeSigner = <NS as Deref>::Target

A type implementing NodeSigner
Source§

type NS = NS

A type that may be dereferenced to Self::NodeSigner.
Source§

type AChannelManager = <CM as Deref>::Target

A type implementing AChannelManager
Source§

type CM = CM

A type that may be dereferenced to Self::AChannelManager.
Source§

type Filter = <C as Deref>::Target

A type implementing Filter.
Source§

type C = C

A type that may be dereferenced to Self::Filter.
Source§

type KVStore = <K as Deref>::Target

A type implementing KVStore.
Source§

type K = K

A type that may be dereferenced to Self::KVStore.
Source§

type TimeProvider = <TP as Deref>::Target

A type implementing TimeProvider.
Source§

type TP = TP

A type that may be dereferenced to Self::TimeProvider.
Source§

type BroadcasterInterface = <T as Deref>::Target

A type implementing BroadcasterInterface.
Source§

type T = T

A type that may be dereferenced to Self::BroadcasterInterface.
Source§

fn get_lm(&self) -> &LiquidityManager<ES, NS, CM, C, K, TP, T>

Returns a reference to the actual LiquidityManager object.
Source§

impl<ES: Deref + Clone, NS: Deref + Clone, CM: Deref + Clone, C: Deref + Clone, K: Deref + Clone, TP: Deref + Clone, T: Deref + Clone> Confirm for LiquidityManager<ES, NS, CM, C, K, TP, T>

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, NS: Deref + Clone, CM: Deref + Clone, C: Deref + Clone, K: Deref + Clone, TP: Deref + Clone, T: Deref + Clone> CustomMessageHandler for LiquidityManager<ES, NS, CM, C, K, TP, T>

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, counterparty_node_id: PublicKey, _: &Init, _: bool, ) -> Result<(), ()>

Handle a peer connecting. Read more
Source§

impl<ES: Deref + Clone, NS: Deref + Clone, CM: Deref + Clone, C: Deref + Clone, K: Deref + Clone, TP: Deref + Clone, T: Deref + Clone> CustomMessageReader for LiquidityManager<ES, NS, CM, C, K, TP, T>

Source§

type CustomMessage = RawLSPSMessage

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

fn read<RD: LengthLimitedRead>( &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, NS: Deref + Clone, CM: Deref + Clone, C: Deref + Clone, K: Deref + Clone, TP: Deref + Clone, T: Deref + Clone> Listen for LiquidityManager<ES, NS, CM, C, K, TP, T>

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 blocks_disconnected(&self, fork_point: BestBlock)

Notifies the listener that one or more blocks were removed in anticipation of a reorg. Read more
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, NS, CM, C, K, TP, T> !Freeze for LiquidityManager<ES, NS, CM, C, K, TP, T>

§

impl<ES, NS, CM, C, K, TP, T> RefUnwindSafe for LiquidityManager<ES, NS, CM, C, K, TP, T>

§

impl<ES, NS, CM, C, K, TP, T> Send for LiquidityManager<ES, NS, CM, C, K, TP, T>
where ES: Send, C: Send, K: Sync + Send, CM: Send, T: Send, TP: Send, NS: Send,

§

impl<ES, NS, CM, C, K, TP, T> Sync for LiquidityManager<ES, NS, CM, C, K, TP, T>
where ES: Sync, C: Sync, K: Sync + Send, CM: Sync, T: Sync, TP: Sync, NS: Sync,

§

impl<ES, NS, CM, C, K, TP, T> Unpin for LiquidityManager<ES, NS, CM, C, K, TP, T>
where ES: Unpin, C: Unpin, CM: Unpin, K: Unpin, T: Unpin, TP: Unpin, NS: Unpin,

§

impl<ES, NS, CM, C, K, TP, T> UnwindSafe for LiquidityManager<ES, NS, CM, C, K, TP, T>

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.