@@ -8,6 +8,14 @@ import (
88 "github.com/lightninglabs/loop/swapserverrpc"
99)
1010
11+ type ProtocolVersion uint32
12+
13+ const (
14+ // ProtocolVersionServerInitiated is the protocol version where the
15+ // server initiates the reservation.
16+ ProtocolVersionServerInitiated ProtocolVersion = 0
17+ )
18+
1119const (
1220 // defaultObserverSize is the size of the fsm observer channel.
1321 defaultObserverSize = 15
@@ -43,9 +51,10 @@ type FSM struct {
4351}
4452
4553// NewFSM creates a new reservation FSM.
46- func NewFSM (cfg * Config ) * FSM {
54+ func NewFSM (cfg * Config , protocolVersion ProtocolVersion ) * FSM {
4755 reservation := & Reservation {
48- State : fsm .EmptyState ,
56+ State : fsm .EmptyState ,
57+ ProtocolVersion : protocolVersion ,
4958 }
5059
5160 return NewFSMFromReservation (cfg , reservation )
@@ -59,10 +68,18 @@ func NewFSMFromReservation(cfg *Config, reservation *Reservation) *FSM {
5968 reservation : reservation ,
6069 }
6170
71+ var states fsm.States
72+ switch reservation .ProtocolVersion {
73+ case ProtocolVersionServerInitiated :
74+ states = reservationFsm .GetServerInitiatedReservationStates ()
75+ default :
76+ states = make (fsm.States )
77+ }
78+
6279 reservationFsm .StateMachine = fsm .NewStateMachineWithState (
63- reservationFsm .GetReservationStates (), reservation .State ,
64- defaultObserverSize ,
80+ states , reservation .State , defaultObserverSize ,
6581 )
82+
6683 reservationFsm .ActionEntryFunc = reservationFsm .updateReservation
6784
6885 return reservationFsm
@@ -133,9 +150,9 @@ var (
133150 OnUnlocked = fsm .EventType ("OnUnlocked" )
134151)
135152
136- // GetReservationStates returns the statemap that defines the reservation
137- // state machine.
138- func (f * FSM ) GetReservationStates () fsm.States {
153+ // GetServerInitiatedReservationStates returns the statemap that defines the
154+ // reservation state machine, where the server initiates the reservation .
155+ func (f * FSM ) GetServerInitiatedReservationStates () fsm.States {
139156 return fsm.States {
140157 fsm .EmptyState : fsm.State {
141158 Transitions : fsm.Transitions {
0 commit comments