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

Function pollForAggregateDebitBalance

lineage_integration_test.go:97–125  ·  view source on GitHub ↗

pollForAggregateDebitBalance polls until the aggregate balance's DebitBalance reaches the expected value

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

Source from the content-addressed store, hash-verified

95
96// pollForAggregateDebitBalance polls until the aggregate balance's DebitBalance reaches the expected value
97func pollForAggregateDebitBalance(ctx context.Context, ds database.IDataSource, balanceID string, expectedDebit *big.Int, pollInterval, timeout time.Duration) (*model.Balance, error) {
98 timeoutCtx, cancel := context.WithTimeout(ctx, timeout)
99 defer cancel()
100
101 ticker := time.NewTicker(pollInterval)
102 defer ticker.Stop()
103
104 var lastBalance *model.Balance
105 for {
106 select {
107 case <-timeoutCtx.Done():
108 if lastBalance != nil {
109 return nil, fmt.Errorf("timed out waiting for aggregate balance %s DebitBalance to reach %s (got %s): %w",
110 balanceID, expectedDebit.String(), lastBalance.DebitBalance.String(), timeoutCtx.Err())
111 }
112 return nil, fmt.Errorf("timed out waiting for aggregate balance %s DebitBalance to reach %s: %w",
113 balanceID, expectedDebit.String(), timeoutCtx.Err())
114 case <-ticker.C:
115 balance, err := ds.GetBalanceByIDLite(balanceID)
116 if err != nil {
117 continue
118 }
119 lastBalance = balance
120 if balance.DebitBalance.Cmp(expectedDebit) == 0 {
121 return balance, nil
122 }
123 }
124 }
125}
126
127// pollForTransactionFundAllocation polls until the transaction has fund allocation metadata populated
128func pollForTransactionFundAllocation(ctx context.Context, ledgerforge *LedgerForge, transactionID string, expectedCount int, pollInterval, timeout time.Duration) (*TransactionLineage, error) {

Callers 1

Calls 2

GetBalanceByIDLiteMethod · 0.65
StopMethod · 0.45

Tested by

no test coverage detected