Files
payments/internal/api/services/pools_balances.go
Paul NicolasandGitHub f44e68aac9 feat(accounts,pools): compute balances inside postgres (#605)
* feat(accounts,pools): compute balances inside postgres

* fix dirty

* remove useless prints

* add check about accounts id length
2025-11-27 10:01:46 +00:00

34 lines
793 B
Go

package services
import (
"context"
"github.com/formancehq/payments/internal/models"
"github.com/google/uuid"
)
func (s *Service) PoolsBalances(
ctx context.Context,
poolID uuid.UUID,
) ([]models.AggregatedBalance, error) {
pool, err := s.storage.PoolsGet(ctx, poolID)
if err != nil {
return nil, newStorageError(err, "cannot get pool")
}
if pool.Type == models.POOL_TYPE_DYNAMIC {
// populate the pool accounts from the query
pool.PoolAccounts, err = s.populatePoolAccounts(ctx, pool)
if err != nil {
return nil, newStorageError(err, "cannot populate pool accounts")
}
}
balances, err := s.storage.BalancesGetFromAccountIDs(ctx, pool.PoolAccounts, nil)
if err != nil {
return nil, newStorageError(err, "cannot get latest balances")
}
return balances, nil
}