1- // This file is Copyright its original authors, visible in version contror
1+ // This file is Copyright its original authors, visible in version control
22// history.
33//
44// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
@@ -35,8 +35,6 @@ use bitcoin::secp256k1::PublicKey;
3535
3636use core:: ops:: Deref ;
3737
38- const SUPPORTED_SPEC_VERSIONS : [ u16 ; 1 ] = [ 1 ] ;
39-
4038/// Client-side configuration options for LSPS1 channel requests.
4139#[ derive( Clone , Debug ) ]
4240pub struct LSPS1ClientConfig {
@@ -55,43 +53,30 @@ impl From<ChannelStateError> for LightningError {
5553#[ derive( PartialEq , Debug ) ]
5654enum InboundRequestState {
5755 InfoRequested ,
58- OptionsSupport { version : u16 , options_supported : OptionsSupported } ,
59- OrderRequested { version : u16 , order : OrderParams } ,
56+ OptionsSupport { options_supported : OptionsSupported } ,
57+ OrderRequested { order : OrderParams } ,
6058 PendingPayment { order_id : OrderId } ,
6159 AwaitingConfirmation { id : u128 , order_id : OrderId } ,
6260}
6361
6462impl InboundRequestState {
65- fn info_received (
66- & self , versions : Vec < u16 > , options : OptionsSupported ,
67- ) -> Result < Self , ChannelStateError > {
68- let max_shared_version = versions
69- . iter ( )
70- . filter ( |version| SUPPORTED_SPEC_VERSIONS . contains ( version) )
71- . max ( )
72- . cloned ( )
73- . ok_or ( ChannelStateError ( format ! (
74- "LSP does not support any of our specification versions. ours = {:?}. theirs = {:?}" ,
75- SUPPORTED_SPEC_VERSIONS , versions
76- ) ) ) ?;
77-
63+ fn info_received ( & self , options : OptionsSupported ) -> Result < Self , ChannelStateError > {
7864 match self {
79- InboundRequestState :: InfoRequested => Ok ( InboundRequestState :: OptionsSupport {
80- version : max_shared_version,
81- options_supported : options,
82- } ) ,
65+ InboundRequestState :: InfoRequested => {
66+ Ok ( InboundRequestState :: OptionsSupport { options_supported : options } )
67+ }
8368 state => Err ( ChannelStateError ( format ! (
84- "Received unexpected get_versions response. Channel was in state: {:?}" ,
69+ "Received unexpected get_info response. Channel was in state: {:?}" ,
8570 state
8671 ) ) ) ,
8772 }
8873 }
8974
9075 fn order_requested ( & self , order : OrderParams ) -> Result < Self , ChannelStateError > {
9176 match self {
92- InboundRequestState :: OptionsSupport { version , options_supported } => {
77+ InboundRequestState :: OptionsSupport { options_supported } => {
9378 if is_valid ( & order, options_supported) {
94- Ok ( InboundRequestState :: OrderRequested { version : * version , order } )
79+ Ok ( InboundRequestState :: OrderRequested { order } )
9580 } else {
9681 return Err ( ChannelStateError ( format ! (
9782 "The order created does not match options supported by LSP. Options Supported by LSP are {:?}. The order created was {:?}" ,
@@ -110,7 +95,7 @@ impl InboundRequestState {
11095 & self , response_order : & OrderParams , order_id : OrderId ,
11196 ) -> Result < Self , ChannelStateError > {
11297 match self {
113- InboundRequestState :: OrderRequested { version , order } => {
98+ InboundRequestState :: OrderRequested { order } => {
11499 if response_order == order {
115100 Ok ( InboundRequestState :: PendingPayment { order_id } )
116101 } else {
@@ -153,25 +138,23 @@ impl InboundCRChannel {
153138 Self { id, state : InboundRequestState :: InfoRequested }
154139 }
155140
156- fn info_received (
157- & mut self , versions : Vec < u16 > , options : OptionsSupported ,
158- ) -> Result < u16 , LightningError > {
159- self . state = self . state . info_received ( versions, options) ?;
141+ fn info_received ( & mut self , options : OptionsSupported ) -> Result < ( ) , LightningError > {
142+ self . state = self . state . info_received ( options) ?;
160143
161144 match self . state {
162- InboundRequestState :: OptionsSupport { version , .. } => Ok ( version ) ,
145+ InboundRequestState :: OptionsSupport { .. } => Ok ( ( ) ) ,
163146 _ => Err ( LightningError {
164147 action : ErrorAction :: IgnoreAndLog ( Level :: Error ) ,
165148 err : "impossible state transition" . to_string ( ) ,
166149 } ) ,
167150 }
168151 }
169152
170- fn order_requested ( & mut self , order : OrderParams ) -> Result < u16 , LightningError > {
153+ fn order_requested ( & mut self , order : OrderParams ) -> Result < ( ) , LightningError > {
171154 self . state = self . state . order_requested ( order) ?;
172155
173156 match self . state {
174- InboundRequestState :: OrderRequested { version , .. } => Ok ( version ) ,
157+ InboundRequestState :: OrderRequested { .. } => Ok ( ( ) ) ,
175158 _ => {
176159 return Err ( LightningError {
177160 action : ErrorAction :: IgnoreAndLog ( Level :: Error ) ,
@@ -301,10 +284,8 @@ where
301284 action : ErrorAction :: IgnoreAndLog ( Level :: Info ) ,
302285 } ) ?;
303286
304- let version = match inbound_channel
305- . info_received ( result. supported_versions , result. options . clone ( ) )
306- {
307- Ok ( version) => version,
287+ match inbound_channel. info_received ( result. options . clone ( ) ) {
288+ Ok ( ( ) ) => ( ) ,
308289 Err ( e) => {
309290 peer_state_lock. remove_inbound_channel ( channel_id) ;
310291 return Err ( e) ;
@@ -315,7 +296,6 @@ where
315296 id : channel_id,
316297 request_id,
317298 counterparty_node_id : * counterparty_node_id,
318- version,
319299 website : result. website ,
320300 options_supported : result. options ,
321301 } ) )
@@ -349,8 +329,8 @@ where
349329 err : format ! ( "Channel with id {} not found" , channel_id) ,
350330 } ) ?;
351331
352- let version = match inbound_channel. order_requested ( order. clone ( ) ) {
353- Ok ( version ) => version ,
332+ match inbound_channel. order_requested ( order. clone ( ) ) {
333+ Ok ( ( ) ) => ( ) ,
354334 Err ( e) => {
355335 peer_state_lock. remove_inbound_channel ( channel_id) ;
356336 return Err ( APIError :: APIMisuseError { err : e. err } ) ;
@@ -364,7 +344,7 @@ where
364344 counterparty_node_id,
365345 LSPS1Message :: Request (
366346 request_id,
367- LSPS1Request :: CreateOrder ( CreateOrderRequest { order, version } ) ,
347+ LSPS1Request :: CreateOrder ( CreateOrderRequest { order } ) ,
368348 )
369349 . into ( ) ,
370350 ) ;
@@ -540,7 +520,7 @@ where
540520 let channel_id =
541521 peer_state_lock. request_to_cid . remove ( & request_id) . ok_or ( LightningError {
542522 err : format ! (
543- "Received get_versions response for an unknown request: {:?}" ,
523+ "Received get_order response for an unknown request: {:?}" ,
544524 request_id
545525 ) ,
546526 action : ErrorAction :: IgnoreAndLog ( Level :: Info ) ,
@@ -551,7 +531,7 @@ where
551531 . get_mut ( & channel_id)
552532 . ok_or ( LightningError {
553533 err : format ! (
554- "Received get_versions response for an unknown channel: {:?}" ,
534+ "Received get_order response for an unknown channel: {:?}" ,
555535 channel_id
556536 ) ,
557537 action : ErrorAction :: IgnoreAndLog ( Level :: Info ) ,
0 commit comments