lightning_liquidity/lsps1/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 LSPS1 event types
11
12use super::msgs::OrderId;
13use super::msgs::{ChannelInfo, LSPS1Options, OrderParameters, PaymentInfo};
14
15use crate::lsps0::ser::{RequestId, ResponseError};
16
17use bitcoin::secp256k1::PublicKey;
18
19/// An event which an LSPS1 client should take some action in response to.
20#[derive(Clone, Debug, PartialEq, Eq)]
21pub enum LSPS1ClientEvent {
22 /// A request previously issued via [`LSPS1ClientHandler::request_supported_options`]
23 /// succeeded as the LSP returned the options it supports.
24 ///
25 /// You must check whether LSP supports the parameters the client wants and then call
26 /// [`LSPS1ClientHandler::create_order`] to place an order.
27 ///
28 /// [`LSPS1ClientHandler::request_supported_options`]: crate::lsps1::client::LSPS1ClientHandler::request_supported_options
29 /// [`LSPS1ClientHandler::create_order`]: crate::lsps1::client::LSPS1ClientHandler::create_order
30 SupportedOptionsReady {
31 /// The identifier of the issued LSPS1 `get_info` request, as returned by
32 /// [`LSPS1ClientHandler::request_supported_options`]
33 ///
34 /// This can be used to track which request this event corresponds to.
35 ///
36 /// [`LSPS1ClientHandler::request_supported_options`]: crate::lsps1::client::LSPS1ClientHandler::request_supported_options
37 request_id: RequestId,
38 /// The node id of the LSP that provided this response.
39 counterparty_node_id: PublicKey,
40 /// All options supported by the LSP.
41 supported_options: LSPS1Options,
42 },
43 /// A request previously issued via [`LSPS1ClientHandler::request_supported_options`]
44 /// failed as the LSP returned an error response.
45 ///
46 /// [`LSPS1ClientHandler::request_supported_options`]: crate::lsps1::client::LSPS1ClientHandler::request_supported_options
47 SupportedOptionsRequestFailed {
48 /// The identifier of the issued LSPS1 `get_info` request, as returned by
49 /// [`LSPS1ClientHandler::request_supported_options`]
50 ///
51 /// This can be used to track which request this event corresponds to.
52 ///
53 /// [`LSPS1ClientHandler::request_supported_options`]: crate::lsps1::client::LSPS1ClientHandler::request_supported_options
54 request_id: RequestId,
55 /// The node id of the LSP that provided this response.
56 counterparty_node_id: PublicKey,
57 /// The error that was returned.
58 error: ResponseError,
59 },
60 /// Confirmation from the LSP about the order created by the client.
61 ///
62 /// When the payment is confirmed, the LSP will open a channel to you
63 /// with the below agreed upon parameters.
64 ///
65 /// You must pay the invoice or onchain address if you want to continue and then
66 /// call [`LSPS1ClientHandler::check_order_status`] with the order id
67 /// to get information from LSP about progress of the order.
68 ///
69 /// [`LSPS1ClientHandler::check_order_status`]: crate::lsps1::client::LSPS1ClientHandler::check_order_status
70 OrderCreated {
71 /// The identifier of the issued LSPS1 `create_order` request, as returned by
72 /// [`LSPS1ClientHandler::create_order`]
73 ///
74 /// This can be used to track which request this event corresponds to.
75 ///
76 /// [`LSPS1ClientHandler::create_order`]: crate::lsps1::client::LSPS1ClientHandler::create_order
77 request_id: RequestId,
78 /// The node id of the LSP.
79 counterparty_node_id: PublicKey,
80 /// The id of the channel order.
81 order_id: OrderId,
82 /// The order created by client and approved by LSP.
83 order: OrderParameters,
84 /// The details regarding payment of the order
85 payment: PaymentInfo,
86 /// The details regarding state of the channel ordered.
87 channel: Option<ChannelInfo>,
88 },
89 /// Information from the LSP about the status of a previously created order.
90 ///
91 /// Will be emitted in response to calling [`LSPS1ClientHandler::check_order_status`].
92 ///
93 /// [`LSPS1ClientHandler::check_order_status`]: crate::lsps1::client::LSPS1ClientHandler::check_order_status
94 OrderStatus {
95 /// The identifier of the issued LSPS1 `get_order` request, as returned by
96 /// [`LSPS1ClientHandler::check_order_status`]
97 ///
98 /// This can be used to track which request this event corresponds to.
99 ///
100 /// [`LSPS1ClientHandler::check_order_status`]: crate::lsps1::client::LSPS1ClientHandler::check_order_status
101 request_id: RequestId,
102 /// The node id of the LSP.
103 counterparty_node_id: PublicKey,
104 /// The id of the channel order.
105 order_id: OrderId,
106 /// The order created by client and approved by LSP.
107 order: OrderParameters,
108 /// The details regarding payment of the order
109 payment: PaymentInfo,
110 /// The details regarding state of the channel ordered.
111 channel: Option<ChannelInfo>,
112 },
113 /// A request previously issued via [`LSPS1ClientHandler::create_order`] or [`LSPS1ClientHandler::check_order_status`].
114 /// failed as the LSP returned an error response.
115 ///
116 /// [`LSPS1ClientHandler::create_order`]: crate::lsps1::client::LSPS1ClientHandler::create_order
117 /// [`LSPS1ClientHandler::check_order_status`]: crate::lsps1::client::LSPS1ClientHandler::check_order_status
118 OrderRequestFailed {
119 /// The identifier of the issued LSPS1 `create_order` or `get_order` request, as returned by
120 /// [`LSPS1ClientHandler::create_order`] or [`LSPS1ClientHandler::check_order_status`].
121 ///
122 /// This can be used to track which request this event corresponds to.
123 ///
124 /// [`LSPS1ClientHandler::create_order`]: crate::lsps1::client::LSPS1ClientHandler::create_order
125 /// [`LSPS1ClientHandler::check_order_status`]: crate::lsps1::client::LSPS1ClientHandler::check_order_status
126 request_id: RequestId,
127 /// The node id of the LSP.
128 counterparty_node_id: PublicKey,
129 /// The error that was returned.
130 error: ResponseError,
131 },
132}
133
134/// An event which an LSPS1 server should take some action in response to.
135#[cfg(lsps1_service)]
136#[derive(Clone, Debug, PartialEq, Eq)]
137pub enum LSPS1ServiceEvent {
138 /// A client has selected the parameters to use from the supported options of the LSP
139 /// and would like to open a channel with the given payment parameters.
140 ///
141 /// You must call [`LSPS1ServiceHandler::send_payment_details`] to
142 /// send order parameters including the details regarding the
143 /// payment and order id for this order for the client.
144 ///
145 /// [`LSPS1ServiceHandler::send_payment_details`]: crate::lsps1::service::LSPS1ServiceHandler::send_payment_details
146 RequestForPaymentDetails {
147 /// An identifier that must be passed to [`LSPS1ServiceHandler::send_payment_details`].
148 ///
149 /// [`LSPS1ServiceHandler::send_payment_details`]: crate::lsps1::service::LSPS1ServiceHandler::send_payment_details
150 request_id: RequestId,
151 /// The node id of the client making the information request.
152 counterparty_node_id: PublicKey,
153 /// The order requested by the client.
154 order: OrderParameters,
155 },
156 /// A request from client to check the status of the payment.
157 ///
158 /// An event to poll for checking payment status either onchain or lightning.
159 ///
160 /// You must call [`LSPS1ServiceHandler::update_order_status`] to update the client
161 /// regarding the status of the payment and order.
162 ///
163 /// [`LSPS1ServiceHandler::update_order_status`]: crate::lsps1::service::LSPS1ServiceHandler::update_order_status
164 CheckPaymentConfirmation {
165 /// An identifier that must be passed to [`LSPS1ServiceHandler::update_order_status`].
166 ///
167 /// [`LSPS1ServiceHandler::update_order_status`]: crate::lsps1::service::LSPS1ServiceHandler::update_order_status
168 request_id: RequestId,
169 /// The node id of the client making the information request.
170 counterparty_node_id: PublicKey,
171 /// The order id of order with pending payment.
172 order_id: OrderId,
173 },
174 /// If error is encountered, refund the amount if paid by the client.
175 Refund {
176 /// An identifier.
177 request_id: RequestId,
178 /// The node id of the client making the information request.
179 counterparty_node_id: PublicKey,
180 /// The order id of the refunded order.
181 order_id: OrderId,
182 },
183}