loopin: extract persistState

This commit is contained in:
Joost Jager 2020-06-25 13:15:58 +02:00
parent 6b8fcc547c
commit e33d2fb762
No known key found for this signature in database
GPG key ID: A61B9D4C393C59C7

View file

@ -694,14 +694,7 @@ func (s *loopInSwap) publishTimeoutTx(ctx context.Context,
// update notification.
func (s *loopInSwap) persistAndAnnounceState(ctx context.Context) error {
// Update state in store.
err := s.store.UpdateLoopIn(
s.hash, s.lastUpdateTime,
loopdb.SwapStateData{
State: s.state,
Cost: s.cost,
},
)
if err != nil {
if err := s.persistState(); err != nil {
return err
}
@ -709,6 +702,17 @@ func (s *loopInSwap) persistAndAnnounceState(ctx context.Context) error {
return s.sendUpdate(ctx)
}
// persistState updates the swap state on disk.
func (s *loopInSwap) persistState() error {
return s.store.UpdateLoopIn(
s.hash, s.lastUpdateTime,
loopdb.SwapStateData{
State: s.state,
Cost: s.cost,
},
)
}
// setState updates the swap state and last update timestamp.
func (s *loopInSwap) setState(state loopdb.SwapState) {
s.lastUpdateTime = time.Now()