pollForBalance polls until the balance reaches the expected value
(ctx context.Context, ds database.IDataSource, balanceID string, expectedBalance *big.Int, pollInterval, timeout time.Duration)
| 40 | |
| 41 | // pollForBalance polls until the balance reaches the expected value |
| 42 | func pollForBalance(ctx context.Context, ds database.IDataSource, balanceID string, expectedBalance *big.Int, pollInterval, timeout time.Duration) (*model.Balance, error) { |
| 43 | timeoutCtx, cancel := context.WithTimeout(ctx, timeout) |
| 44 | defer cancel() |
| 45 | |
| 46 | ticker := time.NewTicker(pollInterval) |
| 47 | defer ticker.Stop() |
| 48 | |
| 49 | for { |
| 50 | select { |
| 51 | case <-timeoutCtx.Done(): |
| 52 | return nil, fmt.Errorf("timed out waiting for balance %s to reach %s: %w", balanceID, expectedBalance.String(), timeoutCtx.Err()) |
| 53 | case <-ticker.C: |
| 54 | balance, err := ds.GetBalanceByIDLite(balanceID) |
| 55 | if err != nil { |
| 56 | continue |
| 57 | } |
| 58 | if balance.Balance.Cmp(expectedBalance) == 0 { |
| 59 | return balance, nil |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | // pollForShadowCreditBalance polls until the shadow balance's CreditBalance reaches the expected value |
| 66 | func pollForShadowCreditBalance(ctx context.Context, ds database.IDataSource, balanceID string, expectedCredit *big.Int, pollInterval, timeout time.Duration) (*model.Balance, error) { |
no test coverage detected