lightning_liquidity/lsps2/event.rs
1// This file is Copyright its original authors, visible in version control
2// history.
3//
4// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
5// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
7// You may not use this file except in accordance with one or both of these
8// licenses.
9
10//! Contains LSPS2 event types
11
12use super::msgs::OpeningFeeParams;
13use crate::lsps0::ser::RequestId;
14use crate::prelude::{String, Vec};
15
16use bitcoin::secp256k1::PublicKey;
17
18/// An event which an LSPS2 client should take some action in response to.
19#[derive(Clone, Debug, PartialEq, Eq)]
20pub enum LSPS2ClientEvent {
21 /// Information from the LSP about their current fee rates and channel parameters.
22 ///
23 /// You must call [`LSPS2ClientHandler::select_opening_params`] with the fee parameter
24 /// you want to use if you wish to proceed opening a channel.
25 ///
26 /// [`LSPS2ClientHandler::select_opening_params`]: crate::lsps2::client::LSPS2ClientHandler::select_opening_params
27 OpeningParametersReady {
28 /// The identifier of the issued LSPS2 `get_info` request, as returned by
29 /// [`LSPS2ClientHandler::request_opening_params`]
30 ///
31 /// This can be used to track which request this event corresponds to.
32 ///
33 /// [`LSPS2ClientHandler::request_opening_params`]: crate::lsps2::client::LSPS2ClientHandler::request_opening_params
34 request_id: RequestId,
35 /// The node id of the LSP that provided this response.
36 counterparty_node_id: PublicKey,
37 /// The menu of fee parameters the LSP is offering at this time.
38 /// You must select one of these if you wish to proceed.
39 opening_fee_params_menu: Vec<OpeningFeeParams>,
40 },
41 /// Provides the necessary information to generate a payable invoice that then may be given to
42 /// the payer.
43 ///
44 /// When the invoice is paid, the LSP will open a channel with the previously agreed upon
45 /// parameters to you.
46 InvoiceParametersReady {
47 /// The identifier of the issued LSPS2 `buy` request, as returned by
48 /// [`LSPS2ClientHandler::select_opening_params`].
49 ///
50 /// This can be used to track which request this event corresponds to.
51 ///
52 /// [`LSPS2ClientHandler::select_opening_params`]: crate::lsps2::client::LSPS2ClientHandler::select_opening_params
53 request_id: RequestId,
54 /// The node id of the LSP.
55 counterparty_node_id: PublicKey,
56 /// The intercept short channel id to use in the route hint.
57 intercept_scid: u64,
58 /// The `cltv_expiry_delta` to use in the route hint.
59 cltv_expiry_delta: u32,
60 /// The initial payment size you specified.
61 payment_size_msat: Option<u64>,
62 },
63}
64
65/// An event which an LSPS2 server should take some action in response to.
66#[derive(Clone, Debug, PartialEq, Eq)]
67pub enum LSPS2ServiceEvent {
68 /// A request from a client for information about JIT Channel parameters.
69 ///
70 /// You must calculate the parameters for this client and pass them to
71 /// [`LSPS2ServiceHandler::opening_fee_params_generated`].
72 ///
73 /// If an unrecognized or stale token is provided you can use
74 /// `[LSPS2ServiceHandler::invalid_token_provided`] to error the request.
75 ///
76 /// [`LSPS2ServiceHandler::opening_fee_params_generated`]: crate::lsps2::service::LSPS2ServiceHandler::opening_fee_params_generated
77 /// [`LSPS2ServiceHandler::invalid_token_provided`]: crate::lsps2::service::LSPS2ServiceHandler::invalid_token_provided
78 GetInfo {
79 /// An identifier that must be passed to [`LSPS2ServiceHandler::opening_fee_params_generated`].
80 ///
81 /// [`LSPS2ServiceHandler::opening_fee_params_generated`]: crate::lsps2::service::LSPS2ServiceHandler::opening_fee_params_generated
82 request_id: RequestId,
83 /// The node id of the client making the information request.
84 counterparty_node_id: PublicKey,
85 /// An optional token that can be used as an API key, coupon code, etc.
86 token: Option<String>,
87 },
88 /// A client has selected a opening fee parameter to use and would like to
89 /// purchase a channel with an optional initial payment size.
90 ///
91 /// If `payment_size_msat` is [`Option::Some`] then the payer is allowed to use MPP.
92 /// If `payment_size_msat` is [`Option::None`] then the payer cannot use MPP.
93 ///
94 /// You must generate an intercept scid and `cltv_expiry_delta` for them to use
95 /// and call [`LSPS2ServiceHandler::invoice_parameters_generated`].
96 ///
97 /// [`LSPS2ServiceHandler::invoice_parameters_generated`]: crate::lsps2::service::LSPS2ServiceHandler::invoice_parameters_generated
98 BuyRequest {
99 /// An identifier that must be passed into [`LSPS2ServiceHandler::invoice_parameters_generated`].
100 ///
101 /// [`LSPS2ServiceHandler::invoice_parameters_generated`]: crate::lsps2::service::LSPS2ServiceHandler::invoice_parameters_generated
102 request_id: RequestId,
103 /// The client node id that is making this request.
104 counterparty_node_id: PublicKey,
105 /// The channel parameters they have selected.
106 opening_fee_params: OpeningFeeParams,
107 /// The size of the initial payment they would like to receive.
108 payment_size_msat: Option<u64>,
109 },
110 /// You should open a channel using [`ChannelManager::create_channel`].
111 ///
112 /// [`ChannelManager::create_channel`]: lightning::ln::channelmanager::ChannelManager::create_channel
113 OpenChannel {
114 /// The node to open channel with.
115 their_network_key: PublicKey,
116 /// The amount to forward after fees.
117 amt_to_forward_msat: u64,
118 /// The fee earned for opening the channel.
119 opening_fee_msat: u64,
120 /// A user specified id used to track channel open.
121 user_channel_id: u128,
122 /// The intercept short channel id to use in the route hint.
123 intercept_scid: u64,
124 },
125}