MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / pollForBalance

Function pollForBalance

lineage_integration_test.go:42–63  ·  view source on GitHub ↗

pollForBalance polls until the balance reaches the expected value

(ctx context.Context, ds database.IDataSource, balanceID string, expectedBalance *big.Int, pollInterval, timeout time.Duration)

Source from the content-addressed store, hash-verified

40
41// pollForBalance polls until the balance reaches the expected value
42func 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
66func pollForShadowCreditBalance(ctx context.Context, ds database.IDataSource, balanceID string, expectedCredit *big.Int, pollInterval, timeout time.Duration) (*model.Balance, error) {

Callers 3

TestLineageFullFlowFunction · 0.85

Calls 2

GetBalanceByIDLiteMethod · 0.65
StopMethod · 0.45

Tested by

no test coverage detected