getOrCreateLineageBalances retrieves or creates the shadow and aggregate balances for lineage tracking. Parameters: - ctx context.Context: The context for the operation. - identityID string: The identity ID associated with the balance. - provider string: The fund provider identifier. - currency str
(ctx context.Context, identityID, provider, currency string)
| 287 | // - *model.Balance: The aggregate balance for all providers. |
| 288 | // - error: An error if the balances could not be retrieved or created. |
| 289 | func (l *LedgerForge) getOrCreateLineageBalances(ctx context.Context, identityID, provider, currency string) (*model.Balance, *model.Balance, error) { |
| 290 | identity, err := l.datasource.GetIdentityByID(identityID) |
| 291 | if err != nil { |
| 292 | return nil, nil, fmt.Errorf("failed to get identity %s: %w", identityID, err) |
| 293 | } |
| 294 | |
| 295 | identifier := l.getIdentityIdentifier(identity) |
| 296 | shadowBalanceIndicator := fmt.Sprintf("@%s_%s_lineage", provider, identifier) |
| 297 | aggregateBalanceIndicator := fmt.Sprintf("@%s_lineage", identifier) |
| 298 | |
| 299 | shadowBalance, err := l.getOrCreateBalanceByIndicator(ctx, shadowBalanceIndicator, currency) |
| 300 | if err != nil { |
| 301 | return nil, nil, fmt.Errorf("failed to get/create shadow balance: %w", err) |
| 302 | } |
| 303 | |
| 304 | aggregateBalance, err := l.getOrCreateBalanceByIndicator(ctx, aggregateBalanceIndicator, currency) |
| 305 | if err != nil { |
| 306 | return nil, nil, fmt.Errorf("failed to get/create aggregate balance: %w", err) |
| 307 | } |
| 308 | |
| 309 | return shadowBalance, aggregateBalance, nil |
| 310 | } |
| 311 | |
| 312 | // upsertCreditLineageMapping creates or updates the lineage mapping for a credit transaction. |
| 313 | // |
no test coverage detected