@@ -19,8 +19,9 @@ use crate::lsps0::ser::{
1919} ;
2020
2121use bitcoin:: { Address , FeeRate , OutPoint } ;
22-
2322use lightning:: offers:: offer:: Offer ;
23+ use lightning:: util:: ser:: { Readable , Writeable } ;
24+ use lightning:: { impl_writeable_tlv_based, impl_writeable_tlv_based_enum} ;
2425use lightning_invoice:: Bolt11Invoice ;
2526
2627use serde:: { Deserialize , Serialize } ;
@@ -39,6 +40,23 @@ pub(crate) const LSPS1_GET_ORDER_REQUEST_ORDER_NOT_FOUND_ERROR_CODE: i32 = 101;
3940#[ derive( Clone , Debug , PartialEq , Eq , Deserialize , Serialize , Hash ) ]
4041pub struct LSPS1OrderId ( pub String ) ;
4142
43+ impl Writeable for LSPS1OrderId {
44+ fn write < W : lightning:: util:: ser:: Writer > (
45+ & self , writer : & mut W ,
46+ ) -> Result < ( ) , lightning:: io:: Error > {
47+ self . 0 . write ( writer)
48+ }
49+ }
50+
51+ impl Readable for LSPS1OrderId {
52+ fn read < R : bitcoin:: io:: Read > (
53+ reader : & mut R ,
54+ ) -> Result < Self , lightning:: ln:: msgs:: DecodeError > {
55+ let inner = Readable :: read ( reader) ?;
56+ Ok ( Self ( inner) )
57+ }
58+ }
59+
4260/// A request made to an LSP to retrieve the supported options.
4361///
4462/// Please refer to the [bLIP-51 / LSPS1
@@ -128,6 +146,16 @@ pub struct LSPS1OrderParams {
128146 pub announce_channel : bool ,
129147}
130148
149+ impl_writeable_tlv_based ! ( LSPS1OrderParams , {
150+ ( 0 , lsp_balance_sat, required) ,
151+ ( 2 , client_balance_sat, required) ,
152+ ( 4 , required_channel_confirmations, required) ,
153+ ( 6 , funding_confirms_within_blocks, required) ,
154+ ( 8 , channel_expiry_blocks, required) ,
155+ ( 10 , token, option) ,
156+ ( 12 , announce_channel, required) ,
157+ } ) ;
158+
131159/// A response to a [`LSPS1CreateOrderRequest`].
132160#[ derive( Clone , Debug , PartialEq , Eq , Deserialize , Serialize ) ]
133161pub struct LSPS1CreateOrderResponse {
@@ -158,6 +186,12 @@ pub enum LSPS1OrderState {
158186 Failed ,
159187}
160188
189+ impl_writeable_tlv_based_enum ! ( LSPS1OrderState ,
190+ ( 0 , Created ) => { } ,
191+ ( 2 , Completed ) => { } ,
192+ ( 4 , Failed ) => { }
193+ ) ;
194+
161195/// Details regarding how to pay for an order.
162196#[ derive( Clone , Debug , PartialEq , Eq , Deserialize , Serialize ) ]
163197pub struct LSPS1PaymentInfo {
@@ -169,6 +203,12 @@ pub struct LSPS1PaymentInfo {
169203 pub onchain : Option < LSPS1OnchainPaymentInfo > ,
170204}
171205
206+ impl_writeable_tlv_based ! ( LSPS1PaymentInfo , {
207+ ( 0 , bolt11, option) ,
208+ ( 2 , bolt12, option) ,
209+ ( 4 , onchain, option) ,
210+ } ) ;
211+
172212/// A Lightning payment using BOLT 11.
173213#[ derive( Clone , Debug , PartialEq , Eq , Deserialize , Serialize ) ]
174214pub struct LSPS1Bolt11PaymentInfo {
@@ -186,6 +226,14 @@ pub struct LSPS1Bolt11PaymentInfo {
186226 pub invoice : Bolt11Invoice ,
187227}
188228
229+ impl_writeable_tlv_based ! ( LSPS1Bolt11PaymentInfo , {
230+ ( 0 , state, required) ,
231+ ( 2 , expires_at, required) ,
232+ ( 4 , fee_total_sat, required) ,
233+ ( 6 , order_total_sat, required) ,
234+ ( 8 , invoice, required) ,
235+ } ) ;
236+
189237/// A Lightning payment using BOLT 12.
190238#[ derive( Clone , Debug , PartialEq , Eq , Deserialize , Serialize ) ]
191239pub struct LSPS1Bolt12PaymentInfo {
@@ -204,6 +252,14 @@ pub struct LSPS1Bolt12PaymentInfo {
204252 pub offer : Offer ,
205253}
206254
255+ impl_writeable_tlv_based ! ( LSPS1Bolt12PaymentInfo , {
256+ ( 0 , state, required) ,
257+ ( 2 , expires_at, required) ,
258+ ( 4 , fee_total_sat, required) ,
259+ ( 6 , order_total_sat, required) ,
260+ ( 8 , offer, required) ,
261+ } ) ;
262+
207263/// An onchain payment.
208264#[ derive( Clone , Debug , PartialEq , Eq , Deserialize , Serialize ) ]
209265pub struct LSPS1OnchainPaymentInfo {
@@ -235,6 +291,17 @@ pub struct LSPS1OnchainPaymentInfo {
235291 pub refund_onchain_address : Option < Address > ,
236292}
237293
294+ impl_writeable_tlv_based ! ( LSPS1OnchainPaymentInfo , {
295+ ( 0 , state, required) ,
296+ ( 2 , expires_at, required) ,
297+ ( 4 , fee_total_sat, required) ,
298+ ( 6 , order_total_sat, required) ,
299+ ( 8 , address, required) ,
300+ ( 10 , min_onchain_payment_confirmations, option) ,
301+ ( 12 , min_fee_for_0conf, required) ,
302+ ( 14 , refund_onchain_address, option) ,
303+ } ) ;
304+
238305/// The state of a payment.
239306///
240307/// *Note*: Previously, the spec also knew a `CANCELLED` state for BOLT11 payments, which has since
@@ -251,6 +318,12 @@ pub enum LSPS1PaymentState {
251318 Refunded ,
252319}
253320
321+ impl_writeable_tlv_based_enum ! ( LSPS1PaymentState ,
322+ ( 0 , ExpectPayment ) => { } ,
323+ ( 2 , Paid ) => { } ,
324+ ( 4 , Refunded ) => { }
325+ ) ;
326+
254327/// Details regarding a detected on-chain payment.
255328#[ derive( Clone , Debug , PartialEq , Eq , Deserialize , Serialize ) ]
256329pub struct LSPS1OnchainPayment {
@@ -274,6 +347,12 @@ pub struct LSPS1ChannelInfo {
274347 pub expires_at : LSPSDateTime ,
275348}
276349
350+ impl_writeable_tlv_based ! ( LSPS1ChannelInfo , {
351+ ( 0 , funded_at, required) ,
352+ ( 2 , funding_outpoint, required) ,
353+ ( 4 , expires_at, required) ,
354+ } ) ;
355+
277356/// A request made to an LSP to retrieve information about an previously made order.
278357///
279358/// Please refer to the [bLIP-51 / LSPS1
0 commit comments