Skip to content
This repository has been archived by the owner on Feb 24, 2021. It is now read-only.

Commit

Permalink
✨ [client] use dispute phases in Channel.Settle
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastianst committed Mar 5, 2020
1 parent 5cccf23 commit a5e1002
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions client/channel.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,26 @@ func (c *Channel) Settle(ctx context.Context) error {
return errors.New("currently, only channels in a final state can be settled")
}

if err := c.machine.SetRegistering(); err != nil {
return err // this should never happen
}

req := c.machine.AdjudicatorReq()

if reg, err := c.adjudicator.Register(ctx, req); err != nil {
reg, err := c.adjudicator.Register(ctx, req)
if err != nil {
return errors.WithMessage(err, "calling Register")
} else if reg.Version != req.Tx.Version {
}
if err := c.machine.SetRegistered(); err != nil {
return err // this should never happen
}

if reg.Version != req.Tx.Version {
return errors.Errorf(
"unexpected version %d registered, expected %d", reg.Version, req.Tx.Version)
} else if reg.Timeout.After(time.Now()) {
}

if reg.Timeout.After(time.Now()) {
c.log.Warnf("Unexpected withdrawal timeout during Settle(). Waiting until %v.", reg.Timeout)
timeout := time.After(time.Until(reg.Timeout))
select {
Expand All @@ -189,9 +201,11 @@ func (c *Channel) Settle(ctx context.Context) error {
}
}

if err := c.machine.SetWithdrawing(); err != nil {
return err // this should never happen
}
if err := c.adjudicator.Withdraw(ctx, req); err != nil {
return errors.WithMessage(err, "calling Withdraw")
}

return c.machine.SetSettled()
return c.machine.SetWithdrawn()
}

0 comments on commit a5e1002

Please sign in to comment.