pub struct LiquidityManager<ES: Deref + Clone, NS: Deref + Clone, CM: Deref + Clone, C: Deref + Clone, K: Deref + Clone, TP: Deref + Clone, T: Deref + Clone>where
ES::Target: EntropySource,
NS::Target: NodeSigner,
CM::Target: AChannelManager,
C::Target: Filter,
K::Target: KVStore,
TP::Target: TimeProvider,
T::Target: BroadcasterInterface,{ /* 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>where
ES::Target: EntropySource,
NS::Target: NodeSigner,
CM::Target: AChannelManager,
C::Target: Filter,
K::Target: KVStore,
T::Target: BroadcasterInterface,
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>where
ES::Target: EntropySource,
NS::Target: NodeSigner,
CM::Target: AChannelManager,
C::Target: Filter,
K::Target: KVStore,
T::Target: BroadcasterInterface,
Sourcepub 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.
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>
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>where
ES::Target: EntropySource,
NS::Target: NodeSigner,
CM::Target: AChannelManager,
C::Target: Filter,
K::Target: KVStore,
TP::Target: TimeProvider,
T::Target: BroadcasterInterface,
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>where
ES::Target: EntropySource,
NS::Target: NodeSigner,
CM::Target: AChannelManager,
C::Target: Filter,
K::Target: KVStore,
TP::Target: TimeProvider,
T::Target: BroadcasterInterface,
Sourcepub 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>
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.
Sourcepub fn lsps0_client_handler(&self) -> &LSPS0ClientHandler<ES, K>
pub fn lsps0_client_handler(&self) -> &LSPS0ClientHandler<ES, K>
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, K>>
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.
Sourcepub fn lsps2_client_handler(&self) -> Option<&LSPS2ClientHandler<ES, K>>
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.
Sourcepub fn lsps2_service_handler(&self) -> Option<&LSPS2ServiceHandler<CM, K, T>>
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.
Sourcepub fn lsps5_client_handler(&self) -> Option<&LSPS5ClientHandler<ES, K>>
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
Sourcepub fn lsps5_service_handler(
&self,
) -> Option<&LSPS5ServiceHandler<CM, NS, K, TP>>
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.
Sourcepub fn get_pending_msgs_or_needs_persist_future(&self) -> Future
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.
Sourcepub fn next_event(&self) -> Option<LiquidityEvent>
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.
Sourcepub async fn next_event_async(&self) -> LiquidityEvent
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.
Sourcepub fn get_and_clear_pending_events(&self) -> Vec<LiquidityEvent>
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.
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>where
ES::Target: EntropySource,
NS::Target: NodeSigner,
CM::Target: AChannelManager,
C::Target: Filter,
K::Target: KVStore,
TP::Target: TimeProvider,
T::Target: BroadcasterInterface,
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>where
ES::Target: EntropySource,
NS::Target: NodeSigner,
CM::Target: AChannelManager,
C::Target: Filter,
K::Target: KVStore,
TP::Target: TimeProvider,
T::Target: BroadcasterInterface,
Source§type EntropySource = <ES as Deref>::Target
type EntropySource = <ES as Deref>::Target
EntropySourceSource§type ES = ES
type ES = ES
Self::EntropySource.Source§type NodeSigner = <NS as Deref>::Target
type NodeSigner = <NS as Deref>::Target
NodeSignerSource§type NS = NS
type NS = NS
Self::NodeSigner.Source§type AChannelManager = <CM as Deref>::Target
type AChannelManager = <CM as Deref>::Target
AChannelManagerSource§type CM = CM
type CM = CM
Self::AChannelManager.Source§type C = C
type C = C
Self::Filter.Source§type K = K
type K = K
Self::KVStore.Source§type TimeProvider = <TP as Deref>::Target
type TimeProvider = <TP as Deref>::Target
TimeProvider.Source§type TP = TP
type TP = TP
Self::TimeProvider.Source§type BroadcasterInterface = <T as Deref>::Target
type BroadcasterInterface = <T as Deref>::Target
BroadcasterInterface.Source§type T = T
type T = T
Self::BroadcasterInterface.Source§fn get_lm(&self) -> &LiquidityManager<ES, NS, CM, C, K, TP, T>
fn get_lm(&self) -> &LiquidityManager<ES, NS, CM, C, K, TP, T>
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>where
ES::Target: EntropySource,
NS::Target: NodeSigner,
CM::Target: AChannelManager,
C::Target: Filter,
K::Target: KVStore,
TP::Target: TimeProvider,
T::Target: BroadcasterInterface,
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>where
ES::Target: EntropySource,
NS::Target: NodeSigner,
CM::Target: AChannelManager,
C::Target: Filter,
K::Target: KVStore,
TP::Target: TimeProvider,
T::Target: BroadcasterInterface,
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, 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>where
ES::Target: EntropySource,
NS::Target: NodeSigner,
CM::Target: AChannelManager,
C::Target: Filter,
K::Target: KVStore,
TP::Target: TimeProvider,
T::Target: BroadcasterInterface,
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>where
ES::Target: EntropySource,
NS::Target: NodeSigner,
CM::Target: AChannelManager,
C::Target: Filter,
K::Target: KVStore,
TP::Target: TimeProvider,
T::Target: BroadcasterInterface,
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, 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>where
ES::Target: EntropySource,
NS::Target: NodeSigner,
CM::Target: AChannelManager,
C::Target: Filter,
K::Target: KVStore,
TP::Target: TimeProvider,
T::Target: BroadcasterInterface,
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>where
ES::Target: EntropySource,
NS::Target: NodeSigner,
CM::Target: AChannelManager,
C::Target: Filter,
K::Target: KVStore,
TP::Target: TimeProvider,
T::Target: BroadcasterInterface,
Source§type CustomMessage = RawLSPSMessage
type CustomMessage = RawLSPSMessage
Source§fn read<RD: LengthLimitedRead>(
&self,
message_type: u16,
buffer: &mut RD,
) -> Result<Option<Self::CustomMessage>, DecodeError>
fn read<RD: LengthLimitedRead>( &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.