lightningdevkit.org
lightningdevkit.org copied to clipboard
Add instructions on how to use lightning-liquidity crate
- To allow 0-conf channels, set UserConfig::manually_accept_inbound_channel and start handling OpenChannelRequest events via the ChannelManager::accept_inbound_channel_from_trusted_peer_0conf call
- Configure LiquidityManager by setting the LSPS2ClientConfig and set it as your CustomMessageHandler in MessagHandler that you give to PeerManager
- Set ChannelConfig:: accept_underpaying_htlcs to true and ChannelHandshakeConfig::max_inbound_value_in_flight_percent_of_channel to 100.
- Start handling LiquidityManager events (returned via next_event, next_event_async, or wait_next_event)
- Connect to the LSP
- Call LiquidityManager::lsps2_client_handler to get an LSPS2ClientHandler
- Call LSPS2ClientHandler::request_opening_params, you'll get an OpeningParametersReady event when the LSP responds
- Pick one of the opening parameters and remember them (to later check if the LSP just takes the fee you agreed on)
- Call LSPS2ClientHandler::select_opening_parameters, you'll get an InvoiceParametersReady event when the LSP responds
- Create a JIT invoice with the information given in said InvoiceParametersReady event
- Hand out that invoice, once it's paid, the LSP will open a channel to you and forward the HTLC
- In your event handling logic for the PaymentClaimable event, check that the LSP only withheld what you agreed upon above (you can use the compute_opening_fee util for that)
- Claim the payment if the LSP didn't cheat you
Note: This is for LSPS2
For LSPS1 the steps are roughly:
- Configure
LiquidityManagerby setting theLSPS1ClientConfigand set it as yourCustomMessageHandlerinMessagHandlerthat you give toPeerManager - Start handling
LiquidityManagerevents (returned vianext_event,next_event_async, orwait_next_event) - Connect to the LSP
- Call
LiquidityManager::lsps1_client_handlerto get anLSPS1ClientHandler - Call
LSPS1ClientHandler::request_supported_options, you'll get aSupportedOptionsReadyevent - Check params for your order against the
LSPS1Optionslimits returned by the LSP - If all is clear, call
LSPS1ClientHandler::create_order, you'll get aOrderCreatedevent in response - Choose one of the payment methods as given in
OrderCreated::payment, pay for the channel open - The LSP will open the channel to you
- (Optionally) Check order status inbetween via
LSPS1ClientHandler::check_order_status