@@ -122,6 +122,7 @@ pub struct CreateOrderResponse {
122
122
/// The id of the channel order.
123
123
pub order_id : OrderId ,
124
124
/// The parameters of channel order.
125
+ #[ serde( flatten) ]
125
126
pub order : OrderParams ,
126
127
/// The datetime when the order was created
127
128
pub created_at : chrono:: DateTime < Utc > ,
@@ -137,6 +138,7 @@ pub struct CreateOrderResponse {
137
138
138
139
/// An object representing the state of an order.
139
140
#[ derive( Clone , Debug , PartialEq , Eq , Deserialize , Serialize ) ]
141
+ #[ serde( rename_all = "SCREAMING_SNAKE_CASE" ) ]
140
142
pub enum OrderState {
141
143
/// The order has been created.
142
144
Created ,
@@ -169,11 +171,12 @@ pub struct OrderPayment {
169
171
/// confirmed without a confirmation.
170
172
pub min_fee_for_0conf : u8 ,
171
173
/// Details regarding a detected on-chain payment.
172
- pub onchain_payment : OnchainPayment ,
174
+ pub onchain_payment : Option < OnchainPayment > ,
173
175
}
174
176
175
177
/// The state of an [`OrderPayment`].
176
178
#[ derive( Clone , Debug , PartialEq , Eq , Deserialize , Serialize ) ]
179
+ #[ serde( rename_all = "SCREAMING_SNAKE_CASE" ) ]
177
180
pub enum PaymentState {
178
181
/// A payment is expected.
179
182
ExpectPayment ,
@@ -313,4 +316,95 @@ mod tests {
313
316
assert_eq ! ( json_str, serde_json:: json!( options_supported) . to_string( ) ) ;
314
317
assert_eq ! ( options_supported, serde_json:: from_str( json_str) . unwrap( ) ) ;
315
318
}
319
+
320
+ #[ test]
321
+ fn parse_spec_test_vectors ( ) {
322
+ // Here, we simply assert that we're able to parse all examples given in LSPS1.
323
+ let json_str = r#"{}"# ;
324
+ let _get_info_request: GetInfoRequest = serde_json:: from_str ( json_str) . unwrap ( ) ;
325
+
326
+ let json_str = r#"{
327
+ "options": {
328
+ "min_required_channel_confirmations": 0,
329
+ "min_funding_confirms_within_blocks" : 6,
330
+ "min_onchain_payment_confirmations": null,
331
+ "supports_zero_channel_reserve": true,
332
+ "min_onchain_payment_size_sat": null,
333
+ "max_channel_expiry_blocks": 20160,
334
+ "min_initial_client_balance_sat": "20000",
335
+ "max_initial_client_balance_sat": "100000000",
336
+ "min_initial_lsp_balance_sat": "0",
337
+ "max_initial_lsp_balance_sat": "100000000",
338
+ "min_channel_balance_sat": "50000",
339
+ "max_channel_balance_sat": "100000000"
340
+ }
341
+ }"# ;
342
+ let _get_info_response: GetInfoResponse = serde_json:: from_str ( json_str) . unwrap ( ) ;
343
+
344
+ let json_str = r#"{
345
+ "lsp_balance_sat": "5000000",
346
+ "client_balance_sat": "2000000",
347
+ "required_channel_confirmations" : 0,
348
+ "funding_confirms_within_blocks": 6,
349
+ "channel_expiry_blocks": 144,
350
+ "token": "",
351
+ "refund_onchain_address": "bc1qvmsy0f3yyes6z9jvddk8xqwznndmdwapvrc0xrmhd3vqj5rhdrrq6hz49h",
352
+ "announce_channel": true
353
+ }"# ;
354
+ let _create_order_request: CreateOrderRequest = serde_json:: from_str ( json_str) . unwrap ( ) ;
355
+
356
+ let json_str = r#"{
357
+ "order_id": "bb4b5d0a-8334-49d8-9463-90a6d413af7c",
358
+ "lsp_balance_sat": "5000000",
359
+ "client_balance_sat": "2000000",
360
+ "required_channel_confirmations" : 0,
361
+ "funding_confirms_within_blocks": 1,
362
+ "channel_expiry_blocks": 12,
363
+ "token": "",
364
+ "created_at": "2012-04-23T18:25:43.511Z",
365
+ "expires_at": "2015-01-25T19:29:44.612Z",
366
+ "announce_channel": true,
367
+ "order_state": "CREATED",
368
+ "payment": {
369
+ "state": "EXPECT_PAYMENT",
370
+ "fee_total_sat": "8888",
371
+ "order_total_sat": "2008888",
372
+ "bolt11_invoice": "lnbc252u1p3aht9ysp580g4633gd2x9lc5al0wd8wx0mpn9748jeyz46kqjrpxn52uhfpjqpp5qgf67tcqmuqehzgjm8mzya90h73deafvr4m5705l5u5l4r05l8cqdpud3h8ymm4w3jhytnpwpczqmt0de6xsmre2pkxzm3qydmkzdjrdev9s7zhgfaqxqyjw5qcqpjrzjqt6xptnd85lpqnu2lefq4cx070v5cdwzh2xlvmdgnu7gqp4zvkus5zapryqqx9qqqyqqqqqqqqqqqcsq9q9qyysgqen77vu8xqjelum24hgjpgfdgfgx4q0nehhalcmuggt32japhjuksq9jv6eksjfnppm4hrzsgyxt8y8xacxut9qv3fpyetz8t7tsymygq8yzn05",
373
+ "onchain_address": "bc1p5uvtaxzkjwvey2tfy49k5vtqfpjmrgm09cvs88ezyy8h2zv7jhas9tu4yr",
374
+ "min_onchain_payment_confirmations": 0,
375
+ "min_fee_for_0conf": 253,
376
+ "onchain_payment": null
377
+ },
378
+ "channel": null
379
+ }"# ;
380
+ let _create_order_response: CreateOrderResponse = serde_json:: from_str ( json_str) . unwrap ( ) ;
381
+
382
+ let json_str = r#"{
383
+ "order_id": "bb4b5d0a-8334-49d8-9463-90a6d413af7c"
384
+ }"# ;
385
+ let _get_order_request: GetOrderRequest = serde_json:: from_str ( json_str) . unwrap ( ) ;
386
+
387
+ let json_str = r#"{
388
+ "state": "EXPECT_PAYMENT",
389
+ "fee_total_sat": "8888",
390
+ "order_total_sat": "2008888",
391
+ "bolt11_invoice": "lnbc252u1p3aht9ysp580g4633gd2x9lc5al0wd8wx0mpn9748jeyz46kqjrpxn52uhfpjqpp5qgf67tcqmuqehzgjm8mzya90h73deafvr4m5705l5u5l4r05l8cqdpud3h8ymm4w3jhytnpwpczqmt0de6xsmre2pkxzm3qydmkzdjrdev9s7zhgfaqxqyjw5qcqpjrzjqt6xptnd85lpqnu2lefq4cx070v5cdwzh2xlvmdgnu7gqp4zvkus5zapryqqx9qqqyqqqqqqqqqqqcsq9q9qyysgqen77vu8xqjelum24hgjpgfdgfgx4q0nehhalcmuggt32japhjuksq9jv6eksjfnppm4hrzsgyxt8y8xacxut9qv3fpyetz8t7tsymygq8yzn05",
392
+ "onchain_address": "bc1p5uvtaxzkjwvey2tfy49k5vtqfpjmrgm09cvs88ezyy8h2zv7jhas9tu4yr",
393
+ "min_onchain_payment_confirmations": 1,
394
+ "min_fee_for_0conf": 253,
395
+ "onchain_payment": {
396
+ "outpoint": "0301e0480b374b32851a9462db29dc19fe830a7f7d7a88b81612b9d42099c0ae:1",
397
+ "sat": "1200",
398
+ "confirmed": false
399
+ }
400
+ }"# ;
401
+ let _payment: OrderPayment = serde_json:: from_str ( json_str) . unwrap ( ) ;
402
+
403
+ let json_str = r#"{
404
+ "funded_at": "2012-04-23T18:25:43.511Z",
405
+ "funding_outpoint": "0301e0480b374b32851a9462db29dc19fe830a7f7d7a88b81612b9d42099c0ae:0",
406
+ "expires_at": "2012-04-23T18:25:43.511Z"
407
+ }"# ;
408
+ let _channel: ChannelInfo = serde_json:: from_str ( json_str) . unwrap ( ) ;
409
+ }
316
410
}
0 commit comments