mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
* feat(accounts,pools): compute balances inside postgres * fix dirty * remove useless prints * add check about accounts id length
34 lines
793 B
Go
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
|
|
}
|