@@ -27,16 +27,16 @@ pub(crate) const LSPS2_BUY_REQUEST_PAYMENT_SIZE_TOO_LARGE_ERROR_CODE: i32 = 203;
27
27
28
28
#[ derive( Clone , Debug , PartialEq , Eq , Deserialize , Serialize ) ]
29
29
/// A request made to an LSP to learn their current channel fees and parameters.
30
- pub struct GetInfoRequest {
30
+ pub struct LSPS2GetInfoRequest {
31
31
/// An optional token to provide to the LSP.
32
32
pub token : Option < String > ,
33
33
}
34
34
35
35
/// Fees and parameters for a JIT Channel without the promise.
36
36
///
37
37
/// The promise will be calculated automatically for the LSP and this type converted
38
- /// into an [`OpeningFeeParams `] for transit over the wire.
39
- pub struct RawOpeningFeeParams {
38
+ /// into an [`LSPS2OpeningFeeParams `] for transit over the wire.
39
+ pub struct LSPS2RawOpeningFeeParams {
40
40
/// The minimum fee required for the channel open.
41
41
pub min_fee_msat : u64 ,
42
42
/// A fee proportional to the size of the initial payment.
@@ -53,8 +53,10 @@ pub struct RawOpeningFeeParams {
53
53
pub max_payment_size_msat : u64 ,
54
54
}
55
55
56
- impl RawOpeningFeeParams {
57
- pub ( crate ) fn into_opening_fee_params ( self , promise_secret : & [ u8 ; 32 ] ) -> OpeningFeeParams {
56
+ impl LSPS2RawOpeningFeeParams {
57
+ pub ( crate ) fn into_opening_fee_params (
58
+ self , promise_secret : & [ u8 ; 32 ] ,
59
+ ) -> LSPS2OpeningFeeParams {
58
60
let mut hmac = HmacEngine :: < Sha256 > :: new ( promise_secret) ;
59
61
hmac. input ( & self . min_fee_msat . to_be_bytes ( ) ) ;
60
62
hmac. input ( & self . proportional . to_be_bytes ( ) ) ;
@@ -65,7 +67,7 @@ impl RawOpeningFeeParams {
65
67
hmac. input ( & self . max_payment_size_msat . to_be_bytes ( ) ) ;
66
68
let promise_bytes = Hmac :: from_engine ( hmac) . to_byte_array ( ) ;
67
69
let promise = utils:: hex_str ( & promise_bytes[ ..] ) ;
68
- OpeningFeeParams {
70
+ LSPS2OpeningFeeParams {
69
71
min_fee_msat : self . min_fee_msat ,
70
72
proportional : self . proportional ,
71
73
valid_until : self . valid_until . clone ( ) ,
@@ -82,9 +84,9 @@ impl RawOpeningFeeParams {
82
84
/// Fees and parameters for a JIT Channel including the promise.
83
85
///
84
86
/// The promise is an HMAC calculated using a secret known to the LSP and the rest of the fields as input.
85
- /// It exists so the LSP can verify the authenticity of a client provided OpeningFeeParams by recalculating
87
+ /// It exists so the LSP can verify the authenticity of a client provided LSPS2OpeningFeeParams by recalculating
86
88
/// the promise using the secret. Once verified they can be confident it was not modified by the client.
87
- pub struct OpeningFeeParams {
89
+ pub struct LSPS2OpeningFeeParams {
88
90
/// The minimum fee required for the channel open.
89
91
#[ serde( with = "string_amount" ) ]
90
92
pub min_fee_msat : u64 ,
@@ -106,18 +108,18 @@ pub struct OpeningFeeParams {
106
108
pub promise : String ,
107
109
}
108
110
109
- /// A response to a [`GetInfoRequest `]
111
+ /// A response to a [`LSPS2GetInfoRequest `]
110
112
#[ derive( Clone , Debug , PartialEq , Eq , Deserialize , Serialize ) ]
111
- pub struct GetInfoResponse {
113
+ pub struct LSPS2GetInfoResponse {
112
114
/// A set of opening fee parameters.
113
- pub opening_fee_params_menu : Vec < OpeningFeeParams > ,
115
+ pub opening_fee_params_menu : Vec < LSPS2OpeningFeeParams > ,
114
116
}
115
117
116
118
/// A request to buy a JIT channel.
117
119
#[ derive( Clone , Debug , PartialEq , Eq , Deserialize , Serialize ) ]
118
- pub struct BuyRequest {
120
+ pub struct LSPS2BuyRequest {
119
121
/// The fee parameters you would like to use.
120
- pub opening_fee_params : OpeningFeeParams ,
122
+ pub opening_fee_params : LSPS2OpeningFeeParams ,
121
123
/// The size of the initial payment you expect to receive.
122
124
#[ serde( default ) ]
123
125
#[ serde( skip_serializing_if = "Option::is_none" ) ]
@@ -127,9 +129,9 @@ pub struct BuyRequest {
127
129
128
130
/// A newtype that holds a `short_channel_id` in human readable format of BBBxTTTx000.
129
131
#[ derive( Clone , Debug , PartialEq , Eq , Deserialize , Serialize ) ]
130
- pub struct InterceptScid ( String ) ;
132
+ pub struct LSPS2InterceptScid ( String ) ;
131
133
132
- impl From < u64 > for InterceptScid {
134
+ impl From < u64 > for LSPS2InterceptScid {
133
135
fn from ( scid : u64 ) -> Self {
134
136
let block = scid_utils:: block_from_scid ( scid) ;
135
137
let tx_index = scid_utils:: tx_index_from_scid ( scid) ;
@@ -139,20 +141,20 @@ impl From<u64> for InterceptScid {
139
141
}
140
142
}
141
143
142
- impl InterceptScid {
143
- /// Try to convert a [`InterceptScid `] into a u64 used by LDK.
144
+ impl LSPS2InterceptScid {
145
+ /// Try to convert a [`LSPS2InterceptScid `] into a u64 used by LDK.
144
146
pub fn to_scid ( & self ) -> Result < u64 , ( ) > {
145
147
utils:: scid_from_human_readable_string ( & self . 0 )
146
148
}
147
149
}
148
150
149
- /// A response to a [`BuyRequest `].
151
+ /// A response to a [`LSPS2BuyRequest `].
150
152
///
151
153
/// Includes information needed to construct an invoice.
152
154
#[ derive( Clone , Debug , PartialEq , Eq , Deserialize , Serialize ) ]
153
- pub struct BuyResponse {
155
+ pub struct LSPS2BuyResponse {
154
156
/// The intercept short channel id used by LSP to identify need to open channel.
155
- pub jit_channel_scid : InterceptScid ,
157
+ pub jit_channel_scid : LSPS2InterceptScid ,
156
158
/// The locktime expiry delta the lsp requires.
157
159
pub lsp_cltv_expiry_delta : u32 ,
158
160
/// A flag that indicates who is trusting who.
@@ -164,20 +166,20 @@ pub struct BuyResponse {
164
166
/// An enum that captures all the valid JSON-RPC requests in the bLIP-52 / LSPS2 protocol.
165
167
pub enum LSPS2Request {
166
168
/// A request to learn an LSP's channel fees and parameters.
167
- GetInfo ( GetInfoRequest ) ,
169
+ GetInfo ( LSPS2GetInfoRequest ) ,
168
170
/// A request to buy a JIT channel from an LSP.
169
- Buy ( BuyRequest ) ,
171
+ Buy ( LSPS2BuyRequest ) ,
170
172
}
171
173
172
174
#[ derive( Clone , Debug , PartialEq , Eq ) ]
173
175
/// An enum that captures all the valid JSON-RPC responses in the bLIP-52 / LSPS2 protocol.
174
176
pub enum LSPS2Response {
175
177
/// A successful response to a [`LSPS2Request::GetInfo`] request.
176
- GetInfo ( GetInfoResponse ) ,
178
+ GetInfo ( LSPS2GetInfoResponse ) ,
177
179
/// An error response to a [`LSPS2Request::GetInfo`] request.
178
180
GetInfoError ( ResponseError ) ,
179
181
/// A successful response to a [`LSPS2Request::Buy`] request.
180
- Buy ( BuyResponse ) ,
182
+ Buy ( LSPS2BuyResponse ) ,
181
183
/// An error response to a [`LSPS2Request::Buy`] request.
182
184
BuyError ( ResponseError ) ,
183
185
}
@@ -226,7 +228,7 @@ mod tests {
226
228
let min_payment_size_msat = 1 ;
227
229
let max_payment_size_msat = 100_000_000 ;
228
230
229
- let raw = RawOpeningFeeParams {
231
+ let raw = LSPS2RawOpeningFeeParams {
230
232
min_fee_msat,
231
233
proportional,
232
234
valid_until : valid_until. clone ( ) . into ( ) ,
@@ -261,7 +263,7 @@ mod tests {
261
263
let min_payment_size_msat = 1 ;
262
264
let max_payment_size_msat = 100_000_000 ;
263
265
264
- let raw = RawOpeningFeeParams {
266
+ let raw = LSPS2RawOpeningFeeParams {
265
267
min_fee_msat,
266
268
proportional,
267
269
valid_until : valid_until. into ( ) ,
@@ -288,7 +290,7 @@ mod tests {
288
290
let min_payment_size_msat = 1 ;
289
291
let max_payment_size_msat = 100_000_000 ;
290
292
291
- let raw = RawOpeningFeeParams {
293
+ let raw = LSPS2RawOpeningFeeParams {
292
294
min_fee_msat,
293
295
proportional,
294
296
valid_until : valid_until. into ( ) ,
@@ -317,7 +319,7 @@ mod tests {
317
319
let min_payment_size_msat = 1 ;
318
320
let max_payment_size_msat = 100_000_000 ;
319
321
320
- let raw = RawOpeningFeeParams {
322
+ let raw = LSPS2RawOpeningFeeParams {
321
323
min_fee_msat,
322
324
proportional,
323
325
valid_until : valid_until. into ( ) ,
@@ -343,7 +345,7 @@ mod tests {
343
345
let min_payment_size_msat = 1 ;
344
346
let max_payment_size_msat = 100_000_000 ;
345
347
346
- let raw = RawOpeningFeeParams {
348
+ let raw = LSPS2RawOpeningFeeParams {
347
349
min_fee_msat,
348
350
proportional,
349
351
valid_until : valid_until. into ( ) ,
@@ -362,13 +364,13 @@ mod tests {
362
364
363
365
let payment_size_msat = Some ( 1234 ) ;
364
366
let buy_request_fixed =
365
- BuyRequest { opening_fee_params : opening_fee_params. clone ( ) , payment_size_msat } ;
367
+ LSPS2BuyRequest { opening_fee_params : opening_fee_params. clone ( ) , payment_size_msat } ;
366
368
let json_str = r#"{"opening_fee_params":{"max_client_to_self_delay":128,"max_payment_size_msat":"100000000","min_fee_msat":"100","min_lifetime":144,"min_payment_size_msat":"1","promise":"1134a5c51e3ba2e8f4259610d5e12c1bf4c50ddcd3f8af563e0a00d1fff41dea","proportional":21,"valid_until":"2023-05-20T08:30:45Z"},"payment_size_msat":"1234"}"# ;
367
369
assert_eq ! ( json_str, serde_json:: json!( buy_request_fixed) . to_string( ) ) ;
368
370
assert_eq ! ( buy_request_fixed, serde_json:: from_str( json_str) . unwrap( ) ) ;
369
371
370
372
let payment_size_msat = None ;
371
- let buy_request_variable = BuyRequest { opening_fee_params, payment_size_msat } ;
373
+ let buy_request_variable = LSPS2BuyRequest { opening_fee_params, payment_size_msat } ;
372
374
373
375
// Check we skip serialization if payment_size_msat is None.
374
376
let json_str = r#"{"opening_fee_params":{"max_client_to_self_delay":128,"max_payment_size_msat":"100000000","min_fee_msat":"100","min_lifetime":144,"min_payment_size_msat":"1","promise":"1134a5c51e3ba2e8f4259610d5e12c1bf4c50ddcd3f8af563e0a00d1fff41dea","proportional":21,"valid_until":"2023-05-20T08:30:45Z"}}"# ;
@@ -407,7 +409,7 @@ mod tests {
407
409
}
408
410
]
409
411
}"# ;
410
- let _get_info_response: GetInfoResponse = serde_json:: from_str ( json_str) . unwrap ( ) ;
412
+ let _get_info_response: LSPS2GetInfoResponse = serde_json:: from_str ( json_str) . unwrap ( ) ;
411
413
412
414
let json_str = r#"{
413
415
"opening_fee_params": {
@@ -422,13 +424,13 @@ mod tests {
422
424
},
423
425
"payment_size_msat": "42000"
424
426
}"# ;
425
- let _buy_request: BuyRequest = serde_json:: from_str ( json_str) . unwrap ( ) ;
427
+ let _buy_request: LSPS2BuyRequest = serde_json:: from_str ( json_str) . unwrap ( ) ;
426
428
427
429
let json_str = r#"{
428
430
"jit_channel_scid": "29451x4815x1",
429
431
"lsp_cltv_expiry_delta" : 144,
430
432
"client_trusts_lsp": false
431
433
}"# ;
432
- let _buy_response: BuyResponse = serde_json:: from_str ( json_str) . unwrap ( ) ;
434
+ let _buy_response: LSPS2BuyResponse = serde_json:: from_str ( json_str) . unwrap ( ) ;
433
435
}
434
436
}
0 commit comments