Skip to content

Commit

Permalink
contract: retrying confirming orders if failed after 30 s
Browse files Browse the repository at this point in the history
  • Loading branch information
tok-kkk committed Sep 24, 2018
1 parent 5331455 commit 9bd5c04
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions contract/binder.go
Original file line number Diff line number Diff line change
Expand Up @@ -968,30 +968,35 @@ func (binder *Binder) ConfirmOrder(id order.ID, match order.ID) error {
binder.checkBalance()
}

orderStatus, err := binder.status(id)
if err != nil {
return err
}

switch orderStatus {
case order.Nil, order.Canceled:
return nil
case order.Open:
tx, err := binder.SendTx(func() (*types.Transaction, error) {
return binder.confirmOrder(id, match)
})
for {
orderStatus, err := binder.status(id)
if err != nil {
return err
}

ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
defer cancel()
switch orderStatus {
case order.Nil, order.Canceled:
log.Printf("[debug] order =%v has unexpected status %v", id, orderStatus)
return nil
case order.Open:
tx, err := binder.SendTx(func() (*types.Transaction, error) {
return binder.confirmOrder(id, match)
})
if err != nil {
return err
}

ctx, cancel := context.WithTimeout(context.Background(), 120*time.Second)
defer cancel()

_, err = binder.conn.PatchedWaitMined(ctx, tx)
if err != nil {
return err
_, err = binder.conn.PatchedWaitMined(ctx, tx)
if err != nil {
return err
}
case order.Confirmed:
break
}
case order.Confirmed:
time.Sleep(30 * time.Second)
}

return binder.waitForOrderDepth(id)
Expand Down Expand Up @@ -1256,8 +1261,9 @@ func (binder *Binder) waitForOrderDepth(id order.ID) error {
binder.mu.RUnlock()
return nil
}
time.Sleep(30 * time.Second)
binder.mu.RUnlock()

time.Sleep(30 * time.Second)
}
}

Expand Down

0 comments on commit 9bd5c04

Please sign in to comment.