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

Method getOrCreateDestinationLineageBalances

lineage.go:683–704  ·  view source on GitHub ↗

getOrCreateDestinationLineageBalances retrieves or creates shadow and aggregate balances for the destination. Parameters: - ctx context.Context: The context for the operation. - provider string: The fund provider identifier. - destinationBalance *model.Balance: The destination balance. Returns: -

(ctx context.Context, provider string, destinationBalance *model.Balance)

Source from the content-addressed store, hash-verified

681// - *model.Balance: The destination aggregate balance.
682// - error: An error if the balances could not be retrieved or created.
683func (l *LedgerForge) getOrCreateDestinationLineageBalances(ctx context.Context, provider string, destinationBalance *model.Balance) (*model.Balance, *model.Balance, error) {
684 destIdentity, err := l.datasource.GetIdentityByID(destinationBalance.IdentityID)
685 if err != nil {
686 return nil, nil, fmt.Errorf("failed to get destination identity: %w", err)
687 }
688
689 destIdentifier := l.getIdentityIdentifier(destIdentity)
690 destShadowIndicator := fmt.Sprintf("@%s_%s_lineage", provider, destIdentifier)
691 destAggIndicator := fmt.Sprintf("@%s_lineage", destIdentifier)
692
693 destShadowBalance, err := l.getOrCreateBalanceByIndicator(ctx, destShadowIndicator, destinationBalance.Currency)
694 if err != nil {
695 return nil, nil, fmt.Errorf("failed to create destination shadow balance: %w", err)
696 }
697
698 destAggBalance, err := l.getOrCreateBalanceByIndicator(ctx, destAggIndicator, destinationBalance.Currency)
699 if err != nil {
700 return nil, nil, fmt.Errorf("failed to create destination aggregate balance: %w", err)
701 }
702
703 return destShadowBalance, destAggBalance, nil
704}
705
706// queueReceiveTransaction queues a transaction to receive funds into the destination's shadow balance.
707//

Callers 1

Calls 3

getIdentityIdentifierMethod · 0.95
GetIdentityByIDMethod · 0.65

Tested by

no test coverage detected