|
@ -10,11 +10,11 @@ import ( |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
// Waiter is informed of current height, decided whether to quit early
|
|
|
// Waiter is informed of current height, decided whether to quit early
|
|
|
type Waiter func(delta int) (abort error) |
|
|
|
|
|
|
|
|
type Waiter func(delta int64) (abort error) |
|
|
|
|
|
|
|
|
// DefaultWaitStrategy is the standard backoff algorithm,
|
|
|
// DefaultWaitStrategy is the standard backoff algorithm,
|
|
|
// but you can plug in another one
|
|
|
// but you can plug in another one
|
|
|
func DefaultWaitStrategy(delta int) (abort error) { |
|
|
|
|
|
|
|
|
func DefaultWaitStrategy(delta int64) (abort error) { |
|
|
if delta > 10 { |
|
|
if delta > 10 { |
|
|
return errors.Errorf("Waiting for %d blocks... aborting", delta) |
|
|
return errors.Errorf("Waiting for %d blocks... aborting", delta) |
|
|
} else if delta > 0 { |
|
|
} else if delta > 0 { |
|
@ -36,13 +36,13 @@ func WaitForHeight(c StatusClient, h int64, waiter Waiter) error { |
|
|
if waiter == nil { |
|
|
if waiter == nil { |
|
|
waiter = DefaultWaitStrategy |
|
|
waiter = DefaultWaitStrategy |
|
|
} |
|
|
} |
|
|
delta := 1 |
|
|
|
|
|
|
|
|
delta := int64(1) |
|
|
for delta > 0 { |
|
|
for delta > 0 { |
|
|
s, err := c.Status() |
|
|
s, err := c.Status() |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return err |
|
|
return err |
|
|
} |
|
|
} |
|
|
delta = int(h - s.LatestBlockHeight) |
|
|
|
|
|
|
|
|
delta = h - s.LatestBlockHeight |
|
|
// wait for the time, or abort early
|
|
|
// wait for the time, or abort early
|
|
|
if err := waiter(delta); err != nil { |
|
|
if err := waiter(delta); err != nil { |
|
|
return err |
|
|
return err |
|
|