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

Method getOrCreateLineageBalances

lineage.go:289–310  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

287// - *model.Balance: The aggregate balance for all providers.
288// - error: An error if the balances could not be retrieved or created.
289func (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//

Callers 1

processLineageCreditMethod · 0.95

Calls 3

getIdentityIdentifierMethod · 0.95
GetIdentityByIDMethod · 0.65

Tested by

no test coverage detected