1
1
//! Message, request, and other primitive types used to implement bLIP-51 / LSPS1.
2
2
3
3
use crate :: lsps0:: ser:: {
4
- string_amount, u32_fee_rate, unchecked_address, unchecked_address_option, LSPSDateTime ,
5
- LSPSMessage , LSPSRequestId , LSPSResponseError ,
4
+ string_amount, string_offer , u32_fee_rate, unchecked_address, unchecked_address_option,
5
+ LSPSDateTime , LSPSMessage , LSPSRequestId , LSPSResponseError ,
6
6
} ;
7
7
8
8
use crate :: prelude:: String ;
9
9
10
10
use bitcoin:: { Address , FeeRate , OutPoint } ;
11
11
12
+ use lightning:: offers:: offer:: Offer ;
12
13
use lightning_invoice:: Bolt11Invoice ;
13
14
14
15
use serde:: { Deserialize , Serialize } ;
@@ -151,6 +152,8 @@ pub enum LSPS1OrderState {
151
152
pub struct LSPS1PaymentInfo {
152
153
/// A Lightning payment using BOLT 11.
153
154
pub bolt11 : Option < LSPS1Bolt11PaymentInfo > ,
155
+ /// A Lightning payment using BOLT 12.
156
+ pub bolt12 : Option < LSPS1Bolt12PaymentInfo > ,
154
157
/// An onchain payment.
155
158
pub onchain : Option < LSPS1OnchainPaymentInfo > ,
156
159
}
@@ -172,6 +175,24 @@ pub struct LSPS1Bolt11PaymentInfo {
172
175
pub invoice : Bolt11Invoice ,
173
176
}
174
177
178
+ /// A Lightning payment using BOLT 12.
179
+ #[ derive( Clone , Debug , PartialEq , Eq , Deserialize , Serialize ) ]
180
+ pub struct LSPS1Bolt12PaymentInfo {
181
+ /// Indicates the current state of the payment.
182
+ pub state : LSPS1PaymentState ,
183
+ /// The datetime when the payment option expires.
184
+ pub expires_at : LSPSDateTime ,
185
+ /// The total fee the LSP will charge to open this channel in satoshi.
186
+ #[ serde( with = "string_amount" ) ]
187
+ pub fee_total_sat : u64 ,
188
+ /// The amount the client needs to pay to have the requested channel openend.
189
+ #[ serde( with = "string_amount" ) ]
190
+ pub order_total_sat : u64 ,
191
+ /// A BOLT12 offer the client can pay to have to channel opened.
192
+ #[ serde( with = "string_offer" ) ]
193
+ pub offer : Offer ,
194
+ }
195
+
175
196
/// An onchain payment.
176
197
#[ derive( Clone , Debug , PartialEq , Eq , Deserialize , Serialize ) ]
177
198
pub struct LSPS1OnchainPaymentInfo {
@@ -387,6 +408,15 @@ mod tests {
387
408
}"# ;
388
409
let _bolt11_payment: LSPS1Bolt11PaymentInfo = serde_json:: from_str ( json_str) . unwrap ( ) ;
389
410
411
+ let json_str = r#"{
412
+ "state" : "EXPECT_PAYMENT",
413
+ "expires_at": "2025-01-01T00:00:00Z",
414
+ "fee_total_sat": "8888",
415
+ "order_total_sat": "200888",
416
+ "offer": "lno1qgsqvgnwgcg35z6ee2h3yczraddm72xrfua9uve2rlrm9deu7xyfzrcgqvp3pwq2q3shxerxzzfqyxdxxkjqxfpt9tz94zj79m4n99kwjddq92uqryuwsu4nt0t3lthfq02jzqla96dtkf4rew8edxw0p85swe89wd8ldekdl5j262n76qyl2qgzajm08clzr74z6ssy0qlvvp9f5kvrxf27yz4pcy99jge69kxu8ttsqt8gw8jsk5397zvvdf4lfd52paf73thcg6xf57xmvtdrwny5mn2r4jw2d5jzalqrq537mmt6u9qpqytzzql6zemrme07jqqwtza76lldcj9wgc0ccd4d2w584cdcx6szsuupvy"
417
+ }"# ;
418
+ let _bolt11_payment: LSPS1Bolt12PaymentInfo = serde_json:: from_str ( json_str) . unwrap ( ) ;
419
+
390
420
let json_str = r#"{
391
421
"state": "EXPECT_PAYMENT",
392
422
"expires_at": "2025-01-01T00:00:00Z",
@@ -406,6 +436,13 @@ mod tests {
406
436
"order_total_sat": "200888",
407
437
"invoice": "lnbc252u1p3aht9ysp580g4633gd2x9lc5al0wd8wx0mpn9748jeyz46kqjrpxn52uhfpjqpp5qgf67tcqmuqehzgjm8mzya90h73deafvr4m5705l5u5l4r05l8cqdpud3h8ymm4w3jhytnpwpczqmt0de6xsmre2pkxzm3qydmkzdjrdev9s7zhgfaqxqyjw5qcqpjrzjqt6xptnd85lpqnu2lefq4cx070v5cdwzh2xlvmdgnu7gqp4zvkus5zapryqqx9qqqyqqqqqqqqqqqcsq9q9qyysgqen77vu8xqjelum24hgjpgfdgfgx4q0nehhalcmuggt32japhjuksq9jv6eksjfnppm4hrzsgyxt8y8xacxut9qv3fpyetz8t7tsymygq8yzn05"
408
438
},
439
+ "bolt12": {
440
+ "state" : "EXPECT_PAYMENT",
441
+ "expires_at": "2025-01-01T00:00:00Z",
442
+ "fee_total_sat": "8888",
443
+ "order_total_sat": "200888",
444
+ "offer": "lno1qgsqvgnwgcg35z6ee2h3yczraddm72xrfua9uve2rlrm9deu7xyfzrcgqvp3pwq2q3shxerxzzfqyxdxxkjqxfpt9tz94zj79m4n99kwjddq92uqryuwsu4nt0t3lthfq02jzqla96dtkf4rew8edxw0p85swe89wd8ldekdl5j262n76qyl2qgzajm08clzr74z6ssy0qlvvp9f5kvrxf27yz4pcy99jge69kxu8ttsqt8gw8jsk5397zvvdf4lfd52paf73thcg6xf57xmvtdrwny5mn2r4jw2d5jzalqrq537mmt6u9qpqytzzql6zemrme07jqqwtza76lldcj9wgc0ccd4d2w584cdcx6szsuupvy"
445
+ },
409
446
"onchain": {
410
447
"state": "EXPECT_PAYMENT",
411
448
"expires_at": "2025-01-01T00:00:00Z",
@@ -416,7 +453,10 @@ mod tests {
416
453
"min_fee_for_0conf": 253
417
454
}
418
455
}"# ;
419
- let _payment: LSPS1PaymentInfo = serde_json:: from_str ( json_str) . unwrap ( ) ;
456
+ let payment: LSPS1PaymentInfo = serde_json:: from_str ( json_str) . unwrap ( ) ;
457
+ assert ! ( payment. bolt11. is_some( ) ) ;
458
+ assert ! ( payment. bolt12. is_some( ) ) ;
459
+ assert ! ( payment. onchain. is_some( ) ) ;
420
460
421
461
let json_str = r#"{
422
462
"order_id": "bb4b5d0a-8334-49d8-9463-90a6d413af7c",
@@ -437,6 +477,13 @@ mod tests {
437
477
"order_total_sat": "2008888",
438
478
"invoice" : "lnbc252u1p3aht9ysp580g4633gd2x9lc5al0wd8wx0mpn9748jeyz46kqjrpxn52uhfpjqpp5qgf67tcqmuqehzgjm8mzya90h73deafvr4m5705l5u5l4r05l8cqdpud3h8ymm4w3jhytnpwpczqmt0de6xsmre2pkxzm3qydmkzdjrdev9s7zhgfaqxqyjw5qcqpjrzjqt6xptnd85lpqnu2lefq4cx070v5cdwzh2xlvmdgnu7gqp4zvkus5zapryqqx9qqqyqqqqqqqqqqqcsq9q9qyysgqen77vu8xqjelum24hgjpgfdgfgx4q0nehhalcmuggt32japhjuksq9jv6eksjfnppm4hrzsgyxt8y8xacxut9qv3fpyetz8t7tsymygq8yzn05"
439
479
},
480
+ "bolt12": {
481
+ "state" : "EXPECT_PAYMENT",
482
+ "expires_at": "2025-01-01T00:00:00Z",
483
+ "fee_total_sat": "8888",
484
+ "order_total_sat": "200888",
485
+ "offer": "lno1qgsqvgnwgcg35z6ee2h3yczraddm72xrfua9uve2rlrm9deu7xyfzrcgqvp3pwq2q3shxerxzzfqyxdxxkjqxfpt9tz94zj79m4n99kwjddq92uqryuwsu4nt0t3lthfq02jzqla96dtkf4rew8edxw0p85swe89wd8ldekdl5j262n76qyl2qgzajm08clzr74z6ssy0qlvvp9f5kvrxf27yz4pcy99jge69kxu8ttsqt8gw8jsk5397zvvdf4lfd52paf73thcg6xf57xmvtdrwny5mn2r4jw2d5jzalqrq537mmt6u9qpqytzzql6zemrme07jqqwtza76lldcj9wgc0ccd4d2w584cdcx6szsuupvy"
486
+ },
440
487
"onchain": {
441
488
"state": "EXPECT_PAYMENT",
442
489
"expires_at": "2015-01-25T19:29:44.612Z",
@@ -450,8 +497,11 @@ mod tests {
450
497
},
451
498
"channel": null
452
499
}"# ;
453
- let _create_order_response : LSPS1CreateOrderResponse =
500
+ let create_order_response : LSPS1CreateOrderResponse =
454
501
serde_json:: from_str ( json_str) . unwrap ( ) ;
502
+ assert ! ( create_order_response. payment. bolt11. is_some( ) ) ;
503
+ assert ! ( create_order_response. payment. bolt12. is_some( ) ) ;
504
+ assert ! ( create_order_response. payment. onchain. is_some( ) ) ;
455
505
456
506
let json_str = r#"{
457
507
"order_id": "bb4b5d0a-8334-49d8-9463-90a6d413af7c"
0 commit comments