@@ -8,6 +8,17 @@ import (
88 "github.com/lightninglabs/loop/swapserverrpc"
99)
1010
11+ type ProtocolVersion uint32
12+
13+ const (
14+ // CurrentProtocolVersion is the current protocol version.
15+ CurrentProtocolVersion ProtocolVersion = ProtocolVersionServerInitiated
16+
17+ // ProtocolVersionServerInitiated is the protocol version where the
18+ // server initiates the reservation.
19+ ProtocolVersionServerInitiated ProtocolVersion = 0
20+ )
21+
1122const (
1223 // defaultObserverSize is the size of the fsm observer channel.
1324 defaultObserverSize = 15
@@ -45,7 +56,8 @@ type FSM struct {
4556// NewFSM creates a new reservation FSM.
4657func NewFSM (cfg * Config ) * FSM {
4758 reservation := & Reservation {
48- State : fsm .EmptyState ,
59+ State : fsm .EmptyState ,
60+ ProtocolVersion : CurrentProtocolVersion ,
4961 }
5062
5163 return NewFSMFromReservation (cfg , reservation )
@@ -59,10 +71,18 @@ func NewFSMFromReservation(cfg *Config, reservation *Reservation) *FSM {
5971 reservation : reservation ,
6072 }
6173
74+ var states fsm.States
75+ switch reservation .ProtocolVersion {
76+ case ProtocolVersionServerInitiated :
77+ states = reservationFsm .GetServerInitiatedReservationStates ()
78+ default :
79+ states = make (fsm.States )
80+ }
81+
6282 reservationFsm .StateMachine = fsm .NewStateMachineWithState (
63- reservationFsm .GetReservationStates (), reservation .State ,
64- defaultObserverSize ,
83+ states , reservation .State , defaultObserverSize ,
6584 )
85+
6686 reservationFsm .ActionEntryFunc = reservationFsm .updateReservation
6787
6888 return reservationFsm
@@ -133,9 +153,9 @@ var (
133153 OnUnlocked = fsm .EventType ("OnUnlocked" )
134154)
135155
136- // GetReservationStates returns the statemap that defines the reservation
137- // state machine.
138- func (f * FSM ) GetReservationStates () fsm.States {
156+ // GetServerInitiatedReservationStates returns the statemap that defines the
157+ // reservation state machine, where the server initiates the reservation .
158+ func (f * FSM ) GetServerInitiatedReservationStates () fsm.States {
139159 return fsm.States {
140160 fsm .EmptyState : fsm.State {
141161 Transitions : fsm.Transitions {
0 commit comments